Skip to content

Commit

Permalink
Output from getIP (IP and ISP info) is now stored in the results data…
Browse files Browse the repository at this point in the history
…base
  • Loading branch information
adolfintel committed Aug 5, 2018
1 parent c17d58a commit cfbbfa3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 24 deletions.
4 changes: 2 additions & 2 deletions doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ If you see a table called `speedtest_users`, empty, you did it right.

### Configuring `telemetry.php`
Open telemetry_settings.php with notepad or a similar text editor.
Set your preferred database, ``$db_type="mysql";``, ``$db_type="sqlite";``, ``$db_type="postgresql";`` or or ``$db_type="csv";``
Set your preferred database, ``$db_type="mysql";``, ``$db_type="sqlite";``, ``$db_type="postgresql";`` or ``$db_type="csv";``
If you choose to use Sqlite3, you must set the path to your database file:
```php
$Sqlite_db_file = "../telemetry.sql";
Expand Down Expand Up @@ -363,7 +363,7 @@ __Note__: CSV currently only supports basic telemetry, the log will not be saved
Edit your test page; where you start the worker, you need to specify the `telemetry_level`.
There are 3 levels:
* `none`: telemetry is disabled (default)
* `basic`: telemetry collects IP, User Agent, Preferred language, Test results
* `basic`: telemetry collects IP, ISP info, User Agent, Preferred language, Test results
* `full`: same as above, but also collects a log (10-150 Kb each, not recommended)

Example:
Expand Down
7 changes: 4 additions & 3 deletions speedtest_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ function pingTest (done) {
if (i < settings.count_ping) doPing(); else done() // more pings to do?
}
}.bind(this)
// sent xhr
// send xhr
xhr[0].open('GET', settings.url_ping + url_sep(settings.url_ping) + 'r=' + Math.random(), true) // random string to prevent caching
xhr[0].send()
}.bind(this)
Expand All @@ -457,14 +457,15 @@ function sendTelemetry(){
xhr.open('POST', settings.url_telemetry+url_sep(settings.url_telemetry)+"r="+Math.random(), true);
try{
var fd = new FormData()
fd.append('dl', dlStatus)
fd.append('ispinfo', clientIp) //clientIp also contains ISP info
fd.append('dl', dlStatus)
fd.append('ul', ulStatus)
fd.append('ping', pingStatus)
fd.append('jitter', jitterStatus)
fd.append('log', settings.telemetry_level>1?log:"")
xhr.send(fd)
}catch(ex){
var postData = 'dl='+encodeURIComponent(dlStatus)+'&ul='+encodeURIComponent(ulStatus)+'&ping='+encodeURIComponent(pingStatus)+'&jitter='+encodeURIComponent(jitterStatus)+'&log='+encodeURIComponent(settings.telemetry_level>1?log:'')
var postData = 'ispinfo='+encodeURIComponent(clientIp)+'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)
}
Expand Down
2 changes: 1 addition & 1 deletion speedtest_worker.min.js

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions telemetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
include_once('telemetry_settings.php');

$ip=($_SERVER['REMOTE_ADDR']);
$ispinfo=($_POST["ispinfo"]);
$ua=($_SERVER['HTTP_USER_AGENT']);
$lang=""; if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) $lang=($_SERVER['HTTP_ACCEPT_LANGUAGE']);
$dl=($_POST["dl"]);
Expand All @@ -12,8 +13,8 @@

if($db_type=="mysql"){
$conn = new mysqli($MySql_hostname, $MySql_username, $MySql_password, $MySql_databasename) or die("1");
$stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?)") or die("2");
$stmt->bind_param("ssssssss",$ip,$ua,$lang,$dl,$ul,$ping,$jitter,$log) or die("3");
$stmt = $conn->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->execute() or die("4");
$stmt->close() or die("5");
$conn->close() or die("6");
Expand All @@ -23,6 +24,7 @@
$conn->exec("
CREATE TABLE IF NOT EXISTS `speedtest_users` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`ispinfo` text,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`ip` text NOT NULL,
`ua` text NOT NULL,
Expand All @@ -34,8 +36,8 @@
`log` longtext
);
");
$stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?)") or die("2");
$stmt->execute(array($ip,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3");
$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");
$conn = null;
}elseif($db_type=="postgresql"){
// Prepare connection parameters for db connection
Expand All @@ -45,8 +47,8 @@
$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,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?)") or die("2");
$stmt->execute(array($ip,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3");
$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");
$conn = null;
}
elseif($db_type=="csv"){
Expand All @@ -55,6 +57,7 @@
$date = date('Y-m-d H:i:s');
$str = '"' . $date . '",';
$str .= '"' . $ip . '",';
$str .= '"' . $ispinfo . '",';
$str .= '"' . $ua . '",';
$str .= '"' . $dl . '",';
$str .= '"' . $ul . '",';
Expand All @@ -63,11 +66,11 @@

// Set header if this is a new file
if (!file_exists($Csv_File)) {
$header = '"date","ip","ua","download","upload","ping","jitter"' . "\n";
$header = '"date","ip","ispinfo","ua","download","upload","ping","jitter"' . "\n";
file_put_contents($Csv_File, $header, FILE_APPEND);
}

// Writting line to file
// Write line to file
file_put_contents($Csv_File, $str, FILE_APPEND);
}
?>
10 changes: 1 addition & 9 deletions telemetry_mysql.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
-- phpMyAdmin SQL Dump
-- version 4.7.0
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Aug 24, 2017 at 02:16 PM
-- Server version: 10.1.25-MariaDB
-- PHP Version: 7.1.7

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
Expand All @@ -32,6 +23,7 @@ CREATE TABLE `speedtest_users` (
`id` int(11) NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`ip` text NOT NULL,
`ispinfo` text,
`ua` text NOT NULL,
`lang` text NOT NULL,
`dl` text,
Expand Down
1 change: 1 addition & 0 deletions telemetry_postgresql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ CREATE TABLE speedtest_users (
id integer NOT NULL,
"timestamp" timestamp without time zone DEFAULT now() NOT NULL,
ip text NOT NULL,
ispinfo text,
ua text NOT NULL,
lang text NOT NULL,
dl text,
Expand Down
2 changes: 1 addition & 1 deletion telemetry_settings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$db_type="mysql"; //Type of db: "mysql", "sqlite" or "postgresql" or "csv"
$db_type="mysql"; //Type of db: "mysql", "sqlite", "postgresql" or "csv"

// Sqlite3 settings
$Sqlite_db_file = "../telemetry.sql";
Expand Down

0 comments on commit cfbbfa3

Please sign in to comment.