telemetry.php 2.8 KB

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