diff --git a/doc.md b/doc.md index ca23c20..04b5373 100644 --- a/doc.md +++ b/doc.md @@ -209,6 +209,10 @@ w.postMessage('start '+JSON.stringify(params)) * __url_getIp__: path to getIP.php or replacement * Default: `getIP.php` * __Important:__ path is relative to js file +* __url_telemetry__: path to telemetry.php or replacement + * Default: `telemetry/telemetry.php` + * __Important:__ path is relative to js file + * __Note:__ you can ignore this parameter if you're not using the telemetry #### Advanced test parameters * __test_order__: the order in which tests will be performed. Each character represents an operation: @@ -274,7 +278,8 @@ w.postMessage('start '+JSON.stringify(params)) * `1514 / 1460`: TCP+IPv4+ETH, ignoring HTTP overhead * `1514 / 1440`: TCP+IPv6+ETH, ignoring HTTP overhead * `1`: ignore overheads. This measures the speed at which you actually download and upload files rather than the raw connection speed - +* __telemetry_extra__: Extra data that you want to be passed to the telemetry. This is a string field, if you want to pass an object, make sure you use ``JSON.stringify``. + ### Aborting the test prematurely The test can be aborted at any time by sending an abort command to the worker: diff --git a/speedtest_worker.js b/speedtest_worker.js index 83a96d6..cc214ec 100644 --- a/speedtest_worker.js +++ b/speedtest_worker.js @@ -17,11 +17,6 @@ var ulProgress = 0 //progress of upload test 0-1 var pingProgress = 0 //progress of ping+jitter test 0-1 var testId = 'noID' //test ID (sent back by telemetry if used, the string 'noID' otherwise) -var HTML_ESCAPE_MAP={'&': '&','<': '<','>': '>','"': '"',"'": '''}; -String.prototype.escapeHtml=function(){ - return this.replace(/[&<>"']/g, function(m){return HTML_ESCAPE_MAP[m]}); -} - var log='' //telemetry log function tlog(s){log+=Date.now()+': '+s+'\n'} function twarn(s){log+=Date.now()+' WARN: '+s+'\n'; console.warn(s)} @@ -52,7 +47,8 @@ var settings = { overheadCompensationFactor: 1.06, //can be changed to compensatie for transport overhead. (see doc.md for some other values) useMebibits: false, //if set to true, speed will be reported in mebibits/s instead of megabits/s telemetry_level: 0, // 0=disabled, 1=basic (results only), 2=full (results+log) - url_telemetry: 'telemetry/telemetry.php' // path to the script that adds telemetry data to the database + url_telemetry: 'telemetry/telemetry.php', // path to the script that adds telemetry data to the database + telemetry_extra: '' //extra data that can be passed to the telemetry through the settings } var xhr = null // array of currently active xhr requests @@ -181,10 +177,10 @@ function getIp (done) { tlog("IP: "+xhr.responseText) try{ var data=JSON.parse(xhr.responseText) - clientIp=data.processedString.escapeHtml() + clientIp=data.processedString ispInfo=data.rawIspInfo }catch(e){ - clientIp = xhr.responseText.escapeHtml() + clientIp = xhr.responseText ispInfo='' } done() @@ -498,9 +494,10 @@ function sendTelemetry(done){ fd.append('ping', pingStatus) fd.append('jitter', jitterStatus) fd.append('log', settings.telemetry_level>1?log:"") + fd.append('extra', settings.telemetry_extra); xhr.send(fd) }catch(ex){ - var postData = 'ispinfo='+encodeURIComponent(JSON.stringify(telemetryIspInfo))+'&dl='+encodeURIComponent(dlStatus)+'&ul='+encodeURIComponent(ulStatus)+'&ping='+encodeURIComponent(pingStatus)+'&jitter='+encodeURIComponent(jitterStatus)+'&log='+encodeURIComponent(settings.telemetry_level>1?log:'') + var postData = 'extra='+encodeURIComponent(settings.telemetry_extra)+'&ispinfo='+encodeURIComponent(JSON.stringify(telemetryIspInfo))+'&dl='+encodeURIComponent(dlStatus)+'&ul='+encodeURIComponent(ulStatus)+'&ping='+encodeURIComponent(pingStatus)+'&jitter='+encodeURIComponent(jitterStatus)+'&log='+encodeURIComponent(settings.telemetry_level>1?log:'') xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded') xhr.send(postData) } diff --git a/speedtest_worker.min.js b/speedtest_worker.min.js index efeb13d..9d0421d 100644 --- a/speedtest_worker.min.js +++ b/speedtest_worker.min.js @@ -1 +1 @@ -var testStatus=-1,dlStatus="",ulStatus="",pingStatus="",jitterStatus="",clientIp="",dlProgress=0,ulProgress=0,pingProgress=0,testId="noID",HTML_ESCAPE_MAP={"&":"&","<":"<",">":">",'"':""","'":"'"};String.prototype.escapeHtml=function(){return this.replace(/[&<>"']/g,function(m){return HTML_ESCAPE_MAP[m]})};var log="";function tlog(s){log+=Date.now()+": "+s+"\n"}function twarn(s){log+=Date.now()+" WARN: "+s+"\n",console.warn(s)}var settings={test_order:"IP_D_U",time_ul:15,time_dl:15,time_ulGraceTime:3,time_dlGraceTime:1.5,count_ping:35,url_dl:"garbage.php",url_ul:"empty.php",url_ping:"empty.php",url_getIp:"getIP.php",getIp_ispInfo:!0,getIp_ispInfo_distance:"km",xhr_dlMultistream:10,xhr_ulMultistream:3,xhr_multistreamDelay:300,xhr_ignoreErrors:1,xhr_dlUseBlob:!1,xhr_ul_blob_megabytes:20,garbagePhp_chunkSize:20,enable_quirks:!0,ping_allowPerformanceApi:!0,overheadCompensationFactor:1.06,useMebibits:!1,telemetry_level:0,url_telemetry:"telemetry/telemetry.php"},xhr=null,interval=null,test_pointer=0;function url_sep(url){return url.match(/\?/)?"&":"?"}function clearRequests(){if(tlog("stopping pending XHRs"),xhr){for(var i=0;i=settings.test_order.length)0settings.time_dl&&01e3*settings.time_dlGraceTime&&(0settings.time_ul&&01e3*settings.time_ulGraceTime&&(0=settings.test_order.length)0settings.time_dl&&01e3*settings.time_dlGraceTime&&(0settings.time_ul&&01e3*settings.time_ulGraceTime&&(0prepare("select id,timestamp,ip,ispinfo,ua,lang,dl,ul,ping,jitter,log from speedtest_users where id=?"); + $q=$conn->prepare("select id,timestamp,ip,ispinfo,ua,lang,dl,ul,ping,jitter,log,extra from speedtest_users where id=?"); $q->bind_param("i",$_POST["id"]); $q->execute(); - $q->bind_result($id,$timestamp,$ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log); + $q->bind_result($id,$timestamp,$ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log,$extra); } else if($db_type=="sqlite"||$db_type=="postgresql"){ - $q=$conn->prepare("select id,timestamp,ip,ispinfo,ua,lang,dl,ul,ping,jitter,log from speedtest_users where id=?"); + $q=$conn->prepare("select id,timestamp,ip,ispinfo,ua,lang,dl,ul,ping,jitter,log,extra from speedtest_users where id=?"); $q->execute(array($id)); } else die(); }else{ if($db_type=="mysql"){ - $q=$conn->prepare("select id,timestamp,ip,ispinfo,ua,lang,dl,ul,ping,jitter,log from speedtest_users order by timestamp desc limit 0,100"); + $q=$conn->prepare("select id,timestamp,ip,ispinfo,ua,lang,dl,ul,ping,jitter,log,extra from speedtest_users order by timestamp desc limit 0,100"); $q->execute(); - $q->bind_result($id,$timestamp,$ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log); + $q->bind_result($id,$timestamp,$ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log,$extra); } else if($db_type=="sqlite"||$db_type=="postgresql"){ - $q=$conn->prepare("select id,timestamp,ip,ispinfo,ua,lang,dl,ul,ping,jitter,log from speedtest_users order by timestamp desc limit 0,100"); + $q=$conn->prepare("select id,timestamp,ip,ispinfo,ua,lang,dl,ul,ping,jitter,log,extra from speedtest_users order by timestamp desc limit 0,100"); $q->execute(); }else die(); } while(true){ - $id=null; $timestamp=null; $ip=null; $ispinfo=null; $ua=null; $lang=null; $dl=null; $ul=null; $ping=null; $jitter=null; $log=null; + $id=null; $timestamp=null; $ip=null; $ispinfo=null; $ua=null; $lang=null; $dl=null; $ul=null; $ping=null; $jitter=null; $log=null; $extra=null; if($db_type=="mysql"){ if(!$q->fetch()) break; } else if($db_type=="sqlite"||$db_type=="postgresql"){ @@ -123,6 +123,7 @@ if($stats_password=="PASSWORD"){ $ping=$row["ping"]; $jitter=$row["jitter"]; $log=$row["log"]; + $extra=$row["extra"]; }else die(); ?> @@ -135,6 +136,7 @@ if($stats_password=="PASSWORD"){ +
Ping
Jitter
Log
Extra info
prepare("INSERT INTO speedtest_users (ip,ispinfo,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?)") or die("2"); - $stmt->bind_param("sssssssss",$ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log) or die("3"); + $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,extra,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?,?)") or die("2"); + $stmt->bind_param("ssssssssss",$ip,$ispinfo,$extra,$ua,$lang,$dl,$ul,$ping,$jitter,$log) or die("3"); $stmt->execute() or die("4"); $stmt->close() or die("5"); echo "id ".$conn->insert_id; @@ -26,6 +27,7 @@ if($db_type=="mysql"){ CREATE TABLE IF NOT EXISTS `speedtest_users` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `ispinfo` text, + `extra` text, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `ip` text NOT NULL, `ua` text NOT NULL, @@ -37,8 +39,8 @@ if($db_type=="mysql"){ `log` longtext ); "); - $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?)") or die("2"); - $stmt->execute(array($ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3"); + $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,extra,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?,?)") or die("2"); + $stmt->execute(array($ip,$ispinfo,$extra,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3"); echo "id ".$conn->lastInsertId(); $conn = null; }elseif($db_type=="postgresql"){ @@ -49,8 +51,8 @@ if($db_type=="mysql"){ $conn_password = "password=$PostgreSql_password"; // Create db connection $conn = new PDO("pgsql:$conn_host;$conn_db;$conn_user;$conn_password") or die("1"); - $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?)") or die("2"); - $stmt->execute(array($ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3"); + $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,extra,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?,?)") or die("2"); + $stmt->execute(array($ip,$ispinfo,$extra,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3"); echo "id ".$conn->lastInsertId(); $conn = null; } diff --git a/telemetry/telemetry_mysql.sql b/telemetry/telemetry_mysql.sql index abdd299..ed897f7 100644 --- a/telemetry/telemetry_mysql.sql +++ b/telemetry/telemetry_mysql.sql @@ -24,6 +24,7 @@ CREATE TABLE `speedtest_users` ( `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `ip` text NOT NULL, `ispinfo` text, + `extra` text, `ua` text NOT NULL, `lang` text NOT NULL, `dl` text, diff --git a/telemetry/telemetry_postgresql.sql b/telemetry/telemetry_postgresql.sql index a750c98..e28e8ef 100644 --- a/telemetry/telemetry_postgresql.sql +++ b/telemetry/telemetry_postgresql.sql @@ -43,6 +43,7 @@ CREATE TABLE speedtest_users ( "timestamp" timestamp without time zone DEFAULT now() NOT NULL, ip text NOT NULL, ispinfo text, + extra text, ua text NOT NULL, lang text NOT NULL, dl text,