'
+ . gui_help_icon('paste') . 'click to open';
+echo '
Paste lines in KEY=VALUE form. You review them before anything is written.
';
+echo '';
+
echo '
';
-echo '
New OIDC client
';
+echo '
New OIDC client
' . gui_help_icon('oidc_client')
+ . 'click to open';
echo '
Creates the variables for a client that apps use to log in through tinyauth. '
. 'Leave the secret blank to generate one.
';
echo '';
+echo '';
-echo '
New app ACL
';
+echo '
New app ACL
' . gui_help_icon('app_acl')
+ . 'click to open';
echo '
Creates the access rules for an app behind tinyauth (forward auth). '
. 'Fill in what you need; empty fields are skipped.
';
echo '';
+echo '';
echo '
';
-echo '
Local users
';
+echo '
Local users
' . gui_help_icon('local_users')
+ . 'click to open';
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 '';
@@ -239,9 +266,10 @@ 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.
';
foreach (known_keys() as $entry) {
diff --git a/src/help.php b/src/help.php
new file mode 100644
index 0000000..00bf0e8
--- /dev/null
+++ b/src/help.php
@@ -0,0 +1,272 @@
+ match any client or app name.
+ */
+function key_help(): array
+{
+ return [
+ ['key' => 'TINYAUTH_APPURL',
+ 'layman' => 'The web address people type to reach tinyauth.',
+ 'expert' => 'Public base URL of this tinyauth instance. Tinyauth builds its OIDC issuer and cookie domain from it. Must be a full https URL on a real domain, not an IP or localhost.',
+ 'example' => 'https://auth.example.com'],
+ ['key' => 'TINYAUTH_SERVER_ADDRESS',
+ 'layman' => 'Which network address tinyauth listens on. Use 127.0.0.1 if only a local reverse proxy should reach it.',
+ 'expert' => 'Bind address for the HTTP server. Default 0.0.0.0 listens on all interfaces. 127.0.0.1 restricts it to loopback, which is typical behind nginx.',
+ 'example' => '127.0.0.1'],
+ ['key' => 'TINYAUTH_SERVER_PORT',
+ 'layman' => 'The port tinyauth listens on. nginx forwards to this port.',
+ 'expert' => 'TCP port for the HTTP server. Default 3000. Must match the proxy_pass or upstream in nginx.',
+ 'example' => '3008'],
+ ['key' => 'TINYAUTH_AUTH_SECURECOOKIE',
+ 'layman' => 'Only send login cookies over https. Turn on when the site uses https.',
+ 'expert' => 'Sets the Secure flag on session cookies. Default false. Use true whenever APPURL is https; false is only for plain-http testing.',
+ 'example' => 'true'],
+ ['key' => 'TINYAUTH_AUTH_SUBDOMAINSENABLED',
+ 'layman' => 'Share the login between your subdomains, so logging in once works on wiki.example.com and auth.example.com.',
+ 'expert' => 'Scopes session cookies to the parent domain. Default true. Set false if every protected app shares one exact hostname.',
+ 'example' => 'true'],
+ ['key' => 'TINYAUTH_ANALYTICS_ENABLED',
+ 'layman' => 'Whether tinyauth periodically reports its version. Turn off if you want no phoning home.',
+ 'expert' => 'Enables periodic version information collection. Default true. Set false to disable all outbound analytics.',
+ 'example' => 'false'],
+ ['key' => 'TINYAUTH_AUTH_TRUSTEDPROXIES',
+ 'layman' => 'The servers allowed to tell tinyauth the real visitor IP, such as nginx.',
+ 'expert' => 'Comma-separated IPs or CIDR ranges of reverse proxies trusted to set X-Forwarded-For and related headers. Requests from other sources have those headers ignored.',
+ 'example' => '127.0.0.1,192.168.1.0/24'],
+ ['key' => 'TINYAUTH_AUTH_USERS',
+ 'layman' => 'The local username and password accounts tinyauth knows about.',
+ 'expert' => 'Comma-separated username:bcrypt_hash pairs. Create each hash with "tinyauth user create --interactive" and paste the printed pair here, then restart.',
+ 'example' => 'alice:$2a$10$...,bob:$2a$10$...'],
+ ['key' => 'TINYAUTH_AUTH_SESSIONEXPIRY',
+ 'layman' => 'How long a login lasts before people must log in again.',
+ 'expert' => 'Session lifetime in seconds. Default 86400 (one day).',
+ 'example' => '604800 (one week)'],
+ ['key' => 'TINYAUTH_AUTH_SESSIONMAXLIFETIME',
+ 'layman' => 'A hard cap on how long a login can last, even if the person is active.',
+ 'expert' => 'Maximum session lifetime in seconds, regardless of activity. Default 0, which means no cap.',
+ 'example' => '2592000 (30 days)'],
+ ['key' => 'TINYAUTH_AUTH_LOGINMAXRETRIES',
+ 'layman' => 'How many wrong passwords are allowed before tinyauth slows down or blocks further tries.',
+ 'expert' => 'Maximum failed login attempts before the login is throttled. Default 3.',
+ 'example' => '5'],
+ ['key' => 'TINYAUTH_AUTH_LOGINTIMEOUT',
+ 'layman' => 'How long a login attempt can sit idle before it times out.',
+ 'expert' => 'Login timeout in seconds, used for the throttle window and pending logins. Default 300.',
+ 'example' => '300'],
+ ['key' => 'TINYAUTH_LDAP_ADDRESS',
+ 'layman' => 'The address of your LDAP directory (for example Active Directory or OpenLDAP).',
+ 'expert' => 'LDAP server URL. Use ldaps:// for TLS, or ldap:// only with TLS upgrade. Port 636 for ldaps, 389 for plain ldap.',
+ 'example' => 'ldaps://ldap.example.com:636'],
+ ['key' => 'TINYAUTH_LDAP_BINDDN',
+ 'layman' => 'The account tinyauth uses to look up users in LDAP.',
+ 'expert' => 'Distinguished name of the read-only service account used to bind and search. Leave empty for anonymous bind if your directory allows it.',
+ 'example' => 'cn=tinyauth,ou=services,dc=example,dc=com'],
+ ['key' => 'TINYAUTH_LDAP_BINDPASSWORD',
+ 'layman' => 'The password for the LDAP lookup account above.',
+ 'expert' => 'Password for the bind DN. Store it here or point TINYAUTH_LDAP_BINDPASSWORDFILE at a file with the password. Treat as a secret.',
+ 'example' => '(a long random password)'],
+ ['key' => 'TINYAUTH_LDAP_BASEDN',
+ 'layman' => 'Where in the LDAP directory to look for users.',
+ 'expert' => 'Base DN for user searches. Usually the domain root or the users container.',
+ 'example' => 'ou=people,dc=example,dc=com'],
+ ['key' => 'TINYAUTH_LDAP_SEARCHFILTER',
+ 'layman' => 'How tinyauth finds a user from the username they typed. %s is replaced with that username.',
+ 'expert' => 'LDAP filter with %s for the username. Default (uid=%s). For Active Directory use (sAMAccountName=%s).',
+ 'example' => '(sAMAccountName=%s)'],
+ ['key' => 'TINYAUTH_LDAP_INSECURE',
+ 'layman' => 'Allows LDAP connections without proper encryption or certificate checks. Only for testing.',
+ 'expert' => 'Skips TLS certificate verification and allows unencrypted LDAP. Default false. Avoid in production.',
+ 'example' => 'false'],
+ ['key' => 'TINYAUTH_OIDC_CLIENTS__CLIENTID',
+ 'layman' => 'The public name an app uses to identify itself to tinyauth.',
+ 'expert' => 'OAuth/OIDC client_id. Must match the client_id configured in the app exactly.',
+ 'example' => 'tinyauth-web'],
+ ['key' => 'TINYAUTH_OIDC_CLIENTS__CLIENTSECRET',
+ 'layman' => 'A private password shared between the app and tinyauth. Keep it secret.',
+ 'expert' => 'Client secret used in the token exchange. Generate a long random value, for example "openssl rand -hex 32". Rotating it means updating both sides.',
+ 'example' => 'a 64-character random hex string'],
+ ['key' => 'TINYAUTH_OIDC_CLIENTS__TRUSTEDREDIRECTURIS',
+ 'layman' => 'The exact web addresses tinyauth may send people back to after login. Anything else is refused.',
+ 'expert' => 'Comma-separated list of allowed redirect_uri values. Matched exactly: scheme, host, path, and trailing slash all count.',
+ 'example' => 'https://app.example.com/api/auth/callback/oidc'],
+ ['key' => 'TINYAUTH_OIDC_CLIENTS__NAME',
+ 'layman' => 'The friendly name shown for this app on the login screen.',
+ 'expert' => 'Display name for the client ("Client name in UI" in tinyauth help). Cosmetic only.',
+ 'example' => 'Seerr'],
+ ['key' => 'TINYAUTH_OIDC_PRIVATEKEYPATH',
+ 'layman' => 'Where tinyauth keeps the private key it uses to sign login tokens. Back it up and keep it private.',
+ 'expert' => 'Path to the RSA private key used to sign ID tokens. Default ./tinyauth_oidc_key, relative to the service working directory. Replacing it invalidates existing tokens.',
+ 'example' => '/var/lib/tinyauth/oidc_key'],
+ ['key' => 'TINYAUTH_OIDC_PUBLICKEYPATH',
+ 'layman' => 'Where the public half of that key is kept. Apps use it to check login tokens.',
+ 'expert' => 'Path to the matching public key. Default ./tinyauth_oidc_key.pub. Keep it paired with the private key.',
+ 'example' => '/var/lib/tinyauth/oidc_key.pub'],
+ ['key' => 'TINYAUTH_APPS__CONFIG_DOMAIN',
+ 'layman' => 'The website address that tinyauth protects with a login.',
+ 'expert' => 'Domain matched against the forwarded Host header in forward-auth requests. Without it, tinyauth does not match this app.',
+ 'example' => 'wiki.example.com'],
+ ['key' => 'TINYAUTH_APPS__USERS_ALLOW',
+ 'layman' => 'Which usernames may open this app. Leave empty to allow any logged-in user.',
+ 'expert' => 'Comma-separated usernames allowed by the ACL. Combine with group rules as your tinyauth version defines them.',
+ 'example' => 'alice,bob'],
+ ['key' => 'TINYAUTH_APPS__LDAP_GROUPS',
+ 'layman' => 'LDAP groups that may open this app. Members of any listed group get in.',
+ 'expert' => 'Comma-separated LDAP group names required for access.',
+ 'example' => 'wiki-users,admins'],
+ ['key' => 'TINYAUTH_APPS__OAUTH_GROUPS',
+ 'layman' => 'OAuth or OIDC groups that may open this app.',
+ 'expert' => 'Comma-separated group claims from the upstream OAuth/OIDC provider that are required for access.',
+ 'example' => 'wiki-users'],
+ ['key' => 'TINYAUTH_LOG_LEVEL',
+ 'layman' => 'How much detail tinyauth writes to its log. Use debug only while troubleshooting.',
+ 'expert' => 'Log verbosity, for example debug, info (default), warn, or error.',
+ 'example' => 'info'],
+ ['key' => 'TINYAUTH_DATABASE_PATH',
+ 'layman' => 'The file where tinyauth keeps its data, such as sessions.',
+ 'expert' => 'SQLite database file path. Default ./tinyauth.db relative to the service working directory. Back it up with the rest of the state.',
+ 'example' => '/var/lib/tinyauth/tinyauth.db'],
+ ['key' => 'TINYAUTH_UI_TITLE',
+ 'layman' => 'The title shown on the tinyauth login page.',
+ 'expert' => 'Page title and header text for the tinyauth UI. Default "Tinyauth".',
+ 'example' => 'Clayton\'s Login'],
+ ];
+}
+
+/** Tooltip text for the tool's own forms and sections. */
+function gui_help(): array
+{
+ return [
+ 'paste' => [
+ 'layman' => 'Paste several variables at once, one per line. The page shows a review first, and nothing is written until you confirm.',
+ 'expert' => 'Lines are KEY=VALUE. Blank lines and lines starting with # are ignored. Any malformed or duplicated line fails the whole paste. Existing keys need a choice: keep or update.',
+ 'example' => 'TINYAUTH_OIDC_CLIENTS_WIKI_CLIENTID=wiki',
+ ],
+ 'duplicate' => [
+ 'layman' => 'This variable already exists in your config. Keep leaves the current value; update replaces it with the pasted one.',
+ 'expert' => 'A duplicate is any pasted key already present in the env file. Keep is the safe default. Update rewrites only that line, and a backup is taken first.',
+ 'example' => 'Keep = safe default',
+ ],
+ 'oidc_client' => [
+ 'layman' => 'An OIDC client is an app that uses tinyauth to log its users in, like "Sign in with tinyauth".',
+ 'expert' => 'Creates the CLIENTID, CLIENTSECRET, NAME, and TRUSTEDREDIRECTURIS variables for one client. You still need to put the same ID and secret in the app.',
+ 'example' => 'Client name SEERR, client ID seerr',
+ ],
+ 'client_name' => [
+ 'layman' => 'A short name for the app, used in the variable names. Letters and digits only.',
+ 'expert' => 'Becomes the NAME part of TINYAUTH_OIDC_CLIENTS__*. Uppercased, letters and digits only, no underscores.',
+ 'example' => 'SEERR',
+ ],
+ 'client_id' => [
+ 'layman' => 'The ID the app sends to tinyauth. Leave blank to use the name in lowercase.',
+ 'expert' => 'Written as CLIENTID. Must match the client ID configured in the app.',
+ 'example' => 'seerr',
+ ],
+ 'client_secret' => [
+ 'layman' => 'The password the app uses with tinyauth. Leave blank and the tool generates a strong one.',
+ 'expert' => 'Written as CLIENTSECRET. A generated secret is shown once after saving, so copy it into the app then.',
+ 'example' => 'leave blank to generate',
+ ],
+ 'display_name' => [
+ 'layman' => 'The name people see on the login screen for this app. Defaults to the client name.',
+ 'expert' => 'Written as NAME. Cosmetic only.',
+ 'example' => 'Seerr',
+ ],
+ 'redirect_uris' => [
+ 'layman' => 'Where tinyauth may send people after they log in. Separate several with commas. The address must be exact.',
+ 'expert' => 'Written as TRUSTEDREDIRECTURIS. Must match the callback URL the app uses, including scheme, host, and path.',
+ 'example' => 'https://seerr.example.com/api/v1/auth/oidc/callback',
+ ],
+ 'app_acl' => [
+ 'layman' => 'Rules for an app that sits behind nginx. nginx asks tinyauth before showing the app, and these rules decide who gets in.',
+ 'expert' => 'Forward-auth app ACL. Writes TINYAUTH_APPS__* keys. Needs a matching nginx auth_request or forward-auth setup.',
+ 'example' => 'app WIKI, domain wiki.example.com',
+ ],
+ 'app_name' => [
+ 'layman' => 'A short name for the app, used in the variable names. Letters and digits only.',
+ 'expert' => 'Becomes the NAME part of TINYAUTH_APPS__*.',
+ 'example' => 'WIKI',
+ ],
+ 'domain' => [
+ 'layman' => 'The address of the app that tinyauth should protect.',
+ 'expert' => 'Written as CONFIG_DOMAIN. The forwarded Host header must match it.',
+ 'example' => 'wiki.example.com',
+ ],
+ 'users_allow' => [
+ 'layman' => 'Usernames allowed into this app, separated by commas.',
+ 'expert' => 'Written as USERS_ALLOW. Comma-separated.',
+ 'example' => 'alice, bob',
+ ],
+ 'ldap_groups' => [
+ 'layman' => 'LDAP groups whose members may open this app.',
+ 'expert' => 'Written as LDAP_GROUPS. Comma-separated LDAP group names.',
+ 'example' => 'wiki-users',
+ ],
+ 'oauth_groups' => [
+ 'layman' => 'Groups from your OIDC or OAuth provider whose members may open this app.',
+ 'expert' => 'Written as OAUTH_GROUPS. Comma-separated group names from the upstream provider.',
+ 'example' => 'wiki-users',
+ ],
+ 'local_users' => [
+ 'layman' => 'Accounts that live in tinyauth itself, not in LDAP or another provider.',
+ 'expert' => 'Stored as username:bcrypt pairs in TINYAUTH_AUTH_USERS. This tool does not hash passwords, so tinyauth creates the hash.',
+ 'example' => 'alice:$2a$10$...',
+ ],
+ 'access_group' => [
+ 'layman' => 'Only members of this tinyauth group can use this tool.',
+ 'expert' => 'Checked against the groups claim of your OIDC login on every request. Changing it means picking a group from your own groups again.',
+ 'example' => 'tinyauth-admins',
+ ],
+ 'backup' => [
+ 'layman' => 'Before any change, the current env file is copied, so you can roll back.',
+ 'expert' => 'Each write copies the env file to data/backups/ with a timestamp, then writes the new file in place. Permissions are kept.',
+ 'example' => 'data/backups/tinyauth.env.20261201-204852',
+ ],
+ 'blank' => [
+ 'layman' => 'A variable with no value. Allowed, but tinyauth may not work with it empty.',
+ 'expert' => 'An empty KEY= line overrides defaults with an empty string in systemd. Fill it in or delete it.',
+ 'example' => 'TINYAUTH_OIDC_CLIENTS_SEERR_CLIENTID=',
+ ],
+ 'key_reference' => [
+ 'layman' => 'Every setting tinyauth accepts, with a plain description and default.',
+ 'expert' => 'Generated from "tinyauth --help" for tinyauth v5.2.0. Names with are templates: replace NAME with your client or app name.',
+ 'example' => 'TINYAUTH_APPS__CONFIG_DOMAIN',
+ ],
+ ];
+}
+
+/** Finds tooltip text for a key from the table above, or null. */
+function help_for_key(string $key): ?array
+{
+ static $entries = null;
+ if ($entries === null) {
+ $entries = [];
+ foreach (key_help() as $entry) {
+ $entries[] = ['regex' => template_regex($entry['key'])] + $entry;
+ }
+ }
+ foreach ($entries as $entry) {
+ if (preg_match($entry['regex'], $key)) {
+ return $entry;
+ }
+ }
+ return null;
+}
+
+function help_icon(array $help): string
+{
+ return '?'
+ . ''
+ . 'Plain: ' . h($help['layman']) . ''
+ . 'Expert: ' . h($help['expert']) . ''
+ . 'Example:' . h($help['example']) . ''
+ . '';
+}
+
+function gui_help_icon(string $id): string
+{
+ $all = gui_help();
+ return isset($all[$id]) ? help_icon($all[$id]) : '';
+}
diff --git a/src/lib.php b/src/lib.php
index 989f319..b037890 100644
--- a/src/lib.php
+++ b/src/lib.php
@@ -7,15 +7,20 @@ const SERVICE_ACTIONS = ['status', 'start', 'stop', 'restart'];
require_once __DIR__ . '/keys.php';
+/** Turns a key template such as TINYAUTH_APPS__CONFIG_DOMAIN into a regex. */
+function template_regex(string $template): string
+{
+ $parts = array_map(fn (string $p): string => preg_quote($p, '/'), explode('', $template));
+ return '/^' . implode('[A-Z0-9]+', $parts) . '$/';
+}
+
function key_info(string $key): ?array
{
static $entries = null;
if ($entries === null) {
$entries = [];
foreach (known_keys() as $entry) {
- $parts = array_map(fn (string $p): string => preg_quote($p, '/'), explode('', $entry['key']));
- $regex = '/^' . implode('[A-Z0-9]+', $parts) . '$/';
- $entries[] = ['regex' => $regex] + $entry;
+ $entries[] = ['regex' => template_regex($entry['key'])] + $entry;
}
}
foreach ($entries as $entry) {
diff --git a/src/paste.php b/src/paste.php
new file mode 100644
index 0000000..c663c1e
--- /dev/null
+++ b/src/paste.php
@@ -0,0 +1,185 @@
+ $raw) {
+ $lineNo = $index + 1;
+ $line = trim($raw);
+ if ($line === '' || str_starts_with($line, '#')) {
+ continue;
+ }
+ if (!preg_match('/^([^=]*)=(.*)$/', $line, $m)) {
+ $errors[] = "Line $lineNo: expected KEY=VALUE, got \"" . $line . '".';
+ continue;
+ }
+ $key = trim($m[1]);
+ $value = trim($m[2]);
+
+ if (!preg_match(KEY_PATTERN, $key)) {
+ $errors[] = "Line $lineNo: \"$key\" is not a valid variable name (letters, digits and underscores).";
+ continue;
+ }
+ if (preg_match('/^<.*>$/', $value)) {
+ $errors[] = "Line $lineNo: $key still has the placeholder $value. Replace it with a real value.";
+ continue;
+ }
+ if (isset($lineOf[$key])) {
+ $errors[] = "Line $lineNo: $key is also on line {$lineOf[$key]}. Keep only one.";
+ continue;
+ }
+ if ($value === '') {
+ $warnings[] = "$key has no value.";
+ }
+ if (key_info($key) === null) {
+ $warnings[] = "$key is not a known tinyauth key. Check the spelling.";
+ }
+ $entries[$key] = $value;
+ $lineOf[$key] = $lineNo;
+ }
+
+ if ($entries === [] && $errors === []) {
+ $errors[] = 'Nothing to add. Paste at least one KEY=VALUE line.';
+ }
+ return ['entries' => $entries, 'errors' => $errors, 'warnings' => $warnings];
+}
+
+/** Splits parsed entries into new variables and duplicates of what is already in the env file. */
+function paste_plan(string $text): array
+{
+ $parsed = parse_env_paste($text);
+ $current = env_parse(current_env());
+ $new = [];
+ $dups = [];
+ foreach ($parsed['entries'] as $key => $value) {
+ if (array_key_exists($key, $current)) {
+ $dups[$key] = ['current' => $current[$key], 'new' => $value];
+ } else {
+ $new[$key] = $value;
+ }
+ }
+ return $parsed + ['new' => $new, 'dups' => $dups];
+}
+
+function display_value(string $key, string $value): string
+{
+ if (preg_match(SECRET_PATTERN, $key)) {
+ return $value === '' ? '(empty)' : '(hidden)';
+ }
+ return $value === '' ? '(empty)' : $value;
+}
+
+/** Runs the paste check. Stores the text for the apply step when it is valid. */
+function paste_preview(string $text, string $token): string
+{
+ $plan = paste_plan($text);
+ if ($plan['errors'] === []) {
+ $_SESSION['paste_pending'] = $text;
+ } else {
+ unset($_SESSION['paste_pending']);
+ }
+ return paste_modal($plan, $token);
+}
+
+function paste_modal(array $plan, string $token): string
+{
+ $hasErrors = $plan['errors'] !== [];
+ $title = $hasErrors ? 'Paste needs fixing' : 'Review pasted variables';
+
+ $html = '';
+}
+
+function handle_paste_apply(): void
+{
+ $text = $_SESSION['paste_pending'] ?? null;
+ unset($_SESSION['paste_pending']);
+ if ($text === null) {
+ flash('error', 'Nothing is waiting to be added. Paste the variables again.');
+ return;
+ }
+
+ $plan = paste_plan($text);
+ if ($plan['errors'] !== []) {
+ flash('error', 'Not added: ' . implode(' ', $plan['errors']));
+ return;
+ }
+
+ $choices = (array) ($_POST['dup'] ?? []);
+ $changes = $plan['new'];
+ $updated = 0;
+ foreach ($plan['dups'] as $key => $dup) {
+ if (($choices[$key] ?? 'keep') === 'update') {
+ $changes[$key] = $dup['new'];
+ $updated++;
+ }
+ }
+ if ($changes === []) {
+ flash('info', 'No changes. Every pasted variable was kept as it was.');
+ return;
+ }
+
+ $backup = apply_env_changes($changes, []);
+ if ($backup === null) {
+ return;
+ }
+ $added = count($plan['new']);
+ flash('ok', "Added $added, updated $updated. Restart tinyauth to apply. Backup: $backup.");
+}