Sichert den bisherigen Relaunch-Stand vor dem Gameplay/Community-Update: - Neues helles Design auf allen Seiten (Landing, Spiel, Login, Profil, Admin, Setup) - index.html = Landingpage, play.html = Spiel, regeln/datenschutz/impressum - Chat-Overlay mit Emoji + Giphy-GIF, Lobby Teilnehmen/Starten, App-Shell Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
158 lines
6.2 KiB
PHP
158 lines
6.2 KiB
PHP
<?php
|
||
/**
|
||
* One-time admin setup.
|
||
* Visit: https://yourdomain.com/setup.php
|
||
* This file deletes itself automatically after a successful setup.
|
||
*/
|
||
declare(strict_types=1);
|
||
|
||
$cfg = require __DIR__ . '/config.php';
|
||
|
||
function db(array $cfg): PDO
|
||
{
|
||
$dsn = sprintf('mysql:host=%s;dbname=%s;charset=%s', $cfg['host'], $cfg['dbname'], $cfg['charset']);
|
||
return new PDO($dsn, $cfg['user'], $cfg['pass'], [
|
||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||
PDO::ATTR_EMULATE_PREPARES => false,
|
||
]);
|
||
}
|
||
|
||
$error = '';
|
||
$success = false;
|
||
$deleted = false;
|
||
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||
$adminUser = trim($_POST['username'] ?? '');
|
||
$adminPass = $_POST['password'] ?? '';
|
||
$adminPass2 = $_POST['password2'] ?? '';
|
||
|
||
if (!preg_match('/^[a-zA-Z0-9_\-]{2,40}$/', $adminUser)) {
|
||
$error = 'Username: 2–40 characters, only letters / digits / _ / -';
|
||
} elseif (strlen($adminPass) < 8) {
|
||
$error = 'Password must be at least 8 characters.';
|
||
} elseif ($adminPass !== $adminPass2) {
|
||
$error = 'Passwords do not match.';
|
||
} else {
|
||
try {
|
||
$pdo = db($cfg);
|
||
|
||
// Run migrations so all tables exist before we insert
|
||
require __DIR__ . '/migrate.php';
|
||
runMigrations($pdo, $cfg['dbname']);
|
||
|
||
$check = $pdo->prepare("SELECT id FROM gtl_users WHERE role = 'admin' LIMIT 1");
|
||
$check->execute();
|
||
if ($check->fetch()) {
|
||
$error = 'An admin account already exists. Delete this file manually.';
|
||
} else {
|
||
$hash = password_hash($adminPass, PASSWORD_DEFAULT);
|
||
$now = time();
|
||
|
||
$ins = $pdo->prepare(
|
||
"INSERT INTO gtl_users (username, credential_hash, role, created_at)
|
||
VALUES (?, ?, 'admin', ?)"
|
||
);
|
||
$ins->execute([$adminUser, $hash, $now]);
|
||
$uid = (int) $pdo->lastInsertId();
|
||
|
||
$pdo->prepare("INSERT INTO gtl_user_stats (user_id) VALUES (?)")->execute([$uid]);
|
||
|
||
// Ensure upload directory exists
|
||
$dir = __DIR__ . '/uploads/avatars';
|
||
if (!is_dir($dir)) {
|
||
mkdir($dir, 0755, true);
|
||
}
|
||
|
||
$success = htmlspecialchars($adminUser);
|
||
|
||
// Self-destruct — delete this file now that setup is complete
|
||
$deleted = @unlink(__FILE__);
|
||
}
|
||
} catch (Throwable $e) {
|
||
$error = 'Database error: ' . $e->getMessage();
|
||
}
|
||
}
|
||
}
|
||
?><!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<meta name="robots" content="noindex, nofollow">
|
||
<title>Setup – Black Sheep Bluff</title>
|
||
<style>
|
||
*{box-sizing:border-box;margin:0;padding:0}
|
||
body{font-family:'Inter',system-ui,sans-serif;background:#ffffff;color:#16203a;
|
||
min-height:100vh;display:flex;align-items:center;justify-content:center;padding:20px}
|
||
.box{background:#ffffff;border:1px solid #e7ebf2;border-radius:18px;
|
||
padding:32px;width:100%;max-width:400px;box-shadow:0 10px 34px -16px rgba(20,30,60,.22)}
|
||
h1{font-size:22px;font-weight:800;margin-bottom:6px;color:#243154}
|
||
p.sub{color:#5e6b85;font-size:13px;margin-bottom:24px;line-height:1.5}
|
||
label{display:block;font-size:12px;color:#5e6b85;font-weight:600;
|
||
text-transform:uppercase;letter-spacing:.6px;margin-bottom:6px}
|
||
input{width:100%;background:#ffffff;border:1.5px solid #e7ebf2;color:#16203a;
|
||
border-radius:12px;padding:12px 14px;margin-bottom:16px;font-size:15px;
|
||
font-family:inherit;outline:none;transition:border-color .15s}
|
||
input:focus{border-color:#3ECC5C}
|
||
button{width:100%;background:linear-gradient(180deg,#3ECC5C,#27a948);
|
||
color:#06270f;border:none;border-radius:12px;padding:14px;
|
||
font-weight:700;font-size:15px;cursor:pointer;font-family:inherit;
|
||
transition:filter .15s}
|
||
button:hover{filter:brightness(1.05)}
|
||
.err{background:rgba(232,93,92,.12);border:1px solid rgba(232,93,92,.3);
|
||
color:#c0392b;padding:11px 14px;border-radius:12px;font-size:13px;margin-bottom:16px}
|
||
.ok{background:rgba(43,181,133,.1);border:1px solid rgba(43,181,133,.3);
|
||
color:#1f8f3e;padding:14px;border-radius:12px;font-size:14px;line-height:1.6}
|
||
.ok strong{color:#16203a}
|
||
.warn{margin-top:16px;font-size:12px;color:#a86f00;
|
||
background:rgba(201,138,0,.1);border:1px solid rgba(201,138,0,.25);
|
||
border-radius:8px;padding:10px 12px;line-height:1.5}
|
||
.gone{margin-top:12px;font-size:12px;color:#5e6b85;font-style:italic}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="box">
|
||
<h1>🐑 Admin Setup</h1>
|
||
|
||
<?php if ($success): ?>
|
||
|
||
<div class="ok">
|
||
✅ Admin account <strong><?= $success ?></strong> created successfully.<br><br>
|
||
You can now <a href="login.php" style="color:#3ECC5C">log in</a> and start playing.
|
||
</div>
|
||
<?php if ($deleted): ?>
|
||
<p class="gone">🗑 setup.php has been deleted automatically.</p>
|
||
<?php else: ?>
|
||
<div class="warn">⚠️ Could not delete setup.php automatically — please remove it manually from your server.</div>
|
||
<?php endif; ?>
|
||
|
||
<?php else: ?>
|
||
|
||
<p class="sub">Creates the first admin account. This file will delete itself after a successful setup.</p>
|
||
|
||
<?php if ($error): ?>
|
||
<div class="err"><?= htmlspecialchars($error) ?></div>
|
||
<?php endif; ?>
|
||
|
||
<form method="POST">
|
||
<label for="username">Admin username</label>
|
||
<input id="username" type="text" name="username"
|
||
value="<?= htmlspecialchars($_POST['username'] ?? 'admin') ?>"
|
||
maxlength="40" autocomplete="off" autofocus>
|
||
|
||
<label for="password">Password (min. 8 characters)</label>
|
||
<input id="password" type="password" name="password" autocomplete="new-password">
|
||
|
||
<label for="password2">Confirm password</label>
|
||
<input id="password2" type="password" name="password2" autocomplete="new-password">
|
||
|
||
<button type="submit">Create admin account</button>
|
||
</form>
|
||
|
||
<div class="warn">⚠️ Run setup only once. The file deletes itself on success — if it doesn't, remove it manually.</div>
|
||
|
||
<?php endif; ?>
|
||
</div>
|
||
</body>
|
||
</html>
|