Some checks failed
CI / PHP Lint (push) Waiting to run
CI / PHP Lint-1 (push) Waiting to run
CI / Unit Tests & Static Analysis (push) Waiting to run
CI / PHP Lint (pull_request) Has been cancelled
CI / PHP Lint-1 (pull_request) Has been cancelled
CI / Unit Tests & Static Analysis (pull_request) Has been cancelled
Frontend, Login/Installer/Updater und der komplette Admin-Bereich nutzen jetzt ein einziges Stylesheet (assets/global.css) statt pro Seite dupliziertem Inline-CSS. Design-System - Tokens für Flächen, Text, Linien, Marke, Status, Radien, Schatten und Layout-Maße; Dark Mode ausschließlich über Tokens (keine !important- Overrides mehr) - Komponenten: Buttons, Formularfelder, Cards, Tabellen, Badges, Alerts, Tabs, Pagination, Modals, Toasts, Statistik-Kacheln, Empty States - Schrift Inter mit System-Fallback Oberfläche - Admin-Shell neu: durchgehende Sidebar mit Marke, gruppierter Navigation und Benutzerbereich; schlanke Topbar mit Breadcrumb - Dashboard: ruhige KPI-Kacheln mit Icon-Chips, Charts an Theme-Farben gekoppelt - Öffentliche Voucher-Seite: App-Topbar, klare Formularstruktur und Ticket-Darstellung des erstellten Codes inkl. QR-Code - Login/Passwort/2FA: zweispaltiges Auth-Layout bzw. Fokus-Karten - Updater und Wartungsmodus im gleichen Look (Wartungsseite bleibt bewusst eigenständig ohne externe Abhängigkeiten) - Emoji-Icons in der UI durch Font-Awesome-Icons ersetzt Nebenbei behoben - Falscher SRI-Hash blockierte qrcode.min.js – QR-Codes wurden auf der Voucher-Seite und bei der 2FA-Einrichtung nie gerendert - assets/global.css wurde in mehreren Admin-Seiten über einen falschen Pfad eingebunden ($adminBase = '' statt '../') - TinyMCE lädt ohne API-Key jetzt die GPL-Variante von cdnjs – kein "valid API key required"-Banner mehr im Einstellungs-Editor - Tabellen in Cards scrollen horizontal statt zu überlaufen Screenshots in docs/screenshots neu erstellt, README aktualisiert (neuer Abschnitt "Design-System", Version 2.5.0). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
316 lines
15 KiB
PHP
316 lines
15 KiB
PHP
<?php
|
||
error_reporting(E_ALL);
|
||
ini_set('display_errors', 0);
|
||
ini_set('log_errors', 1);
|
||
|
||
require_once __DIR__ . '/../config.php';
|
||
require_once __DIR__ . '/../includes/Database.php';
|
||
require_once __DIR__ . '/../includes/Auth.php';
|
||
require_once __DIR__ . '/../includes/UniFiController.php';
|
||
require_once __DIR__ . '/../includes/I18n.php';
|
||
|
||
$auth = new Auth();
|
||
$auth->requireAdmin();
|
||
$db = Database::getInstance();
|
||
$appTitle = $db->getSetting('app_title', 'UniFi Voucher System');
|
||
I18n::init();
|
||
|
||
$error = '';
|
||
$success = '';
|
||
|
||
// Edit site
|
||
if ($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['edit_site'])) {
|
||
if (!$auth->validateCsrfToken($_POST['csrf_token']??'')) {
|
||
$error = __('error_csrf');
|
||
} else {
|
||
try {
|
||
$siteId = (int)$_POST['site_id'];
|
||
$name = trim($_POST['name']);
|
||
$siteIdStr = trim($_POST['site_id_str']);
|
||
$controllerUrl = trim($_POST['controller_url']);
|
||
$username = trim($_POST['username']);
|
||
$password = $_POST['password'];
|
||
$publicAccess = isset($_POST['public_access']) ? 1 : 0;
|
||
if (empty($name)||empty($siteIdStr)||empty($controllerUrl)||empty($username)) throw new Exception(__('error_fill_all'));
|
||
if (!empty($password)) {
|
||
$test = UniFiController::testConnection($controllerUrl,$username,$password,$siteIdStr);
|
||
if ($test !== true) throw new Exception('Verbindung fehlgeschlagen: '.$test);
|
||
$db->execute("UPDATE sites SET name=?,site_id=?,unifi_controller_url=?,unifi_username=?,unifi_password=?,public_access=? WHERE id=?",
|
||
[$name,$siteIdStr,$controllerUrl,$username,Crypto::encrypt($password),$publicAccess,$siteId]);
|
||
} else {
|
||
$db->execute("UPDATE sites SET name=?,site_id=?,unifi_controller_url=?,unifi_username=?,public_access=? WHERE id=?",
|
||
[$name,$siteIdStr,$controllerUrl,$username,$publicAccess,$siteId]);
|
||
}
|
||
$auth->writeAuditLog($_SESSION['user_id'],'site_edit','site',$siteId,"Site {$name} aktualisiert");
|
||
$success = __('sites_updated');
|
||
} catch (Exception $e) { $error = $e->getMessage(); }
|
||
}
|
||
}
|
||
|
||
// Add site
|
||
if ($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['add_site'])) {
|
||
if (!$auth->validateCsrfToken($_POST['csrf_token']??'')) {
|
||
$error = __('error_csrf');
|
||
} else {
|
||
try {
|
||
$name = trim($_POST['name']);
|
||
$siteId = trim($_POST['site_id']);
|
||
$controllerUrl = trim($_POST['controller_url']);
|
||
$username = trim($_POST['username']);
|
||
$password = $_POST['password'];
|
||
$publicAccess = isset($_POST['public_access']) ? 1 : 0;
|
||
if (empty($name)||empty($siteId)||empty($controllerUrl)||empty($username)) throw new Exception(__('error_fill_all'));
|
||
$test = UniFiController::testConnection($controllerUrl,$username,$password,$siteId);
|
||
if ($test !== true) throw new Exception('Verbindung fehlgeschlagen: '.$test);
|
||
$newId = $db->execute("INSERT INTO sites (name,site_id,unifi_controller_url,unifi_username,unifi_password,public_access) VALUES (?,?,?,?,?,?)",
|
||
[$name,$siteId,$controllerUrl,$username,Crypto::encrypt($password),$publicAccess]);
|
||
$auth->writeAuditLog($_SESSION['user_id'],'site_create','site',$newId,"Site {$name} erstellt");
|
||
$success = __('sites_added');
|
||
} catch (Exception $e) { $error = $e->getMessage(); }
|
||
}
|
||
}
|
||
|
||
// Delete site
|
||
if (isset($_GET['delete']) && isset($_GET['token'])) {
|
||
if ($auth->validateCsrfToken($_GET['token'])) {
|
||
$delId = (int)$_GET['delete'];
|
||
$db->query("DELETE FROM sites WHERE id=?", [$delId]);
|
||
$auth->writeAuditLog($_SESSION['user_id'],'site_delete','site',$delId,'Site gelöscht');
|
||
$success = __('sites_deleted');
|
||
} else { $error = __('error_csrf'); }
|
||
}
|
||
|
||
// Toggle site
|
||
if (isset($_GET['toggle']) && isset($_GET['token'])) {
|
||
if ($auth->validateCsrfToken($_GET['token'])) {
|
||
$site = $db->fetchOne("SELECT is_active FROM sites WHERE id=?", [(int)$_GET['toggle']]);
|
||
if ($site) {
|
||
$db->query("UPDATE sites SET is_active=? WHERE id=?", [$site['is_active']?0:1,(int)$_GET['toggle']]);
|
||
$success = 'Site-Status aktualisiert!';
|
||
}
|
||
} else { $error = __('error_csrf'); }
|
||
}
|
||
|
||
$sites = $db->fetchAll("SELECT * FROM sites ORDER BY name");
|
||
$currentPage = 'sites';
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html lang="<?= I18n::getLanguage() ?>">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title><?= __('sites_title') ?> – <?= htmlspecialchars($appTitle) ?></title>
|
||
<?php include __DIR__ . '/../includes/admin_nav.php'; ?>
|
||
|
||
<div class="page-header">
|
||
<h1 class="page-title"><?= __('sites_title') ?></h1>
|
||
<button onclick="openModal()" class="btn btn-primary">
|
||
<i class="fas fa-plus"></i> <?= __('sites_add') ?>
|
||
</button>
|
||
</div>
|
||
|
||
<?php if ($error): ?>
|
||
<div class="alert alert-error"><i class="fas fa-exclamation-circle"></i> <?= htmlspecialchars($error) ?></div>
|
||
<?php endif; ?>
|
||
<?php if ($success): ?>
|
||
<div class="alert alert-success"><i class="fas fa-check-circle"></i> <?= htmlspecialchars($success) ?></div>
|
||
<?php endif; ?>
|
||
|
||
<?php if (empty($sites)): ?>
|
||
<div class="empty-card">
|
||
<i class="fas fa-map-marker-alt" style="font-size:48px;margin-bottom:20px;opacity:.3;display:block;"></i>
|
||
<p><?= __('sites_none') ?></p>
|
||
</div>
|
||
<?php else: ?>
|
||
<div class="sites-grid">
|
||
<?php foreach ($sites as $site): ?>
|
||
<div class="site-card">
|
||
<div class="site-card-header">
|
||
<div>
|
||
<div class="site-name"><?= htmlspecialchars($site['name']) ?></div>
|
||
<div class="site-id-label">ID: <?= htmlspecialchars($site['site_id']) ?></div>
|
||
</div>
|
||
<div>
|
||
<?php if ($site['is_active']): ?>
|
||
<span class="badge badge-success"><i class="fas fa-check"></i> <?= __('status_active') ?></span>
|
||
<?php else: ?>
|
||
<span class="badge badge-warning"><i class="fas fa-pause"></i> <?= __('status_inactive') ?></span>
|
||
<?php endif; ?>
|
||
<?php if ($site['public_access']): ?>
|
||
<span class="badge badge-info"><i class="fas fa-globe"></i> <?= __('status_public') ?></span>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
<div class="site-info">
|
||
<div class="site-info-item">
|
||
<i class="fas fa-server" style="color:var(--accent);width:16px;"></i>
|
||
<span style="word-break:break-all;"><?= htmlspecialchars($site['unifi_controller_url']) ?></span>
|
||
</div>
|
||
<div class="site-info-item">
|
||
<i class="fas fa-user" style="color:var(--accent);width:16px;"></i>
|
||
<span><?= htmlspecialchars($site['unifi_username']) ?></span>
|
||
</div>
|
||
<div class="site-info-item">
|
||
<i class="fas fa-clock" style="color:var(--text-muted);width:16px;"></i>
|
||
<span style="color:var(--text-muted);"><?= date('d.m.Y', strtotime($site['created_at'])) ?></span>
|
||
</div>
|
||
</div>
|
||
<div class="site-actions">
|
||
<button onclick="openEditModal(<?= $site['id'] ?>, '<?= htmlspecialchars($site['name'], ENT_QUOTES) ?>', '<?= htmlspecialchars($site['site_id'], ENT_QUOTES) ?>', '<?= htmlspecialchars($site['unifi_controller_url'], ENT_QUOTES) ?>', '<?= htmlspecialchars($site['unifi_username'], ENT_QUOTES) ?>', <?= $site['public_access'] ?>)"
|
||
class="btn btn-secondary btn-sm">
|
||
<i class="fas fa-edit"></i> <?= __('btn_edit') ?>
|
||
</button>
|
||
<a href="?toggle=<?= $site['id'] ?>&token=<?= $auth->getCsrfToken() ?>"
|
||
class="btn btn-secondary btn-sm">
|
||
<i class="fas fa-<?= $site['is_active'] ? 'pause' : 'play' ?>"></i>
|
||
<?= $site['is_active'] ? __('sites_deactivate') : __('sites_activate') ?>
|
||
</a>
|
||
<a href="?delete=<?= $site['id'] ?>&token=<?= $auth->getCsrfToken() ?>"
|
||
class="btn btn-danger-soft btn-sm"
|
||
onclick="return confirm('Möchten Sie diese Site wirklich löschen?')">
|
||
<i class="fas fa-trash"></i>
|
||
</a>
|
||
</div>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
</main>
|
||
|
||
<!-- Add Site Modal -->
|
||
<div id="addSiteModal" class="modal">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h2 class="modal-title"><?= __('sites_add_title') ?></h2>
|
||
<button class="modal-close" onclick="closeModal('addSiteModal')">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form method="post" id="addSiteForm">
|
||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||
<input type="hidden" name="add_site" value="1">
|
||
<div class="form-group">
|
||
<label><?= __('sites_name') ?></label>
|
||
<input type="text" name="name" required placeholder="z.B. Hauptgebäude">
|
||
</div>
|
||
<div class="form-group">
|
||
<label><?= __('sites_site_id') ?></label>
|
||
<input type="text" name="site_id" required placeholder="z.B. default">
|
||
<small style="color:var(--text-muted);font-size:12px;">Zu finden in der UniFi Controller URL</small>
|
||
</div>
|
||
<div class="form-group">
|
||
<label><?= __('sites_controller') ?></label>
|
||
<input type="url" name="controller_url" required placeholder="https://unifi.example.com:11443">
|
||
<small style="color:var(--text-muted);font-size:12px;">Vollständige URL inkl. Port</small>
|
||
</div>
|
||
<div class="form-grid">
|
||
<div class="form-group">
|
||
<label><?= __('sites_username') ?></label>
|
||
<input type="text" name="username" required placeholder="admin">
|
||
</div>
|
||
<div class="form-group">
|
||
<label><?= __('sites_password') ?></label>
|
||
<input type="password" name="password" required>
|
||
</div>
|
||
</div>
|
||
<div class="form-group checkbox-group">
|
||
<input type="checkbox" id="add_public" name="public_access">
|
||
<label for="add_public" style="margin:0;"><?= __('sites_public') ?></label>
|
||
</div>
|
||
<div style="display:flex;gap:10px;margin-top:20px;">
|
||
<button type="submit" class="btn btn-primary" style="flex:1;" id="addSiteSubmitBtn">
|
||
<i class="fas fa-save"></i> <?= __('sites_add') ?>
|
||
</button>
|
||
<button type="button" onclick="closeModal('addSiteModal')" class="btn btn-secondary"><?= __('btn_cancel') ?></button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Edit Site Modal -->
|
||
<div id="editSiteModal" class="modal">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h2 class="modal-title"><?= __('sites_edit_title') ?></h2>
|
||
<button class="modal-close" onclick="closeModal('editSiteModal')">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form method="post" id="editSiteForm">
|
||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||
<input type="hidden" name="edit_site" value="1">
|
||
<input type="hidden" name="site_id" id="edit_site_id">
|
||
<div class="form-group">
|
||
<label><?= __('sites_name') ?></label>
|
||
<input type="text" id="edit_name" name="name" required>
|
||
</div>
|
||
<div class="form-group">
|
||
<label><?= __('sites_site_id') ?></label>
|
||
<input type="text" id="edit_site_id_str" name="site_id_str" required>
|
||
</div>
|
||
<div class="form-group">
|
||
<label><?= __('sites_controller') ?></label>
|
||
<input type="url" id="edit_controller_url" name="controller_url" required>
|
||
</div>
|
||
<div class="form-grid">
|
||
<div class="form-group">
|
||
<label><?= __('sites_username') ?></label>
|
||
<input type="text" id="edit_username" name="username" required>
|
||
</div>
|
||
<div class="form-group">
|
||
<label><?= __('sites_password_edit') ?></label>
|
||
<input type="password" id="edit_password" name="password" placeholder="Leer lassen = nicht ändern">
|
||
<small style="color:var(--text-muted);font-size:12px;"><?= __('sites_password_hint') ?></small>
|
||
</div>
|
||
</div>
|
||
<div class="form-group checkbox-group">
|
||
<input type="checkbox" id="edit_public_access" name="public_access">
|
||
<label for="edit_public_access" style="margin:0;"><?= __('sites_public') ?></label>
|
||
</div>
|
||
<div style="display:flex;gap:10px;margin-top:20px;">
|
||
<button type="submit" class="btn btn-primary" style="flex:1;" id="editSiteSubmitBtn">
|
||
<i class="fas fa-save"></i> <?= __('btn_save') ?>
|
||
</button>
|
||
<button type="button" onclick="closeModal('editSiteModal')" class="btn btn-secondary"><?= __('btn_cancel') ?></button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="toast-container"></div>
|
||
<script src="../assets/global.js"></script>
|
||
<script>
|
||
function openModal() { document.getElementById('addSiteModal').classList.add('active'); }
|
||
function closeModal(id) { document.getElementById(id).classList.remove('active'); }
|
||
|
||
function openEditModal(id, name, siteIdStr, controllerUrl, username, publicAccess) {
|
||
document.getElementById('edit_site_id').value = id;
|
||
document.getElementById('edit_name').value = name;
|
||
document.getElementById('edit_site_id_str').value = siteIdStr;
|
||
document.getElementById('edit_controller_url').value = controllerUrl;
|
||
document.getElementById('edit_username').value = username;
|
||
document.getElementById('edit_password').value = '';
|
||
document.getElementById('edit_public_access').checked = publicAccess == 1;
|
||
document.getElementById('editSiteModal').classList.add('active');
|
||
}
|
||
|
||
document.getElementById('addSiteForm').addEventListener('submit', function() {
|
||
const btn = document.getElementById('addSiteSubmitBtn');
|
||
btn.disabled = true;
|
||
btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> <?= addslashes(__('sites_testing')) ?>';
|
||
});
|
||
document.getElementById('editSiteForm').addEventListener('submit', function() {
|
||
const btn = document.getElementById('editSiteSubmitBtn');
|
||
btn.disabled = true;
|
||
btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> <?= addslashes(__('sites_testing')) ?>';
|
||
});
|
||
|
||
['addSiteModal','editSiteModal'].forEach(id => {
|
||
document.getElementById(id).addEventListener('click', function(e) {
|
||
if (e.target === this) closeModal(id);
|
||
});
|
||
});
|
||
</script>
|
||
</body>
|
||
</html>
|