forked from xmpp-observatory/xmppoke-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbadge.php
121 lines (93 loc) · 4.65 KB
/
badge.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
include("common.php");
header("Content-Security-Policy: default-src 'self'; style-src 'self' 'unsafe-inline'");
header("Cache-Control: max-age=600");
header("Content-Type: image/svg+xml");
$result_domain = idn_to_utf8(strtolower(idn_to_ascii($_GET['domain'])));
if (isset($result_domain)) {
pg_prepare($dbconn, "find_result", "SELECT * FROM test_results WHERE server_name = $1 AND type = $2 AND EXISTS (SELECT 1 FROM srv_results WHERE srv_results.test_id = test_results.test_id AND done = 't' AND error IS NULL) ORDER BY test_date DESC LIMIT 1");
$res = pg_execute($dbconn, "find_result", array($result_domain, "client"));
$result_c2s = pg_fetch_object($res);
$res = pg_execute($dbconn, "find_result", array($result_domain, "server"));
$result_s2s = pg_fetch_object($res);
pg_prepare($dbconn, "find_srvs", "SELECT * FROM srv_results WHERE test_id = $1");
$c2s_srvs = array();
if ($result_c2s) {
$res = pg_execute($dbconn, "find_srvs", array($result_c2s->test_id));
$c2s_srvs = pg_fetch_all($res);
if ($c2s_srvs === FALSE) $c2s_srvs = array();
}
$s2s_srvs = array();
if ($result_s2s) {
$res = pg_execute($dbconn, "find_srvs", array($result_s2s->test_id));
$s2s_srvs = pg_fetch_all($res);
if ($s2s_srvs === FALSE) $s2s_srvs = array();
}
$c2s_final_score = NULL;
$s2s_final_score = NULL;
foreach ($c2s_srvs as $score) {
if (grade($score) && (!$c2s_final_score || grade($score) < $c2s_final_score)) {
$c2s_final_score = grade($score);
}
}
foreach ($s2s_srvs as $score) {
if (grade($score) && (!$s2s_final_score || grade($score) < $s2s_final_score)) {
$s2s_final_score = grade($score);
}
}
$date = NULL;
if ($result_c2s && $result_s2s) {
$date = max(strtotime($result_s2s->test_date), strtotime($result_c2s->test_date));
} else if ($result_c2s) {
$date = strtotime($result_c2s->test_date);
} else if ($result_s2s) {
$date = strtotime($result_s2s->test_date);
}
if ($date) {
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $date) . " GMT");
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function svg_color($score) {
switch ($score[0]) {
case 'A': return "#5CB85C";
case 'B':
case 'C':
case 'T':
case 'D': return "#EC971F";
case 'E':
case 'F':
default: return "#C9302C";
}
}
echo '<?xml version="1.0" standalone="no"?>';
?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" width="201" height="18" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
<linearGradient id="a" x2="0" y2="100%">
<stop offset="0" stop-color="#fff" stop-opacity=".7"/>
<stop offset=".1" stop-color="#aaa" stop-opacity=".1"/>
<stop offset=".9" stop-opacity=".3"/>
<stop offset="1" stop-opacity=".5"/>
</linearGradient>
<rect rx="4" width="201" height="18" fill="#555"/>
<rect x="99" width="51" height="18" fill="<?= svg_color($c2s_final_score) ?>"/>
<rect rx="4" x="150" width="51" height="18" fill="<?= svg_color($s2s_final_score) ?>"/>
<path fill="<?= svg_color($s2s_final_score) ?>" d="M150 0h4v18h-4z"/>
<rect rx="4" width="201" height="18" fill="url(#a)"/>
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<a xlink:href="https://xmpp.net/result.php?domain=<?= urlencode($result_domain) ?>&type=client">
<text x="50.5" y="14" fill="#010101" fill-opacity=".3">xmpp.net score</text>
<text x="50.5" y="13">xmpp.net score</text>
<text x="123.5" y="14" fill="#010101" fill-opacity=".3">c2s: <?= $c2s_final_score ? $c2s_final_score : "-" ?></text>
<text x="123.5" y="13">c2s: <?= $c2s_final_score ? $c2s_final_score : "-" ?></text>
</a>
<a xlink:href="https://xmpp.net/result.php?domain=<?= urlencode($result_domain) ?>&type=server">
<text x="174.5" y="14" fill="#010101" fill-opacity=".3">s2s: <?= $s2s_final_score ? $s2s_final_score : "-" ?></text>
<text x="174.5" y="13">s2s: <?= $s2s_final_score ? $s2s_final_score : "-" ?></text>
</a>
</g>
</svg>