Add auth
This commit is contained in:
parent
bb811b3b46
commit
72a37d9f1a
4 changed files with 35 additions and 25 deletions
31
access.php
31
access.php
|
@ -1,10 +1,14 @@
|
|||
<?php
|
||||
|
||||
$status = 0;
|
||||
|
||||
include_once("config.php");
|
||||
|
||||
if (!$access) {
|
||||
if (!$access)
|
||||
die("Access not enabled in configuration file. Make sure that this page is not public before enabling it.");
|
||||
}
|
||||
|
||||
if ($accessverification)
|
||||
include("auth.php");
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
|
||||
|
@ -21,20 +25,17 @@ if ($result->num_rows > 0) {
|
|||
echo '<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2">
|
||||
<Document>
|
||||
<Style id="yellowPoly">
|
||||
<LineStyle>
|
||||
<color>7f00ffff</color>
|
||||
<width>4</width>
|
||||
</LineStyle>
|
||||
<PolyStyle>
|
||||
<color>7f00ff00</color>
|
||||
</PolyStyle>
|
||||
</Style>
|
||||
<Placemark><styleUrl>#yellowPoly</styleUrl>
|
||||
<Placemark>
|
||||
<ExtendedData>
|
||||
<Data name="styleUrl"><value>#style</value></Data>
|
||||
<Data name="styleHash"><value>1a1ac94e</value></Data>
|
||||
<Data name="stroke"><value>#ffff00</value></Data>
|
||||
<Data name="stroke-opacity"><value>0.4980392156862745</value></Data>
|
||||
<Data name="stroke-width"><value>4</value></Data>
|
||||
<Data name="fill"><value>#00ff00</value></Data>
|
||||
<Data name="fill-opacity"><value>0.4980392156862745</value></Data>
|
||||
</ExtendedData>
|
||||
<LineString>
|
||||
<extrude>1</extrude>
|
||||
<tesselate>1</tesselate>
|
||||
<altitudeMode>absolute</altitudeMode>
|
||||
<coordinates>
|
||||
';
|
||||
|
||||
|
|
|
@ -6,8 +6,12 @@ $password = "password";
|
|||
$dbname = "database";
|
||||
|
||||
$endpoint = True;
|
||||
$access = False;
|
||||
$location = False;
|
||||
$access = True;
|
||||
$location = True;
|
||||
|
||||
$endpointverification = True;
|
||||
$accessverification = True;
|
||||
$locationverification = True;
|
||||
|
||||
$headercode = <<<EOD
|
||||
<!-- Code displayed in header - use for analytics and stuff -->
|
||||
|
|
11
location.php
11
location.php
|
@ -1,16 +1,19 @@
|
|||
<?php
|
||||
|
||||
$status = 1;
|
||||
|
||||
include_once("config.php");
|
||||
|
||||
if (!$location) {
|
||||
if (!$location)
|
||||
die("Location access not enabled in configuration file. Make sure that this page is not public before enabling it.");
|
||||
}
|
||||
|
||||
if ($locationverification)
|
||||
include("auth.php");
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
if ($conn->connect_error)
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
$sql = "SELECT ts, lat, lon FROM tracker WHERE device='" . mysqli_real_escape_string($conn, $_GET["device"]) . "' ORDER BY ts DESC LIMIT 1;";
|
||||
$result = $conn->query($sql);
|
||||
|
|
10
setup.php
10
setup.php
|
@ -8,11 +8,13 @@ if ($conn->connect_error) {
|
|||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
$sql = "CREATE TABLE tracker ( ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, device VARCHAR(38), lat DOUBLE, lon DOUBLE, PRIMARY KEY(ts, device) );";
|
||||
$sql = "CREATE TABLE IF NOT EXISTS tracker ( ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, device VARCHAR(38), lat DOUBLE, lon DOUBLE, PRIMARY KEY(ts, device) );";
|
||||
$sql2 = "CREATE TABLE IF NOT EXISTS users ( user VARCHAR(64) PRIMARY KEY, password VARCHAR(128), admin BOOLEAN );";
|
||||
$sql3 = "CREATE TABLE IF NOT EXISTS device ( device VARCHAR(38) PRIMARY KEY, passkey VARCHAR(128) );";
|
||||
|
||||
if (!mysqli_query($conn, $sql)) {
|
||||
die('Error: ' . mysqli_error($conn));
|
||||
}
|
||||
if (!mysqli_query($conn, $sql)) die('Error: ' . mysqli_error($conn));
|
||||
if (!mysqli_query($conn, $sql2)) die('Error: ' . mysqli_error($conn));
|
||||
if (!mysqli_query($conn, $sql3)) die('Error: ' . mysqli_error($conn));
|
||||
|
||||
mysqli_close($conn);
|
||||
|
||||
|
|
Loading…
Reference in a new issue