Kaynağa Gözat

customized frontend

tags/v1.1.0^0
Robin Thoni 5 yıl önce
ebeveyn
işleme
4989580437

+ 5
- 1
speedtest/Dockerfile Dosyayı Görüntüle

@@ -1 +1,5 @@
1
-FROM adolfintel/speedtest
1
+FROM php:5.6-apache
2
+
3
+COPY ./speedtest /var/www/html
4
+
5
+ENTRYPOINT ["/usr/local/bin/apache2-foreground"]

+ 7
- 0
speedtest/speedtest/empty.php Dosyayı Görüntüle

@@ -0,0 +1,7 @@
1
+<?php
2
+header( "HTTP/1.1 200 OK" );
3
+header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
4
+header("Cache-Control: post-check=0, pre-check=0", false);
5
+header("Pragma: no-cache");
6
+header("Connection: keep-alive");
7
+?>

+ 27
- 0
speedtest/speedtest/garbage.php Dosyayı Görüntüle

@@ -0,0 +1,27 @@
1
+<?php
2
+// Disable Compression
3
+@ini_set('zlib.output_compression', 'Off');
4
+@ini_set('output_buffering', 'Off');
5
+@ini_set('output_handler', '');
6
+// Headers
7
+header('HTTP/1.1 200 OK');
8
+// Download follows...
9
+header('Content-Description: File Transfer');
10
+header('Content-Type: application/octet-stream');
11
+header('Content-Disposition: attachment; filename=random.dat');
12
+header('Content-Transfer-Encoding: binary');
13
+// Never cache me
14
+header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
15
+header('Cache-Control: post-check=0, pre-check=0', false);
16
+header('Pragma: no-cache');
17
+// Generate data
18
+$data=openssl_random_pseudo_bytes(1048576);
19
+// Deliver chunks of 1048576 bytes
20
+$chunks=isset($_GET['ckSize']) ? intval($_GET['ckSize']) : 4;
21
+if(empty($chunks)){$chunks = 4;}
22
+if($chunks>100){$chunks = 100;}
23
+for($i=0;$i<$chunks;$i++){
24
+    echo $data;
25
+    flush();
26
+}
27
+?>

+ 127
- 0
speedtest/speedtest/getIP.php Dosyayı Görüntüle

@@ -0,0 +1,127 @@
1
+<?php
2
+/*
3
+	This script detects the client's IP address and fetches ISP info from ipinfo.io/
4
+	Output from this script is a JSON string composed of 2 objects: a string called processedString which contains the combined IP, ISP, Contry and distance as it can be presented to the user; and an object called rawIspInfo which contains the raw data from ipinfo.io (will be empty if isp detection is disabled).
5
+	Client side, the output of this script can be treated as JSON or as regular text. If the output is regular text, it will be shown to the user as is.
6
+*/
7
+error_reporting(0);
8
+$ip = "";
9
+header('Content-Type: application/json; charset=utf-8');
10
+if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
11
+    $ip = $_SERVER['HTTP_CLIENT_IP'];
12
+} elseif (!empty($_SERVER['X-Real-IP'])) {
13
+    $ip = $_SERVER['X-Real-IP'];
14
+} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
15
+    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
16
+    $ip = preg_replace("/,.*/", "", $ip); # hosts are comma-separated, client is first
17
+} else {
18
+    $ip = $_SERVER['REMOTE_ADDR'];
19
+}
20
+
21
+$ip = preg_replace("/^::ffff:/", "", $ip);
22
+
23
+if ($ip == "::1") { // ::1/128 is the only localhost ipv6 address. there are no others, no need to strpos this
24
+    echo json_encode(['processedString' => $ip . " - localhost IPv6 access", 'rawIspInfo' => ""]);
25
+    die();
26
+}
27
+if (stripos($ip, 'fe80:') === 0) { // simplified IPv6 link-local address (should match fe80::/10)
28
+    echo json_encode(['processedString' => $ip . " - link-local IPv6 access", 'rawIspInfo' => ""]);
29
+    die();
30
+}
31
+if (strpos($ip, '127.') === 0) { //anything within the 127/8 range is localhost ipv4, the ip must start with 127.0
32
+    echo json_encode(['processedString' => $ip . " - localhost IPv4 access", 'rawIspInfo' => ""]);
33
+    die();
34
+}
35
+if (strpos($ip, '10.') === 0) { // 10/8 private IPv4
36
+    echo json_encode(['processedString' => $ip . " - private IPv4 access", 'rawIspInfo' => ""]);
37
+    die();
38
+}
39
+if (preg_match('/^172\.(1[6-9]|2\d|3[01])\./', $ip) === 1) { // 172.16/12 private IPv4
40
+    echo json_encode(['processedString' => $ip . " - private IPv4 access", 'rawIspInfo' => ""]);
41
+    die();
42
+}
43
+if (strpos($ip, '192.168.') === 0) { // 192.168/16 private IPv4
44
+    echo json_encode(['processedString' => $ip . " - private IPv4 access", 'rawIspInfo' => ""]);
45
+    die();
46
+}
47
+if (strpos($ip, '169.254.') === 0) { // IPv4 link-local
48
+    echo json_encode(['processedString' => $ip . " - link-local IPv4 access", 'rawIspInfo' => ""]);
49
+    die();
50
+}
51
+
52
+/**
53
+ * Optimized algorithm from http://www.codexworld.com
54
+ *
55
+ * @param float $latitudeFrom
56
+ * @param float $longitudeFrom
57
+ * @param float $latitudeTo
58
+ * @param float $longitudeTo
59
+ *
60
+ * @return float [km]
61
+ */
62
+function distance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo) {
63
+    $rad = M_PI / 180;
64
+    $theta = $longitudeFrom - $longitudeTo;
65
+    $dist = sin($latitudeFrom * $rad) * sin($latitudeTo * $rad) + cos($latitudeFrom * $rad) * cos($latitudeTo * $rad) * cos($theta * $rad);
66
+    return acos($dist) / $rad * 60 * 1.853;
67
+}
68
+
69
+if (isset($_GET["isp"])) {
70
+    $isp = "";
71
+	$rawIspInfo=null;
72
+    try {
73
+        $json = file_get_contents("https://ipinfo.io/" . $ip . "/json");
74
+        $details = json_decode($json, true);
75
+		$rawIspInfo=$details;
76
+        if (array_key_exists("org", $details)){
77
+            $isp .= $details["org"];
78
+			$isp=preg_replace("/AS\d{1,}\s/","",$isp); //Remove AS##### from ISP name, if present
79
+		}else{
80
+            $isp .= "Unknown ISP";
81
+		}
82
+		if (array_key_exists("country", $details)){
83
+			$isp .= ", " . $details["country"];
84
+		}
85
+        $clientLoc = NULL;
86
+        $serverLoc = NULL;
87
+        if (array_key_exists("loc", $details)){
88
+            $clientLoc = $details["loc"];
89
+		}
90
+        if (isset($_GET["distance"])) {
91
+            if ($clientLoc) {
92
+                $json = file_get_contents("https://ipinfo.io/json");
93
+                $details = json_decode($json, true);
94
+                if (array_key_exists("loc", $details)){
95
+                    $serverLoc = $details["loc"];
96
+				}
97
+                if ($serverLoc) {
98
+                    try {
99
+                        $clientLoc = explode(",", $clientLoc);
100
+                        $serverLoc = explode(",", $serverLoc);
101
+                        $dist = distance($clientLoc[0], $clientLoc[1], $serverLoc[0], $serverLoc[1]);
102
+                        if ($_GET["distance"] == "mi") {
103
+                            $dist /= 1.609344;
104
+                            $dist = round($dist, -1);
105
+                            if ($dist < 15)
106
+                                $dist = "<15";
107
+                            $isp .= " (" . $dist . " mi)";
108
+                        }else if ($_GET["distance"] == "km") {
109
+                            $dist = round($dist, -1);
110
+                            if ($dist < 20)
111
+                                $dist = "<20";
112
+                            $isp .= " (" . $dist . " km)";
113
+                        }
114
+                    } catch (Exception $e) {
115
+                        
116
+                    }
117
+                }
118
+            }
119
+        }
120
+    } catch (Exception $ex) {
121
+        $isp = "Unknown ISP";
122
+    }
123
+    echo json_encode(['processedString' => $ip . " - " . $isp, 'rawIspInfo' => $rawIspInfo]);
124
+} else {
125
+    echo json_encode(['processedString' => $ip, 'rawIspInfo' => ""]);
126
+}
127
+?>

+ 221
- 0
speedtest/speedtest/index.html Dosyayı Görüntüle

@@ -0,0 +1,221 @@
1
+<!DOCTYPE html>
2
+<html>
3
+<head>
4
+<meta charset="UTF-8" />
5
+<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no" />
6
+<title>HTML5 Speedtest</title>
7
+<style type="text/css">
8
+	html,body{
9
+		border:none; padding:0; margin:0;
10
+		background:#FFFFFF;
11
+		color:#202020;
12
+	}
13
+	body{
14
+		text-align:center;
15
+		font-family:"Roboto",sans-serif;
16
+	}
17
+	h1{
18
+		color:#404040;
19
+	}
20
+	#startStopBtn{
21
+		display:inline-block;
22
+		margin:0 auto;
23
+		color:#6060AA;
24
+		background-color:rgba(0,0,0,0);
25
+		border:0.15em solid #6060FF;
26
+		border-radius:0.3em;
27
+		transition:all 0.3s;
28
+		box-sizing:border-box;
29
+		width:8em; height:3em;
30
+		line-height:2.7em;
31
+		cursor:pointer;
32
+		box-shadow: 0 0 0 rgba(0,0,0,0.1), inset 0 0 0 rgba(0,0,0,0.1);
33
+	}
34
+	#startStopBtn:hover{
35
+		box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1);
36
+	}
37
+	#startStopBtn.running{
38
+		background-color:#FF3030;
39
+		border-color:#FF6060;
40
+		color:#FFFFFF;
41
+	}
42
+	#startStopBtn:before{
43
+		content:"Start";
44
+	}
45
+	#startStopBtn.running:before{
46
+		content:"Abort";
47
+	}
48
+	#test{
49
+		margin-top:2em;
50
+		margin-bottom:12em;
51
+	}
52
+	div.testArea{
53
+		display:inline-block;
54
+		width:14em;
55
+		height:9em;
56
+		position:relative;
57
+		box-sizing:border-box;
58
+	}
59
+	div.testName{
60
+		position:absolute;
61
+		top:0.1em; left:0;
62
+		width:100%;
63
+		font-size:1.4em;
64
+		z-index:9;
65
+	}
66
+	div.meterText{
67
+		position:absolute;
68
+		bottom:1.5em; left:0;
69
+		width:100%;
70
+		font-size:2.5em;
71
+		z-index:9;
72
+	}
73
+	#dlText{
74
+		color:#6060AA;
75
+	}
76
+	#ulText{
77
+		color:#309030;
78
+	}
79
+	#pingText,#jitText{
80
+		color:#AA6060;
81
+	}
82
+	div.meterText:empty:before{
83
+		color:#505050 !important;
84
+		content:"0.00";
85
+	}
86
+	div.unit{
87
+		position:absolute;
88
+		bottom:2em; left:0;
89
+		width:100%;
90
+		z-index:9;
91
+	}
92
+	div.testGroup{
93
+		display:inline-block;
94
+	}
95
+	@media all and (max-width:65em){
96
+		body{
97
+			font-size:1.5vw;
98
+		}
99
+	}
100
+	@media all and (max-width:40em){
101
+		body{
102
+			font-size:0.8em;
103
+		}
104
+		div.testGroup{
105
+			display:block;
106
+			margin: 0 auto;
107
+		}
108
+	}
109
+	#progressBar{
110
+		width:90%;
111
+		height:0.3em;
112
+		background-color:#EEEEEE;
113
+		position:relative;
114
+		display:block;
115
+		margin:0 auto;
116
+		margin-bottom:2em;
117
+	}
118
+	#progress{
119
+		position:absolute;
120
+		top:0; left:0;
121
+		height:100%;
122
+		width:0%;
123
+		transition: width 2s;
124
+		background-color:#90BBFF;
125
+	}
126
+
127
+
128
+</style>
129
+<script type="text/javascript">
130
+function I(id){return document.getElementById(id);}
131
+
132
+var w=null; //speedtest worker
133
+function startStop(){
134
+	if(w!=null){
135
+		//speedtest is running, abort
136
+		w.postMessage('abort');
137
+		w=null;
138
+		I("startStopBtn").className="";
139
+		initUI();
140
+	}else{
141
+		//test is not running, begin
142
+		w=new Worker('speedtest_worker.min.js');
143
+                w.postMessage('start', {
144
+                  time_dl_max: 20,
145
+                  time_ul_max: 20,
146
+                  time_auto: false,
147
+                  getIp_ispInfo: false,
148
+                  getIp_ispInfo_distance: false
149
+                }); //Add optional parameters as a JSON object to this command
150
+		I("startStopBtn").className="running";
151
+		w.onmessage=function(e){
152
+			var data=JSON.parse(e.data);
153
+			var status=data.testState;
154
+			if(status>=4){
155
+				//test completed
156
+				I("startStopBtn").className="";
157
+				w=null;
158
+			}
159
+			I("ip").textContent=data.clientIp;
160
+			I("dlText").textContent=(status==1&&data.dlStatus==0)?"...":data.dlStatus;
161
+			I("ulText").textContent=(status==3&&data.ulStatus==0)?"...":data.ulStatus;
162
+			I("pingText").textContent=data.pingStatus;
163
+			I("jitText").textContent=data.jitterStatus;
164
+			var prog=(Number(data.dlProgress)*2+Number(data.ulProgress)*2+Number(data.pingProgress))/5;
165
+			I("progress").style.width=(100*prog)+"%";
166
+		};
167
+	}
168
+}
169
+//poll the status from the worker every 200ms (this will also update the UI)
170
+setInterval(function(){
171
+	if(w) w.postMessage('status');
172
+},200);
173
+//function to (re)initialize UI
174
+function initUI(){
175
+	I("dlText").textContent="";
176
+	I("ulText").textContent="";
177
+	I("pingText").textContent="";
178
+	I("jitText").textContent="";
179
+	I("ip").textContent="";
180
+	I("progress").style.width="";
181
+}
182
+
183
+</script>
184
+</head>
185
+<body>
186
+<h1>HTML5 Speedtest</h1>
187
+<div id="startStopBtn" onclick="startStop()"></div>
188
+<div id="test">
189
+	<div id="progressBar"><div id="progress"></div></div>
190
+	<div class="testGroup">
191
+		<div class="testArea">
192
+			<div class="testName">Download</div>
193
+			<div id="dlText" class="meterText"></div>
194
+			<div class="unit">Mbps</div>
195
+		</div>
196
+		<div class="testArea">
197
+			<div class="testName">Upload</div>
198
+			<div id="ulText" class="meterText"></div>
199
+			<div class="unit">Mbps</div>
200
+		</div>
201
+	</div>
202
+	<div class="testGroup">
203
+		<div class="testArea">
204
+			<div class="testName">Ping</div>
205
+			<div id="pingText" class="meterText"></div>
206
+			<div class="unit">ms</div>
207
+		</div>
208
+		<div class="testArea">
209
+			<div class="testName">Jitter</div>
210
+			<div id="jitText" class="meterText"></div>
211
+			<div class="unit">ms</div>
212
+		</div>
213
+	</div>
214
+	<div id="ipArea">
215
+		IP Address: <span id="ip"></span>
216
+	</div>
217
+</div>
218
+<a href="https://github.com/adolfintel/speedtest">Source code</a>
219
+<script type="text/javascript">initUI();</script>
220
+</body>
221
+</html>

+ 1
- 0
speedtest/speedtest/speedtest_worker.min.js
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


Loading…
İptal
Kaydet