Core settings section: install-level variables in a closed group, configurable via core_keys

This commit is contained in:
Clarth 2026-12-01 17:14:15 -05:00
parent f553bc6b89
commit e74746bea9
4 changed files with 101 additions and 22 deletions

View file

@ -24,6 +24,23 @@ return [
// Full path to systemctl. Must match the path in sudoers. // Full path to systemctl. Must match the path in sudoers.
'systemctl' => '/usr/bin/systemctl', 'systemctl' => '/usr/bin/systemctl',
// Variables shown in the closed "Core settings" section (install-level, rarely changed).
// Patterns use * wildcards. Remove this line to use the built-in default list (see src/lib.php).
'core_keys' => [
'TINYAUTH_APPURL',
'TINYAUTH_SERVER_*',
'TINYAUTH_AUTH_SECURECOOKIE',
'TINYAUTH_AUTH_SUBDOMAINSENABLED',
'TINYAUTH_AUTH_TRUSTEDPROXIES',
'TINYAUTH_ANALYTICS_*',
'TINYAUTH_LDAP_*',
'TINYAUTH_OIDC_PRIVATEKEYPATH',
'TINYAUTH_OIDC_PUBLICKEYPATH',
'TINYAUTH_DATABASE_*',
'TINYAUTH_LOG_*',
'TINYAUTH_UI_*',
],
// Settings, backups and other writable state. Keep it outside public/. // Settings, backups and other writable state. Keep it outside public/.
'data_dir' => dirname(__DIR__) . '/data', 'data_dir' => dirname(__DIR__) . '/data',
]; ];

View file

@ -578,3 +578,10 @@ dialog.modal code {
dialog.modal .table-wrap { overflow-x: visible; } dialog.modal .table-wrap { overflow-x: visible; }
dialog.modal .dup-choice label { white-space: nowrap; } dialog.modal .dup-choice label { white-space: nowrap; }
/* Core settings group inside the config card */
.core-group { margin: 0.5rem 0 1rem; }
.core-group > summary { padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.core-group > summary h3 { margin: 0; font-size: 0.95rem; }
.core-group > .muted { margin: 0.8rem 0 0.4rem; font-size: 0.9rem; }
.group-title { margin: 1rem 0 0.2rem; font-size: 0.95rem; }

View file

@ -180,30 +180,28 @@ if (!$envReadable) {
echo '<div class="flash flash-error">The env file cannot be read by this user.</div>'; echo '<div class="flash flash-error">The env file cannot be read by this user.</div>';
} else { } else {
$vars = env_parse((string) file_get_contents($envPath)); $vars = env_parse((string) file_get_contents($envPath));
$core = [];
$other = [];
foreach ($vars as $key => $value) {
if (is_core_key($key)) {
$core[$key] = $value;
} else {
$other[$key] = $value;
}
}
echo '<form method="post"><input type="hidden" name="csrf" value="' . h($token) . '">'; echo '<form method="post"><input type="hidden" name="csrf" value="' . h($token) . '">';
echo '<input type="hidden" name="action" value="save_config">'; echo '<input type="hidden" name="action" value="save_config">';
echo '<div class="table-wrap"><table class="table">';
echo '<thead><tr><th>Variable</th><th>Value</th><th class="delete">Delete</th></tr></thead><tbody>'; echo '<details class="collapsible core-group"><summary><h3>Core settings (' . count($core) . ')</h3>'
foreach ($vars as $key => $value) { . '<span class="hint">set once, click to edit</span></summary>';
$name = h($key); echo '<p class="muted">Install-level settings: addresses, URLs, cookies, LDAP connection, keys, database and logs. '
$info = key_info($key); . 'Rarely changed. Edit them here only when you need to.</p>';
$help = help_for_key($key); echo config_table($core, false);
echo '<tr><td><code>' . $name . '</code>' . ($help !== null ? ' ' . help_icon($help) : ''); echo '</details>';
if ($info !== null) {
echo '<div class="key-desc">' . h($info['desc']) . '</div>'; echo '<h3 class="group-title">Other settings</h3>';
} echo config_table($other, true);
echo '</td><td>';
if (preg_match(SECRET_PATTERN, $key)) {
$hint = $value === '' ? '(not set)' : '(set, leave blank to keep)';
echo '<input type="password" name="value[' . $name . ']" aria-label="Value for ' . $name . '" placeholder="' . h($hint) . '" autocomplete="off">';
} else {
echo '<input type="text" name="value[' . $name . ']" aria-label="Value for ' . $name . '" value="' . h($value) . '">';
}
echo '</td><td class="delete"><input type="checkbox" name="delete[]" value="' . $name . '"></td></tr>';
}
echo '<tr class="add-row"><td><input type="text" name="new_key" list="known-keys" placeholder="NEW_VARIABLE"></td>';
echo '<td><input type="text" name="new_value" placeholder="value"></td><td class="delete muted">add</td></tr>';
echo '</tbody></table></div>';
echo '<datalist id="known-keys">'; echo '<datalist id="known-keys">';
foreach (known_keys() as $entry) { foreach (known_keys() as $entry) {
echo '<option value="' . h($entry['key']) . '">' . h($entry['desc']) . '</option>'; echo '<option value="' . h($entry['key']) . '">' . h($entry['desc']) . '</option>';
@ -280,6 +278,37 @@ foreach (known_keys() as $entry) {
echo '</tbody></table></div></details>'; echo '</tbody></table></div></details>';
page_end(); page_end();
function config_table(array $vars, bool $withAddRow): string
{
$html = '<div class="table-wrap"><table class="table">'
. '<thead><tr><th>Variable</th><th>Value</th><th class="delete">Delete</th></tr></thead><tbody>';
if ($vars === [] && !$withAddRow) {
$html .= '<tr><td colspan="3" class="muted">No core settings in this file.</td></tr>';
}
foreach ($vars as $key => $value) {
$name = h($key);
$info = key_info($key);
$help = help_for_key($key);
$html .= '<tr><td><code>' . $name . '</code>' . ($help !== null ? ' ' . help_icon($help) : '');
if ($info !== null) {
$html .= '<div class="key-desc">' . h($info['desc']) . '</div>';
}
$html .= '</td><td>';
if (preg_match(SECRET_PATTERN, $key)) {
$hint = $value === '' ? '(not set)' : '(set, leave blank to keep)';
$html .= '<input type="password" name="value[' . $name . ']" aria-label="Value for ' . $name . '" placeholder="' . h($hint) . '" autocomplete="off">';
} else {
$html .= '<input type="text" name="value[' . $name . ']" aria-label="Value for ' . $name . '" value="' . h($value) . '">';
}
$html .= '</td><td class="delete"><input type="checkbox" name="delete[]" value="' . $name . '"></td></tr>';
}
if ($withAddRow) {
$html .= '<tr class="add-row"><td><input type="text" name="new_key" list="known-keys" placeholder="NEW_VARIABLE"></td>'
. '<td><input type="text" name="new_value" placeholder="value"></td><td class="delete muted">add</td></tr>';
}
return $html . '</tbody></table></div>';
}
function permission_row(string $label, bool $ok, ?string $detail = null): string function permission_row(string $label, bool $ok, ?string $detail = null): string
{ {
$class = $ok ? 'check-ok' : 'check-missing'; $class = $ok ? 'check-ok' : 'check-missing';

View file

@ -14,6 +14,32 @@ function template_regex(string $template): string
return '/^' . implode('[A-Z0-9]+', $parts) . '$/'; return '/^' . implode('[A-Z0-9]+', $parts) . '$/';
} }
/** Install-level settings that rarely change. Shown in a closed "Core settings" section. Patterns use * wildcards. */
const DEFAULT_CORE_KEYS = [
'TINYAUTH_APPURL',
'TINYAUTH_SERVER_*',
'TINYAUTH_AUTH_SECURECOOKIE',
'TINYAUTH_AUTH_SUBDOMAINSENABLED',
'TINYAUTH_AUTH_TRUSTEDPROXIES',
'TINYAUTH_ANALYTICS_*',
'TINYAUTH_LDAP_*',
'TINYAUTH_OIDC_PRIVATEKEYPATH',
'TINYAUTH_OIDC_PUBLICKEYPATH',
'TINYAUTH_DATABASE_*',
'TINYAUTH_LOG_*',
'TINYAUTH_UI_*',
];
function is_core_key(string $key): bool
{
foreach ((config()['core_keys'] ?? DEFAULT_CORE_KEYS) as $pattern) {
if (fnmatch($pattern, $key)) {
return true;
}
}
return false;
}
function key_info(string $key): ?array function key_info(string $key): ?array
{ {
static $entries = null; static $entries = null;