Inital stuff
This commit is contained in:
commit
f65958a859
6
config.php
Normal file
6
config.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
$servername = "localhost";
|
||||
$username = "username";
|
||||
$password = "password";
|
||||
$dbname = "database";
|
33
endpoint.php
Normal file
33
endpoint.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
require_once("config.php");
|
||||
|
||||
if (isset($_GET["lat"]) && preg_match("/^-?\d+\.\d+$/", $_GET["lat"])
|
||||
&& isset($_GET["lon"]) && preg_match("/^-?\d+\.\d+$/", $_GET["lon"]) ) {
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO tracker (lat, lon) VALUES (" . 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 'Please type this URL in the <a href="https://play.google.com/store/apps/details?id=fr.herverenault.selfhostedgpstracker">Self-Hosted GPS Tracker</a> Android app on your phone.';
|
||||
|
||||
}
|
19
setup.php
Normal file
19
setup.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
include_once("config.php");
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
$sql = "CREATE TABLE tracker ( ts TIMESTAMP PRIMARY KEY DEFAULT CURRENT_TIMESTAMP, lat DOUBLE, lon DOUBLE );";
|
||||
|
||||
if (!mysqli_query($con,$sql)) {
|
||||
die('Error: ' . mysqli_error($con));
|
||||
}
|
||||
|
||||
mysqli_close($conn);
|
||||
|
||||
echo "OK";
|
Loading…
Reference in a new issue