Mirrors the bot's event planner (/event_planen, /event_liste) on the
website: list all scheduled reminders with a filter for recurring/one-off,
create, edit and delete them. Both sides talk to the same bot database, so
a reminder scheduled in Discord shows up here right away and vice versa -
sending stays with the bot's background job.
Channel and role are real dropdowns pulled from the Discord server instead
of raw IDs (channels the bot cannot post in are disabled), and the form
shows a live preview of the later Discord message, like the bot does before
scheduling. The timestamp is sent as "TT.MM.JJJJ HH:MM" and converted on
the bot side, exactly like the raids, so both ends use the same timezone.
New permissions events.view / events.manage - existing installs have to
add and assign them once under Berechtigungsgruppen.
Needs the matching bot-side API additions (PATCH /api/events/{id},
GET /api/guilds/{id}/channels and /roles, next_run_raw on POST /api/events,
channel/role names in the event list), which live in the separate bot repo.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
137 lines
5.8 KiB
PHP
137 lines
5.8 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/bootstrap.php';
|
|
|
|
$pdo = db();
|
|
|
|
$userCount = (int) $pdo->query('SELECT COUNT(*) FROM users')->fetchColumn();
|
|
if ($userCount > 0) {
|
|
http_response_code(403);
|
|
$pageTitle = 'Installation abgeschlossen';
|
|
include __DIR__ . '/includes/header.php';
|
|
?>
|
|
<div class="panel panel-narrow">
|
|
<h1>Installation bereits abgeschlossen</h1>
|
|
<p>Es existiert bereits mindestens ein Benutzer. Aus Sicherheitsgründen bitte diese Datei (install.php) jetzt vom Server löschen.</p>
|
|
<p><a class="button" href="/login.php">Zum Login</a></p>
|
|
</div>
|
|
<?php
|
|
include __DIR__ . '/includes/footer.php';
|
|
exit;
|
|
}
|
|
|
|
function seed_defaults(PDO $pdo): array
|
|
{
|
|
$permissionIds = [];
|
|
foreach (CORE_PERMISSIONS as $perm) {
|
|
$stmt = $pdo->prepare('INSERT INTO permissions (`key`, description) VALUES (?, ?)
|
|
ON DUPLICATE KEY UPDATE description = VALUES(description)');
|
|
$stmt->execute([$perm['key'], $perm['description']]);
|
|
|
|
$idStmt = $pdo->prepare('SELECT id FROM permissions WHERE `key` = ?');
|
|
$idStmt->execute([$perm['key']]);
|
|
$permissionIds[$perm['key']] = (int) $idStmt->fetchColumn();
|
|
}
|
|
|
|
// Rolle "Administrator" mit allen Berechtigungen.
|
|
$pdo->prepare('INSERT INTO roles (name, description, is_system) VALUES (?, ?, 1)
|
|
ON DUPLICATE KEY UPDATE description = VALUES(description)')
|
|
->execute(['Administrator', 'Voller Zugriff auf alle Bereiche und Einstellungen']);
|
|
$adminRoleId = (int) $pdo->query("SELECT id FROM roles WHERE name = 'Administrator'")->fetchColumn();
|
|
|
|
foreach ($permissionIds as $permId) {
|
|
$pdo->prepare('INSERT IGNORE INTO role_permissions (role_id, permission_id) VALUES (?, ?)')
|
|
->execute([$adminRoleId, $permId]);
|
|
}
|
|
|
|
// Rolle "Mitglied" mit Basiszugriff.
|
|
$pdo->prepare('INSERT INTO roles (name, description, is_system) VALUES (?, ?, 1)
|
|
ON DUPLICATE KEY UPDATE description = VALUES(description)')
|
|
->execute(['Mitglied', 'Standardrolle für Gildenmitglieder']);
|
|
$memberRoleId = (int) $pdo->query("SELECT id FROM roles WHERE name = 'Mitglied'")->fetchColumn();
|
|
|
|
$pdo->prepare('INSERT IGNORE INTO role_permissions (role_id, permission_id) VALUES (?, ?)')
|
|
->execute([$memberRoleId, $permissionIds['dashboard.view']]);
|
|
$pdo->prepare('INSERT IGNORE INTO role_permissions (role_id, permission_id) VALUES (?, ?)')
|
|
->execute([$memberRoleId, $permissionIds['raids.view']]);
|
|
$pdo->prepare('INSERT IGNORE INTO role_permissions (role_id, permission_id) VALUES (?, ?)')
|
|
->execute([$memberRoleId, $permissionIds['premades.view']]);
|
|
$pdo->prepare('INSERT IGNORE INTO role_permissions (role_id, permission_id) VALUES (?, ?)')
|
|
->execute([$memberRoleId, $permissionIds['members.view']]);
|
|
$pdo->prepare('INSERT IGNORE INTO role_permissions (role_id, permission_id) VALUES (?, ?)')
|
|
->execute([$memberRoleId, $permissionIds['events.view']]);
|
|
|
|
return ['admin_role_id' => $adminRoleId];
|
|
}
|
|
|
|
$error = null;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
verify_csrf();
|
|
|
|
$username = trim((string) ($_POST['username'] ?? ''));
|
|
$displayName = trim((string) ($_POST['display_name'] ?? ''));
|
|
$password = (string) ($_POST['password'] ?? '');
|
|
$passwordConfirm = (string) ($_POST['password_confirm'] ?? '');
|
|
|
|
if ($username === '' || $password === '') {
|
|
$error = 'Bitte alle Pflichtfelder ausfüllen.';
|
|
} elseif (strlen($password) < 8) {
|
|
$error = 'Das Passwort muss mindestens 8 Zeichen lang sein.';
|
|
} elseif ($password !== $passwordConfirm) {
|
|
$error = 'Die Passwörter stimmen nicht überein.';
|
|
} else {
|
|
try {
|
|
$pdo->beginTransaction();
|
|
|
|
$seeded = seed_defaults($pdo);
|
|
|
|
$stmt = $pdo->prepare('INSERT INTO users (username, password_hash, display_name) VALUES (?, ?, ?)');
|
|
$stmt->execute([$username, password_hash($password, PASSWORD_DEFAULT), $displayName]);
|
|
$newUserId = (int) $pdo->lastInsertId();
|
|
|
|
$pdo->prepare('INSERT INTO user_roles (user_id, role_id) VALUES (?, ?)')
|
|
->execute([$newUserId, $seeded['admin_role_id']]);
|
|
|
|
$pdo->commit();
|
|
|
|
set_flash('success', 'Installation abgeschlossen. Du kannst dich jetzt anmelden. Bitte lösche install.php vom Server.');
|
|
redirect('/login.php');
|
|
} catch (PDOException $e) {
|
|
$pdo->rollBack();
|
|
$error = 'Fehler bei der Installation: Benutzername bereits vergeben?';
|
|
}
|
|
}
|
|
}
|
|
|
|
$pageTitle = 'Installation';
|
|
include __DIR__ . '/includes/header.php';
|
|
?>
|
|
<div class="panel panel-narrow">
|
|
<h1>Ersteinrichtung</h1>
|
|
<p class="text-muted">Lege den ersten Administrator-Account an. Dieser Schritt ist nur einmal möglich.</p>
|
|
<?php if ($error): ?>
|
|
<div class="flash flash-error"><?= e($error) ?></div>
|
|
<?php endif; ?>
|
|
<form method="post" action="/install.php">
|
|
<?= csrf_field() ?>
|
|
<div>
|
|
<label for="username">Benutzername</label>
|
|
<input type="text" id="username" name="username" required value="<?= e($_POST['username'] ?? '') ?>">
|
|
</div>
|
|
<div>
|
|
<label for="display_name">Anzeigename (optional)</label>
|
|
<input type="text" id="display_name" name="display_name" value="<?= e($_POST['display_name'] ?? '') ?>">
|
|
</div>
|
|
<div>
|
|
<label for="password">Passwort</label>
|
|
<input type="password" id="password" name="password" required>
|
|
<div class="field-hint">Mindestens 8 Zeichen.</div>
|
|
</div>
|
|
<div>
|
|
<label for="password_confirm">Passwort wiederholen</label>
|
|
<input type="password" id="password_confirm" name="password_confirm" required>
|
|
</div>
|
|
<button type="submit">Administrator anlegen</button>
|
|
</form>
|
|
</div>
|
|
<?php include __DIR__ . '/includes/footer.php'; ?>
|