gpstools/endpoint.php

39 lines
1 KiB
PHP
Raw Normal View History

2016-01-15 07:11:36 +00:00
<?php
2017-10-08 10:14:04 +00:00
$status = -1;
2016-01-15 07:11:36 +00:00
require_once("config.php");
if (!$endpoint) {
2016-08-14 22:53:18 +00:00
die("Endpoint not enabled in config. You should do something about that.");
}
2016-08-03 17:37:08 +00:00
if (isset($_GET["lat"]) && preg_match("/^-?\d+\.\d+$/", $_GET["lat"]) && isset($_GET["lon"]) && preg_match("/^-?\d+\.\d+$/", $_GET["lon"]) && isset($_GET["device"]) ) {
2016-01-15 07:11:36 +00:00
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
2016-08-05 18:26:10 +00:00
$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']) . ");";
2016-01-15 07:11:36 +00:00
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');
2016-02-07 21:29:56 +00:00
echo 'This is an endpoint for compatible GPS trackers only.';
2016-01-15 07:11:36 +00:00
}