telemetry.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. require 'telemetry_settings.php';
  3. require_once 'telemetry_db.php';
  4. $ip = $_SERVER['REMOTE_ADDR'];
  5. $ispinfo = $_POST['ispinfo'];
  6. $extra = $_POST['extra'];
  7. $ua = $_SERVER['HTTP_USER_AGENT'];
  8. $lang = '';
  9. if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  10. $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  11. }
  12. $dl = $_POST['dl'];
  13. $ul = $_POST['ul'];
  14. $ping = $_POST['ping'];
  15. $jitter = $_POST['jitter'];
  16. $log = $_POST['log'];
  17. if (isset($redact_ip_addresses) && true === $redact_ip_addresses) {
  18. $ip = '0.0.0.0';
  19. $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]?)/';
  20. $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]))/';
  21. $hostname_regex = '/"hostname":"([^\\\\"]|\\\\")*"/';
  22. $ispinfo = preg_replace($ipv4_regex, '0.0.0.0', $ispinfo);
  23. $ispinfo = preg_replace($ipv6_regex, '0.0.0.0', $ispinfo);
  24. $ispinfo = preg_replace($hostname_regex, '"hostname":"REDACTED"', $ispinfo);
  25. $log = preg_replace($ipv4_regex, '0.0.0.0', $log);
  26. $log = preg_replace($ipv6_regex, '0.0.0.0', $log);
  27. $log = preg_replace($hostname_regex, '"hostname":"REDACTED"', $log);
  28. }
  29. header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, s-maxage=0');
  30. header('Cache-Control: post-check=0, pre-check=0', false);
  31. header('Pragma: no-cache');
  32. $id = insertSpeedtestUser($ip, $ispinfo, $extra, $ua, $lang, $dl, $ul, $ping, $jitter, $log);
  33. if (false === $id) {
  34. exit(1);
  35. }
  36. echo 'id '.$id;