stats.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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->bind_result($id,$timestamp,$ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log,$extra);
  95. } else if($db_type=="sqlite"||$db_type=="postgresql"){
  96. $q=$conn->prepare("select id,timestamp,ip,ispinfo,ua,lang,dl,ul,ping,jitter,log,extra from speedtest_users where id=?");
  97. $q->execute(array($id));
  98. } else die();
  99. }else{
  100. if($db_type=="mysql"){
  101. $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");
  102. $q->execute();
  103. $q->bind_result($id,$timestamp,$ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log,$extra);
  104. } else if($db_type=="sqlite"||$db_type=="postgresql"){
  105. $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");
  106. $q->execute();
  107. }else die();
  108. }
  109. while(true){
  110. $id=null; $timestamp=null; $ip=null; $ispinfo=null; $ua=null; $lang=null; $dl=null; $ul=null; $ping=null; $jitter=null; $log=null; $extra=null;
  111. if($db_type=="mysql"){
  112. if(!$q->fetch()) break;
  113. } else if($db_type=="sqlite"||$db_type=="postgresql"){
  114. if(!($row=$q->fetch())) break;
  115. $id=$row["id"];
  116. $timestamp=$row["timestamp"];
  117. $ip=$row["ip"];
  118. $ispinfo=$row["ispinfo"];
  119. $ua=$row["ua"];
  120. $lang=$row["lang"];
  121. $dl=$row["dl"];
  122. $ul=$row["ul"];
  123. $ping=$row["ping"];
  124. $jitter=$row["jitter"];
  125. $log=$row["log"];
  126. $extra=$row["extra"];
  127. }else die();
  128. ?>
  129. <table>
  130. <tr><th>Test ID</th><td><?=htmlspecialchars($id, ENT_HTML5, 'UTF-8') ?></td></tr>
  131. <tr><th>Date and time</th><td><?=htmlspecialchars($timestamp, ENT_HTML5, 'UTF-8') ?></td></tr>
  132. <tr><th>IP and ISP Info</th><td><?=$ip ?><br/><?=htmlspecialchars($ispinfo, ENT_HTML5, 'UTF-8') ?></td></tr>
  133. <tr><th>User agent and locale</th><td><?=$ua ?><br/><?=htmlspecialchars($lang, ENT_HTML5, 'UTF-8') ?></td></tr>
  134. <tr><th>Download speed</th><td><?=htmlspecialchars($dl, ENT_HTML5, 'UTF-8') ?></td></tr>
  135. <tr><th>Upload speed</th><td><?=htmlspecialchars($ul, ENT_HTML5, 'UTF-8') ?></td></tr>
  136. <tr><th>Ping</th><td><?=htmlspecialchars($ping, ENT_HTML5, 'UTF-8') ?></td></tr>
  137. <tr><th>Jitter</th><td><?=htmlspecialchars($jitter, ENT_HTML5, 'UTF-8') ?></td></tr>
  138. <tr><th>Log</th><td><?=htmlspecialchars($log, ENT_HTML5, 'UTF-8') ?></td></tr>
  139. <tr><th>Extra info</th><td><?=htmlspecialchars($extra, ENT_HTML5, 'UTF-8') ?></td></tr>
  140. </table>
  141. <?php
  142. }
  143. ?>
  144. <?php
  145. }
  146. }else{
  147. if($_GET["op"]=="login"&&$_POST["password"]===$stats_password){
  148. $_SESSION["logged"]=true;
  149. ?><script type="text/javascript">window.location.search=""</script><?php
  150. }else{
  151. ?>
  152. <form action="stats.php?op=login" method="POST">
  153. <h3>Login</h3>
  154. <input type="password" name="password" placeholder="Password" value=""/>
  155. <input type="submit" value="Login" />
  156. </form>
  157. <?php
  158. }
  159. }
  160. ?>
  161. </body>
  162. </html>