Reworked managment container
Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
parent
0c06cac2ad
commit
a15af89dd6
7 changed files with 360 additions and 7 deletions
|
@ -1,16 +1,10 @@
|
|||
FROM docker.io/library/php:7.2-apache
|
||||
|
||||
RUN apt-get update -y && apt-get install -y git
|
||||
|
||||
RUN docker-php-ext-install -j$(nproc) mysqli
|
||||
|
||||
WORKDIR /
|
||||
|
||||
RUN git clone https://gitlab.com/merspieler/osm2city-scripts.git && cp /osm2city-scripts/web/index.php /var/www/html/ && rm -rf /osm2city-scripts
|
||||
|
||||
WORKDIR /var/www/html/
|
||||
|
||||
COPY config.php .
|
||||
COPY www/* .
|
||||
|
||||
# Set default env vars
|
||||
ENV SQL_HOST mysql
|
||||
|
|
216
managment/www/api.php
Normal file
216
managment/www/api.php
Normal file
|
@ -0,0 +1,216 @@
|
|||
<?php
|
||||
include("config.php");
|
||||
$API_VERSION = 0.1;
|
||||
|
||||
function quit()
|
||||
{
|
||||
$ret = new stdClass;
|
||||
$ret->success = False;
|
||||
$ret->version = $GLOBALS["API_VERSION"];
|
||||
echo(json_encode($ret));
|
||||
exit();
|
||||
}
|
||||
|
||||
$ret = new stdClass;
|
||||
$ret->success = True;
|
||||
$ret->version = $API_VERSION;
|
||||
|
||||
// Make sure we've got at least auth and an action in the request
|
||||
if (isset($_POST['auth']) && $_POST['auth'] != "" && isset($_POST['action']) && $_POST['action'] != "")
|
||||
{
|
||||
$auth = $_POST['auth'];
|
||||
$action = $_POST['action'];
|
||||
}
|
||||
else
|
||||
{
|
||||
quit();
|
||||
}
|
||||
|
||||
// Connect to DB
|
||||
$con = new mysqli($SQL_SERVER, $SQL_USER, $SQL_PASSWORD, $SQL_DATABASE, $SQL_PORT);
|
||||
if ($con->connect_error)
|
||||
{
|
||||
quit();
|
||||
}
|
||||
|
||||
// Check auth
|
||||
$stmt = $con->prepare("SELECT id FROM auth WHERE token = ?");
|
||||
$stmt->bind_param("s", $auth);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$res = $result->fetch_assoc();
|
||||
$stmt->close();
|
||||
if ($res == Null)
|
||||
{
|
||||
quit();
|
||||
}
|
||||
|
||||
// Setup helper functions
|
||||
function get_lock($con)
|
||||
{
|
||||
$sql = "SELECT GET_LOCK('tile-status-lock', 10)";
|
||||
$ret = $con->query($sql)->fetch_array()[0];
|
||||
if ($ret == 0)
|
||||
{
|
||||
quit();
|
||||
}
|
||||
}
|
||||
|
||||
function rel_lock($con)
|
||||
{
|
||||
$con->query("SELECT RELEASE_LOCK('tile-status-lock')");
|
||||
}
|
||||
|
||||
function set_status($con, $name, $status, $type)
|
||||
{
|
||||
if ($type == "area")
|
||||
{
|
||||
// Get parent ID
|
||||
$sql = "SELECT id FROM secondLevel WHERE name = ?";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bind_param("s", $name);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$stmt->close();
|
||||
if ($result == False)
|
||||
{
|
||||
rel_lock($con);
|
||||
quit();
|
||||
}
|
||||
$pid = $result->fetch_array()[0];
|
||||
|
||||
// Get status ID
|
||||
$sql = "SELECT id FROM status WHERE name = ?";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bind_param("s", $status);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$stmt->close();
|
||||
if ($result == False)
|
||||
{
|
||||
rel_lock($con);
|
||||
quit();
|
||||
}
|
||||
$sid = $result->fetch_array()[0];
|
||||
|
||||
// Update tiles in area
|
||||
$sql = "UPDATE tile SET status_id = ? WHERE parent_id = ?";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bind_param("ii", $sid, $pid);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "UPDATE tile SET status_id = (SELECT id FROM status WHERE name = ?) WHERE id = ?";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bind_param("si", $status, $name);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == "set")
|
||||
{
|
||||
if (isset($_POST['tile']) && $_POST['tile'] != "")
|
||||
{
|
||||
get_lock($con);
|
||||
set_status($con, $_POST['tile'], $_POST['status'], "tile");
|
||||
rel_lock($con);
|
||||
}
|
||||
else if (isset($_POST['area']) && $_POST['area'] != "")
|
||||
{
|
||||
get_lock($con);
|
||||
set_status($con, $_POST['area'], $_POST['status'], "area");
|
||||
rel_lock($con);
|
||||
}
|
||||
else
|
||||
{
|
||||
quit();
|
||||
}
|
||||
}
|
||||
else if ($action == "get-job")
|
||||
{
|
||||
get_lock($con);
|
||||
if (isset($_POST["additional-type"]) && $_POST["additional-type"] != "")
|
||||
{
|
||||
$sql = "SELECT id FROM tile WHERE status_id = (SELECT id FROM status WHERE name = 'pending') OR status_id = (SELECT id FROM status WHERE name = ?) ORDER BY parent_id LIMIT 1";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bind_param("s", $_POST["additional-type"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "SELECT id FROM tile WHERE status_id = (SELECT id FROM status WHERE name = 'pending') ORDER BY parent_id LIMIT 1";
|
||||
$stmt = $con->prepare($sql);
|
||||
}
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$stmt->close();
|
||||
if ($result == False)
|
||||
{
|
||||
quit();
|
||||
}
|
||||
$ret->job = $result->fetch_array()[0];
|
||||
if ($ret->job == Null)
|
||||
{
|
||||
$ret->job = "None";
|
||||
}
|
||||
else
|
||||
{
|
||||
set_status($con, $ret->job, "started", "tile");
|
||||
}
|
||||
rel_lock($con);
|
||||
}
|
||||
else if ($action == "get-done")
|
||||
{
|
||||
$sql = "SELECT name FROM secondLevel WHERE status_id = (SELECT id FROM status WHERE name = 'done') LIMIT 1";
|
||||
$ret->job = $con->query($sql)->fetch_array()[0];
|
||||
if ($ret->job == Null)
|
||||
{
|
||||
$ret->job = "None";
|
||||
}
|
||||
}
|
||||
else if ($action == "status")
|
||||
{
|
||||
if (isset($_POST['tile']) && $_POST['tile'] != "")
|
||||
{
|
||||
$sql = "SELECT name FROM status WHERE id = (SELECT status_id FROM tile WHERE id = ?)";
|
||||
$pattern = "i";
|
||||
$req = $_POST['tile'];
|
||||
}
|
||||
else if (isset($_POST['area']) && $_POST['area'] != "")
|
||||
{
|
||||
$sql = "SELECT name FROM status WHERE id = (SELECT status_id FROM secondLevel WHERE name = ?)";
|
||||
$pattern = "s";
|
||||
$req = $_POST['area'];
|
||||
}
|
||||
else
|
||||
{
|
||||
quit();
|
||||
}
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bind_param($pattern, $req);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
if ($result == False)
|
||||
{
|
||||
quit();
|
||||
}
|
||||
$res = $result->fetch_assoc();
|
||||
$stmt->close();
|
||||
if ($res == Null)
|
||||
{
|
||||
quit();
|
||||
}
|
||||
$ret->status = $res["name"];
|
||||
}
|
||||
else
|
||||
{
|
||||
quit();
|
||||
}
|
||||
|
||||
// https://www.w3schools.com/php/php_mysql_prepared_statements.asp
|
||||
|
||||
$con->close();
|
||||
echo(json_encode($ret));
|
||||
?>
|
92
managment/www/index.php
Normal file
92
managment/www/index.php
Normal file
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
include("config.php");
|
||||
// Returns numbers in string format as needed for file names
|
||||
function clipNumber($number, $length)
|
||||
{
|
||||
$number = abs($number) . "";
|
||||
while (strlen($number) < $length)
|
||||
{
|
||||
$number = "0" . $number;
|
||||
}
|
||||
return $number;
|
||||
}
|
||||
$con = new mysqli($SQL_SERVER, $SQL_USER, $SQL_PASSWORD, $SQL_DATABASE, $SQL_PORT);
|
||||
if ($con->connect_error)
|
||||
{
|
||||
quit();
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Osm2City Worldbuild Progress</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Osm2City Worldbuild Progress</h2>
|
||||
Colors:
|
||||
<table border="0">
|
||||
<?php
|
||||
$sql = "SELECT id, name, color FROM status";
|
||||
$ret = $con->query($sql)->fetch_all(MYSQLI_ASSOC);
|
||||
if ($ret != False)
|
||||
{
|
||||
foreach($ret as $row)
|
||||
{
|
||||
echo '<tr style="background-color: ' . $row["color"] . '"><td>' . $row["name"] . '</td></tr>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
Click on a tile to see it's detailed status.<br/>
|
||||
<ul id="container">
|
||||
<li>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="720" height="450" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
||||
<image width="720" height="450" href="map.png"/>
|
||||
<?php
|
||||
$sql = "SELECT topLevel.name AS name, status.color AS color FROM topLevel JOIN status ON topLevel.status_id = status.id";
|
||||
$ret = $con->query($sql)->fetch_all(MYSQLI_ASSOC);
|
||||
if ($ret != False)
|
||||
{
|
||||
$tiles = [];
|
||||
foreach($ret as $row)
|
||||
{
|
||||
$tiles[$row["name"]] = $row["color"];
|
||||
}
|
||||
}
|
||||
for ($i = 80; $i >= -90; $i -= 10)
|
||||
{
|
||||
if ($i >= 0)
|
||||
{
|
||||
$ns = "n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$ns = "s";
|
||||
}
|
||||
$y = (abs($i - 80) / 10) * 25;
|
||||
for ($j = -180; $j <= 170; $j += 10)
|
||||
{
|
||||
if ($j < 0)
|
||||
{
|
||||
$ew = "w";
|
||||
}
|
||||
else
|
||||
{
|
||||
$ew = "e";
|
||||
}
|
||||
$x = 700 - (abs($j - 170) / 10) * 20;
|
||||
$name = $ew . clipNumber($j, 3) . $ns . clipNumber($i, 2);
|
||||
echo '<a href="progressinfo.php?tile=' . $name . '" target="progressinfo"><rect x="' . $x . '" y="' . $y . '" width="20" height="25" style="fill: ' . $tiles[$name] . '; opacity: 0.5;"/></a>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</svg>
|
||||
</li>
|
||||
<li>
|
||||
<iframe name="progressinfo" style="border: 0px; height: 450px; width: 100%;" src="progressinfo.php"></iframe>
|
||||
</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
BIN
managment/www/map.png
Normal file
BIN
managment/www/map.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 164 KiB |
45
managment/www/progressinfo.php
Normal file
45
managment/www/progressinfo.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
include("config.php");
|
||||
if (isset($_GET['tile']))
|
||||
{
|
||||
$tile = $_GET['tile'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$tile = "None";
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="style.css"/>
|
||||
</head>
|
||||
<body padding="0" margin="0">
|
||||
<?php
|
||||
if ($tile == "None")
|
||||
{
|
||||
echo "No tile selected";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Connect to DB
|
||||
$con = new mysqli($SQL_SERVER, $SQL_USER, $SQL_PASSWORD, $SQL_DATABASE, $SQL_PORT);
|
||||
if ($con->connect_error)
|
||||
{
|
||||
quit();
|
||||
}
|
||||
$stmt = $con->prepare("SELECT status.name AS status, COUNT(*) AS sCount, status.color AS color FROM secondLevel JOIN status ON secondLevel.status_id = status.id WHERE secondLevel.parent_id = (SELECT id FROM topLevel WHERE name = ?) GROUP BY status.id");
|
||||
$stmt->bind_param("s", $tile);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$ret = $result->fetch_all(MYSQLI_ASSOC);
|
||||
echo '<table border="1"><tr><td>Tile Name</td><td>' . $tile . '</td></tr>';
|
||||
foreach ($ret as $row)
|
||||
{
|
||||
echo '<tr style="background-color: ' . $row["color"] . '"><td>' . $row["status"] . '</td><td>' . $row["sCount"] . '</td></tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
6
managment/www/style.css
Normal file
6
managment/www/style.css
Normal file
|
@ -0,0 +1,6 @@
|
|||
#container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
list-style: none;
|
||||
align-content: flex-start;
|
||||
}
|
Loading…
Reference in a new issue