|
|
@@ -3,7 +3,7 @@ require_once __DIR__ . "/../config.php";
|
|
|
require_once __DIR__ . "/../includes/functions.php";
|
|
|
|
|
|
// Check admin login
|
|
|
-if (!isset($_SESSION["admin_logged_in"]) || !$_SESSION["admin_logged_in"]) {
|
|
|
+if (!isset($_SESSION['admin_logged_in']) || !$_SESSION['admin_logged_in']) {
|
|
|
header("Location: login.php");
|
|
|
exit();
|
|
|
}
|
|
|
@@ -24,20 +24,20 @@ function isValidAdminEmailInput($email)
|
|
|
return isValidAdminEmail($email);
|
|
|
}
|
|
|
|
|
|
-if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|
|
+if ($_SERVER['REQUEST_METHOD'] === "POST") {
|
|
|
// Validate CSRF token
|
|
|
- if (!validateCsrfToken($_POST["csrf_token"] ?? "")) {
|
|
|
+ if (!validateCsrfToken($_POST['csrf_token'] ?? "")) {
|
|
|
$message = "Ungültiges Token. Bitte versuchen Sie es erneut.";
|
|
|
$messageType = "error";
|
|
|
} else {
|
|
|
- if (isset($_POST["add_admin"])) {
|
|
|
- $username = normalizeAdminUsername($_POST["username"] ?? "");
|
|
|
+ if (isset($_POST['add_admin'])) {
|
|
|
+ $username = normalizeAdminUsername($_POST['username'] ?? "");
|
|
|
$description = normalizeAdminDescription(
|
|
|
- $_POST["description"] ?? "",
|
|
|
+ $_POST['description'] ?? "",
|
|
|
);
|
|
|
- $email = normalizeAdminEmail($_POST["email"] ?? "");
|
|
|
- $password = $_POST["password"] ?? "";
|
|
|
- $passwordConfirm = $_POST["password_confirm"] ?? "";
|
|
|
+ $email = normalizeAdminEmail($_POST['email'] ?? "");
|
|
|
+ $password = $_POST['password'] ?? "";
|
|
|
+ $passwordConfirm = $_POST['password_confirm'] ?? "";
|
|
|
|
|
|
if (!isValidAdminUsername($username)) {
|
|
|
$message =
|
|
|
@@ -67,24 +67,28 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|
|
"description" => $description,
|
|
|
"email" => $email,
|
|
|
];
|
|
|
- saveAdminAccounts($adminAccounts);
|
|
|
- logAccess("Admin added admin account", [
|
|
|
- "username" => $username,
|
|
|
- "description" => $description,
|
|
|
- ]);
|
|
|
- $message = "Admin wurde erfolgreich angelegt.";
|
|
|
- $messageType = "success";
|
|
|
+ if (saveAdminAccounts($adminAccounts)) {
|
|
|
+ logAccess("Admin added admin account", [
|
|
|
+ "username" => $username,
|
|
|
+ "description" => $description,
|
|
|
+ ]);
|
|
|
+ $message = "Admin wurde erfolgreich angelegt.";
|
|
|
+ $messageType = "success";
|
|
|
+ } else {
|
|
|
+ $message = "Admin konnte nicht gespeichert werden.";
|
|
|
+ $messageType = "error";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (isset($_POST["update_description"])) {
|
|
|
+ if (isset($_POST['update_description'])) {
|
|
|
$targetUsername = normalizeAdminUsername(
|
|
|
- $_POST["target_username"] ?? "",
|
|
|
+ $_POST['target_username'] ?? "",
|
|
|
);
|
|
|
$description = normalizeAdminDescription(
|
|
|
- $_POST["description"] ?? "",
|
|
|
+ $_POST['description'] ?? "",
|
|
|
);
|
|
|
- $email = normalizeAdminEmail($_POST["email"] ?? "");
|
|
|
+ $email = normalizeAdminEmail($_POST['email'] ?? "");
|
|
|
|
|
|
if (!isset($adminAccounts[$targetUsername])) {
|
|
|
$message = "Admin nicht gefunden.";
|
|
|
@@ -98,21 +102,25 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|
|
} else {
|
|
|
$adminAccounts[$targetUsername]["description"] = $description;
|
|
|
$adminAccounts[$targetUsername]["email"] = $email;
|
|
|
- saveAdminAccounts($adminAccounts);
|
|
|
- logAccess("Admin updated admin description", [
|
|
|
- "username" => $targetUsername,
|
|
|
- ]);
|
|
|
- $message = "Beschreibung und E-Mail wurden aktualisiert.";
|
|
|
- $messageType = "success";
|
|
|
+ if (saveAdminAccounts($adminAccounts)) {
|
|
|
+ logAccess("Admin updated admin description", [
|
|
|
+ "username" => $targetUsername,
|
|
|
+ ]);
|
|
|
+ $message = "Beschreibung und E-Mail wurden aktualisiert.";
|
|
|
+ $messageType = "success";
|
|
|
+ } else {
|
|
|
+ $message = "Änderungen konnten nicht gespeichert werden.";
|
|
|
+ $messageType = "error";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (isset($_POST["change_password"])) {
|
|
|
+ if (isset($_POST['change_password'])) {
|
|
|
$targetUsername = normalizeAdminUsername(
|
|
|
- $_POST["target_username"] ?? "",
|
|
|
+ $_POST['target_username'] ?? "",
|
|
|
);
|
|
|
- $newPassword = $_POST["new_password"] ?? "";
|
|
|
- $newPasswordConfirm = $_POST["new_password_confirm"] ?? "";
|
|
|
+ $newPassword = $_POST['new_password'] ?? "";
|
|
|
+ $newPasswordConfirm = $_POST['new_password_confirm'] ?? "";
|
|
|
|
|
|
if (!isset($adminAccounts[$targetUsername])) {
|
|
|
$message = "Admin nicht gefunden.";
|
|
|
@@ -127,18 +135,22 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|
|
$adminAccounts[$targetUsername][
|
|
|
"password_hash"
|
|
|
] = password_hash($newPassword, PASSWORD_BCRYPT);
|
|
|
- saveAdminAccounts($adminAccounts);
|
|
|
- logAccess("Admin changed admin password", [
|
|
|
- "username" => $targetUsername,
|
|
|
- ]);
|
|
|
- $message = "Passwort wurde aktualisiert.";
|
|
|
- $messageType = "success";
|
|
|
+ if (saveAdminAccounts($adminAccounts)) {
|
|
|
+ logAccess("Admin changed admin password", [
|
|
|
+ "username" => $targetUsername,
|
|
|
+ ]);
|
|
|
+ $message = "Passwort wurde aktualisiert.";
|
|
|
+ $messageType = "success";
|
|
|
+ } else {
|
|
|
+ $message = "Passwort konnte nicht gespeichert werden.";
|
|
|
+ $messageType = "error";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (isset($_POST["delete_admin"])) {
|
|
|
+ if (isset($_POST['delete_admin'])) {
|
|
|
$targetUsername = normalizeAdminUsername(
|
|
|
- $_POST["target_username"] ?? "",
|
|
|
+ $_POST['target_username'] ?? "",
|
|
|
);
|
|
|
|
|
|
if (!isset($adminAccounts[$targetUsername])) {
|
|
|
@@ -146,24 +158,29 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|
|
$messageType = "error";
|
|
|
} else {
|
|
|
unset($adminAccounts[$targetUsername]);
|
|
|
- saveAdminAccounts($adminAccounts);
|
|
|
- logAccess("Admin deleted admin account", [
|
|
|
- "username" => $targetUsername,
|
|
|
- ]);
|
|
|
+ if (!saveAdminAccounts($adminAccounts)) {
|
|
|
+ $message = "Admin konnte nicht gelöscht werden.";
|
|
|
+ $messageType = "error";
|
|
|
+ $adminAccounts = getAdminAccounts();
|
|
|
+ } else {
|
|
|
+ logAccess("Admin deleted admin account", [
|
|
|
+ "username" => $targetUsername,
|
|
|
+ ]);
|
|
|
|
|
|
- if (
|
|
|
- isset($_SESSION["admin_username"]) &&
|
|
|
- $_SESSION["admin_username"] === $targetUsername
|
|
|
- ) {
|
|
|
- $_SESSION["admin_logged_in"] = false;
|
|
|
- unset($_SESSION["admin_username"]);
|
|
|
- session_destroy();
|
|
|
- header("Location: login.php");
|
|
|
- exit();
|
|
|
- }
|
|
|
+ if (
|
|
|
+ isset($_SESSION['admin_username']) &&
|
|
|
+ $_SESSION['admin_username'] === $targetUsername
|
|
|
+ ) {
|
|
|
+ $_SESSION['admin_logged_in'] = false;
|
|
|
+ unset($_SESSION['admin_username']);
|
|
|
+ session_destroy();
|
|
|
+ header("Location: login.php");
|
|
|
+ exit();
|
|
|
+ }
|
|
|
|
|
|
- $message = "Admin wurde gelöscht.";
|
|
|
- $messageType = "success";
|
|
|
+ $message = "Admin wurde gelöscht.";
|
|
|
+ $messageType = "success";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -171,13 +188,13 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-$currentAdmin = isset($_SESSION["admin_username"])
|
|
|
- ? normalizeAdminUsername($_SESSION["admin_username"])
|
|
|
+$currentAdmin = isset($_SESSION['admin_username'])
|
|
|
+ ? normalizeAdminUsername($_SESSION['admin_username'])
|
|
|
: "";
|
|
|
-$changeUsername = normalizeAdminUsername($_GET["change"] ?? "");
|
|
|
+$changeUsername = normalizeAdminUsername($_GET['change'] ?? "");
|
|
|
$selectedChangeUser = null;
|
|
|
$editDescriptionUsername = normalizeAdminUsername(
|
|
|
- $_GET["edit_description"] ?? "",
|
|
|
+ $_GET['edit_description'] ?? "",
|
|
|
);
|
|
|
$selectedDescriptionUser = null;
|
|
|
|