deploy
All checks were successful
Deploy / deploy-staging (push) Successful in 24s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-06-20 01:50:07 +02:00
parent 3f81f7a670
commit 2cdd14c400
210 changed files with 55853 additions and 36 deletions

View File

@@ -0,0 +1,128 @@
<?php
$moduleName = (string)($_GET['module'] ?? '');
$module = modules()->get($moduleName);
$notice = null;
require_admin();
if (!$module) {
http_response_code(404);
echo '<div class="card">Modul nicht gefunden.</div>';
return;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$selectedUsers = is_array($_POST['auth_user_values'] ?? null) ? $_POST['auth_user_values'] : [];
$selectedGroups = is_array($_POST['auth_group_values'] ?? null) ? $_POST['auth_group_values'] : [];
$manualUsers = (string)($_POST['auth_users'] ?? '');
$manualGroups = (string)($_POST['auth_groups'] ?? '');
modules()->saveAuth($moduleName, [
'required' => isset($_POST['auth_required']),
'users' => array_merge($selectedUsers, preg_split('/[,\\n]+/', $manualUsers) ?: []),
'groups' => array_merge($selectedGroups, preg_split('/[,\\n]+/', $manualGroups) ?: []),
]);
$notice = 'Zugriff gespeichert.';
$module = modules()->get($moduleName) ?: $module;
}
$authConfig = is_array($module['auth'] ?? null) ? $module['auth'] : ['required' => false, 'users' => [], 'groups' => []];
$allowedUsers = is_array($authConfig['users'] ?? null) ? array_values(array_filter(array_map('strval', $authConfig['users']))) : [];
$allowedGroups = is_array($authConfig['groups'] ?? null) ? array_values(array_filter(array_map('strval', $authConfig['groups']))) : [];
$knownUsers = modules()->knownAuthUsers();
$knownGroups = modules()->knownAuthGroups();
$currentUser = auth_user();
if (is_array($currentUser) && trim((string)($currentUser['sub'] ?? '')) !== '') {
$currentSub = (string)$currentUser['sub'];
$hasCurrentUser = false;
foreach ($knownUsers as $knownUser) {
if ((string)($knownUser['sub'] ?? '') === $currentSub) {
$hasCurrentUser = true;
break;
}
}
if (!$hasCurrentUser) {
$knownUsers[] = [
'sub' => $currentSub,
'username' => (string)($currentUser['username'] ?? ''),
'email' => (string)($currentUser['email'] ?? ''),
'name' => (string)($currentUser['name'] ?? ''),
'groups' => is_array($currentUser['groups'] ?? null) ? $currentUser['groups'] : [],
];
}
}
$knownGroups = array_values(array_unique(array_merge($knownGroups, auth_groups())));
sort($knownGroups, SORT_NATURAL | SORT_FLAG_CASE);
$knownUserValues = array_column($knownUsers, 'sub');
$manualUsers = array_values(array_filter($allowedUsers, fn (string $value): bool => !in_array($value, $knownUserValues, true)));
$manualGroups = array_values(array_filter($allowedGroups, fn (string $value): bool => !in_array($value, $knownGroups, true)));
?>
<div class="card">
<div class="pill">Zugriff</div>
<h1 style="margin-top:.75rem;"><?= e($module['title']) ?> - Zugriffsrechte</h1>
<p class="muted">Diese Seite ist nur fuer eingeloggte Mitglieder der Gruppe <?= e(app()->config()->oidcAdminGroup) ?> verfuegbar.</p>
<?php if ($notice): ?>
<div class="card" style="margin-top:1rem; border-color:var(--accent-2);">
<?= e($notice) ?>
</div>
<?php endif; ?>
<form method="post" style="margin-top:1rem; display:grid; gap:14px; max-width:520px;">
<label class="muted" style="display:flex; align-items:center; gap:10px;">
<input type="checkbox" name="auth_required" value="1" <?= !empty($authConfig['required']) ? 'checked' : '' ?>>
<span>Login fuer dieses Modul erforderlich</span>
</label>
<div class="muted" style="display:grid; gap:8px;">
<span>Erlaubte Benutzer</span>
<?php if ($knownUsers === []): ?>
<small class="muted">Noch keine Keycloak-User bekannt. User erscheinen hier, nachdem sie sich einmal angemeldet haben.</small>
<?php else: ?>
<div style="display:grid; gap:6px;">
<?php foreach ($knownUsers as $knownUser): ?>
<?php
$sub = (string)($knownUser['sub'] ?? '');
$label = trim((string)($knownUser['name'] ?? ''));
if ($label === '') {
$label = trim((string)($knownUser['username'] ?? ''));
}
$email = trim((string)($knownUser['email'] ?? ''));
$suffix = $email !== '' && $email !== $label ? ' (' . $email . ')' : '';
?>
<label style="display:flex; align-items:center; gap:10px;">
<input type="checkbox" name="auth_user_values[]" value="<?= e($sub) ?>" <?= in_array($sub, $allowedUsers, true) ? 'checked' : '' ?>>
<span><?= e(($label !== '' ? $label : $sub) . $suffix) ?></span>
</label>
<?php endforeach; ?>
</div>
<?php endif; ?>
<textarea name="auth_users" rows="3" placeholder="Weitere Keycloak-Sub, Benutzername oder E-Mail, je Zeile oder Komma"><?= e(implode("\n", $manualUsers)) ?></textarea>
</div>
<div class="muted" style="display:grid; gap:8px;">
<span>Erlaubte Gruppen</span>
<?php if ($knownGroups === []): ?>
<small class="muted">Noch keine Keycloak-Gruppen bekannt. Gruppen werden aus angemeldeten Usern und gespeicherten Modulrechten gesammelt.</small>
<?php else: ?>
<div style="display:grid; gap:6px;">
<?php foreach ($knownGroups as $knownGroup): ?>
<label style="display:flex; align-items:center; gap:10px;">
<input type="checkbox" name="auth_group_values[]" value="<?= e($knownGroup) ?>" <?= in_array($knownGroup, $allowedGroups, true) ? 'checked' : '' ?>>
<span><?= e($knownGroup) ?></span>
</label>
<?php endforeach; ?>
</div>
<?php endif; ?>
<textarea name="auth_groups" rows="3" placeholder="Weitere Gruppen, je Zeile oder Komma"><?= e(implode("\n", $manualGroups)) ?></textarea>
</div>
<small class="muted">Wenn Login aktiv ist und Benutzer/Gruppen leer bleiben, darf jeder eingeloggte Benutzer das Modul oeffnen.</small>
<div style="display:flex; gap:10px;">
<button class="cta-button" type="submit">Zugriff speichern</button>
<a class="nav-link" href="/modules/setup/<?= e($moduleName) ?>">Setup</a>
<a class="nav-link" href="/modules">Zurück</a>
</div>
</form>
</div>

View File

@@ -0,0 +1,158 @@
<?php
$modules = modules()->all();
$error = null;
$notice = null;
$GLOBALS['layout_header_base_title'] = 'Modulverwaltung';
$GLOBALS['layout_header_title'] = 'Modulverwaltung';
$GLOBALS['layout_header_context'] = 'Aktive Module';
$GLOBALS['layout_header_text'] = '';
$GLOBALS['layout_header_actions'] = [];
$knownAuthUsers = modules()->knownAuthUsers();
$authUserLabels = [];
foreach ($knownAuthUsers as $knownAuthUser) {
if (!is_array($knownAuthUser)) {
continue;
}
$label = trim((string) ($knownAuthUser['name'] ?? ''));
if ($label === '') {
$label = trim((string) ($knownAuthUser['username'] ?? ''));
}
if ($label === '') {
$label = trim((string) ($knownAuthUser['email'] ?? ''));
}
foreach (['sub', 'username', 'email'] as $key) {
$value = trim((string) ($knownAuthUser[$key] ?? ''));
if ($value !== '' && $label !== '') {
$authUserLabels[$value] = $label;
}
}
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
require_admin();
$name = (string)($_POST['module'] ?? '');
$action = (string)($_POST['action'] ?? '');
if ($name !== '' && ($action === 'enable' || $action === 'disable')) {
$enabled = $action === 'enable';
modules()->setEnabled($name, $enabled);
$notice = $enabled ? 'Modul aktiviert.' : 'Modul deaktiviert.';
$modules = modules()->all();
} elseif ($name !== '' && $action === 'migrate') {
$applied = modules()->applyPendingMigrations($name);
$notice = count($applied) . ' Migration(en) angewendet.';
$modules = modules()->all();
} else {
$error = 'Ungültige Aktion.';
}
}
?>
<?php require_auth(); ?>
<div class="module-shell"><div class="module-page-bg"><div class="module-page-stack">
<?php if ($error): ?>
<div class="section-box bg-red-900 border-l-4 border-red-500 text-red-100" role="alert">
<?= e($error) ?>
</div>
<?php elseif ($notice): ?>
<div class="section-box" style="border-color:var(--accent-2);">
<?= e($notice) ?>
</div>
<?php endif; ?>
<div class="submenu-box">
<div class="module-hero-top module-hero-top--compact">
<nav class="module-tabs" aria-label="Modulverwaltung">
<a class="module-button module-button--tab-active" href="/modules">Aktive Module</a>
<a class="module-button module-button--tab" href="/modules/install">Module installieren/aktivieren</a>
<a class="module-button module-button--tab" href="/modules/sql-import">Zentralen SQL-Import</a>
</nav>
<div class="module-submenu-actions">
<a class="module-button module-button--secondary module-button--small" href="/">Nexus Übersicht</a>
</div>
</div>
</div>
<div class="module-admin-grid">
<?php foreach ($modules as $module): ?>
<?php if (empty($module['enabled'])) { continue; } ?>
<?php
$auth = is_array($module['auth'] ?? null) ? $module['auth'] : [];
$authRequired = !empty($auth['required']);
$authUsers = is_array($auth['users'] ?? null) ? array_filter($auth['users']) : [];
$authGroups = is_array($auth['groups'] ?? null) ? array_filter($auth['groups']) : [];
$hasSpecificAccess = $authRequired && ($authUsers !== [] || $authGroups !== []);
if ($hasSpecificAccess) {
$accessParts = [];
if ($authGroups !== []) {
$accessParts[] = 'Gruppen: ' . implode(', ', $authGroups);
}
if ($authUsers !== []) {
$userLabels = array_map(
static fn (string $user): string => $authUserLabels[$user] ?? $user,
$authUsers
);
$accessParts[] = 'Nutzer: ' . implode(', ', $userLabels);
}
$accessLabel = implode(' · ', $accessParts);
$accessClass = ' module-admin-badge--success';
} elseif ($authRequired) {
$accessLabel = 'Login erforderlich';
$accessClass = ' module-admin-badge--warning';
} else {
$accessLabel = 'Offen ohne Modulschutz';
$accessClass = ' module-admin-badge--danger';
}
$migrationStatus = modules()->migrationStatus($module['name']);
$pendingMigrations = $migrationStatus['pending'] ?? [];
$changedMigrations = $migrationStatus['changed'] ?? [];
$migrationLabel = $pendingMigrations !== []
? count($pendingMigrations) . ' ausstehend'
: (($migrationStatus['available'] ?? 0) > 0 ? 'Schema aktuell' : 'Keine Migrationen');
?>
<article class="card-box module-admin-card">
<div class="module-admin-card__head">
<div class="module-admin-card__title">
<h2><?= e($module['title']) ?></h2>
<p><?= e($module['description'] ?? '') ?></p>
</div>
</div>
<div class="module-admin-meta">
<div class="module-admin-meta__item">
<span class="module-admin-meta__label">Status</span>
<strong class="module-admin-badge module-admin-badge--success">Aktiv</strong>
</div>
<div class="module-admin-meta__item">
<span class="module-admin-meta__label">Zugriff</span>
<strong class="module-admin-badge<?= e($accessClass) ?>"><?= e($accessLabel) ?></strong>
</div>
<div class="module-admin-meta__item">
<span class="module-admin-meta__label">Migrationen</span>
<strong class="module-admin-badge<?= $pendingMigrations !== [] ? ' module-admin-badge--accent' : (($migrationStatus['available'] ?? 0) > 0 ? ' module-admin-badge--success' : '') ?>"><?= e($migrationLabel) ?></strong>
</div>
</div>
<?php if ($changedMigrations !== []): ?>
<div class="module-admin-warning">
Achtung: <?= e((string)count($changedMigrations)) ?> bereits angewendete Migration(en) wurden verändert.
</div>
<?php endif; ?>
<div class="module-admin-actions">
<a class="nav-link" href="/module/<?= e($module['name']) ?>">Öffnen</a>
<a class="nav-link" href="/modules/setup/<?= e($module['name']) ?>">Setup</a>
<a class="nav-link" href="/modules/access/<?= e($module['name']) ?>">Zugriff</a>
<?php if ($pendingMigrations !== []): ?>
<form method="post" style="margin:0;">
<input type="hidden" name="module" value="<?= e($module['name']) ?>">
<button class="cta-button" name="action" value="migrate">Migrationen anwenden</button>
</form>
<?php endif; ?>
<form method="post" style="margin:0;">
<input type="hidden" name="module" value="<?= e($module['name']) ?>">
<button class="cta-button" name="action" value="disable" style="background:var(--panel); color:var(--text);">Deaktivieren</button>
</form>
</div>
</article>
<?php endforeach; ?>
</div>
</div></div></div>

View File

@@ -0,0 +1,164 @@
<?php
$modules = modules()->all();
$error = null;
$notice = null;
$GLOBALS['layout_header_base_title'] = 'Modulverwaltung';
$GLOBALS['layout_header_title'] = 'Modulverwaltung';
$GLOBALS['layout_header_context'] = 'Module installieren/aktivieren';
$GLOBALS['layout_header_text'] = '';
$GLOBALS['layout_header_actions'] = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
require_admin();
$name = (string)($_POST['module'] ?? '');
$action = (string)($_POST['action'] ?? '');
if ($name !== '' && ($action === 'enable' || $action === 'disable')) {
modules()->setEnabled($name, $action === 'enable');
$notice = $action === 'enable' ? 'Modul aktiviert.' : 'Modul deaktiviert.';
$modules = modules()->all();
} elseif ($name !== '' && $action === 'migrate') {
$applied = modules()->applyPendingMigrations($name);
$notice = count($applied) . ' Migration(en) angewendet.';
$modules = modules()->all();
} else {
$error = 'Ungültige Aktion.';
}
}
$active = [];
$inactive = [];
foreach ($modules as $m) {
if (!empty($m['enabled'])) {
$active[] = $m;
} else {
$inactive[] = $m;
}
}
?>
<?php require_auth(); ?>
<div class="module-shell"><div class="module-page-bg"><div class="module-page-stack">
<?php if ($error): ?>
<div class="section-box bg-red-900 border-l-4 border-red-500 text-red-100" role="alert">
<?= e($error) ?>
</div>
<?php elseif ($notice): ?>
<div class="section-box" style="border-color:var(--accent-2);">
<?= e($notice) ?>
</div>
<?php endif; ?>
<div class="submenu-box">
<div class="module-hero-top module-hero-top--compact">
<nav class="module-tabs" aria-label="Modulverwaltung">
<a class="module-button module-button--tab" href="/modules">Aktive Module</a>
<a class="module-button module-button--tab-active" href="/modules/install">Module installieren/aktivieren</a>
<a class="module-button module-button--tab" href="/modules/sql-import">Zentralen SQL-Import</a>
</nav>
<div class="module-submenu-actions">
<a class="module-button module-button--secondary module-button--small" href="/">Nexus Übersicht</a>
</div>
</div>
</div>
<section class="section-box">
<div class="module-box-head">
<div>
<h2 class="module-box-title">Aktive Module</h2>
<p>Bereits aktivierte Module mit optionalen Migrationsschritten.</p>
</div>
</div>
<div class="module-admin-grid module-admin-grid--compact">
<?php foreach ($active as $module): ?>
<?php
$migrationStatus = modules()->migrationStatus($module['name']);
$pendingMigrations = $migrationStatus['pending'] ?? [];
$migrationLabel = $pendingMigrations !== []
? count($pendingMigrations) . ' ausstehend'
: (($migrationStatus['available'] ?? 0) > 0 ? 'Schema aktuell' : 'Keine Migrationen');
?>
<article class="card-box module-admin-card">
<div class="module-admin-card__head">
<div class="module-admin-card__title">
<h2><?= e($module['title']) ?></h2>
<p><?= e($module['description'] ?? '') ?></p>
</div>
</div>
<div class="module-admin-meta">
<div class="module-admin-meta__item">
<span class="module-admin-meta__label">Status</span>
<strong class="module-admin-badge module-admin-badge--success">Aktiv</strong>
</div>
<div class="module-admin-meta__item">
<span class="module-admin-meta__label">Migrationen</span>
<strong class="module-admin-badge<?= $pendingMigrations !== [] ? ' module-admin-badge--accent' : (($migrationStatus['available'] ?? 0) > 0 ? ' module-admin-badge--success' : '') ?>"><?= e($migrationLabel) ?></strong>
</div>
</div>
<div class="module-admin-actions">
<a class="nav-link" href="/module/<?= e($module['name']) ?>">Öffnen</a>
<?php if ($pendingMigrations !== []): ?>
<form method="post" style="margin:0;">
<input type="hidden" name="module" value="<?= e($module['name']) ?>">
<button class="cta-button" name="action" value="migrate">Migrationen anwenden</button>
</form>
<?php endif; ?>
<form method="post" style="margin:0;">
<input type="hidden" name="module" value="<?= e($module['name']) ?>">
<button class="cta-button" name="action" value="disable" style="background:var(--panel); color:var(--text);">Deaktivieren</button>
</form>
</div>
</article>
<?php endforeach; ?>
</div>
</section>
<section class="section-box">
<div class="module-box-head">
<div>
<h2 class="module-box-title">Deaktivierte Module</h2>
<p>Erkannte Module basieren auf Ordnern in <code>modules/</code>.</p>
</div>
</div>
<div class="module-admin-grid module-admin-grid--compact">
<?php foreach ($inactive as $module): ?>
<?php
$migrationStatus = modules()->migrationStatus($module['name']);
$pendingMigrations = $migrationStatus['pending'] ?? [];
$migrationLabel = $pendingMigrations !== []
? count($pendingMigrations) . ' ausstehend'
: (($migrationStatus['available'] ?? 0) > 0 ? 'Schema aktuell' : 'Keine Migrationen');
?>
<article class="card-box module-admin-card">
<div class="module-admin-card__head">
<div class="module-admin-card__title">
<h2><?= e($module['title']) ?></h2>
<p><?= e($module['description'] ?? '') ?></p>
</div>
</div>
<div class="module-admin-meta">
<div class="module-admin-meta__item">
<span class="module-admin-meta__label">Status</span>
<strong class="module-admin-badge">Deaktiviert</strong>
</div>
<div class="module-admin-meta__item">
<span class="module-admin-meta__label">Migrationen</span>
<strong class="module-admin-badge<?= $pendingMigrations !== [] ? ' module-admin-badge--accent' : (($migrationStatus['available'] ?? 0) > 0 ? ' module-admin-badge--success' : '') ?>"><?= e($migrationLabel) ?></strong>
</div>
</div>
<div class="module-admin-actions">
<a class="nav-link" href="/modules/setup/<?= e($module['name']) ?>">Setup</a>
<?php if ($pendingMigrations !== []): ?>
<form method="post" style="margin:0;">
<input type="hidden" name="module" value="<?= e($module['name']) ?>">
<button class="cta-button" name="action" value="migrate">Migrationen anwenden</button>
</form>
<?php endif; ?>
<form method="post" style="margin:0;">
<input type="hidden" name="module" value="<?= e($module['name']) ?>">
<button class="cta-button" name="action" value="enable">Aktivieren</button>
</form>
</div>
</article>
<?php endforeach; ?>
</div>
</section>
</div></div></div>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,129 @@
<?php
require_admin();
$GLOBALS['layout_header_base_title'] = 'Modulverwaltung';
$GLOBALS['layout_header_title'] = 'Modulverwaltung';
$GLOBALS['layout_header_context'] = 'SQL-Import';
$GLOBALS['layout_header_text'] = '';
$GLOBALS['layout_header_actions'] = [];
$service = new \App\ModuleSqlImportService(modules());
$availableModules = $service->importableModules();
$selectedModule = (string) ($_POST['module'] ?? ($_GET['module'] ?? ''));
$error = null;
$notice = null;
$result = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
if (!isset($_FILES['sql_file']) || !is_array($_FILES['sql_file'])) {
throw new RuntimeException('Bitte eine SQL-Datei auswählen.');
}
$result = $service->importUploadedFile($selectedModule, $_FILES['sql_file']);
$notice = sprintf(
'%s %d Statements aus %s wurden nach %s importiert.',
(string) ($result['message'] ?? 'Import erfolgreich.'),
(int) ($result['statement_count'] ?? 0),
(string) ($result['file'] ?? 'der Datei'),
(string) ($result['target_label'] ?? 'der Ziel-Datenbank')
);
} catch (Throwable $exception) {
$error = $exception->getMessage();
}
}
?>
<div class="module-shell"><div class="module-page-bg"><div class="module-page-stack">
<?php if ($error): ?>
<div class="section-box bg-red-900 border-l-4 border-red-500 text-red-100" role="alert">
<?= e($error) ?>
</div>
<?php elseif ($notice): ?>
<div class="section-box" style="border-color:var(--accent-2);">
<?= e($notice) ?>
</div>
<?php endif; ?>
<div class="submenu-box">
<div class="module-hero-top module-hero-top--compact">
<nav class="module-tabs" aria-label="Modulverwaltung">
<a class="module-button module-button--tab" href="/modules">Aktive Module</a>
<a class="module-button module-button--tab" href="/modules/install">Module installieren/aktivieren</a>
<a class="module-button module-button--tab-active" href="/modules/sql-import">Zentralen SQL-Import</a>
</nav>
<div class="module-submenu-actions">
<a class="module-button module-button--secondary module-button--small" href="/">Nexus Übersicht</a>
</div>
</div>
</div>
<section class="section-box">
<div class="module-box-head">
<div>
<h2 class="module-box-title">Zentraler SQL-Import</h2>
<p>Gemeinsame Standard-Lösung für Module mit SQL-Upload in die konfigurierte Ziel-Datenbank.</p>
</div>
</div>
<?php if ($availableModules === []): ?>
<div class="card-box">
Aktuell ist kein Modul für den generischen SQL-Import vorbereitet.
</div>
<?php else: ?>
<form method="post" enctype="multipart/form-data" class="section-box" style="padding:0; border:0; box-shadow:none; background:transparent;">
<div style="display:grid; gap:1rem;">
<label style="display:grid; gap:.35rem;">
<span>Modul</span>
<select name="module" required>
<option value="">Bitte wählen</option>
<?php foreach ($availableModules as $module): ?>
<option value="<?= e($module['name']) ?>" <?= $selectedModule === $module['name'] ? 'selected' : '' ?>>
<?= e($module['title']) ?>
</option>
<?php endforeach; ?>
</select>
</label>
<label style="display:grid; gap:.35rem;">
<span>SQL-Datei</span>
<input type="file" name="sql_file" accept=".sql,text/sql,application/sql" required>
</label>
<div class="muted" style="font-size:.95rem;">
Der generische Import nutzt die Standard-Datenbankverbindung des Moduls oder einen optionalen Modul-Callback für Spezialfälle.
</div>
<div style="display:flex; gap:10px; flex-wrap:wrap;">
<button class="cta-button" type="submit">SQL importieren</button>
</div>
</div>
</form>
<?php endif; ?>
</section>
<?php if ($availableModules !== []): ?>
<section class="section-box">
<div class="module-box-head">
<div>
<h2 class="module-box-title">Importierbare Module</h2>
<p>Schnelleinstieg für den Import mit bereits vorausgewähltem Modul.</p>
</div>
</div>
<div class="module-admin-grid module-admin-grid--compact">
<?php foreach ($availableModules as $module): ?>
<article class="card-box module-admin-card">
<div class="module-admin-card__head">
<div class="module-admin-card__title">
<h2><?= e($module['title']) ?></h2>
<p><?= e($module['description']) ?></p>
</div>
</div>
<div class="module-admin-actions">
<a class="nav-link" href="/modules/sql-import?module=<?= e($module['name']) ?>">Für dieses Modul importieren</a>
</div>
</article>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
</div></div></div>