317 lines
14 KiB
PHP
317 lines
14 KiB
PHP
<?php
|
|
|
|
$configFile = 'config.php';
|
|
$backupDir = 'config_backups';
|
|
|
|
if (!is_dir($backupDir)) {
|
|
mkdir($backupDir, 0755, true);
|
|
}
|
|
|
|
require $configFile;
|
|
|
|
if (isset($_POST['password'])) {
|
|
if (isset($superuser['admin']['password']) && $_POST['password'] === $superuser['admin']['password']) {
|
|
$_SESSION['logged_in'] = true;
|
|
} else {
|
|
$error = "Falsches Passwort!";
|
|
}
|
|
}
|
|
|
|
if (isset($_GET['logout'])) {
|
|
session_destroy();
|
|
header("Location: " . $_SERVER['PHP_SELF']);
|
|
exit;
|
|
}
|
|
|
|
if (isset($_POST['logout'])) {
|
|
unset($_SESSION['logged_in']);
|
|
header("Location: " . (new getSpecificData())->getReferer());
|
|
exit;
|
|
}
|
|
|
|
if (isset($_POST['save']) && ($_SESSION['logged_in'] ?? false)) {
|
|
copy($configFile, $backupDir . '/config_' . date('Y-m-d_H-i-s') . '.php');
|
|
|
|
$newServices = [];
|
|
$serviceToGroupMapping = [];
|
|
if(isset($_POST['services'])){
|
|
foreach ($_POST['services'] as $id => $s) {
|
|
$finalId = !empty($s['new_id']) ? trim($s['new_id']) : $id;
|
|
if (empty($finalId)) continue;
|
|
$newServices[$finalId] = [
|
|
'name' => $s['name'],
|
|
'active' => isset($s['active']),
|
|
'adminOnly' => isset($s['adminOnly'])
|
|
];
|
|
if(!empty($s['targetGroup'])) {
|
|
$serviceToGroupMapping[$s['targetGroup']][] = $finalId;
|
|
}
|
|
}
|
|
}
|
|
|
|
$newServiceGroups = [];
|
|
if(isset($_POST['serviceGroups'])){
|
|
foreach ($_POST['serviceGroups'] as $id => $groupData) {
|
|
$finalId = !empty($groupData['new_id']) ? trim($groupData['new_id']) : $id;
|
|
if (empty($finalId)) continue;
|
|
$currentServices = $serviceToGroupMapping[$finalId] ?? ($serviceGroups[$id]['services'] ?? []);
|
|
$newServiceGroups[$finalId] = [
|
|
'label' => $groupData['label'],
|
|
'defaultOpen' => isset($groupData['defaultOpen']),
|
|
'services' => array_values(array_unique($currentServices))
|
|
];
|
|
}
|
|
}
|
|
|
|
$newLinkGroups = [];
|
|
if(isset($_POST['linkGroups'])){
|
|
foreach ($_POST['linkGroups'] as $id => $lg) {
|
|
$finalId = !empty($lg['new_id']) ? trim($lg['new_id']) : $id;
|
|
if (empty($finalId)) continue;
|
|
$newLinkGroups[$finalId] = [
|
|
'label' => $lg['label'],
|
|
'color' => $lg['color'],
|
|
'defaultOpen' => isset($lg['defaultOpen'])
|
|
];
|
|
}
|
|
}
|
|
|
|
$newLinkButtons = [];
|
|
if(isset($_POST['linkButtons'])){
|
|
foreach ($_POST['linkButtons'] as $btn) {
|
|
if (empty($btn['label'])) continue;
|
|
$newLinkButtons[] = [
|
|
'label' => $btn['label'],
|
|
'url' => $btn['url'],
|
|
'newTab' => isset($btn['newTab']),
|
|
'adminOnly' => isset($btn['adminOnly']),
|
|
'group' => $btn['group']
|
|
];
|
|
}
|
|
}
|
|
|
|
$content = "<?php\n\n";
|
|
$content .= '$superuser = ' . var_export($superuser, true) . ";\n\n";
|
|
$content .= '$serviceGroups = ' . var_export($newServiceGroups, true) . ";\n\n";
|
|
$content .= '$services = ' . var_export($newServices, true) . ";\n\n";
|
|
$content .= '$linkGroups = ' . var_export($newLinkGroups, true) . ";\n\n";
|
|
$content .= '$linkButtons = ' . var_export($newLinkButtons, true) . ";\n";
|
|
|
|
if (file_put_contents($configFile, $content)) {
|
|
if (function_exists('opcache_invalidate')) { @opcache_invalidate($configFile, true); }
|
|
$_SESSION['status_message'] = "✅ Konfiguration erfolgreich aktualisiert!";
|
|
header("Location: " . $_SERVER['PHP_SELF']);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$message = $_SESSION['status_message'] ?? null;
|
|
unset($_SESSION['status_message']);
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="de">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Admin Site Control</title>
|
|
<link rel="stylesheet" href="style.css">
|
|
</head>
|
|
|
|
<body class="<?= ($_SESSION['dark_mode'] ?? false) ? 'dark-mode' : '' ?>">
|
|
<div class="content">
|
|
<?php if (!($_SESSION['logged_in'] ?? false)): ?>
|
|
<div class="login-container">
|
|
<div class="login-box">
|
|
<form method="post">
|
|
<h2>🔐 Login</h2>
|
|
<?php if(isset($error)): ?>
|
|
<div class="status-msg" style="background:#dc3545; color:#fff;"><?= htmlspecialchars($error) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<input type="password" name="password" placeholder="Passwort" required>
|
|
<button type="submit">Einloggen</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="content">
|
|
<h2>Seitenverwaltung</h2>
|
|
<form method="post">
|
|
<button type="submit" name="logout" id="logoutSiteButton">Logout</button>
|
|
</form>
|
|
<?php if($message): ?><div class="status-msg"><?= htmlspecialchars($message) ?></div><?php endif; ?>
|
|
|
|
<form method="post">
|
|
|
|
<!-- Sidebar Gruppen -->
|
|
<h2>📦 Sidebar Gruppen
|
|
<button type="button" class="btn-add" onclick="addNew('serviceGroup')">+ Neue Gruppe</button>
|
|
</h2>
|
|
<div class="admin-grid" id="container-serviceGroup">
|
|
<?php foreach ($serviceGroups as $id => $group): ?>
|
|
<div class="admin-card">
|
|
<span class="badge">ID: <?= htmlspecialchars($id) ?></span>
|
|
<input type="text" name="serviceGroups[<?= $id ?>][label]"
|
|
value="<?= htmlspecialchars($group['label']) ?>" placeholder="Anzeigename">
|
|
<label>
|
|
<input type="checkbox" name="serviceGroups[<?= $id ?>][defaultOpen]"
|
|
<?= ($group['defaultOpen'] ?? false) ? 'checked' : '' ?>>
|
|
Offen
|
|
</label>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<!-- Sidebar Services -->
|
|
<h2>🖥 Sidebar Services
|
|
<button type="button" class="btn-add" onclick="addNew('service')">+ Neuer Service</button>
|
|
</h2>
|
|
<div class="admin-grid" id="container-service">
|
|
<?php foreach ($services as $id => $s): ?>
|
|
<div class="admin-card">
|
|
<span class="badge">Datei: <?= htmlspecialchars($id) ?>.php</span>
|
|
<input type="text" name="services[<?= $id ?>][name]" value="<?= htmlspecialchars($s['name']) ?>"
|
|
placeholder="Name">
|
|
<label>Sidebar-Gruppe:</label>
|
|
<select name="services[<?= $id ?>][targetGroup]">
|
|
<?php foreach ($serviceGroups as $gid => $g): ?>
|
|
<option value="<?= $gid ?>"
|
|
<?= (isset($g['services']) && in_array($id, $g['services'])) ? 'selected' : '' ?>>
|
|
<?= htmlspecialchars($g['label']) ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<label>
|
|
<input type="checkbox" name="services[<?= $id ?>][active]"
|
|
<?= ($s['active'] ?? false) ? 'checked' : '' ?>>
|
|
Aktiv
|
|
</label>
|
|
|
|
|
<label>
|
|
<input type="checkbox" name="services[<?= $id ?>][adminOnly]"
|
|
<?= ($s['adminOnly'] ?? false) ? 'checked' : '' ?>>
|
|
Nur Admins
|
|
</label>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<!-- Dashboard Kategorien -->
|
|
<h2>🎨 Dashboard Kategorien
|
|
<button type="button" class="btn-add" onclick="addNew('linkGroup')">+ Neue Kategorie</button>
|
|
</h2>
|
|
<div class="admin-grid" id="container-linkGroup">
|
|
<?php foreach ($linkGroups as $id => $lg): ?>
|
|
<div class="admin-card">
|
|
<span class="badge">ID: <?= htmlspecialchars($id) ?></span>
|
|
<input type="text" name="linkGroups[<?= $id ?>][label]"
|
|
value="<?= htmlspecialchars($lg['label']) ?>" placeholder="Gruppen-Label">
|
|
<label>Farbe:</label>
|
|
<input type="color" name="linkGroups[<?= $id ?>][color]"
|
|
value="<?= $lg['color'] ?? '#3498db' ?>">
|
|
<label>
|
|
<input type="checkbox" name="linkGroups[<?= $id ?>][defaultOpen]"
|
|
<?= ($lg['defaultOpen'] ?? false) ? 'checked' : '' ?>>
|
|
Offen
|
|
</label>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<!-- Dashboard Kacheln -->
|
|
<h2>🔘 Dashboard Kacheln
|
|
<button type="button" class="btn-add" onclick="addNew('linkButton')">+ Neue Kachel</button>
|
|
</h2>
|
|
<div class="admin-grid" id="container-linkButton">
|
|
<?php foreach ($linkButtons as $key => $btn): ?>
|
|
<div class="admin-card">
|
|
<input type="text" name="linkButtons[<?= $key ?>][label]"
|
|
value="<?= htmlspecialchars($btn['label']) ?>" placeholder="Name">
|
|
<input type="text" name="linkButtons[<?= $key ?>][url]"
|
|
value="<?= htmlspecialchars($btn['url']) ?>" placeholder="URL">
|
|
<label>Dashboard Kategorie:</label>
|
|
<select name="linkButtons[<?= $key ?>][group]">
|
|
<?php foreach ($linkGroups as $id => $lg): ?>
|
|
<option value="<?= $id ?>" <?= ($btn['group'] == $id) ? 'selected' : '' ?>>
|
|
<?= htmlspecialchars($lg['label']) ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<div style="margin-top:5px;">
|
|
<label>
|
|
<input type="checkbox" name="linkButtons[<?= $key ?>][newTab]"
|
|
<?= ($btn['newTab'] ?? false) ? 'checked' : '' ?>>
|
|
Neuer Tab
|
|
</label>
|
|
|
|
|
<label>
|
|
<input type="checkbox" name="linkButtons[<?= $key ?>][adminOnly]"
|
|
<?= ($btn['adminOnly'] ?? false) ? 'checked' : '' ?>>
|
|
Nur Admins
|
|
</label>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<div class="save-bar">
|
|
<button type="submit" name="save" class="btn-save">💾 Gesamte Konfiguration speichern</button>
|
|
</div>
|
|
|
|
</form>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<script>
|
|
function addNew(type) {
|
|
const container = document.getElementById('container-' + type);
|
|
const tempId = 'new_' + Date.now();
|
|
const card = document.createElement('div');
|
|
card.className = 'admin-card new-item';
|
|
|
|
let html = `<div><span class="badge">Neu hinzufügen</span></div>`;
|
|
|
|
if (type === 'serviceGroup') {
|
|
html +=
|
|
`<input type="text" name="serviceGroups[${tempId}][new_id]" placeholder="ID">
|
|
<input type="text" name="serviceGroups[${tempId}][label]" placeholder="Name">
|
|
<label><input type="checkbox" name="serviceGroups[${tempId}][defaultOpen]" checked> Ausgeklappt</label>`;
|
|
} else if (type === 'service') {
|
|
html += `<input type="text" name="services[${tempId}][new_id]" placeholder="Datei ohne .php">
|
|
<input type="text" name="services[${tempId}][name]" placeholder="Anzeigename">
|
|
<label>Gruppe:</label>
|
|
<select name="services[${tempId}][targetGroup]">
|
|
<?php foreach ($serviceGroups as $gid => $gl): ?>
|
|
<option value="<?= $gid ?>"><?= $gl['label'] ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<label><input type="checkbox" name="services[${tempId}][active]" checked> Aktiv</label>`;
|
|
} else if (type === 'linkGroup') {
|
|
html += `<input type="text" name="linkGroups[${tempId}][new_id]" placeholder="ID">
|
|
<input type="text" name="linkGroups[${tempId}][label]" placeholder="Label">
|
|
<input type="color" name="linkGroups[${tempId}][color]" value="#3498db">`;
|
|
} else if (type === 'linkButton') {
|
|
html += `<input type="text" name="linkButtons[${tempId}][label]" placeholder="Anzeigename">
|
|
<input type="text" name="linkButtons[${tempId}][url]" placeholder="https://...">
|
|
<label>Kategorie:</label>
|
|
<select name="linkButtons[${tempId}][group]">
|
|
<?php foreach ($linkGroups as $gid => $gl): ?>
|
|
<option value="<?= $gid ?>"><?= $gl['label'] ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<label><input type="checkbox" name="linkButtons[${tempId}][newTab]" checked> Tab</label>
|
|
| <label><input type="checkbox" name="linkButtons[${tempId}][adminOnly]"> Nur Admins</label>`;
|
|
}
|
|
|
|
card.innerHTML = html;
|
|
container.appendChild(card);
|
|
card.scrollIntoView({
|
|
behavior: 'smooth'
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
|
|
</html>
|