Initial upload to Gitea
This commit is contained in:
1 parent
78193254ad
commit
8478998cae
1485 files changed
+461025
-42348
No files matched your search
+416
-9
@@ -4,7 +4,9 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Opening <%= serviceLabel %>...</title>
|
||||
<style>
|
||||
<link id="favicon" rel="icon" type="<%= (typeof branding !== 'undefined' && branding && branding.faviconMimeType) ? branding.faviconMimeType : 'image/webp' %>" sizes="<%= (typeof branding !== 'undefined' && branding && branding.faviconMimeType === 'image/svg+xml') ? 'any' : '16x16' %>" href="<%= (typeof branding !== 'undefined' && branding && branding.faviconUrl) ? branding.faviconUrl : ((typeof branding !== 'undefined' && branding && branding.logoUrl) ? branding.logoUrl : '/images/adpanel-dark.svg') %>" />
|
||||
<link rel="alternate icon" type="<%= (typeof branding !== 'undefined' && branding && branding.faviconMimeType) ? branding.faviconMimeType : 'image/webp' %>" href="<%= (typeof branding !== 'undefined' && branding && branding.faviconUrl) ? branding.faviconUrl : ((typeof branding !== 'undefined' && branding && branding.logoUrl) ? branding.logoUrl : '/images/adpanel-dark.svg') %>" />
|
||||
<style nonce="<%= cspNonce %>">
|
||||
:root {
|
||||
color-scheme: light;
|
||||
}
|
||||
@@ -96,6 +98,93 @@
|
||||
background: #192742;
|
||||
border: 1px solid rgba(255, 255, 255, 0.14);
|
||||
}
|
||||
/* Inline identity verification for the pgAdmin step-up challenge. The
|
||||
credential is sent only in the JSON POST body and never rendered. */
|
||||
.stepup {
|
||||
margin-top: 16px;
|
||||
display: none;
|
||||
}
|
||||
.stepup.show {
|
||||
display: block;
|
||||
}
|
||||
.stepup-label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
color: #b6c5e5;
|
||||
font-size: 13px;
|
||||
}
|
||||
.stepup-input {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
color: #e7eefc;
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
border: 1px solid rgba(255, 255, 255, 0.14);
|
||||
border-radius: 10px;
|
||||
padding: 10px 12px;
|
||||
font-size: 13px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
/* One-time display of credentials reset by backend recovery. Values are
|
||||
injected via textContent only (never markup, URLs, storage, or logs). */
|
||||
.recover-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(4, 8, 16, 0.78);
|
||||
display: none;
|
||||
place-items: center;
|
||||
padding: 24px;
|
||||
box-sizing: border-box;
|
||||
z-index: 50;
|
||||
}
|
||||
.recover-overlay.show {
|
||||
display: grid;
|
||||
}
|
||||
.recover-warning {
|
||||
margin-top: 12px;
|
||||
color: #ffe1a8;
|
||||
background: rgba(255, 176, 32, 0.12);
|
||||
border: 1px solid rgba(255, 176, 32, 0.35);
|
||||
border-radius: 10px;
|
||||
padding: 10px 12px;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.recover-note {
|
||||
margin-top: 12px;
|
||||
color: #b6c5e5;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
.cred-rows {
|
||||
margin-top: 14px;
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
}
|
||||
.cred-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: stretch;
|
||||
}
|
||||
.cred-value {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
border: 1px solid rgba(255, 255, 255, 0.14);
|
||||
border-radius: 10px;
|
||||
padding: 10px 12px;
|
||||
font-size: 13px;
|
||||
word-break: break-all;
|
||||
align-self: center;
|
||||
}
|
||||
.cred-actions {
|
||||
margin-top: 18px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
@@ -105,7 +194,7 @@
|
||||
<div class="wrap">
|
||||
<div class="card" data-service="<%= service %>">
|
||||
<h1 class="title">Opening <%= serviceLabel %></h1>
|
||||
<p class="subtitle">Generating a secure one-time link and preparing a safe session for this tab.</p>
|
||||
<p class="subtitle">Issuing a short-lived, cookie-scoped session for this browser and preparing a safe session for this tab.</p>
|
||||
<div class="status"><span class="spinner"></span><span id="statusText">Requesting secure token...</span></div>
|
||||
<div id="errorBox" class="error"></div>
|
||||
<div id="actionBox" class="actions">
|
||||
@@ -115,17 +204,288 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="recover-overlay" id="recoverOverlay" role="dialog" aria-modal="true" aria-labelledby="recoverTitle">
|
||||
<div class="card">
|
||||
<h2 class="title" id="recoverTitle">pgAdmin credentials were reset during recovery</h2>
|
||||
<p class="subtitle">Backend recovery reset the pgAdmin admin account. The new login is below — it is sealed on the server and can be re-displayed later via the "Show saved pgAdmin login" button in the panel settings.</p>
|
||||
<div class="recover-warning">Save it now — the previous password no longer works.</div>
|
||||
<div class="recover-note" id="recoverNote" style="display: none;"></div>
|
||||
<div class="cred-rows">
|
||||
<div class="cred-row">
|
||||
<div class="cred-value" id="recoverEmail"></div>
|
||||
<button class="btn secondary" type="button" id="recoverCopyEmail">Copy email</button>
|
||||
</div>
|
||||
<div class="cred-row">
|
||||
<div class="cred-value" id="recoverPassword"></div>
|
||||
<button class="btn secondary" type="button" id="recoverCopyPassword">Copy password</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cred-actions">
|
||||
<button class="btn" type="button" id="recoverOk">I've saved the new password</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script nonce="<%= cspNonce %>">
|
||||
(function () {
|
||||
'use strict';
|
||||
const card = document.querySelector('.card');
|
||||
const service = String(card?.dataset?.service || '').trim();
|
||||
// Session-bound CSRF token for the access-token POST below, issued at
|
||||
// render time; refreshed once from the database settings API if it has
|
||||
// expired by the time an attempt runs.
|
||||
let actionToken = '<%= locals.actionToken || "" %>';
|
||||
const statusText = document.getElementById('statusText');
|
||||
const errorBox = document.getElementById('errorBox');
|
||||
const actionBox = document.getElementById('actionBox');
|
||||
const retryBtn = document.getElementById('retryBtn');
|
||||
const recoverOverlay = document.getElementById('recoverOverlay');
|
||||
const recoverEmailEl = document.getElementById('recoverEmail');
|
||||
const recoverPasswordEl = document.getElementById('recoverPassword');
|
||||
const recoverNoteEl = document.getElementById('recoverNote');
|
||||
const recoverCopyEmail = document.getElementById('recoverCopyEmail');
|
||||
const recoverCopyPassword = document.getElementById('recoverCopyPassword');
|
||||
const recoverOk = document.getElementById('recoverOk');
|
||||
|
||||
// One-time display of credentials reset by a backend recovery. The
|
||||
// values arrive only in this page's no-store JSON response from the
|
||||
// access-token POST; they are injected via textContent — never into
|
||||
// markup, URLs, storage, or logs — and scrubbed once acknowledged.
|
||||
function showRecoveredCredentialsModal(creds, note) {
|
||||
return new Promise(function (resolve) {
|
||||
if (!creds || !recoverOverlay || !recoverOk || !recoverEmailEl || !recoverPasswordEl) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
recoverEmailEl.textContent = String(creds.email || '');
|
||||
recoverPasswordEl.textContent = String(creds.password || '');
|
||||
if (note) {
|
||||
recoverNoteEl.textContent = String(note);
|
||||
recoverNoteEl.style.display = 'block';
|
||||
} else {
|
||||
recoverNoteEl.textContent = '';
|
||||
recoverNoteEl.style.display = 'none';
|
||||
}
|
||||
recoverOverlay.classList.add('show');
|
||||
let acknowledged = false;
|
||||
const acknowledge = function () {
|
||||
if (acknowledged) return;
|
||||
acknowledged = true;
|
||||
recoverEmailEl.textContent = '';
|
||||
recoverPasswordEl.textContent = '';
|
||||
recoverOverlay.classList.remove('show');
|
||||
recoverOk.removeEventListener('click', acknowledge);
|
||||
resolve();
|
||||
};
|
||||
recoverOk.addEventListener('click', acknowledge);
|
||||
});
|
||||
}
|
||||
|
||||
async function copySecretValue(value, btn) {
|
||||
if (!btn || !value) return;
|
||||
const original = btn.textContent;
|
||||
try {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
await navigator.clipboard.writeText(value);
|
||||
} else {
|
||||
// The async clipboard API needs a secure context; fall back to a
|
||||
// transient textarea that is removed immediately after the copy.
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = value;
|
||||
ta.setAttribute('readonly', '');
|
||||
ta.style.position = 'fixed';
|
||||
ta.style.opacity = '0';
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
document.execCommand('copy');
|
||||
ta.remove();
|
||||
}
|
||||
btn.textContent = 'Copied';
|
||||
setTimeout(function () { btn.textContent = original; }, 1500);
|
||||
} catch (err) {
|
||||
btn.textContent = original;
|
||||
}
|
||||
}
|
||||
|
||||
if (recoverCopyEmail) {
|
||||
recoverCopyEmail.addEventListener('click', function () {
|
||||
copySecretValue(recoverEmailEl.textContent, recoverCopyEmail);
|
||||
});
|
||||
}
|
||||
if (recoverCopyPassword) {
|
||||
recoverCopyPassword.addEventListener('click', function () {
|
||||
copySecretValue(recoverPasswordEl.textContent, recoverCopyPassword);
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchFreshActionToken() {
|
||||
try {
|
||||
const res = await fetch('/api/settings/database', {
|
||||
headers: { 'Accept': 'application/json' }
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
const data = await res.json().catch(function () { return null; });
|
||||
return (data && data.actionTokens && data.actionTokens.accessToken) || null;
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// credential: optional pgAdmin step-up payload ({ currentPassword } or
|
||||
// { twoFactorCode }) — the server reads exactly these body fields.
|
||||
// phpMyAdmin and grant-backed pgAdmin opens post { service } only.
|
||||
function postAccessToken(credential) {
|
||||
const body = { service };
|
||||
if (credential && typeof credential === 'object') {
|
||||
if (typeof credential.currentPassword === 'string') body.currentPassword = credential.currentPassword;
|
||||
if (typeof credential.twoFactorCode === 'string') body.twoFactorCode = credential.twoFactorCode;
|
||||
}
|
||||
return fetch('/api/settings/database/access-token', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-action-token': actionToken
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
}
|
||||
|
||||
// Identity verification for the pgAdmin credential step-up (403
|
||||
// password-required / 2fa-required / invalid-password / invalid-2fa).
|
||||
// The entered credential lives only in this closure, is re-attached to
|
||||
// every retry (including a mid-entry action-token refresh), and is
|
||||
// never written to markup, storage, or logs. phpmyadmin never gets
|
||||
// this challenge from the server, and the service guard below keeps
|
||||
// the form off the phpmyadmin page regardless.
|
||||
let stepUpCredential = null;
|
||||
let stepUpBox = null;
|
||||
let stepUpLabel = null;
|
||||
let stepUpInput = null;
|
||||
let stepUpMsg = null;
|
||||
let stepUpVerifyBtn = null;
|
||||
let stepUpMode = '';
|
||||
|
||||
function stepUpModeFor(payload) {
|
||||
const security = payload && payload.revokeSecurity;
|
||||
if (security && (security.authMethod === '2fa' || security.requiresTwoFactor)) return '2fa';
|
||||
return 'password';
|
||||
}
|
||||
|
||||
function hideStepUpForm() {
|
||||
if (stepUpBox) stepUpBox.classList.remove('show');
|
||||
}
|
||||
|
||||
function showStepUpFormError(msg) {
|
||||
if (!stepUpMsg) return;
|
||||
if (msg) {
|
||||
stepUpMsg.textContent = msg;
|
||||
stepUpMsg.style.display = 'block';
|
||||
} else {
|
||||
stepUpMsg.textContent = '';
|
||||
stepUpMsg.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
function submitStepUp() {
|
||||
if (!stepUpInput) return;
|
||||
const value = stepUpInput.value;
|
||||
// The server requires exactly six digits in 2FA mode and bounces any
|
||||
// other payload back as a bare challenge with no message, so the
|
||||
// malformed case must be caught here to keep inline feedback.
|
||||
if (!value || (stepUpMode === '2fa' && !/^\d{6}$/.test(value))) {
|
||||
showStepUpFormError(stepUpMode === '2fa'
|
||||
? 'Enter the 6-digit code from your authenticator app.'
|
||||
: 'Enter your current password.');
|
||||
return;
|
||||
}
|
||||
stepUpCredential = stepUpMode === '2fa'
|
||||
? { twoFactorCode: value }
|
||||
: { currentPassword: value };
|
||||
start();
|
||||
}
|
||||
|
||||
function showStepUpForm(payload) {
|
||||
if (service !== 'pgadmin') return;
|
||||
const mode = stepUpModeFor(payload);
|
||||
if (!stepUpBox) {
|
||||
stepUpBox = document.createElement('div');
|
||||
stepUpBox.className = 'stepup';
|
||||
stepUpLabel = document.createElement('label');
|
||||
stepUpLabel.className = 'stepup-label';
|
||||
stepUpLabel.htmlFor = 'dbOpenStepUpInput';
|
||||
stepUpInput = document.createElement('input');
|
||||
stepUpInput.id = 'dbOpenStepUpInput';
|
||||
stepUpInput.className = 'stepup-input';
|
||||
stepUpInput.autocomplete = 'off';
|
||||
stepUpInput.addEventListener('keydown', function (ev) {
|
||||
if (ev.key === 'Enter') {
|
||||
ev.preventDefault();
|
||||
submitStepUp();
|
||||
}
|
||||
});
|
||||
stepUpMsg = document.createElement('div');
|
||||
stepUpMsg.className = 'error';
|
||||
stepUpVerifyBtn = document.createElement('button');
|
||||
stepUpVerifyBtn.type = 'button';
|
||||
stepUpVerifyBtn.className = 'btn';
|
||||
stepUpVerifyBtn.textContent = 'Verify & continue';
|
||||
stepUpVerifyBtn.addEventListener('click', submitStepUp);
|
||||
stepUpBox.appendChild(stepUpLabel);
|
||||
stepUpBox.appendChild(stepUpInput);
|
||||
stepUpBox.appendChild(stepUpMsg);
|
||||
stepUpBox.appendChild(stepUpVerifyBtn);
|
||||
if (actionBox && actionBox.parentNode) {
|
||||
actionBox.parentNode.insertBefore(stepUpBox, actionBox);
|
||||
} else if (card) {
|
||||
card.appendChild(stepUpBox);
|
||||
}
|
||||
}
|
||||
if (mode !== stepUpMode) {
|
||||
stepUpMode = mode;
|
||||
stepUpInput.value = '';
|
||||
}
|
||||
if (mode === '2fa') {
|
||||
stepUpLabel.textContent = 'Authenticator code (6 digits)';
|
||||
stepUpInput.type = 'text';
|
||||
stepUpInput.inputMode = 'numeric';
|
||||
stepUpInput.autocomplete = 'one-time-code';
|
||||
stepUpInput.setAttribute('maxlength', '6');
|
||||
stepUpInput.placeholder = '123456';
|
||||
} else {
|
||||
stepUpLabel.textContent = 'Current password';
|
||||
stepUpInput.type = 'password';
|
||||
stepUpInput.removeAttribute('inputmode');
|
||||
stepUpInput.autocomplete = 'current-password';
|
||||
stepUpInput.removeAttribute('maxlength');
|
||||
stepUpInput.placeholder = '';
|
||||
}
|
||||
// The server's message is shown inline ONLY for invalid-password /
|
||||
// invalid-2fa retries; the initial challenge shows just the form.
|
||||
const retryError = payload && (payload.code === 'invalid-password' || payload.code === 'invalid-2fa') &&
|
||||
typeof payload.error === 'string' ? payload.error : '';
|
||||
showStepUpFormError(retryError);
|
||||
hideError();
|
||||
stepUpBox.classList.add('show');
|
||||
setStatus('Identity verification required.');
|
||||
}
|
||||
|
||||
// At most one attempt in flight: the Retry button, the Verify button
|
||||
// and the input's Enter key all funnel through start(), and stacked
|
||||
// attempts would double-POST — superseding each other's proxy token
|
||||
// and racing a second readiness run's 503 against the recovery modal.
|
||||
let attemptInFlight = false;
|
||||
|
||||
async function start() {
|
||||
if (attemptInFlight) return;
|
||||
attemptInFlight = true;
|
||||
try {
|
||||
await runAttempt();
|
||||
} finally {
|
||||
attemptInFlight = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function runAttempt() {
|
||||
if (!service) {
|
||||
showError('Missing service identifier.');
|
||||
return;
|
||||
@@ -134,18 +494,62 @@
|
||||
setStatus('Requesting secure token...');
|
||||
hideError();
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/settings/database/access-token', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ service })
|
||||
});
|
||||
// At most one token refresh per attempt, and ONLY for action-token
|
||||
// rejections: the pgAdmin step-up challenge is also a 403 and must
|
||||
// surface as the verification form, never be swallowed by a silent
|
||||
// refresh. The action token is repeatable (TTL 300s), so it stays
|
||||
// valid for verification retries unless it expires mid-entry.
|
||||
let refreshed = false;
|
||||
|
||||
try {
|
||||
let res = await postAccessToken(stepUpCredential);
|
||||
let payload = await res.json().catch(function () { return {}; });
|
||||
|
||||
if (res.status === 403 && !refreshed && payload &&
|
||||
(payload.code === 'ACTION_TOKEN_INVALID' ||
|
||||
(typeof payload.error === 'string' && /action token/i.test(payload.error)))) {
|
||||
refreshed = true;
|
||||
const fresh = await fetchFreshActionToken();
|
||||
if (fresh) {
|
||||
actionToken = fresh;
|
||||
setStatus('Refreshing security token...');
|
||||
res = await postAccessToken(stepUpCredential);
|
||||
payload = await res.json().catch(function () { return {}; });
|
||||
}
|
||||
}
|
||||
|
||||
// pgAdmin credential step-up: no live grant and no credential yet,
|
||||
// or the previous one was rejected. Show the inline verification
|
||||
// form instead of the generic error box and wait for resubmission;
|
||||
// recovery must not run and no credential is received until the
|
||||
// step-up passes.
|
||||
const code = payload && typeof payload.code === 'string' ? payload.code : '';
|
||||
if (res.status === 403 &&
|
||||
(code === 'password-required' || code === '2fa-required' ||
|
||||
code === 'invalid-password' || code === 'invalid-2fa')) {
|
||||
showStepUpForm(payload);
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = await res.json().catch(function () { return {}; });
|
||||
if (!res.ok || !payload || !payload.url) {
|
||||
// A recovery may have reset the pgAdmin admin password even though
|
||||
// the backend is still unhealthy (503): the one-time credential
|
||||
// handoff rides this response, so surface it instead of leaving
|
||||
// only a generic failure message behind.
|
||||
if (payload && payload.recoveredCredentials) {
|
||||
await showRecoveredCredentialsModal(payload.recoveredCredentials, (payload && payload.error) || '');
|
||||
}
|
||||
throw new Error(payload?.error || 'Failed to generate secure link.');
|
||||
}
|
||||
|
||||
// Success path: the readiness probe may have reset the pgAdmin admin
|
||||
// password. Show the one-time handoff BEFORE redirecting (the same
|
||||
// sealed pair is also retrievable via "Show saved pgAdmin login" in
|
||||
// the panel settings).
|
||||
if (payload.recoveredCredentials) {
|
||||
await showRecoveredCredentialsModal(payload.recoveredCredentials, '');
|
||||
}
|
||||
|
||||
setStatus('Redirecting to secure session...');
|
||||
window.location.replace(payload.url);
|
||||
} catch (err) {
|
||||
@@ -158,6 +562,9 @@
|
||||
}
|
||||
|
||||
function showError(msg) {
|
||||
// The verification form and the generic failure box are mutually
|
||||
// exclusive; the Retry button must remain the way back into start().
|
||||
hideStepUpForm();
|
||||
setStatus('Unable to open secure session.');
|
||||
if (errorBox) {
|
||||
errorBox.style.display = 'block';
|
||||
|
||||
Reference in new issue
Block a user