telemetry.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. include_once('telemetry_settings.php');
  3. require 'idObfuscation.php';
  4. $ip=($_SERVER['REMOTE_ADDR']);
  5. $ispinfo=($_POST["ispinfo"]);
  6. $extra=($_POST["extra"]);
  7. $ua=($_SERVER['HTTP_USER_AGENT']);
  8. $lang=""; if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) $lang=($_SERVER['HTTP_ACCEPT_LANGUAGE']);
  9. $dl=($_POST["dl"]);
  10. $ul=($_POST["ul"]);
  11. $ping=($_POST["ping"]);
  12. $jitter=($_POST["jitter"]);
  13. $log=($_POST["log"]);
  14. if($redact_ip_addresses){
  15. $ip="0.0.0.0";
  16. $ispinfo=preg_replace('/((2[0-4]|1\d|[1-9])?\d|25[0-5])(\.(?1)){3}/',"0.0.0.0",preg_replace('/(((?=(?>.*?(::))(?!.+\3)))\3?|([\dA-F]{1,4}(\3|:(?!$)|$)|\2))(?4){5}((?4){2}|((2[0-4]|1\d|[1-9])?\d|25[0-5])(\.(?7)){3})/i',"0.0.0.0",$ispinfo));
  17. $log=preg_replace('/((2[0-4]|1\d|[1-9])?\d|25[0-5])(\.(?1)){3}/',"0.0.0.0",preg_replace('/(((?=(?>.*?(::))(?!.+\3)))\3?|([\dA-F]{1,4}(\3|:(?!$)|$)|\2))(?4){5}((?4){2}|((2[0-4]|1\d|[1-9])?\d|25[0-5])(\.(?7)){3})/i',"0.0.0.0",$log));
  18. }
  19. header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, s-maxage=0');
  20. header('Cache-Control: post-check=0, pre-check=0', false);
  21. header('Pragma: no-cache');
  22. if($db_type=="mysql"){
  23. $conn = new mysqli($MySql_hostname, $MySql_username, $MySql_password, $MySql_databasename) or die("1");
  24. $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,extra,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?,?)") or die("2");
  25. $stmt->bind_param("ssssssssss",$ip,$ispinfo,$extra,$ua,$lang,$dl,$ul,$ping,$jitter,$log) or die("3");
  26. $stmt->execute() or die("4");
  27. $stmt->close() or die("5");
  28. $id=$conn->insert_id;
  29. echo "id ".($enable_id_obfuscation?obfuscateId($id):$id);
  30. $conn->close() or die("6");
  31. }elseif($db_type=="sqlite"){
  32. $conn = new PDO("sqlite:$Sqlite_db_file") or die("1");
  33. $conn->exec("
  34. CREATE TABLE IF NOT EXISTS `speedtest_users` (
  35. `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  36. `ispinfo` text,
  37. `extra` text,
  38. `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  39. `ip` text NOT NULL,
  40. `ua` text NOT NULL,
  41. `lang` text NOT NULL,
  42. `dl` text,
  43. `ul` text,
  44. `ping` text,
  45. `jitter` text,
  46. `log` longtext
  47. );
  48. ");
  49. $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,extra,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?,?)") or die("2");
  50. $stmt->execute(array($ip,$ispinfo,$extra,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3");
  51. $id=$conn->lastInsertId();
  52. echo "id ".($enable_id_obfuscation?obfuscateId($id):$id);
  53. $conn = null;
  54. }elseif($db_type=="postgresql"){
  55. // Prepare connection parameters for db connection
  56. $conn_host = "host=$PostgreSql_hostname";
  57. $conn_db = "dbname=$PostgreSql_databasename";
  58. $conn_user = "user=$PostgreSql_username";
  59. $conn_password = "password=$PostgreSql_password";
  60. // Create db connection
  61. $conn = new PDO("pgsql:$conn_host;$conn_db;$conn_user;$conn_password") or die("1");
  62. $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,extra,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?,?)") or die("2");
  63. $stmt->execute(array($ip,$ispinfo,$extra,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3");
  64. $id=$conn->lastInsertId();
  65. echo "id ".($enable_id_obfuscation?obfuscateId($id):$id);
  66. $conn = null;
  67. }
  68. else die("-1");
  69. ?>