diff --git a/config.example.php b/config.example.php index 752465b..ebd3c45 100644 --- a/config.example.php +++ b/config.example.php @@ -24,6 +24,23 @@ return [ // Full path to systemctl. Must match the path in sudoers. '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/. 'data_dir' => dirname(__DIR__) . '/data', ]; diff --git a/public/assets/style.css b/public/assets/style.css index 0e8e21f..a5cc930 100644 --- a/public/assets/style.css +++ b/public/assets/style.css @@ -578,3 +578,10 @@ dialog.modal code { dialog.modal .table-wrap { overflow-x: visible; } 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; } diff --git a/public/index.php b/public/index.php index 61f8b08..d56512a 100644 --- a/public/index.php +++ b/public/index.php @@ -180,30 +180,28 @@ if (!$envReadable) { echo '
The env file cannot be read by this user.
'; } else { $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 '
'; echo ''; - echo '
'; - echo ''; - foreach ($vars as $key => $value) { - $name = h($key); - $info = key_info($key); - $help = help_for_key($key); - echo ''; - } - echo ''; - echo ''; - echo '
VariableValueDelete
' . $name . '' . ($help !== null ? ' ' . help_icon($help) : ''); - if ($info !== null) { - echo '
' . h($info['desc']) . '
'; - } - echo '
'; - if (preg_match(SECRET_PATTERN, $key)) { - $hint = $value === '' ? '(not set)' : '(set, leave blank to keep)'; - echo ''; - } else { - echo ''; - } - echo '
add
'; + + echo '

Core settings (' . count($core) . ')

' + . 'set once, click to edit
'; + echo '

Install-level settings: addresses, URLs, cookies, LDAP connection, keys, database and logs. ' + . 'Rarely changed. Edit them here only when you need to.

'; + echo config_table($core, false); + echo '
'; + + echo '

Other settings

'; + echo config_table($other, true); echo ''; foreach (known_keys() as $entry) { echo ''; @@ -280,6 +278,37 @@ foreach (known_keys() as $entry) { echo ''; page_end(); +function config_table(array $vars, bool $withAddRow): string +{ + $html = '
' + . ''; + if ($vars === [] && !$withAddRow) { + $html .= ''; + } + foreach ($vars as $key => $value) { + $name = h($key); + $info = key_info($key); + $help = help_for_key($key); + $html .= ''; + } + if ($withAddRow) { + $html .= '' + . ''; + } + return $html . '
VariableValueDelete
No core settings in this file.
' . $name . '' . ($help !== null ? ' ' . help_icon($help) : ''); + if ($info !== null) { + $html .= '
' . h($info['desc']) . '
'; + } + $html .= '
'; + if (preg_match(SECRET_PATTERN, $key)) { + $hint = $value === '' ? '(not set)' : '(set, leave blank to keep)'; + $html .= ''; + } else { + $html .= ''; + } + $html .= '
add
'; +} + function permission_row(string $label, bool $ok, ?string $detail = null): string { $class = $ok ? 'check-ok' : 'check-missing'; diff --git a/src/lib.php b/src/lib.php index b037890..0200752 100644 --- a/src/lib.php +++ b/src/lib.php @@ -14,6 +14,32 @@ function template_regex(string $template): string 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 { static $entries = null;