telemetry.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. echo "id ".$conn->insert_id;
  19. $conn->close() or die("6");
  20. }elseif($db_type=="sqlite"){
  21. $conn = new PDO("sqlite:$Sqlite_db_file") or die("1");
  22. $conn->exec("
  23. CREATE TABLE IF NOT EXISTS `speedtest_users` (
  24. `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  25. `ispinfo` text,
  26. `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  27. `ip` text NOT NULL,
  28. `ua` text NOT NULL,
  29. `lang` text NOT NULL,
  30. `dl` text,
  31. `ul` text,
  32. `ping` text,
  33. `jitter` text,
  34. `log` longtext
  35. );
  36. ");
  37. $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?)") or die("2");
  38. $stmt->execute(array($ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3");
  39. echo "id ".$conn->lastInsertId();
  40. $conn = null;
  41. }elseif($db_type=="postgresql"){
  42. // Prepare connection parameters for db connection
  43. $conn_host = "host=$PostgreSql_hostname";
  44. $conn_db = "dbname=$PostgreSql_databasename";
  45. $conn_user = "user=$PostgreSql_username";
  46. $conn_password = "password=$PostgreSql_password";
  47. // Create db connection
  48. $conn = new PDO("pgsql:$conn_host;$conn_db;$conn_user;$conn_password") or die("1");
  49. $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ispinfo,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?,?)") or die("2");
  50. $stmt->execute(array($ip,$ispinfo,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3");
  51. echo "id ".$conn->lastInsertId();
  52. $conn = null;
  53. }
  54. elseif($db_type=="csv"){
  55. // Prepare the csv formatted string
  56. date_default_timezone_set($timezone);
  57. $date = date('Y-m-d H:i:s');
  58. $str = '"' . $date . '",';
  59. $str .= '"' . $ip . '",';
  60. $str .= '"' . $ispinfo . '",';
  61. $str .= '"' . $ua . '",';
  62. $str .= '"' . $dl . '",';
  63. $str .= '"' . $ul . '",';
  64. $str .= '"' . $ping . '",';
  65. $str .= '"' . $jitter . '"' . "\n";
  66. // Set header if this is a new file
  67. if (!file_exists($Csv_File)) {
  68. $header = '"date","ip","ispinfo","ua","download","upload","ping","jitter"' . "\n";
  69. file_put_contents($Csv_File, $header, FILE_APPEND);
  70. }
  71. // Write line to file
  72. file_put_contents($Csv_File, $str, FILE_APPEND);
  73. }
  74. ?>