Permalink
Browse files

Added ISP info in getIP.php; Fixed a bug that could leave an aborted …

…test running in background
  • Loading branch information...
adolfintel committed Feb 9, 2018
1 parent d51e198 commit c835d9d0b998d87e050169963529a938b8ead406
Showing with 26 additions and 11 deletions.
  1. +5 −2 doc.md
  2. +2 −1 example-customSettings.html
  3. +13 −4 getIP.php
  4. +5 −3 speedtest_worker.js
  5. +1 −1 speedtest_worker.min.js
View
7 doc.md
@@ -1,7 +1,7 @@
# HTML5 Speedtest
> by Federico Dossena
> Version 4.5.1, February 4, 2017
> Version 4.5.2, February 9, 2017
> [https://github.com/adolfintel/speedtest/](https://github.com/adolfintel/speedtest/)
@@ -215,6 +215,8 @@ w.postMessage('start '+JSON.stringify(params))
* Default test order: `IP_D_U`
* __Important:__ Tests can only be run once
* __Important:__ On Firefox, it is better to run the upload test last
* __getIp_ispInfo__: if true, the server will try to get ISP info and pass it along with the IP address. This will add `isp=true` to the request to `url_getIp`. getIP.php accomplishes this using ipinfo.io
* Default: `true`
* __enable_quirks__: enables browser-specific optimizations. These optimizations override some of the default settings. They do not override settings that are explicitly set.
* Default: `true`
* __garbagePhp_chunkSize__: size of chunks sent by garbage.php in megabytes
@@ -295,7 +297,8 @@ A symlink to `/dev/urandom` is also ok.
Your replacement must simply respond with a HTTP code 200 and send nothing else. You may want to send additional headers to disable caching. The test assumes that Connection:keep-alive is sent by the server.
#### Replacement for `getIP.php`
Your replacement must simply respond with the client's IP as plaintext. Nothing fancy.
Your replacement must simply respond with the client's IP as plaintext. Nothing fancy.
If you want, you can also accept the `isp=true` parameter and also include the ISP info.
#### JS
You need to start the test with your replacements like this:
@@ -115,7 +115,8 @@
var parameters={ //custom test parameters. See doc.md for a complete list
time_dl: 10, //download test lasts 10 seconds
time_ul: 10, //upload test lasts 10 seconds
count_ping: 20 //ping+jitter test does 20 pings
count_ping: 20, //ping+jitter test does 20 pings
getIp_ispInfo: false //will only get IP address without ISP info
};
function startStop(){
if(w!=null){
View
@@ -1,12 +1,21 @@
<?php
$ip="";
header('Content-Type: text/plain; charset=utf-8');
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
echo $_SERVER['HTTP_CLIENT_IP'];
$ip=$_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['X-Real-IP'])) {
echo $_SERVER['X-Real-IP'];
$ip=$_SERVER['X-Real-IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
echo $_SERVER['HTTP_X_FORWARDED_FOR'];
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
echo $_SERVER['REMOTE_ADDR'];
$ip=$_SERVER['REMOTE_ADDR'];
}
$isp="";
if(isset($_GET["isp"])){
$json = file_get_contents("https://ipinfo.io/".$ip."/json");
$details = json_decode($json,true);
if(array_key_exists("org",$details)) $isp.=$details["org"]; else $isp.="Unknown ISP";
if(array_key_exists("country",$details)) $isp.=" (".$details["country"].")";
echo $ip." - ".$isp;
} else echo $ip;
?>
View
@@ -1,5 +1,5 @@
/*
HTML5 Speedtest v4.5
HTML5 Speedtest v4.5.2
by Federico Dossena
https://github.com/adolfintel/speedtest/
GNU LGPLv3 License
@@ -32,6 +32,7 @@ var settings = {
url_ul: 'empty.php', // path to an empty file, used for upload test. must be relative to this js file
url_ping: 'empty.php', // path to an empty file, used for ping test. must be relative to this js file
url_getIp: 'getIP.php', // path to getIP.php relative to this js file, or a similar thing that outputs the client's ip
getIp_ispInfo: true, //if set to true, the server will include ISP info with the IP address
xhr_dlMultistream: 10, // number of download streams to use (can be different if enable_quirks is active)
xhr_ulMultistream: 3, // number of upload streams to use (can be different if enable_quirks is active)
xhr_multistreamDelay: 300, //how much concurrent requests should be delayed
@@ -117,6 +118,7 @@ this.addEventListener('message', function (e) {
test_pointer=0;
var iRun=false,dRun=false,uRun=false,pRun=false;
var runNextTest=function(){
if(testStatus==5) return;
if(test_pointer>=settings.test_order.length){testStatus=4; sendTelemetry(); return;}
switch(settings.test_order.charAt(test_pointer)){
case 'I':{test_pointer++; if(iRun) {runNextTest(); return;} else iRun=true; getIp(runNextTest);} break;
@@ -135,7 +137,7 @@ this.addEventListener('message', function (e) {
runNextTest=null;
if (interval) clearInterval(interval) // clear timer if present
if (settings.telemetry_level > 1) sendTelemetry()
testStatus = 5; dlStatus = ''; ulStatus = ''; pingStatus = ''; jitterStatus = '' // set test as aborted
testStatus = 5; dlStatus = ''; ulStatus = ''; pingStatus = ''; jitterStatus = '' // set test as aborted
}
})
// stops all XHR activity, aggressively
@@ -166,7 +168,7 @@ function getIp (done) {
tlog('getIp failed')
done()
}
xhr.open('GET', settings.url_getIp + url_sep(settings.url_getIp) + 'r=' + Math.random(), true)
xhr.open('GET', settings.url_getIp + url_sep(settings.url_getIp) + (settings.getIp_ispInfo?"isp=true":"") + 'r=' + Math.random(), true)
xhr.send()
}
// download test, calls done function when it's over
Oops, something went wrong.

0 comments on commit c835d9d

Please sign in to comment.