106 lines
5.0 KiB
PHP
106 lines
5.0 KiB
PHP
<?php
|
|
$action = $_POST['action'];
|
|
if (!empty($action)){
|
|
$config = json_decode(file_get_contents("../data/config.json"), true);
|
|
|
|
if ($action == "verify"){
|
|
if ($_POST["password"] == $config["admin_pwd"]){
|
|
echo "OK";
|
|
}
|
|
else{
|
|
echo "ERROR";
|
|
}
|
|
}
|
|
|
|
if ($action == "get"){
|
|
if ($_POST["password"] == $config["admin_pwd"]){
|
|
if(!file_exists("../data/pageindex.json")){
|
|
file_put_contents("../data/pageindex.json", "{}");
|
|
}
|
|
$stranky = json_decode(file_get_contents("../data/pageindex.json"), true);
|
|
$out = "<table><tbody><tr><th>ID</th><th>Content ID</th><th>Nickname</th><th>Button</th></tr>";
|
|
foreach($stranky as $idx => $arr) {
|
|
$id = htmlspecialchars($idx);
|
|
$nickname = htmlspecialchars($arr["nickname"]);
|
|
$contentid = htmlspecialchars($arr["contentid"]);
|
|
$out = $out . "<tr><td>$id</td><td>$contentid</td><td>$nickname</td><td><button onclick=\"delthis('$id')\">Delete</button></td></tr>";
|
|
}
|
|
$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;
|
|
}
|
|
}
|
|
|
|
if ($action == "delete" && !empty($_POST["id"])){
|
|
if ($_POST["password"] == $config["admin_pwd"]){
|
|
$stranky = json_decode(file_get_contents("../data/pageindex.json"), true);
|
|
unset($stranky[$_POST["id"]]);
|
|
file_put_contents("../data/pageindex.json", json_encode($stranky, JSON_PRETTY_PRINT));
|
|
}
|
|
}
|
|
|
|
if ($action == "set" && !empty($_POST["id"]) && !empty($_POST["contentid"]) && !empty($_POST["nickname"])){
|
|
if ($_POST["password"] == $config["admin_pwd"]){
|
|
$stranky = json_decode(file_get_contents("../data/pageindex.json"), true);
|
|
$tmp = array("contentid"=>$_POST["contentid"], "nickname"=>$_POST["nickname"]);
|
|
$stranky[$_POST["id"]] = $tmp;
|
|
file_put_contents("../data/pageindex.json", json_encode($stranky, JSON_PRETTY_PRINT));
|
|
}
|
|
}
|
|
|
|
if ($action == "getcontent"){
|
|
if(!file_exists("../data/contents.json")){
|
|
file_put_contents("../data/contents.json", "{}");
|
|
}
|
|
if ($_POST["password"] == $config["admin_pwd"]){
|
|
$contents = json_decode(file_get_contents("../data/contents.json"), true);
|
|
$out = "<table><tbody><tr><th>Content ID</th><th>Content</th><th>Button</th></tr>";
|
|
foreach($contents as $idx => $content) {
|
|
$id = htmlspecialchars($idx);
|
|
$content = htmlspecialchars($content);
|
|
$out = $out . "<tr><td>$id</td><td>$content</td><td><button onclick=\"delcthis('$id')\">Delete</button></td></tr>";
|
|
}
|
|
$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;
|
|
}
|
|
}
|
|
|
|
if ($action == "deletecontent" && !empty($_POST["id"])){
|
|
if ($_POST["password"] == $config["admin_pwd"]){
|
|
$contents = json_decode(file_get_contents("../data/contents.json"), true);
|
|
unset($contents[$_POST["id"]]);
|
|
file_put_contents("../data/contents.json", json_encode($contents, JSON_PRETTY_PRINT));
|
|
}
|
|
}
|
|
|
|
if ($action == "setcontent" && !empty($_POST["id"]) && !empty($_POST["content"])){
|
|
if ($_POST["password"] == $config["admin_pwd"]){
|
|
$contents = json_decode(file_get_contents("../data/contents.json"), true);
|
|
$contents[$_POST["id"]] = $_POST["content"];
|
|
file_put_contents("../data/contents.json", json_encode($contents, JSON_PRETTY_PRINT));
|
|
}
|
|
}
|
|
|
|
if ($action == "getlog"&& !empty($_POST["id"])){
|
|
if(!file_exists("../data/logs.json")){
|
|
file_put_contents("../data/logs.json", "{}");
|
|
}
|
|
if ($_POST["password"] == $config["admin_pwd"]){
|
|
$logy = json_decode(file_get_contents("../data/logs.json"), true)[$_POST["id"]];
|
|
$out = "<table><tbody><tr><th>Action</th><th>Date and Time</th><th>Nickname</th><th>Link</th><th>IP</th></tr>";
|
|
foreach($logy as $arr) {
|
|
$action = htmlspecialchars($arr["action"]);
|
|
$link = htmlspecialchars($arr["link"]);
|
|
$nickname = htmlspecialchars($arr["nickname"]);
|
|
$ip = htmlspecialchars($arr["ip"]);
|
|
$datetime = htmlspecialchars($arr["datetime"]);
|
|
$out = $out . "<tr><td>$action</td><td>$datetime</td><td>$nickname</td><td>$link</td><td>$ip</td></tr>";
|
|
}
|
|
$out = $out . "</tbody></table>";
|
|
echo $out;
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|