Owntracks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.2 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
  1. <?php
  2. header('Content-type: application/json');
  3. define('DB_DIR', getenv('DB_DIR'));
  4. function store_sqlite3($data) {
  5. $db_path = DB_DIR.'/location-'.date('Y-m').'.db';
  6. $db = new SQLite3($db_path);
  7. $db->exec('
  8. CREATE TABLE IF NOT EXISTS history(
  9. tst INTEGER PRIMARY KEY,
  10. lat FLOAT,
  11. lon FLOAT,
  12. acc INTEGER
  13. )
  14. ');
  15. $stm = $db->prepare('
  16. INSERT INTO history(
  17. tst,
  18. lat,
  19. lon,
  20. acc
  21. )
  22. VALUES (
  23. :tst,
  24. :lat,
  25. :lon,
  26. :acc
  27. )
  28. ');
  29. $stm->bindValue(':tst', $data['tst'], SQLITE3_INTEGER);
  30. $stm->bindValue(':lat', $data['lat'], SQLITE3_FLOAT);
  31. $stm->bindValue(':lon', $data['lon'], SQLITE3_FLOAT);
  32. $stm->bindValue(':acc', $data['acc'], SQLITE3_INTEGER);
  33. $res = $stm->execute();
  34. }
  35. function store_raw($data) {
  36. $db_path = DB_DIR.'/location-'.date('Y-m').'.raw';
  37. file_put_contents($db_path, serialize($data), FILE_APPEND);
  38. }
  39. $payload = file_get_contents("php://input");
  40. $data = @json_decode($payload, true);
  41. if ('location' == $data['_type']) {
  42. store_raw($data);
  43. store_sqlite3($data);
  44. }
  45. print json_encode([]);
  46. ?>