2017-01-30 21:36:44 +01:00
|
|
|
<?php
|
|
|
|
/* μlogger
|
|
|
|
*
|
|
|
|
* Copyright(C) 2017 Bartek Fabiszewski (www.fabiszewski.net)
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or modify it under
|
2017-04-07 00:05:28 +02:00
|
|
|
* the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2017-01-30 21:36:44 +01:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
2017-04-07 00:05:28 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2017-01-30 21:36:44 +01:00
|
|
|
*/
|
|
|
|
|
2017-04-09 23:35:55 +02:00
|
|
|
/**
|
|
|
|
* Set response error status and message
|
|
|
|
*
|
|
|
|
* @param array $response Respons
|
|
|
|
* @param string $message Message
|
|
|
|
*/
|
2017-01-30 21:36:44 +01:00
|
|
|
function setError(&$response, $message) {
|
2017-04-09 23:35:55 +02:00
|
|
|
$response['error'] = true;
|
2017-01-30 21:36:44 +01:00
|
|
|
$response['message'] = $message;
|
|
|
|
}
|
|
|
|
|
2017-04-09 23:35:55 +02:00
|
|
|
define("headless", true);
|
2017-04-11 17:00:40 +02:00
|
|
|
require_once(dirname(__DIR__) . "/auth.php"); // sets $mysqli, $user
|
2017-01-30 21:36:44 +01:00
|
|
|
|
|
|
|
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
|
|
|
|
$response = [ 'error' => false ];
|
|
|
|
|
|
|
|
switch ($action) {
|
|
|
|
// action: authorize
|
|
|
|
case "auth":
|
|
|
|
break;
|
|
|
|
|
2017-04-06 18:07:15 +02:00
|
|
|
// action: adduser (currently unused)
|
2017-01-30 21:36:44 +01:00
|
|
|
case "adduser":
|
|
|
|
$login = isset($_REQUEST['login']) ? $_REQUEST['login'] : NULL;
|
2017-04-14 14:00:56 +02:00
|
|
|
$pass = isset($_REQUEST['password']) ? $_REQUEST['password'] : NULL;
|
|
|
|
if (!empty($login) && !empty($pass)) {
|
2017-04-06 18:07:15 +02:00
|
|
|
$newUser = new uUser();
|
2017-04-14 14:00:56 +02:00
|
|
|
$newId = $newUser->add($login, $pass);
|
2017-04-06 18:07:15 +02:00
|
|
|
if ($newId !== false) {
|
|
|
|
// return user id
|
|
|
|
$response['userid'] = $newId;
|
|
|
|
} else {
|
|
|
|
setError($response, "Server error");
|
2017-01-30 21:36:44 +01:00
|
|
|
}
|
|
|
|
} else {
|
2017-04-06 18:07:15 +02:00
|
|
|
setError($response, "Empty login or password");
|
2017-01-30 21:36:44 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// action: addtrack
|
|
|
|
case "addtrack":
|
2017-04-07 16:04:59 +02:00
|
|
|
$trackName = isset($_REQUEST['track']) ? $_REQUEST['track'] : NULL;
|
|
|
|
if (empty($trackName)) {
|
2017-01-30 21:36:44 +01:00
|
|
|
setError($response, "missing required parameter");
|
|
|
|
break;
|
|
|
|
}
|
2017-04-11 17:00:40 +02:00
|
|
|
require_once(ROOT_DIR . "/helpers/track.php");
|
2017-04-07 16:04:59 +02:00
|
|
|
$track = new uTrack();
|
|
|
|
$trackId = $track->add($user->id, $trackName);
|
|
|
|
if ($trackId === false) {
|
|
|
|
setError($response, "Server error");
|
2017-01-30 21:36:44 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// return track id
|
2017-04-07 16:04:59 +02:00
|
|
|
$response['trackid'] = $trackId;
|
2017-01-30 21:36:44 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
// action: addposition
|
|
|
|
case "addpos":
|
|
|
|
$lat = isset($_REQUEST["lat"]) ? $_REQUEST["lat"] : NULL;
|
|
|
|
$lon = isset($_REQUEST["lon"]) ? $_REQUEST["lon"] : NULL;
|
|
|
|
$time = isset($_REQUEST["time"]) ? $_REQUEST["time"] : NULL;
|
|
|
|
$altitude = isset($_REQUEST["altitude"]) ? $_REQUEST["altitude"] : NULL;
|
|
|
|
$speed = isset($_REQUEST["speed"]) ? $_REQUEST["speed"] : NULL;
|
|
|
|
$bearing = isset($_REQUEST["bearing"]) ? $_REQUEST["bearing"] : NULL;
|
|
|
|
$accuracy = isset($_REQUEST["accuracy"]) ? $_REQUEST["accuracy"] : NULL;
|
|
|
|
$provider = isset($_REQUEST["provider"]) ? $_REQUEST["provider"] : NULL;
|
|
|
|
$comment = isset($_REQUEST["comment"]) ? $_REQUEST["comment"] : NULL;
|
2017-04-07 16:04:59 +02:00
|
|
|
$imageId = isset($_REQUEST["imageid"]) ? $_REQUEST["imageid"] : NULL;
|
|
|
|
$trackId = isset($_REQUEST["trackid"]) ? $_REQUEST["trackid"] : NULL;
|
2017-01-30 21:36:44 +01:00
|
|
|
|
2017-04-07 16:04:59 +02:00
|
|
|
if (is_null($lat) || is_null($lon) || is_null($time) || is_null($trackId)) {
|
2017-01-30 21:36:44 +01:00
|
|
|
setError($response, "missing required parameter");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-04-11 17:00:40 +02:00
|
|
|
require_once(ROOT_DIR . "/helpers/position.php");
|
2017-04-07 16:04:59 +02:00
|
|
|
$position = new uPosition();
|
|
|
|
$positionId = $position->add($user->id, $trackId,
|
|
|
|
$time, $lat, $lon, $altitude, $speed, $bearing, $accuracy, $provider, $comment, $imageId);
|
2017-04-09 23:35:55 +02:00
|
|
|
|
2017-04-07 16:04:59 +02:00
|
|
|
if ($positionId === false) {
|
|
|
|
setError($response, "Server error");
|
2017-01-30 21:36:44 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$mysqli->close();
|
|
|
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
echo json_encode($response);
|
|
|
|
exit();
|
|
|
|
?>
|