'
. '
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();
} elseif ($action === 'create_oidc_client') {
handle_create_oidc_client();
} elseif ($action === 'create_app_acl') {
handle_create_app_acl();
}
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 && ($blank = blank_warning()) !== null) {
echo '' . h($blank) . '
';
}
if (!$envReadable) {
echo 'The env file cannot be read by this user.
';
} else {
$vars = env_parse((string) file_get_contents($envPath));
echo '';
}
echo ' ';
echo '';
echo '
New OIDC client ';
echo 'Creates the variables for a client that apps use to log in through tinyauth. '
. 'Leave the secret blank to generate one.
';
echo '';
echo '
New app ACL ';
echo 'Creates the access rules for an app behind tinyauth (forward auth). '
. 'Fill in what you need; empty fields are skipped.
';
echo '';
echo '
';
echo '
Local users ';
echo 'Tinyauth stores local users as username:hash pairs in '
. 'TINYAUTH_AUTH_USERS (comma-separated). This tool does not create passwords, because tinyauth hashes them.
';
echo '';
echo 'On the server, run tinyauth user create --interactive and enter the username and password when asked. '
. 'Avoid typing the password on the command line, so it stays out of your shell history. ';
echo 'Copy the printed username:hash line. ';
echo 'Add it to TINYAUTH_AUTH_USERS in the config above. For several users, separate entries with commas. '
. 'To add a user, append to the existing value. Do not replace it. ';
echo 'Save, then restart tinyauth. Hashes are masked in this tool like other secrets. ';
echo ' ';
echo 'Key reference (' . count(known_keys()) . ' keys) ';
echo ' ';
echo 'Key Description Default ';
foreach (known_keys() as $entry) {
echo '' . h($entry['key']) . '' . h($entry['desc']) . ' '
. ($entry['default'] === '' ? 'none ' : '' . h($entry['default']) . '')
. ' ';
}
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 . ' ';
}