Paste multiple variables with review popup, tooltips with plain/expert/example, collapsible sections
This commit is contained in:
parent
a84a3c4272
commit
6e1e902a76
7 changed files with 711 additions and 26 deletions
|
|
@ -81,6 +81,9 @@ A small PHP web UI to edit the tinyauth environment file, and to start, stop, re
|
|||
- **New app ACL:** Fills in `TINYAUTH_APPS_<NAME>_*` for forward-auth apps. Set the domain and whichever users or groups should have access.
|
||||
- **Local users:** Tinyauth hashes passwords, so create users on the server with `tinyauth user create --interactive`. Add the printed `username:hash` line to `TINYAUTH_AUTH_USERS` (comma-separated), then restart. Hashes are masked here.
|
||||
- **Blank values:** Saving or leaving a blank required value is allowed, but the page warns about every blank variable. Blank values can break tinyauth, so fill them in or delete them.
|
||||
- **Paste multiple variables:** Paste `KEY=VALUE` lines in one box, then click **Review**. A popup lists what's new and what already exists. For existing keys, choose **Keep** or **Update**. Any malformed or duplicated line, or an unfilled `<placeholder>`, fails the whole paste and the popup says why. Nothing is written until you click **Apply**.
|
||||
- **Help icons (?):** Hover or focus a **?** to see a plain-language explanation, an expert explanation, and an example. The most common keys and the tool's forms have them.
|
||||
- **Collapsible sections:** Paste, the client and app forms, local users, and the key reference start closed. Click the heading to open.
|
||||
|
||||
Every change writes a backup to `data/backups/` first.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
(function () {
|
||||
var root = document.documentElement;
|
||||
|
||||
var button = document.getElementById('theme-toggle');
|
||||
if (button) {
|
||||
button.addEventListener('click', function () {
|
||||
|
|
@ -21,4 +22,54 @@
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
document.querySelectorAll('dialog[data-autoopen]').forEach(function (dialog) {
|
||||
if (typeof dialog.showModal === 'function') {
|
||||
dialog.showModal();
|
||||
}
|
||||
});
|
||||
document.querySelectorAll('[data-close]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
var dialog = btn.closest('dialog');
|
||||
if (dialog) {
|
||||
dialog.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var float = document.createElement('div');
|
||||
float.className = 'tip-float';
|
||||
document.body.appendChild(float);
|
||||
|
||||
function place(icon) {
|
||||
var rect = icon.getBoundingClientRect();
|
||||
float.style.display = 'block';
|
||||
var left = Math.min(rect.left, window.innerWidth - float.offsetWidth - 12);
|
||||
float.style.left = Math.max(12, left) + 'px';
|
||||
var top = rect.bottom + 8;
|
||||
if (top + float.offsetHeight > window.innerHeight - 12) {
|
||||
top = Math.max(12, rect.top - float.offsetHeight - 8);
|
||||
}
|
||||
float.style.top = top + 'px';
|
||||
}
|
||||
|
||||
function show(icon) {
|
||||
var tip = icon.querySelector('.tip');
|
||||
if (!tip) {
|
||||
return;
|
||||
}
|
||||
float.innerHTML = tip.innerHTML;
|
||||
place(icon);
|
||||
}
|
||||
|
||||
function hide() {
|
||||
float.style.display = 'none';
|
||||
}
|
||||
|
||||
document.querySelectorAll('.help').forEach(function (icon) {
|
||||
icon.addEventListener('mouseenter', function () { show(icon); });
|
||||
icon.addEventListener('mouseleave', hide);
|
||||
icon.addEventListener('focus', function () { show(icon); });
|
||||
icon.addEventListener('blur', hide);
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -419,3 +419,144 @@ details.reference[open] summary { margin-bottom: 1rem; }
|
|||
display: grid;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
/* Tooltips */
|
||||
.help {
|
||||
display: inline-grid;
|
||||
place-items: center;
|
||||
width: 1.1rem;
|
||||
height: 1.1rem;
|
||||
margin-left: 0.3rem;
|
||||
border-radius: 50%;
|
||||
border: 1px solid var(--muted);
|
||||
color: var(--muted);
|
||||
font-size: 0.7rem;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
cursor: help;
|
||||
vertical-align: middle;
|
||||
text-transform: none;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
.help:hover, .help:focus { color: var(--accent); border-color: var(--accent); outline: none; }
|
||||
|
||||
.tip { display: none; }
|
||||
|
||||
.tip-float {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 100;
|
||||
width: min(360px, calc(100vw - 24px));
|
||||
padding: 0.75rem 0.85rem;
|
||||
border-radius: 10px;
|
||||
background: var(--surface-2);
|
||||
border: 1px solid var(--border);
|
||||
box-shadow: var(--shadow);
|
||||
color: var(--text);
|
||||
font-size: 0.82rem;
|
||||
font-weight: 400;
|
||||
line-height: 1.45;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.tip-float .tip-row { display: block; margin-top: 0.35rem; }
|
||||
.tip-float .tip-row:first-child { margin-top: 0; }
|
||||
.tip-float code { font-size: 0.8rem; }
|
||||
|
||||
/* Collapsible cards */
|
||||
details.collapsible > summary {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
cursor: pointer;
|
||||
list-style: none;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
details.collapsible > summary::-webkit-details-marker { display: none; }
|
||||
|
||||
details.collapsible > summary::before {
|
||||
content: "▸";
|
||||
color: var(--muted);
|
||||
width: 0.9rem;
|
||||
transition: transform 0.15s ease;
|
||||
}
|
||||
|
||||
details.collapsible[open] > summary::before { content: "▾"; }
|
||||
|
||||
details.collapsible > summary h2 { display: inline; }
|
||||
|
||||
details.collapsible .hint {
|
||||
margin-left: auto;
|
||||
color: var(--muted);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
details.collapsible[open] .hint { display: none; }
|
||||
details.collapsible[open] > summary { margin-bottom: 1rem; }
|
||||
|
||||
/* Paste box */
|
||||
.paste-box {
|
||||
width: 100%;
|
||||
min-height: 9rem;
|
||||
padding: 0.7rem 0.8rem;
|
||||
border-radius: 10px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: ui-monospace, Menlo, Consolas, monospace;
|
||||
font-size: 0.85rem;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.paste-box:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
|
||||
}
|
||||
|
||||
/* Review popup */
|
||||
dialog.modal {
|
||||
width: min(680px, 94vw);
|
||||
max-height: 88vh;
|
||||
overflow: auto;
|
||||
padding: 1.25rem 1.4rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
background: var(--surface);
|
||||
color: var(--text);
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
dialog.modal::backdrop { background: rgba(5, 7, 12, 0.6); }
|
||||
dialog.modal h3 { margin: 1rem 0 0.4rem; font-size: 0.95rem; }
|
||||
dialog.modal .card-head { margin-bottom: 0.6rem; }
|
||||
|
||||
.issues {
|
||||
margin: 0.5rem 0;
|
||||
padding: 0.7rem 0.9rem 0.7rem 2rem;
|
||||
border-radius: 10px;
|
||||
border: 1px solid color-mix(in srgb, var(--bad) 50%, transparent);
|
||||
background: color-mix(in srgb, var(--bad) 10%, transparent);
|
||||
color: var(--text);
|
||||
display: grid;
|
||||
gap: 0.35rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.issues.warn {
|
||||
border-color: color-mix(in srgb, var(--warn) 55%, transparent);
|
||||
background: color-mix(in srgb, var(--warn) 10%, transparent);
|
||||
}
|
||||
|
||||
.dup-choice label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
margin-right: 0.8rem;
|
||||
font-size: 0.85rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.dup-choice input { accent-color: var(--accent); }
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
require dirname(__DIR__) . '/src/lib.php';
|
||||
require dirname(__DIR__) . '/src/help.php';
|
||||
require dirname(__DIR__) . '/src/actions.php';
|
||||
require dirname(__DIR__) . '/src/paste.php';
|
||||
|
||||
start_session();
|
||||
|
||||
|
|
@ -20,6 +22,7 @@ if (empty($_SESSION['user'])) {
|
|||
$groups = $_SESSION['groups'] ?? [];
|
||||
$allowedGroup = load_settings()['allowed_group'] ?? '';
|
||||
$authorized = is_authorized($groups);
|
||||
$modalHtml = null;
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
require_csrf();
|
||||
|
|
@ -40,8 +43,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
handle_create_oidc_client();
|
||||
} elseif ($action === 'create_app_acl') {
|
||||
handle_create_app_acl();
|
||||
} elseif ($action === 'paste_preview') {
|
||||
$modalHtml = paste_preview((string) ($_POST['paste'] ?? ''), csrf_token());
|
||||
} elseif ($action === 'paste_apply') {
|
||||
handle_paste_apply();
|
||||
}
|
||||
|
||||
if ($modalHtml === null) {
|
||||
redirect('index.php');
|
||||
}
|
||||
}
|
||||
|
||||
$cfg = config();
|
||||
|
|
@ -57,10 +67,13 @@ page_start('Dashboard', $userHtml);
|
|||
foreach ($flashes as $flash) {
|
||||
echo '<div class="flash flash-' . h($flash['type']) . '">' . h($flash['message']) . '</div>';
|
||||
}
|
||||
if ($modalHtml !== null) {
|
||||
echo $modalHtml;
|
||||
}
|
||||
|
||||
if ($allowedGroup === '') {
|
||||
echo '<section class="card card-center">';
|
||||
echo '<h2>First-time setup</h2>';
|
||||
echo '<h2>First-time setup ' . gui_help_icon('access_group') . '</h2>';
|
||||
echo '<p class="muted">Choose the tinyauth group whose members may use this tool.</p>';
|
||||
if ($groups === []) {
|
||||
echo '<div class="flash flash-error">Your account has no groups in tinyauth. Add yourself to a group, then reload.</div>';
|
||||
|
|
@ -146,14 +159,14 @@ if (in_array(false, $perms, true)) {
|
|||
. 'from this repo and check it with <code>visudo -cf</code>.</p>';
|
||||
}
|
||||
echo '<form method="post" class="form-actions"><input type="hidden" name="csrf" value="' . h($token) . '">';
|
||||
echo '<span class="muted">Current group: <code>' . h($allowedGroup) . '</code></span>';
|
||||
echo '<span class="muted">Current group: <code>' . h($allowedGroup) . '</code> ' . gui_help_icon('access_group') . '</span>';
|
||||
echo '<button type="submit" name="action" value="reset_group" class="btn btn-ghost btn-sm">Change access group</button>';
|
||||
echo '</form>';
|
||||
echo '</section>';
|
||||
|
||||
echo '<section class="card"><div class="card-head"><h2>Quick notes</h2></div>';
|
||||
echo '<ul class="muted notes">';
|
||||
echo '<li>Saving the config writes a backup first.</li>';
|
||||
echo '<li>Saving the config writes a backup first. ' . gui_help_icon('backup') . '</li>';
|
||||
echo '<li>Changes take effect after you restart the service.</li>';
|
||||
echo '<li>Secret values are never shown. Leave a secret blank to keep it.</li>';
|
||||
echo '</ul></section>';
|
||||
|
|
@ -161,7 +174,7 @@ echo '</div>';
|
|||
|
||||
echo '<section class="card"><div class="card-head"><h2>Config <code>' . h($envPath) . '</code></h2></div>';
|
||||
if ($envReadable && ($blank = blank_warning()) !== null) {
|
||||
echo '<div class="flash flash-warn">' . h($blank) . '</div>';
|
||||
echo '<div class="flash flash-warn">' . h($blank) . ' ' . gui_help_icon('blank') . '</div>';
|
||||
}
|
||||
if (!$envReadable) {
|
||||
echo '<div class="flash flash-error">The env file cannot be read by this user.</div>';
|
||||
|
|
@ -174,7 +187,8 @@ if (!$envReadable) {
|
|||
foreach ($vars as $key => $value) {
|
||||
$name = h($key);
|
||||
$info = key_info($key);
|
||||
echo '<tr><td><code>' . $name . '</code>';
|
||||
$help = help_for_key($key);
|
||||
echo '<tr><td><code>' . $name . '</code>' . ($help !== null ? ' ' . help_icon($help) : '');
|
||||
if ($info !== null) {
|
||||
echo '<div class="key-desc">' . h($info['desc']) . '</div>';
|
||||
}
|
||||
|
|
@ -201,35 +215,48 @@ if (!$envReadable) {
|
|||
}
|
||||
echo '</section>';
|
||||
|
||||
echo '<details class="card collapsible"><summary><h2>Paste multiple variables</h2>'
|
||||
. gui_help_icon('paste') . '<span class="hint">click to open</span></summary>';
|
||||
echo '<p class="muted">Paste lines in <code>KEY=VALUE</code> form. You review them before anything is written.</p>';
|
||||
echo '<form method="post" class="stack"><input type="hidden" name="csrf" value="' . h($token) . '">';
|
||||
echo '<input type="hidden" name="action" value="paste_preview">';
|
||||
echo '<textarea name="paste" rows="8" class="paste-box" spellcheck="false" placeholder="TINYAUTH_OIDC_CLIENTS_WIKI_CLIENTID=wiki TINYAUTH_OIDC_CLIENTS_WIKI_NAME=Wiki"></textarea>';
|
||||
echo '<div class="form-actions"><span class="muted">Blank lines and lines starting with # are ignored.</span>';
|
||||
echo '<button type="submit" class="btn btn-primary">Review</button></div>';
|
||||
echo '</form></details>';
|
||||
|
||||
echo '<div class="grid-2">';
|
||||
echo '<section class="card"><div class="card-head"><h2>New OIDC client</h2></div>';
|
||||
echo '<details class="card collapsible"><summary><h2>New OIDC client</h2>' . gui_help_icon('oidc_client')
|
||||
. '<span class="hint">click to open</span></summary>';
|
||||
echo '<p class="muted">Creates the variables for a client that apps use to log in through tinyauth. '
|
||||
. 'Leave the secret blank to generate one.</p>';
|
||||
echo '<form method="post" class="stack"><input type="hidden" name="csrf" value="' . h($token) . '">';
|
||||
echo '<input type="hidden" name="action" value="create_oidc_client">';
|
||||
echo '<label>Client name <input type="text" name="client_name" placeholder="SEERR" required></label>';
|
||||
echo '<label>Client ID <input type="text" name="client_id" placeholder="defaults to the name, lowercase"></label>';
|
||||
echo '<label>Client secret <input type="password" name="client_secret" autocomplete="off" placeholder="blank = generate"></label>';
|
||||
echo '<label>Display name <input type="text" name="display_name" placeholder="defaults to the name"></label>';
|
||||
echo '<label>Redirect URIs <input type="text" name="redirect_uris" placeholder="https://app.example.com/api/callback, ..."></label>';
|
||||
echo '<label>Client name ' . gui_help_icon('client_name') . ' <input type="text" name="client_name" placeholder="SEERR" required></label>';
|
||||
echo '<label>Client ID ' . gui_help_icon('client_id') . ' <input type="text" name="client_id" placeholder="defaults to the name, lowercase"></label>';
|
||||
echo '<label>Client secret ' . gui_help_icon('client_secret') . ' <input type="password" name="client_secret" autocomplete="off" placeholder="blank = generate"></label>';
|
||||
echo '<label>Display name ' . gui_help_icon('display_name') . ' <input type="text" name="display_name" placeholder="defaults to the name"></label>';
|
||||
echo '<label>Redirect URIs ' . gui_help_icon('redirect_uris') . ' <input type="text" name="redirect_uris" placeholder="https://app.example.com/api/callback, ..."></label>';
|
||||
echo '<button type="submit" class="btn btn-primary">Create client</button>';
|
||||
echo '</form></section>';
|
||||
echo '</form></details>';
|
||||
|
||||
echo '<section class="card"><div class="card-head"><h2>New app ACL</h2></div>';
|
||||
echo '<details class="card collapsible"><summary><h2>New app ACL</h2>' . gui_help_icon('app_acl')
|
||||
. '<span class="hint">click to open</span></summary>';
|
||||
echo '<p class="muted">Creates the access rules for an app behind tinyauth (forward auth). '
|
||||
. 'Fill in what you need; empty fields are skipped.</p>';
|
||||
echo '<form method="post" class="stack"><input type="hidden" name="csrf" value="' . h($token) . '">';
|
||||
echo '<input type="hidden" name="action" value="create_app_acl">';
|
||||
echo '<label>App name <input type="text" name="app_name" placeholder="WIKI" required></label>';
|
||||
echo '<label>Domain <input type="text" name="domain" placeholder="wiki.example.com"></label>';
|
||||
echo '<label>Allowed users <input type="text" name="users_allow" placeholder="alice, bob"></label>';
|
||||
echo '<label>LDAP groups <input type="text" name="ldap_groups" placeholder="wiki-users"></label>';
|
||||
echo '<label>OAuth groups <input type="text" name="oauth_groups" placeholder="wiki-users"></label>';
|
||||
echo '<label>App name ' . gui_help_icon('app_name') . ' <input type="text" name="app_name" placeholder="WIKI" required></label>';
|
||||
echo '<label>Domain ' . gui_help_icon('domain') . ' <input type="text" name="domain" placeholder="wiki.example.com"></label>';
|
||||
echo '<label>Allowed users ' . gui_help_icon('users_allow') . ' <input type="text" name="users_allow" placeholder="alice, bob"></label>';
|
||||
echo '<label>LDAP groups ' . gui_help_icon('ldap_groups') . ' <input type="text" name="ldap_groups" placeholder="wiki-users"></label>';
|
||||
echo '<label>OAuth groups ' . gui_help_icon('oauth_groups') . ' <input type="text" name="oauth_groups" placeholder="wiki-users"></label>';
|
||||
echo '<button type="submit" class="btn btn-primary">Create app ACL</button>';
|
||||
echo '</form></section>';
|
||||
echo '</form></details>';
|
||||
echo '</div>';
|
||||
|
||||
echo '<section class="card"><div class="card-head"><h2>Local users</h2></div>';
|
||||
echo '<details class="card collapsible"><summary><h2>Local users</h2>' . gui_help_icon('local_users')
|
||||
. '<span class="hint">click to open</span></summary>';
|
||||
echo '<p class="muted">Tinyauth stores local users as <code>username:hash</code> pairs in '
|
||||
. '<code>TINYAUTH_AUTH_USERS</code> (comma-separated). This tool does not create passwords, because tinyauth hashes them.</p>';
|
||||
echo '<ol class="steps">';
|
||||
|
|
@ -239,9 +266,10 @@ echo '<li>Copy the printed <code>username:hash</code> line.</li>';
|
|||
echo '<li>Add it to <code>TINYAUTH_AUTH_USERS</code> in the config above. For several users, separate entries with commas. '
|
||||
. 'To add a user, append to the existing value. Do not replace it.</li>';
|
||||
echo '<li>Save, then restart tinyauth. Hashes are masked in this tool like other secrets.</li>';
|
||||
echo '</ol></section>';
|
||||
echo '</ol></details>';
|
||||
|
||||
echo '<details class="card reference"><summary><h2>Key reference <span class="muted">(' . count(known_keys()) . ' keys)</span></h2></summary>';
|
||||
echo '<details class="card collapsible reference"><summary><h2>Key reference <span class="muted">(' . count(known_keys()) . ' keys)</span></h2>'
|
||||
. gui_help_icon('key_reference') . '<span class="hint">click to open</span></summary>';
|
||||
echo '<input type="text" id="key-filter" placeholder="Filter keys..." class="key-filter">';
|
||||
echo '<div class="table-wrap"><table class="table" id="key-table"><thead><tr><th>Key</th><th>Description</th><th>Default</th></tr></thead><tbody>';
|
||||
foreach (known_keys() as $entry) {
|
||||
|
|
|
|||
272
src/help.php
Normal file
272
src/help.php
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Tooltip text. Each entry: 'layman' is plain language, 'expert' is the technical detail,
|
||||
* 'example' is a sample value. Keys with <NAME> 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_<NAME>_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_<NAME>_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_<NAME>_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>_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_<NAME>_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_<NAME>_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_<NAME>_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_<NAME>_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_<NAME>_*. 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_<NAME>_* 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_<NAME>_*.',
|
||||
'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 <NAME> are templates: replace NAME with your client or app name.',
|
||||
'example' => 'TINYAUTH_APPS_<NAME>_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 '<span class="help" tabindex="0" role="button" aria-label="Help">?'
|
||||
. '<span class="tip">'
|
||||
. '<span class="tip-row"><b>Plain:</b> ' . h($help['layman']) . '</span>'
|
||||
. '<span class="tip-row"><b>Expert:</b> ' . h($help['expert']) . '</span>'
|
||||
. '<span class="tip-row"><b>Example:</b> <code>' . h($help['example']) . '</code></span>'
|
||||
. '</span></span>';
|
||||
}
|
||||
|
||||
function gui_help_icon(string $id): string
|
||||
{
|
||||
$all = gui_help();
|
||||
return isset($all[$id]) ? help_icon($all[$id]) : '';
|
||||
}
|
||||
11
src/lib.php
11
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_<NAME>_CONFIG_DOMAIN into a regex. */
|
||||
function template_regex(string $template): string
|
||||
{
|
||||
$parts = array_map(fn (string $p): string => preg_quote($p, '/'), explode('<NAME>', $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('<NAME>', $entry['key']));
|
||||
$regex = '/^' . implode('[A-Z0-9]+', $parts) . '$/';
|
||||
$entries[] = ['regex' => $regex] + $entry;
|
||||
$entries[] = ['regex' => template_regex($entry['key'])] + $entry;
|
||||
}
|
||||
}
|
||||
foreach ($entries as $entry) {
|
||||
|
|
|
|||
185
src/paste.php
Normal file
185
src/paste.php
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Parses pasted KEY=VALUE lines. Any error means nothing is added.
|
||||
* Returns entries, errors (block the paste), and warnings (shown, but allowed).
|
||||
*/
|
||||
function parse_env_paste(string $text): array
|
||||
{
|
||||
$entries = [];
|
||||
$errors = [];
|
||||
$warnings = [];
|
||||
$lineOf = [];
|
||||
|
||||
foreach (preg_split('/\r\n|\n|\r/', $text) as $index => $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 = '<dialog class="modal" data-autoopen aria-labelledby="paste-title"><form method="post" class="stack">'
|
||||
. '<input type="hidden" name="csrf" value="' . h($token) . '">'
|
||||
. '<div class="card-head"><h2 id="paste-title">' . h($title) . ' ' . gui_help_icon('paste') . '</h2></div>';
|
||||
|
||||
if ($hasErrors) {
|
||||
$html .= '<p class="muted">Nothing was changed. Fix these lines, then paste again:</p><ul class="issues">';
|
||||
foreach ($plan['errors'] as $error) {
|
||||
$html .= '<li>' . h($error) . '</li>';
|
||||
}
|
||||
$html .= '</ul>';
|
||||
$html .= '<div class="form-actions"><span></span><button type="button" class="btn btn-primary" data-close>Close</button></div>';
|
||||
} else {
|
||||
if ($plan['new'] !== []) {
|
||||
$html .= '<h3>New variables (' . count($plan['new']) . ')</h3><div class="table-wrap"><table class="table"><tbody>';
|
||||
foreach ($plan['new'] as $key => $value) {
|
||||
$html .= '<tr><td><code>' . h($key) . '</code></td><td>' . h(display_value($key, $value)) . '</td></tr>';
|
||||
}
|
||||
$html .= '</tbody></table></div>';
|
||||
}
|
||||
|
||||
if ($plan['dups'] !== []) {
|
||||
$html .= '<h3>Already set (' . count($plan['dups']) . ') ' . gui_help_icon('duplicate') . '</h3>';
|
||||
$html .= '<div class="table-wrap"><table class="table"><thead><tr><th>Variable</th><th>Current</th><th>Pasted</th><th>Action</th></tr></thead><tbody>';
|
||||
foreach ($plan['dups'] as $key => $dup) {
|
||||
$name = h($key);
|
||||
$html .= '<tr><td><code>' . $name . '</code></td>'
|
||||
. '<td>' . h(display_value($key, $dup['current'])) . '</td>'
|
||||
. '<td>' . h(display_value($key, $dup['new'])) . '</td>'
|
||||
. '<td class="dup-choice">'
|
||||
. '<label><input type="radio" name="dup[' . $name . ']" value="keep" checked> Keep</label>'
|
||||
. '<label><input type="radio" name="dup[' . $name . ']" value="update"> Update</label>'
|
||||
. '</td></tr>';
|
||||
}
|
||||
$html .= '</tbody></table></div>';
|
||||
}
|
||||
|
||||
if ($plan['warnings'] !== []) {
|
||||
$html .= '<ul class="issues warn">';
|
||||
foreach ($plan['warnings'] as $warning) {
|
||||
$html .= '<li>' . h($warning) . '</li>';
|
||||
}
|
||||
$html .= '</ul>';
|
||||
}
|
||||
|
||||
$html .= '<input type="hidden" name="action" value="paste_apply">'
|
||||
. '<div class="form-actions"><button type="button" class="btn btn-ghost" data-close>Cancel</button>'
|
||||
. '<button type="submit" class="btn btn-primary">Apply</button></div>';
|
||||
}
|
||||
|
||||
return $html . '</form></dialog>';
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue