telemetry.php 2.1 KB

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