stats.php 5.7 KB

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