New "Karte" tab: a tiled zoom/pan map of the game world with a category sidebar (groups, per-category marker counts, show all / hide all, search) and marker popups, plus tactic layers drawn on top of it. Markers are placed by clicking the map (map.manage) and live in freely editable two-level categories, each with its own emoji and colour. A tactic (map.tactics) is a separate drawing layer that can be toggled on and off: rally points, dashed routes, areas and text notes in any colour, finished by double click, an explicit button or Enter, removed by clicking them. Coordinates are stored as a fraction of the map's width/height rather than in pixels, so re-tiling the map at a different resolution never moves anything. The map data lives entirely in the website database - the Discord bot is not involved. tools/make_map_tiles.php slices a high-resolution image into the zoom pyramid locally; the resulting folder is uploaded by FTP and picked up automatically, one region per folder. Leaflet 1.9.4 is vendored under assets/vendor/ so there is still no CDN and no build step. New permissions map.view / map.manage / map.tactics and four new tables - existing installs have to add both once (see README). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
139 lines
6 KiB
PHP
139 lines
6 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']]);
|
|
$pdo->prepare('INSERT IGNORE INTO role_permissions (role_id, permission_id) VALUES (?, ?)')
|
|
->execute([$memberRoleId, $permissionIds['map.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'; ?>
|