stats.php 6.9 KB

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