telemetry.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. include_once('telemetry_settings.php');
  3. $ip=($_SERVER['REMOTE_ADDR']);
  4. $ispinfo=($_POST["ispinfo"]);
  5. $ua=($_SERVER['HTTP_USER_AGENT']);
  6. $lang=""; if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) $lang=($_SERVER['HTTP_ACCEPT_LANGUAGE']);
  7. $dl=($_POST["dl"]);
  8. $ul=($_POST["ul"]);
  9. $ping=($_POST["ping"]);
  10. $jitter=($_POST["jitter"]);
  11. $log=($_POST["log"]);
  12. if($db_type=="mysql"){
  13. $conn = new mysqli($MySql_hostname, $MySql_username, $MySql_password, $MySql_databasename) or die("1");
  14. $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?)") or die("2");
  15. $stmt->bind_param("sssssssss",$ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log) or die("3");
  16. $stmt->execute() or die("4");
  17. $stmt->close() or die("5");
  18. $conn->close() or die("6");
  19. }elseif($db_type=="sqlite"){
  20. $conn = new PDO("sqlite:$Sqlite_db_file") or die("1");
  21. $conn->exec("
  22. CREATE TABLE IF NOT EXISTS `speedtest_users` (
  23. `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  24. `ispinfo` text,
  25. `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  26. `ip` text NOT NULL,
  27. `ua` text NOT NULL,
  28. `lang` text NOT NULL,
  29. `dl` text,
  30. `ul` text,
  31. `ping` text,
  32. `jitter` text,
  33. `log` longtext
  34. );
  35. ");
  36. $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?)") or die("2");
  37. $stmt->execute(array($ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3");
  38. $conn = null;
  39. }elseif($db_type=="postgresql"){
  40. // Prepare connection parameters for db connection
  41. $conn_host = "host=$PostgreSql_hostname";
  42. $conn_db = "dbname=$PostgreSql_databasename";
  43. $conn_user = "user=$PostgreSql_username";
  44. $conn_password = "password=$PostgreSql_password";
  45. // Create db connection
  46. $conn = new PDO("pgsql:$conn_host;$conn_db;$conn_user;$conn_password") or die("1");
  47. $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?)") or die("2");
  48. $stmt->execute(array($ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3");
  49. $conn = null;
  50. }
  51. elseif($db_type=="csv"){
  52. // Prepare the csv formatted string
  53. date_default_timezone_set($timezone);
  54. $date = date('Y-m-d H:i:s');
  55. $str = '"' . $date . '",';
  56. $str .= '"' . $ip . '",';
  57. $str .= '"' . $ispinfo . '",';
  58. $str .= '"' . $ua . '",';
  59. $str .= '"' . $dl . '",';
  60. $str .= '"' . $ul . '",';
  61. $str .= '"' . $ping . '",';
  62. $str .= '"' . $jitter . '"' . "\n";
  63. // Set header if this is a new file
  64. if (!file_exists($Csv_File)) {
  65. $header = '"date","ip","ispinfo","ua","download","upload","ping","jitter"' . "\n";
  66. file_put_contents($Csv_File, $header, FILE_APPEND);
  67. }
  68. // Write line to file
  69. file_put_contents($Csv_File, $str, FILE_APPEND);
  70. }
  71. ?>