144 lines
4.4 KiB
PHP
144 lines
4.4 KiB
PHP
<?php
|
|
session_start();
|
|
error_reporting(0);
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>HTML5 Speedtest - Stats</title>
|
|
<style type="text/css">
|
|
html,body{
|
|
margin:0;
|
|
padding:0;
|
|
border:none;
|
|
width:100%; min-height:100%;
|
|
}
|
|
html{
|
|
background-color:#304090;
|
|
font-family:Sans-Serif;
|
|
}
|
|
body{
|
|
background-color:#FFFFFF;
|
|
box-sizing:border-box;
|
|
width:100%;
|
|
max-width:70em;
|
|
margin:4em auto;
|
|
box-shadow:0 0 20em #00000040;
|
|
padding:1em 1em 4em 1em;
|
|
border-radius:0.4em;
|
|
}
|
|
table{
|
|
margin:4em 0;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>HTML5 Speedtest - Stats</h1>
|
|
<?php
|
|
include_once("telemetry_settings.php");
|
|
if($stats_password=="PASSWORD"){
|
|
?>
|
|
Please set $stats_password in telemetry_settings.php to enable access.
|
|
<?php
|
|
}else if($_SESSION["logged"]===true){
|
|
if($_GET["op"]=="logout"){
|
|
$_SESSION["logged"]=false;
|
|
?><script type="text/javascript">window.location.search=""</script><?php
|
|
}else{
|
|
$conn=null;
|
|
if($db_type=="mysql"){
|
|
$conn = new mysqli($MySql_hostname, $MySql_username, $MySql_password, $MySql_databasename);
|
|
}else if($db_type=="sqlite"){
|
|
$conn = new PDO("sqlite:$Sqlite_db_file");
|
|
} else if($db_type=="postgresql"){
|
|
$conn_host = "host=$PostgreSql_hostname";
|
|
$conn_db = "dbname=$PostgreSql_databasename";
|
|
$conn_user = "user=$PostgreSql_username";
|
|
$conn_password = "password=$PostgreSql_password";
|
|
$conn = new PDO("pgsql:$conn_host;$conn_db;$conn_user;$conn_password");
|
|
}else die();
|
|
?>
|
|
<form action="stats.php?op=logout" method="POST"><input type="submit" value="Logout" /></form>
|
|
<form action="stats.php?op=id" method="POST">
|
|
<h3>Search test results</h6>
|
|
<input type="text" name="id" id="id" placeholder="Test ID" value=""/>
|
|
<input type="submit" value="Find" />
|
|
<input type="submit" onclick="document.getElementById('id').value=''" value="Show last 100 tests" />
|
|
</form>
|
|
<?php
|
|
$q=null;
|
|
if($_GET["op"]=="id"&&!empty($_POST["id"])){
|
|
$id=$_POST["id"];
|
|
if($db_type=="mysql"){
|
|
$q=$conn->prepare("select id,timestamp,ip,ispinfo,ua,lang,dl,ul,ping,jitter,log 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);
|
|
} 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->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->execute();
|
|
$q->bind_result($id,$timestamp,$ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log);
|
|
} 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->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;
|
|
if($db_type=="mysql"){
|
|
if(!$q->fetch()) break;
|
|
} else if($db_type=="sqlite"||$db_type=="postgresql"){
|
|
if(!($row=$q->fetch())) break;
|
|
$id=$row["id"];
|
|
$timestamp=$row["timestamp"];
|
|
$ip=$row["ip"];
|
|
$ispinfo=$row["ispinfo"];
|
|
$ua=$row["ua"];
|
|
$lang=$row["lang"];
|
|
$dl=$row["dl"];
|
|
$ul=$row["ul"];
|
|
$ping=$row["ping"];
|
|
$jitter=$row["jitter"];
|
|
$log=$row["log"];
|
|
}else die();
|
|
?>
|
|
<table>
|
|
<tr><th>Test ID</th><td><?=$id ?></td></tr>
|
|
<tr><th>Date and time</th><td><?=$timestamp ?></td></tr>
|
|
<tr><th>IP and ISP Info</th><td><?=$ip ?><br/><?=$ispinfo ?></td></tr>
|
|
<tr><th>User agent and locale</th><td><?=$ua ?><br/><?=$lang ?></td></tr>
|
|
<tr><th>Download speed</th><td><?=$dl ?></td></tr>
|
|
<tr><th>Upload speed</th><td><?=$ul ?></td></tr>
|
|
<tr><th>Ping</th><td><?=$ping ?></td></tr>
|
|
<tr><th>Jitter</th><td><?=$jitter ?></td></tr>
|
|
<tr><th>Log</th><td><?=$log ?></td></tr>
|
|
</table>
|
|
<?php
|
|
}
|
|
?>
|
|
<?php
|
|
}
|
|
}else{
|
|
if($_GET["op"]=="login"&&$_POST["password"]===$stats_password){
|
|
$_SESSION["logged"]=true;
|
|
?><script type="text/javascript">window.location.search=""</script><?php
|
|
}else{
|
|
?>
|
|
<form action="stats.php?op=login" method="POST">
|
|
<h3>Login</h3>
|
|
<input type="password" name="password" placeholder="Password" value=""/>
|
|
<input type="submit" value="Login" />
|
|
</form>
|
|
<?php
|
|
}
|
|
}
|
|
?>
|
|
</body>
|
|
</html>
|