'
. '
Welcome back
'
. 'Manage the tinyauth service and its settings. Log in with your tinyauth account.
'
. 'Log in with tinyauth'
. '';
page_end();
exit;
}
$groups = $_SESSION['groups'] ?? [];
$allowedGroup = load_settings()['allowed_group'] ?? '';
$authorized = is_authorized($groups);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
require_csrf();
$action = (string) ($_POST['action'] ?? '');
if ($allowedGroup === '' && $action === 'setup') {
handle_setup($groups);
} elseif (!$authorized) {
http_response_code(403);
exit('Forbidden');
} elseif ($action === 'reset_group') {
handle_reset_group();
} elseif (in_array($action, SERVICE_ACTIONS, true)) {
handle_service($action);
} elseif ($action === 'save_config') {
handle_save_config();
}
redirect('index.php');
}
$cfg = config();
$flashes = take_flashes();
$lastOutput = $_SESSION['last_output'] ?? '';
unset($_SESSION['last_output']);
$token = csrf_token();
$userHtml = '' . h($_SESSION['user']) . ''
. 'Log out';
page_start('Dashboard', $userHtml);
foreach ($flashes as $flash) {
echo '' . h($flash['message']) . '
';
}
if ($allowedGroup === '') {
echo '';
echo 'First-time setup
';
echo 'Choose the tinyauth group whose members may use this tool.
';
if ($groups === []) {
echo 'Your account has no groups in tinyauth. Add yourself to a group, then reload.
';
} else {
echo '';
}
echo '';
page_end();
exit;
}
if (!$authorized) {
echo '';
echo 'Access denied
';
echo 'You are not in the required tinyauth group ' . h($allowedGroup) . '.
';
echo '';
page_end();
exit;
}
$perms = [];
foreach (SERVICE_ACTIONS as $action) {
$perms[$action] = service_allowed($action);
}
$status = $perms['status'] ? service_run('status') : null;
$state = 'unknown';
if ($status !== null && preg_match('/Active:\s+(\S+)/', $status['output'], $m)) {
$state = $m[1];
}
$stateClass = match ($state) {
'active' => 'state-active',
'failed' => 'state-failed',
'inactive' => 'state-inactive',
default => 'state-unknown',
};
$service = $cfg['service'];
echo '';
echo 'Service ' . h($service) . '
';
echo '' . h($state) . '';
echo '';
if ($status !== null) {
echo '' . h($status['output']) . '
';
}
if ($lastOutput !== '') {
echo '' . h($lastOutput) . '
';
}
echo '';
$envPath = $cfg['env_file'];
$envReadable = is_file($envPath) && is_readable($envPath);
$envWritable = $envReadable && is_writable($envPath);
$dataWritable = is_writable(data_dir());
echo '';
echo '
Permission checks
';
foreach (SERVICE_ACTIONS as $action) {
echo permission_row('sudo: systemctl ' . $action . ' ' . $service, $perms[$action]);
}
echo permission_row('Env file readable', $envReadable, $envPath);
echo permission_row('Env file writable', $envWritable);
echo permission_row('Data directory writable', $dataWritable);
echo '
';
if (in_array(false, $perms, true)) {
echo 'Missing sudo rules. Install sudoers/tinyauth-web.sudoers '
. 'from this repo and check it with visudo -cf.
';
}
echo '';
echo '';
echo '
Quick notes
';
echo '';
echo '- Saving the config writes a backup first.
';
echo '- Changes take effect after you restart the service.
';
echo '- Secret values are never shown. Leave a secret blank to keep it.
';
echo '
';
echo '
';
echo 'Config ' . h($envPath) . '
';
if (!$envReadable) {
echo 'The env file cannot be read by this user.
';
} else {
$vars = env_parse((string) file_get_contents($envPath));
echo '';
}
echo '';
page_end();
function permission_row(string $label, bool $ok, ?string $detail = null): string
{
$class = $ok ? 'check-ok' : 'check-missing';
$mark = $ok ? '✔ ok' : '✘ missing';
$extra = $detail !== null ? '
' . h($detail) . '' : '';
return '' . h($label) . $extra . '' . $mark . '';
}