telemetry.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. $ipv4_regex='/(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/';
  17. $ipv6_regex='/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/';
  18. $hostname_regex='/"hostname":"([^\\\\"]|\\\\")*"/';
  19. $ispinfo=preg_replace($ipv4_regex,"0.0.0.0",$ispinfo);
  20. $ispinfo=preg_replace($ipv6_regex,"0.0.0.0",$ispinfo);
  21. $ispinfo=preg_replace($hostname_regex,"\"hostname\":\"REDACTED\"",$ispinfo);
  22. $log=preg_replace($ipv4_regex,"0.0.0.0",$log);
  23. $log=preg_replace($ipv6_regex,"0.0.0.0",$log);
  24. $log=preg_replace($hostname_regex,"\"hostname\":\"REDACTED\"",$log);
  25. }
  26. header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, s-maxage=0');
  27. header('Cache-Control: post-check=0, pre-check=0', false);
  28. header('Pragma: no-cache');
  29. if($db_type=="mysql"){
  30. $conn = new mysqli($MySql_hostname, $MySql_username, $MySql_password, $MySql_databasename, $MySql_port) or die("1");
  31. $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,extra,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?,?)") or die("2");
  32. $stmt->bind_param("ssssssssss",$ip,$ispinfo,$extra,$ua,$lang,$dl,$ul,$ping,$jitter,$log) or die("3");
  33. $stmt->execute() or die("4");
  34. $stmt->close() or die("5");
  35. $id=$conn->insert_id;
  36. echo "id ".($enable_id_obfuscation?obfuscateId($id):$id);
  37. $conn->close() or die("6");
  38. }elseif($db_type=="sqlite"){
  39. $conn = new PDO("sqlite:$Sqlite_db_file") or die("1");
  40. $conn->exec("
  41. CREATE TABLE IF NOT EXISTS `speedtest_users` (
  42. `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  43. `ispinfo` text,
  44. `extra` text,
  45. `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  46. `ip` text NOT NULL,
  47. `ua` text NOT NULL,
  48. `lang` text NOT NULL,
  49. `dl` text,
  50. `ul` text,
  51. `ping` text,
  52. `jitter` text,
  53. `log` longtext
  54. );
  55. ");
  56. $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,extra,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?,?)") or die("2");
  57. $stmt->execute(array($ip,$ispinfo,$extra,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3");
  58. $id=$conn->lastInsertId();
  59. echo "id ".($enable_id_obfuscation?obfuscateId($id):$id);
  60. $conn = null;
  61. }elseif($db_type=="postgresql"){
  62. // Prepare connection parameters for db connection
  63. $conn_host = "host=$PostgreSql_hostname";
  64. $conn_db = "dbname=$PostgreSql_databasename";
  65. $conn_user = "user=$PostgreSql_username";
  66. $conn_password = "password=$PostgreSql_password";
  67. // Create db connection
  68. $conn = new PDO("pgsql:$conn_host;$conn_db;$conn_user;$conn_password") or die("1");
  69. $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,extra,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?,?)") or die("2");
  70. $stmt->execute(array($ip,$ispinfo,$extra,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3");
  71. $id=$conn->lastInsertId();
  72. echo "id ".($enable_id_obfuscation?obfuscateId($id):$id);
  73. $conn = null;
  74. }
  75. else die("-1");
  76. ?>