|
|
@ -1,22 +1,13 @@ |
|
|
<?php |
|
|
<?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); |
|
|
$db = new SQLite3($db_path); |
|
|
|
|
|
|
|
|
# TODO: à commenter quand ready
|
|
|
|
|
|
# TODO: fixer type (https://owntracks.org/booklet/tech/json/)
|
|
|
|
|
|
$db->exec(' |
|
|
$db->exec(' |
|
|
CREATE TABLE IF NOT EXISTS history( |
|
|
CREATE TABLE IF NOT EXISTS history( |
|
|
tst INTEGER PRIMARY KEY, |
|
|
tst INTEGER PRIMARY KEY, |
|
|
@ -47,8 +38,18 @@ if ($data['_type'] == 'location') { |
|
|
$res = $stm->execute(); |
|
|
$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([]); |
|
|
?>
|
|
|
?>
|