contentdispenser/admin/api.php

104 lines
4.8 KiB
PHP
Raw Normal View History

2023-06-09 21:45:45 +02:00
<?php
$action = $_POST['action'];
2023-06-10 09:10:10 +02:00
$config = json_decode(file_get_contents("../data/config.json"), true);
if (!empty($action) && $_POST["password"] == $config["admin_pwd"]){
$mysqli = new mysqli($config["mysqlhost"], $config["mysqluser"], $config["mysqlpass"], $config["mysqldb"]);
2023-06-09 21:45:45 +02:00
if ($action == "verify"){
2023-06-10 09:10:10 +02:00
echo "OK";
2023-06-09 21:45:45 +02:00
}
if ($action == "get"){
2023-06-10 09:10:10 +02:00
$stmt1 = $mysqli->prepare("SELECT `LinkID`, `ContentID`, `Nickname` FROM Links");
$stmt1->bind_result($linkid, $contentid, $nickname);
$stmt1->execute();
$stmt1->store_result();
$out = "<table><tbody><tr><th>ID</th><th>Content ID</th><th>Nickname</th><th>Button</th></tr>";
while ($stmt1->fetch()) {
$id = htmlspecialchars($linkid);
$nickname = htmlspecialchars($nickname);
$contentid = htmlspecialchars($contentid);
$out = $out . "<tr><td>$id</td><td>$contentid</td><td>$nickname</td><td><button onclick=\"delthis('$id')\">Delete</button></td></tr>";
2023-06-09 21:45:45 +02:00
}
2023-06-10 09:10:10 +02:00
$out = $out . "<tr><td><input id=\"addid\" placeholder=\"ID\"></td><td><input id=\"addcontentid\" placeholder=\"Content ID\"></td><td><input id=\"addnickname\" placeholder=\"Nickname\"></td><td><button id=\"linkadder\" onclick=\"justadd()\">Add</button></td></tr>";
$out = $out . "</tbody></table>";
echo $out;
2023-06-09 21:45:45 +02:00
}
if ($action == "delete" && !empty($_POST["id"])){
2023-06-10 09:10:10 +02:00
$stmt2 = $mysqli->prepare("DELETE FROM Links WHERE `LinkID` = ?");
$stmt2->bind_param('s', $_POST["id"]);
$stmt2->execute();
$stmt2->store_result();
2023-06-09 21:45:45 +02:00
}
if ($action == "set" && !empty($_POST["id"]) && !empty($_POST["contentid"]) && !empty($_POST["nickname"])){
2023-06-10 09:10:10 +02:00
$stmt3 = $mysqli->prepare("INSERT INTO Links (`LinkID`, `ContentID`, `Nickname`) VALUES (?, ?, ?);");
$stmt3->bind_param('sss', $_POST["id"], $_POST["contentid"], $_POST["nickname"]);
$stmt3->execute();
$stmt3->store_result();
2023-06-09 21:45:45 +02:00
}
if ($action == "getcontent"){
2023-06-10 09:10:10 +02:00
$stmt4 = $mysqli->prepare("SELECT `ContentID`, `Content` FROM Content");
$stmt4->bind_result ($contentid, $content);
$stmt4->execute();
$stmt4->store_result();
$out = "<table><tbody><tr><th>Content ID</th><th>Content</th><th>Button</th></tr>";
while ($stmt4->fetch()) {
$id = htmlspecialchars($contentid);
$content = htmlspecialchars($content);
$out = $out . "<tr><td>$id</td><td>$content</td><td><button onclick=\"delcthis('$id')\">Delete</button></td></tr>";
2023-06-09 21:45:45 +02:00
}
2023-06-10 09:10:10 +02:00
$out = $out . "<tr><td><input id=\"addidc\" placeholder=\"Content ID\"></td><td><textarea id=\"addcontentc\" placeholder=\"Content\"></textarea></td><td><button id=\"contentadder\" onclick=\"justaddc()\">Add</button></td></tr>";
$out = $out . "</tbody></table>";
echo $out;
2023-06-09 21:45:45 +02:00
}
if ($action == "deletecontent" && !empty($_POST["id"])){
2023-06-10 09:10:10 +02:00
$stmt5 = $mysqli->prepare("DELETE FROM Content WHERE `ContentID` = ?");
$stmt5->bind_param('s', $_POST["id"]);
$stmt5->execute();
$stmt5->store_result();
2023-06-09 21:45:45 +02:00
}
if ($action == "setcontent" && !empty($_POST["id"]) && !empty($_POST["content"])){
2023-06-10 09:10:10 +02:00
$stmt6 = $mysqli->prepare("INSERT INTO Content (`ContentID`, `Content`) VALUES (?, ?);");
$stmt6->bind_param('ss', $_POST["id"], $_POST["content"]);
$stmt6->execute();
$stmt6->store_result();
2023-06-09 21:45:45 +02:00
}
2023-06-10 09:46:33 +02:00
if ($action == "getlog"){
$idcko = $_POST["id"];
if (empty($idcko)||$idcko == "*"){
$query = "SELECT `ID`, `Action`, `LinkID`, `ContentID`, `Datetime`, `Timestamp`, `Nickname`, `IP` FROM Logs";
$stmt7 = $mysqli->prepare($query);
}
else{
$query = "SELECT `ID`, `Action`, `LinkID`, `ContentID`, `Datetime`, `Timestamp`, `Nickname`, `IP` FROM Logs WHERE `LinkID` = ?";
2023-06-10 09:48:29 +02:00
$stmt7 = $mysqli->prepare($query);
2023-06-10 09:46:33 +02:00
$stmt7->bind_param("s", $idcko);
}
2023-06-10 09:10:10 +02:00
$stmt7->bind_result ($rowidx, $actionx, $linkidx, $contentidx, $datetimex, $timestampx, $nicknamex, $ipx);
$stmt7->execute();
$stmt7->store_result();
$out = "<table><tbody><tr><th>Action</th><th>Date and Time</th><th>Nickname</th><th>Link</th><th>Content</th><th>IP</th></tr>";
while ($stmt7->fetch()) {
$action = htmlspecialchars($actionx);
$link = htmlspecialchars($linkidx);
$content = htmlspecialchars($contentidx);
$nickname = htmlspecialchars($nicknamex);
$ip = htmlspecialchars($ipx);
$datetime = htmlspecialchars($datetimex);
$out = $out . "<tr><td>$action</td><td>$datetime</td><td>$nickname</td><td>$link</td><td>$content</td><td>$ip</td></tr>";
2023-06-09 21:45:45 +02:00
}
2023-06-10 09:10:10 +02:00
$out = $out . "</tbody></table>";
echo $out;
2023-06-09 21:45:45 +02:00
}
}
2023-06-10 09:10:10 +02:00
else{
echo "ERROR";
}
2023-06-09 21:45:45 +02:00
?>