gpstools/endpoint.php
Klaus-Uwe Mitterer e944c119fd Fix endpoint...
2017-10-08 12:14:04 +02:00

39 lines
1 KiB
PHP

<?php
$status = -1;
require_once("config.php");
if (!$endpoint) {
die("Endpoint not enabled in config. You should do something about that.");
}
if (isset($_GET["lat"]) && preg_match("/^-?\d+\.\d+$/", $_GET["lat"]) && isset($_GET["lon"]) && preg_match("/^-?\d+\.\d+$/", $_GET["lon"]) && isset($_GET["device"]) ) {
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO tracker (device, lat, lon) VALUES ('" . mysqli_real_escape_string($conn, $_GET['device']) . "', " . mysqli_real_escape_string($conn, $_GET['lat']) . ", " . mysqli_real_escape_string($conn, $_GET['lon']) . ");";
if (!mysqli_query($conn, $sql)) {
die('Error: ' . mysqli_error($conn));
}
mysqli_close($conn);
echo "OK";
} elseif (isset($_GET["tracker"])) {
echo "OK";
} else {
header('HTTP/1.0 400 Bad Request');
echo 'This is an endpoint for compatible GPS trackers only.';
}