tracks/root/push.php
Julien Cabillot 0685a316e8
All checks were successful
Web/tracks/pipeline/head This commit looks good
.
2020-04-17 14:02:53 -04:00

55 lines
1.4 KiB
PHP

<?php
# Obtain the JSON payload from an OwnTracks app POSTed via HTTP
# and insert into database table.
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));
$db_dir = getenv('DB_DIR');
# TODO: pour plus tard afin de dynamiser le nom
$db_path = $db_dir.'/db.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,
lat FLOAT,
lon FLOAT,
acc INTEGER
)
');
$stm = $db->prepare('
INSERT INTO history(
tst,
lat,
lon,
acc
)
VALUES (
:tst,
:lat,
:lon,
:acc
)
');
$stm->bindValue(':tst', $data['tst'], SQLITE3_INTEGER);
$stm->bindValue(':lat', $data['lat'], SQLITE3_FLOAT);
$stm->bindValue(':lon', $data['lon'], SQLITE3_FLOAT);
$stm->bindValue(':acc', $data['acc'], SQLITE3_INTEGER);
$res = $stm->execute();
}
$response = array();
# optionally add objects to return to the app (e.g.
# friends or cards)
print json_encode($response);
?>