stats.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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: hsl(198,72%,35%);
  19. font-family: "Segoe UI","Roboto",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 1em 6em #00000080;
  28. padding:1em 1em 4em 1em;
  29. border-radius:0.4em;
  30. }
  31. h1,h2,h3,h4,h5,h6{
  32. font-weight:300;
  33. margin-bottom: 0.1em;
  34. }
  35. h1{
  36. text-align:center;
  37. }
  38. table{
  39. margin:2em 0;
  40. width:100%;
  41. }
  42. table, tr, th, td {
  43. border: 1px solid #AAAAAA;
  44. }
  45. th {
  46. width: 6em;
  47. }
  48. td {
  49. word-break: break-all;
  50. }
  51. </style>
  52. </head>
  53. <body>
  54. <h1>HTML5 Speedtest - Stats</h1>
  55. <?php
  56. include_once("telemetry_settings.php");
  57. if($stats_password=="PASSWORD"){
  58. ?>
  59. Please set $stats_password in telemetry_settings.php to enable access.
  60. <?php
  61. }else if($_SESSION["logged"]===true){
  62. if($_GET["op"]=="logout"){
  63. $_SESSION["logged"]=false;
  64. ?><script type="text/javascript">window.location.search=""</script><?php
  65. }else{
  66. $conn=null;
  67. if($db_type=="mysql"){
  68. $conn = new mysqli($MySql_hostname, $MySql_username, $MySql_password, $MySql_databasename);
  69. }else if($db_type=="sqlite"){
  70. $conn = new PDO("sqlite:$Sqlite_db_file");
  71. } else if($db_type=="postgresql"){
  72. $conn_host = "host=$PostgreSql_hostname";
  73. $conn_db = "dbname=$PostgreSql_databasename";
  74. $conn_user = "user=$PostgreSql_username";
  75. $conn_password = "password=$PostgreSql_password";
  76. $conn = new PDO("pgsql:$conn_host;$conn_db;$conn_user;$conn_password");
  77. }else die();
  78. ?>
  79. <form action="stats.php?op=logout" method="POST"><input type="submit" value="Logout" /></form>
  80. <form action="stats.php?op=id" method="POST">
  81. <h3>Search test results</h6>
  82. <input type="text" name="id" id="id" placeholder="Test ID" value=""/>
  83. <input type="submit" value="Find" />
  84. <input type="submit" onclick="document.getElementById('id').value=''" value="Show last 100 tests" />
  85. </form>
  86. <?php
  87. $q=null;
  88. if($_GET["op"]=="id"&&!empty($_POST["id"])){
  89. $id=$_POST["id"];
  90. if($db_type=="mysql"){
  91. $q=$conn->prepare("select id,timestamp,ip,ispinfo,ua,lang,dl,ul,ping,jitter,log,extra from speedtest_users where id=?");
  92. $q->bind_param("i",$_POST["id"]);
  93. $q->execute();
  94. $q->store_result();
  95. $q->bind_result($id,$timestamp,$ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log,$extra);
  96. } else if($db_type=="sqlite"||$db_type=="postgresql"){
  97. $q=$conn->prepare("select id,timestamp,ip,ispinfo,ua,lang,dl,ul,ping,jitter,log,extra from speedtest_users where id=?");
  98. $q->execute(array($id));
  99. } else die();
  100. }else{
  101. if($db_type=="mysql"){
  102. $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");
  103. $q->execute();
  104. $q->store_result();
  105. $q->bind_result($id,$timestamp,$ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log,$extra);
  106. } else if($db_type=="sqlite"||$db_type=="postgresql"){
  107. $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");
  108. $q->execute();
  109. }else die();
  110. }
  111. while(true){
  112. $id=null; $timestamp=null; $ip=null; $ispinfo=null; $ua=null; $lang=null; $dl=null; $ul=null; $ping=null; $jitter=null; $log=null; $extra=null;
  113. if($db_type=="mysql"){
  114. if(!$q->fetch()) break;
  115. } else if($db_type=="sqlite"||$db_type=="postgresql"){
  116. if(!($row=$q->fetch())) break;
  117. $id=$row["id"];
  118. $timestamp=$row["timestamp"];
  119. $ip=$row["ip"];
  120. $ispinfo=$row["ispinfo"];
  121. $ua=$row["ua"];
  122. $lang=$row["lang"];
  123. $dl=$row["dl"];
  124. $ul=$row["ul"];
  125. $ping=$row["ping"];
  126. $jitter=$row["jitter"];
  127. $log=$row["log"];
  128. $extra=$row["extra"];
  129. }else die();
  130. ?>
  131. <table>
  132. <tr><th>Test ID</th><td><?=htmlspecialchars($id, ENT_HTML5, 'UTF-8') ?></td></tr>
  133. <tr><th>Date and time</th><td><?=htmlspecialchars($timestamp, ENT_HTML5, 'UTF-8') ?></td></tr>
  134. <tr><th>IP and ISP Info</th><td><?=$ip ?><br/><?=htmlspecialchars($ispinfo, ENT_HTML5, 'UTF-8') ?></td></tr>
  135. <tr><th>User agent and locale</th><td><?=$ua ?><br/><?=htmlspecialchars($lang, ENT_HTML5, 'UTF-8') ?></td></tr>
  136. <tr><th>Download speed</th><td><?=htmlspecialchars($dl, ENT_HTML5, 'UTF-8') ?></td></tr>
  137. <tr><th>Upload speed</th><td><?=htmlspecialchars($ul, ENT_HTML5, 'UTF-8') ?></td></tr>
  138. <tr><th>Ping</th><td><?=htmlspecialchars($ping, ENT_HTML5, 'UTF-8') ?></td></tr>
  139. <tr><th>Jitter</th><td><?=htmlspecialchars($jitter, ENT_HTML5, 'UTF-8') ?></td></tr>
  140. <tr><th>Log</th><td><?=htmlspecialchars($log, ENT_HTML5, 'UTF-8') ?></td></tr>
  141. <tr><th>Extra info</th><td><?=htmlspecialchars($extra, ENT_HTML5, 'UTF-8') ?></td></tr>
  142. </table>
  143. <?php
  144. }
  145. ?>
  146. <?php
  147. }
  148. }else{
  149. if($_GET["op"]=="login"&&$_POST["password"]===$stats_password){
  150. $_SESSION["logged"]=true;
  151. ?><script type="text/javascript">window.location.search=""</script><?php
  152. }else{
  153. ?>
  154. <form action="stats.php?op=login" method="POST">
  155. <h3>Login</h3>
  156. <input type="password" name="password" placeholder="Password" value=""/>
  157. <input type="submit" value="Login" />
  158. </form>
  159. <?php
  160. }
  161. }
  162. ?>
  163. </body>
  164. </html>