| Server IP : 10.200.247.200 / Your IP : 216.73.217.19 Web Server : Apache System : Linux synergy-usa-sites 6.8.0-138-generic #138-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 31 22:41:49 UTC 2026 x86_64 User : jeremy ( 1001) PHP Version : 8.4.25 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/development/callings.lvsaints.com/ |
Upload File : |
<?php
// ONE-TIME setup: create the first ward, the super admin user, and seed the
// first live version from index.html. DELETE THIS FILE once you've run it.
require __DIR__ . '/lib.php';
require __DIR__ . '/releases.php';
// Refuse to run if any user already exists.
$count = (int) db()->query('SELECT COUNT(*) AS c FROM users')->fetch()['c'];
if ($count > 0) {
exit('Setup already completed. Delete setup.php.');
}
$done = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
csrf_check();
$wardName = trim($_POST['ward_name'] ?? '');
$email = trim($_POST['email'] ?? '');
$pass = $_POST['password'] ?? '';
if ($wardName === '' || $email === '' || strlen($pass) < 8) {
$done = 'Enter a ward name, an email, and a password of at least 8 characters.';
} else {
$pdo = db();
$pdo->beginTransaction();
// First ward.
$pdo->prepare('INSERT INTO wards (name, slug) VALUES (?, ?)')
->execute([$wardName, slugify($wardName)]);
$wardId = (int) $pdo->lastInsertId();
// Super admin (spans all wards, so ward_id is NULL).
$pdo->prepare(
'INSERT INTO users (email, password_hash, role, ward_id)
VALUES (?, ?, "super_admin", NULL)'
)->execute([$email, password_hash($pass, PASSWORD_DEFAULT)]);
$pdo->commit();
// Seed the first live version as a release folder from index.html, if present.
$seeded = false;
$seed = @file_get_contents(__DIR__ . '/index.html');
if ($seed !== false && trim($seed) !== '') {
try {
$name = next_version_name();
ensure_dirs();
if (@mkdir(releases_dir() . '/' . $name, 0775, true)) {
file_put_contents(releases_dir() . '/' . $name . '/index.html', $seed);
write_meta($name, [
'note' => 'Initial import from index.html',
'uploaded_by' => $email,
'uploaded_at' => date('Y-m-d H:i:s'),
'orig' => 'index.html',
]);
set_active($name);
$seeded = true;
}
} catch (Throwable $ex) {
// Non-fatal: the admin can upload the first version manually.
}
}
$done = 'Super admin created' . ($seeded ? ' and index.html seeded as the first live version' : '')
. '. NOW DELETE setup.php, then sign in at login.php.';
}
}
?>
<!doctype html>
<html>
<head><meta charset="utf-8"><title>Setup</title>
<style>body{font-family:Arial,sans-serif;max-width:420px;margin:60px auto;color:#101828}
label{display:block;font-weight:700;font-size:13px;margin-top:10px}
input{width:100%;padding:9px;margin:6px 0;border:1px solid #d9e2ee;border-radius:9px}
button{padding:10px 14px;border:0;border-radius:9px;background:#2563d9;color:#fff;font-weight:800}
.msg{background:#eaf1ff;padding:12px;border-radius:9px;margin-bottom:16px}</style></head>
<body>
<h1>First-time setup</h1>
<?php if ($done): ?><div class="msg"><?= e($done) ?></div><?php endif; ?>
<form method="post">
<input type="hidden" name="csrf" value="<?= e(csrf_token()) ?>">
<label>First ward name</label><input type="text" name="ward_name" value="Village Ward" required>
<label>Super admin email</label><input type="email" name="email" required>
<label>Password (min 8 chars)</label><input type="password" name="password" required>
<button type="submit">Create ward, super admin & seed board</button>
</form>
</body>
</html>