36 lines
1,013 B
PHP
36 lines
1,013 B
PHP
<?php
|
|
|
|
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.';
|
|
|
|
}
|