Add sessions and log deleting

This commit is contained in:
2023-06-10 10:13:00 +02:00
parent 2e2a56a751
commit 5834a92a3f
2 changed files with 51 additions and 20 deletions

View File

@@ -1,11 +1,18 @@
<?php
session_start();
$action = $_POST['action'];
$config = json_decode(file_get_contents("../data/config.json"), true);
if (!empty($action) && $_POST["password"] == $config["admin_pwd"]){
if ($_POST["password"] == $config["admin_pwd"] && $action == "verify"){
echo "OK";
$_SESSION["password"] = $_POST["password"];
}
if (!empty($action) && $_SESSION["password"] == $config["admin_pwd"]){
$mysqli = new mysqli($config["mysqlhost"], $config["mysqluser"], $config["mysqlpass"], $config["mysqldb"]);
if ($action == "verify"){
echo "OK";
if ($action == "hassession"){
echo "YES";
}
if ($action == "get"){
@@ -83,19 +90,26 @@ if (!empty($action) && $_POST["password"] == $config["admin_pwd"]){
$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>";
$out = "<table><tbody><tr><th>Action</th><th>Date and Time</th><th>Nickname</th><th>Link</th><th>Content</th><th>IP</th><th>Button</th></tr>";
while ($stmt7->fetch()) {
$action = htmlspecialchars($actionx);
$link = htmlspecialchars($linkidx);
$content = htmlspecialchars($contentidx);
$nickname = htmlspecialchars($nicknamex);
$ip = htmlspecialchars($ipx);
$rowid = htmlspecialchars($rowidx);
$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>";
$out = $out . "<tr><td>$action</td><td>$datetime</td><td>$nickname</td><td>$link</td><td>$content</td><td>$ip</td><td><button onclick=\"dellog('$rowid')\">Delete</button></td></tr>";
}
$out = $out . "</tbody></table>";
echo $out;
}
if ($action == "deletelog" && !empty($_POST["id"])){
$stmt5 = $mysqli->prepare("DELETE FROM Logs WHERE `ID` = ?");
$stmt5->bind_param('i', $_POST["id"]);
$stmt5->execute();
$stmt5->store_result();
}
}
else{