BastionGuard/webui/auth.php
specialworld83 f0f913a209 Release 2.0
2026-07-15 10:52:22 +02:00

36 lines
1.3 KiB
PHP

<?php
require_once __DIR__ . '/includes/users.php';
if (!bg_config_exists()) {
header('Location: setup.php');
exit;
}
if (empty($_SESSION['user'])) {
header('Location: login.php');
exit;
}
// Upgrade old sessions created before roles existed.
if (empty($_SESSION['role'])) {
try {
foreach (bg_users_all() as $u) {
if (($u['username'] ?? '') === $_SESSION['user']) {
$_SESSION['role'] = $u['role'] ?? 'admin';
break;
}
}
} catch (Throwable $e) { $_SESSION['role'] = 'user'; }
}
// Initial BastionGuard application wizard gate: after WebPanel setup/login,
// administrators are sent to the BastionGuard wizard until ~/.config/BastionGuard/config.json
// exists, is valid and has wizard_completed=true with the service map.
$__bg_script = basename((string)($_SERVER['SCRIPT_NAME'] ?? ''));
if ($__bg_script !== 'wizard.php' && function_exists('bg_current_user_is_admin') && bg_current_user_is_admin()) {
require_once __DIR__ . '/includes/config_manager.php';
$opts = bg_web_options();
$target = trim((string)($opts['desktop_user'] ?? bg_detect_desktop_user()));
$st = bg_wizard_config_status($target ?: null);
if (empty($st['completed']) || empty($st['services_ok'])) {
header('Location: wizard.php?first=1');
exit;
}
}
?>