stats.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. session_start();
  3. error_reporting(0);
  4. header('Content-Type: text/html; charset=utf-8');
  5. ?>
  6. <!DOCTYPE html>
  7. <html>
  8. <head>
  9. <title>HTML5 Speedtest - Stats</title>
  10. <style type="text/css">
  11. html,body{
  12. margin:0;
  13. padding:0;
  14. border:none;
  15. width:100%; min-height:100%;
  16. }
  17. html{
  18. background-color:#304090;
  19. font-family:Sans-Serif;
  20. }
  21. body{
  22. background-color:#FFFFFF;
  23. box-sizing:border-box;
  24. width:100%;
  25. max-width:70em;
  26. margin:4em auto;
  27. box-shadow:0 0 20em #00000040;
  28. padding:1em 1em 4em 1em;
  29. border-radius:0.4em;
  30. }
  31. table{
  32. margin:4em 0;
  33. }
  34. </style>
  35. </head>
  36. <body>
  37. <h1>HTML5 Speedtest - Stats</h1>
  38. <?php
  39. include_once("telemetry_settings.php");
  40. if($stats_password=="PASSWORD"){
  41. ?>
  42. Please set $stats_password in telemetry_settings.php to enable access.
  43. <?php
  44. }else if($_SESSION["logged"]===true){
  45. if($_GET["op"]=="logout"){
  46. $_SESSION["logged"]=false;
  47. ?><script type="text/javascript">window.location.search=""</script><?php
  48. }else{
  49. $conn=null;
  50. if($db_type=="mysql"){
  51. $conn = new mysqli($MySql_hostname, $MySql_username, $MySql_password, $MySql_databasename);
  52. }else if($db_type=="sqlite"){
  53. $conn = new PDO("sqlite:$Sqlite_db_file");
  54. } else if($db_type=="postgresql"){
  55. $conn_host = "host=$PostgreSql_hostname";
  56. $conn_db = "dbname=$PostgreSql_databasename";
  57. $conn_user = "user=$PostgreSql_username";
  58. $conn_password = "password=$PostgreSql_password";
  59. $conn = new PDO("pgsql:$conn_host;$conn_db;$conn_user;$conn_password");
  60. }else die();
  61. ?>
  62. <form action="stats.php?op=logout" method="POST"><input type="submit" value="Logout" /></form>
  63. <form action="stats.php?op=id" method="POST">
  64. <h3>Search test results</h6>
  65. <input type="text" name="id" id="id" placeholder="Test ID" value=""/>
  66. <input type="submit" value="Find" />
  67. <input type="submit" onclick="document.getElementById('id').value=''" value="Show last 100 tests" />
  68. </form>
  69. <?php
  70. $q=null;
  71. if($_GET["op"]=="id"&&!empty($_POST["id"])){
  72. $id=$_POST["id"];
  73. if($db_type=="mysql"){
  74. $q=$conn->prepare("select id,timestamp,ip,ispinfo,ua,lang,dl,ul,ping,jitter,log from speedtest_users where id=?");
  75. $q->bind_param("i",$_POST["id"]);
  76. $q->execute();
  77. $q->bind_result($id,$timestamp,$ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log);
  78. } else if($db_type=="sqlite"||$db_type=="postgresql"){
  79. $q=$conn->prepare("select id,timestamp,ip,ispinfo,ua,lang,dl,ul,ping,jitter,log from speedtest_users where id=?");
  80. $q->execute(array($id));
  81. } else die();
  82. }else{
  83. if($db_type=="mysql"){
  84. $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");
  85. $q->execute();
  86. $q->bind_result($id,$timestamp,$ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log);
  87. } else if($db_type=="sqlite"||$db_type=="postgresql"){
  88. $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");
  89. $q->execute();
  90. }else die();
  91. }
  92. while(true){
  93. $id=null; $timestamp=null; $ip=null; $ispinfo=null; $ua=null; $lang=null; $dl=null; $ul=null; $ping=null; $jitter=null; $log=null;
  94. if($db_type=="mysql"){
  95. if(!$q->fetch()) break;
  96. } else if($db_type=="sqlite"||$db_type=="postgresql"){
  97. if(!($row=$q->fetch())) break;
  98. $id=$row["id"];
  99. $timestamp=$row["timestamp"];
  100. $ip=$row["ip"];
  101. $ispinfo=$row["ispinfo"];
  102. $ua=$row["ua"];
  103. $lang=$row["lang"];
  104. $dl=$row["dl"];
  105. $ul=$row["ul"];
  106. $ping=$row["ping"];
  107. $jitter=$row["jitter"];
  108. $log=$row["log"];
  109. }else die();
  110. ?>
  111. <table>
  112. <tr><th>Test ID</th><td><?=htmlspecialchars($id, ENT_HTML5, 'UTF-8') ?></td></tr>
  113. <tr><th>Date and time</th><td><?=htmlspecialchars($timestamp, ENT_HTML5, 'UTF-8') ?></td></tr>
  114. <tr><th>IP and ISP Info</th><td><?=$ip ?><br/><?=htmlspecialchars($ispinfo, ENT_HTML5, 'UTF-8') ?></td></tr>
  115. <tr><th>User agent and locale</th><td><?=$ua ?><br/><?=htmlspecialchars($lang, ENT_HTML5, 'UTF-8') ?></td></tr>
  116. <tr><th>Download speed</th><td><?=htmlspecialchars($dl, ENT_HTML5, 'UTF-8') ?></td></tr>
  117. <tr><th>Upload speed</th><td><?=htmlspecialchars($ul, ENT_HTML5, 'UTF-8') ?></td></tr>
  118. <tr><th>Ping</th><td><?=htmlspecialchars($ping, ENT_HTML5, 'UTF-8') ?></td></tr>
  119. <tr><th>Jitter</th><td><?=htmlspecialchars($jitter, ENT_HTML5, 'UTF-8') ?></td></tr>
  120. <tr><th>Log</th><td><?=htmlspecialchars($log, ENT_HTML5, 'UTF-8') ?></td></tr>
  121. </table>
  122. <?php
  123. }
  124. ?>
  125. <?php
  126. }
  127. }else{
  128. if($_GET["op"]=="login"&&$_POST["password"]===$stats_password){
  129. $_SESSION["logged"]=true;
  130. ?><script type="text/javascript">window.location.search=""</script><?php
  131. }else{
  132. ?>
  133. <form action="stats.php?op=login" method="POST">
  134. <h3>Login</h3>
  135. <input type="password" name="password" placeholder="Password" value=""/>
  136. <input type="submit" value="Login" />
  137. </form>
  138. <?php
  139. }
  140. }
  141. ?>
  142. </body>
  143. </html>