Browse Source

Use functions

master
Julien Cabillot 9 months ago
parent
commit
707741aa4c
1 changed files with 18 additions and 17 deletions
  1. 35
      root/push.php

35
root/push.php

@ -1,22 +1,13 @@
<?php
# Obtain the JSON payload from an OwnTracks app POSTed via HTTP
# and insert into database table.
header("Content-type: application/json");
header('Content-type: application/json');
$payload = file_get_contents("php://input");
$data = @json_decode($payload, true);
if ($data['_type'] == 'location') {
file_put_contents('toto', serialize($data));
define('DB_DIR', getenv('DB_DIR'));
$db_dir = getenv('DB_DIR');
# TODO: pour plus tard afin de dynamiser le nom
$db_path = $db_dir.'/db.db';
function store_sqlite3($data) {
$db_path = DB_DIR.'/location-'.date('Y-m').'.db';
$db = new SQLite3($db_path);
# TODO: à commenter quand ready
# TODO: fixer type (https://owntracks.org/booklet/tech/json/)
$db->exec('
CREATE TABLE IF NOT EXISTS history(
tst INTEGER PRIMARY KEY,
@ -47,8 +38,18 @@ if ($data['_type'] == 'location') {
$res = $stm->execute();
}
$response = array();
# optionally add objects to return to the app (e.g.
# friends or cards)
print json_encode($response);
function store_raw($data) {
$db_path = DB_DIR.'/location-'.date('Y-m').'.raw';
file_put_contents('toto', serialize($data));
}
$payload = file_get_contents("php://input");
$data = @json_decode($payload, true);
if ('location' == $data['_type']) {
store_raw($data);
store_sqlite3($data);
}
print json_encode([]);
?>
Loading…
Cancel
Save