823 lines
40 KiB
Plaintext
823 lines
40 KiB
Plaintext
<% const loginBackgroundType=(branding && branding.loginBackgroundType) ? branding.loginBackgroundType : 'video' ; const
|
|
loginBackgroundUrl='/auth-assets/background' ; const protectedLoginWatermarkUrl='/auth-assets/watermark' ; const
|
|
loginBackgroundMimeType=(branding && branding.loginBackgroundMimeType) ? branding.loginBackgroundMimeType
|
|
: 'video/webm' ; const loginRequiresTwoFactor=typeof requiresTwoFactor !== 'undefined' && !!requiresTwoFactor; const
|
|
loginEmailValue=typeof loginEmail !== 'undefined' ? String(loginEmail || '') : ''; const
|
|
loginExternalCaptchaAvailable=typeof externalCaptchaAvailable !== 'undefined' ? !!externalCaptchaAvailable : !!useExternalCaptcha; const
|
|
loginCaptchaChallengeActive=!!useExternalCaptcha || !!showLocalCaptcha; %>
|
|
<!DOCTYPE html>
|
|
<html lang="ro">
|
|
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>Login - <%= (branding && branding.appName) ? branding.appName : 'Panel' %></title>
|
|
<link rel="preconnect" href="https://cdnjs.cloudflare.com" crossorigin>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" integrity="sha384-nRgPTkuX86pH8yjPJUAFuASXQSSl2/bBUiNV47vSYpKFxHJhbcrGnmlYpYJMeD7a" crossorigin="anonymous" referrerpolicy="no-referrer">
|
|
<link id="favicon" rel="icon" type="image/webp" sizes="16x16"
|
|
href="<%= (branding && branding.faviconUrl) ? branding.faviconUrl : '/auth-assets/favicon' %>" />
|
|
<link rel="preconnect" href="https://cdn.jsdelivr.net">
|
|
<link rel="dns-prefetch" href="https://cdn.jsdelivr.net">
|
|
<% if (loginBackgroundType==='image' && loginBackgroundUrl) { %>
|
|
<link rel="preload" as="image" href="<%= loginBackgroundUrl %>" fetchpriority="high" />
|
|
<% } %>
|
|
<script nonce="<%= cspNonce %>">
|
|
(function () {
|
|
const CHRISTMAS_IMG = '/auth-assets/christmas-logo';
|
|
function isChristmasPeriod() {
|
|
const now = new Date();
|
|
const month = now.getMonth();
|
|
const day = now.getDate();
|
|
return month === 11 && day >= 25 && day <= 28;
|
|
}
|
|
function applyChristmasTheme() {
|
|
if (!isChristmasPeriod()) return;
|
|
const favicon = document.getElementById('favicon') || document.querySelector('link[rel="icon"]');
|
|
if (favicon) favicon.href = CHRISTMAS_IMG;
|
|
document.querySelectorAll('img').forEach(img => {
|
|
if (img.src && (img.src.includes('/auth-assets/logo') || img.src.includes('ADPanel-dark.webp') || img.src.includes('i.imgur.com/k5agjYf'))) {
|
|
img.src = CHRISTMAS_IMG;
|
|
}
|
|
});
|
|
}
|
|
document.addEventListener('DOMContentLoaded', applyChristmasTheme);
|
|
})();
|
|
</script>
|
|
<style nonce="<%= cspNonce %>">
|
|
<%- loginCss || "" %>
|
|
|
|
*,
|
|
*::before,
|
|
*::after {
|
|
-webkit-user-select: none;
|
|
-moz-user-select: none;
|
|
-ms-user-select: none;
|
|
user-select: none;
|
|
}
|
|
|
|
img,
|
|
video,
|
|
canvas {
|
|
-webkit-user-drag: none;
|
|
user-drag: none;
|
|
}
|
|
|
|
<% if (loginBackgroundType === 'image' && loginBackgroundUrl) { %>
|
|
body.login-body--image {
|
|
background-image: url(<%- JSON.stringify(String(loginBackgroundUrl)) %>);
|
|
}
|
|
<% } %>
|
|
</style>
|
|
<script nonce="<%= cspNonce %>">
|
|
document.addEventListener('contextmenu', e => e.preventDefault());
|
|
document.addEventListener('dragstart', e => e.preventDefault());
|
|
document.addEventListener('selectstart', e => e.preventDefault());
|
|
document.addEventListener('copy', e => e.preventDefault());
|
|
document.addEventListener('cut', e => e.preventDefault());
|
|
document.addEventListener('keydown', e => {
|
|
if ((e.ctrlKey || e.metaKey) && ['c', 'C', 'a', 'A', 's', 'S', 'u', 'U'].includes(e.key)) e.preventDefault();
|
|
});
|
|
</script>
|
|
</head>
|
|
|
|
<body class="<%= [loginBackgroundType === 'image' && loginBackgroundUrl ? 'login-body--image' : '', loginRequiresTwoFactor ? 'login-has-2fa' : ''].filter(Boolean).join(' ') %>">
|
|
<div id="toastHost" class="toast-host" aria-live="polite" aria-atomic="true"></div>
|
|
|
|
<script nonce="<%= cspNonce %>">
|
|
(() => {
|
|
const msg = <%- JSON.stringify(String(error || "")).replace(/</g, "\\u003c") %>;
|
|
if (!msg) return;
|
|
|
|
const host = document.getElementById("toastHost");
|
|
if (!host) return;
|
|
|
|
function showToast(text, duration = 4500) {
|
|
const toast = document.createElement("div");
|
|
toast.className = "toast";
|
|
toast.innerHTML = `
|
|
<div class="toast-inner">
|
|
<div class="toast-msg"></div>
|
|
<div class="toast-bar"></div>
|
|
</div>
|
|
`;
|
|
|
|
toast.querySelector(".toast-msg").textContent = text;
|
|
|
|
host.appendChild(toast);
|
|
requestAnimationFrame(() => toast.classList.add("toast-show"));
|
|
|
|
const leaveAt = Math.max(0, duration - 320);
|
|
setTimeout(() => toast.classList.add("toast-hide"), leaveAt);
|
|
setTimeout(() => toast.remove(), duration + 450);
|
|
}
|
|
|
|
showToast(msg, 4500);
|
|
})();
|
|
</script>
|
|
<% if (loginBackgroundType==='video' ) { %>
|
|
<video id="bgVideo" autoplay muted loop playsinline preload="metadata" class="video">
|
|
<source src="<%= loginBackgroundUrl %>" type="<%= loginBackgroundMimeType %>" />
|
|
Your browser does not support instant-video.
|
|
</video>
|
|
<% } %>
|
|
|
|
<form method="POST" action="/login" class="login-form" data-requires-two-factor="<%= loginRequiresTwoFactor ? 'true' : 'false' %>">
|
|
<input type="text" name="company" tabindex="-1" autocomplete="off" aria-hidden="true" hidden>
|
|
<input type="hidden" name="botProof" id="botProofInput" value="<%= botProofSeed || '' %>" autocomplete="off">
|
|
<input type="hidden" name="_csrf" value="<%= csrfToken %>" autocomplete="off">
|
|
<div class="input-holder">
|
|
<i class="input-icon fa-solid fa-envelope" aria-hidden="true"></i>
|
|
<input class="login-input" type="email" name="email" placeholder="Email" value="<%= loginEmailValue %>" required />
|
|
</div>
|
|
<div class="input-holder">
|
|
<i class="input-icon fa-solid fa-lock" aria-hidden="true"></i>
|
|
<input class="login-input" type="password" name="password" placeholder="Password" required />
|
|
</div>
|
|
<div class="input-holder login-two-factor-field" id="loginTwoFactorField" aria-hidden="<%= loginRequiresTwoFactor ? 'false' : 'true' %>">
|
|
<i class="input-icon fa-solid fa-fingerprint" aria-hidden="true"></i>
|
|
<input class="login-input" type="text" name="code" id="loginTwoFactorCode" placeholder="2FA Code" maxlength="6"
|
|
inputmode="numeric" autocomplete="one-time-code" <%= loginRequiresTwoFactor ? 'required' : 'disabled' %> />
|
|
</div>
|
|
<a class="forgot-password" href="/forgot-password">Forgot password?</a>
|
|
|
|
<input type="hidden" name="captchaToken" id="captchaTokenInput" value="" />
|
|
<button type="submit" class="get-started">
|
|
<span>Access</span>
|
|
<img class="get-started__logo" src="/auth-assets/logo" alt="D Logo" draggable="false" />
|
|
<span>Panel</span>
|
|
</button>
|
|
<div class="circle-icon">
|
|
<i class="fa-solid fa-arrow-right-to-bracket circle-icon__glyph"></i>
|
|
</div>
|
|
</form>
|
|
|
|
<div id="captchaModal" class="captcha-modal<%= loginCaptchaChallengeActive ? ' show' : '' %>"
|
|
data-provider="<%= (externalCaptchaProvider || 'recaptcha').toLowerCase() %>"
|
|
data-challenge="<%= loginCaptchaChallengeActive ? '1' : '0' %>"
|
|
aria-hidden="<%= loginCaptchaChallengeActive ? 'false' : 'true' %>">
|
|
<div class="captcha-modal__backdrop"></div>
|
|
<div class="captcha-modal__card">
|
|
<div class="captcha-modal__title">
|
|
<i class="fa-solid fa-shield-halved captcha-modal__title-icon"></i>Security Verification
|
|
</div>
|
|
<div class="captcha-modal__desc">Complete the challenge below to continue</div>
|
|
<div class="captcha-modal__widget">
|
|
<div id="recaptchaWidget" hidden></div>
|
|
<div id="cf-turnstile" hidden></div>
|
|
<div id="hcaptchaWidget" hidden></div>
|
|
</div>
|
|
<% if (showLocalCaptcha && captchaQuestion) { %>
|
|
<div id="localCaptchaUI" class="local-captcha" data-token="<%= captchaQuestion.token %>"
|
|
data-step="<%= captchaQuestion.step %>" data-total="<%= captchaQuestion.total %>">
|
|
<div class="local-captcha__prompt" id="captchaPrompt">
|
|
<%= captchaQuestion.prompt %>
|
|
</div>
|
|
<div class="local-captcha__grid" id="captchaGrid">
|
|
<% captchaQuestion.images.forEach(function(imgUrl, idx) { %>
|
|
<div class="local-captcha__cell" data-idx="<%= idx %>">
|
|
<img src="<%= imgUrl %>" alt="captcha image" draggable="false" loading="lazy" />
|
|
<div class="local-captcha__check"><i class="fa-solid fa-check"></i></div>
|
|
</div>
|
|
<% }); %>
|
|
</div>
|
|
<div class="local-captcha__footer">
|
|
<span class="local-captcha__step" id="captchaStep">Step <%= captchaQuestion.step %> of <%= captchaQuestion.total %></span>
|
|
<button type="button" id="captchaSubmitLocal" class="local-captcha__submit">Verify</button>
|
|
</div>
|
|
<div id="captchaLocalStatus" class="local-captcha__status"></div>
|
|
</div>
|
|
<% } %>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="menu"></div>
|
|
|
|
<div class="sign-up-subline">
|
|
<a class="sign-up-sublines"> and make something special </a>
|
|
</div>
|
|
|
|
<div class="sign-ups">
|
|
<a class="sign-up-desc"> Securely manage your applications with style </a>
|
|
</div>
|
|
|
|
<div>
|
|
<a class="sign-up"> Sign in with email </a>
|
|
</div>
|
|
|
|
<div class="watermark" id="watermark">
|
|
<img
|
|
src="<%= protectedLoginWatermarkUrl %>"
|
|
alt="watermark is not available" draggable="false" />
|
|
</div>
|
|
|
|
<script nonce="<%= cspNonce %>">
|
|
(() => {
|
|
const cfg = {
|
|
enabled: <%- loginExternalCaptchaAvailable ? "true" : "false" %>,
|
|
required: <%- externalCaptchaAutoStart ? "true" : "false" %>,
|
|
provider: <%- JSON.stringify((externalCaptchaProvider || "recaptcha").toLowerCase()) %>,
|
|
siteKey: <%- JSON.stringify(externalCaptchaSiteKey || "") %>,
|
|
hasError: <%- error ? "true" : "false" %>,
|
|
showLocal: <%- showLocalCaptcha ? "true" : "false" %>,
|
|
challengeActive: <%- loginCaptchaChallengeActive ? "true" : "false" %>,
|
|
};
|
|
|
|
const form = document.querySelector("form");
|
|
const modal = document.getElementById("captchaModal");
|
|
const tokenInput = document.getElementById("captchaTokenInput");
|
|
const recaptchaHost = document.getElementById("recaptchaWidget");
|
|
const turnstileHost = document.getElementById("cf-turnstile");
|
|
const hcaptchaHost = document.getElementById("hcaptchaWidget");
|
|
const statusEl = modal ? modal.querySelector(".captcha-modal__desc") : null;
|
|
const defaultStatusText = statusEl ? statusEl.textContent : "";
|
|
|
|
let recaptchaId = null;
|
|
let turnstileId = null;
|
|
let hcaptchaId = null;
|
|
let started = false;
|
|
let timeoutHandle = null;
|
|
|
|
const disableForm = () => {
|
|
if (!form) return;
|
|
form.querySelectorAll("input:not([type=hidden]), button[type=submit]").forEach(el => { el.disabled = true; });
|
|
form.classList.add("login-form--blocked");
|
|
};
|
|
|
|
const enableForm = () => {
|
|
if (!form) return;
|
|
form.querySelectorAll("input, button").forEach(el => { el.disabled = false; });
|
|
const loginTwoFactorInput = document.getElementById("loginTwoFactorCode");
|
|
if (loginTwoFactorInput && form.dataset.requiresTwoFactor !== "true") {
|
|
loginTwoFactorInput.disabled = true;
|
|
}
|
|
form.classList.remove("login-form--blocked");
|
|
};
|
|
|
|
const showModal = () => {
|
|
if (modal) modal.classList.add("show");
|
|
disableForm();
|
|
};
|
|
|
|
const hideModal = () => {
|
|
if (modal) {
|
|
modal.classList.remove("show");
|
|
modal.dataset.challenge = "0";
|
|
modal.setAttribute("aria-hidden", "true");
|
|
}
|
|
enableForm();
|
|
if (timeoutHandle) {
|
|
clearTimeout(timeoutHandle);
|
|
timeoutHandle = null;
|
|
}
|
|
};
|
|
|
|
const resetStatus = () => {
|
|
if (statusEl) statusEl.textContent = defaultStatusText;
|
|
};
|
|
|
|
const markTimeout = () => {
|
|
if (statusEl) {
|
|
statusEl.textContent = "Captcha unavailable. Try again.";
|
|
}
|
|
};
|
|
|
|
const resetCaptchaWidget = () => {
|
|
tokenInput.value = "";
|
|
try {
|
|
if (recaptchaId !== null && window.grecaptcha && typeof window.grecaptcha.reset === "function") {
|
|
window.grecaptcha.reset(recaptchaId);
|
|
}
|
|
} catch { }
|
|
try {
|
|
if (turnstileId !== null && window.turnstile && typeof window.turnstile.reset === "function") {
|
|
window.turnstile.reset(turnstileId);
|
|
}
|
|
} catch { }
|
|
try {
|
|
if (hcaptchaId !== null && window.hcaptcha && typeof window.hcaptcha.reset === "function") {
|
|
window.hcaptcha.reset(hcaptchaId);
|
|
}
|
|
} catch { }
|
|
};
|
|
|
|
async function verifyCaptchaToken(token) {
|
|
tokenInput.value = token || "";
|
|
if (timeoutHandle) { clearTimeout(timeoutHandle); timeoutHandle = null; }
|
|
if (statusEl) statusEl.textContent = "Finalizing sign in...";
|
|
try {
|
|
const resp = await fetch("/api/captcha/verify", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ token }),
|
|
credentials: "same-origin",
|
|
});
|
|
const data = await resp.json().catch(() => ({}));
|
|
if (resp.ok && data.ok) {
|
|
if (data.redirect) {
|
|
window.location.href = data.redirect;
|
|
return;
|
|
}
|
|
hideModal();
|
|
return;
|
|
}
|
|
resetCaptchaWidget();
|
|
if (data.redirect) {
|
|
window.location.href = data.redirect;
|
|
return;
|
|
}
|
|
if (statusEl) statusEl.textContent = data.error || "Captcha verification failed. Try again.";
|
|
} catch {
|
|
resetCaptchaWidget();
|
|
if (statusEl) statusEl.textContent = "Network error. Try again.";
|
|
}
|
|
}
|
|
|
|
function renderRecaptcha() {
|
|
if (!cfg.enabled || recaptchaId !== null) return recaptchaId;
|
|
if (!window.grecaptcha || typeof window.grecaptcha.render !== "function") return null;
|
|
if (turnstileHost) turnstileHost.hidden = true;
|
|
if (hcaptchaHost) hcaptchaHost.hidden = true;
|
|
if (recaptchaHost) recaptchaHost.hidden = false;
|
|
recaptchaId = window.grecaptcha.render("recaptchaWidget", {
|
|
sitekey: cfg.siteKey,
|
|
size: "normal",
|
|
theme: "dark",
|
|
callback: verifyCaptchaToken,
|
|
"expired-callback": () => { tokenInput.value = ""; },
|
|
"error-callback": () => { tokenInput.value = ""; },
|
|
});
|
|
if (timeoutHandle) { clearTimeout(timeoutHandle); timeoutHandle = null; }
|
|
resetStatus();
|
|
return recaptchaId;
|
|
}
|
|
|
|
function ensureRecaptcha(attempt = 0) {
|
|
if (recaptchaId === null) renderRecaptcha();
|
|
if (recaptchaId !== null) return;
|
|
if (attempt < 50) setTimeout(() => ensureRecaptcha(attempt + 1), 200);
|
|
}
|
|
|
|
function renderTurnstile() {
|
|
if (!cfg.enabled || turnstileId !== null) return turnstileId;
|
|
if (!window.turnstile || typeof window.turnstile.render !== "function") return null;
|
|
if (recaptchaHost) recaptchaHost.hidden = true;
|
|
if (hcaptchaHost) hcaptchaHost.hidden = true;
|
|
if (turnstileHost) turnstileHost.hidden = false;
|
|
turnstileId = window.turnstile.render("#cf-turnstile", {
|
|
sitekey: cfg.siteKey,
|
|
size: "normal",
|
|
theme: "dark",
|
|
callback: verifyCaptchaToken,
|
|
"expired-callback": () => { tokenInput.value = ""; },
|
|
"error-callback": () => { tokenInput.value = ""; },
|
|
});
|
|
if (timeoutHandle) { clearTimeout(timeoutHandle); timeoutHandle = null; }
|
|
resetStatus();
|
|
return turnstileId;
|
|
}
|
|
|
|
function ensureTurnstile(attempt = 0) {
|
|
if (turnstileId === null) renderTurnstile();
|
|
if (turnstileId !== null) return;
|
|
if (attempt < 50) setTimeout(() => ensureTurnstile(attempt + 1), 200);
|
|
}
|
|
|
|
function renderHcaptcha() {
|
|
if (!cfg.enabled || hcaptchaId !== null) return hcaptchaId;
|
|
if (!window.hcaptcha || typeof window.hcaptcha.render !== "function") return null;
|
|
if (recaptchaHost) recaptchaHost.hidden = true;
|
|
if (turnstileHost) turnstileHost.hidden = true;
|
|
if (hcaptchaHost) hcaptchaHost.hidden = false;
|
|
hcaptchaId = window.hcaptcha.render("hcaptchaWidget", {
|
|
sitekey: cfg.siteKey,
|
|
size: "normal",
|
|
theme: "dark",
|
|
callback: verifyCaptchaToken,
|
|
"expired-callback": () => { tokenInput.value = ""; },
|
|
"error-callback": () => { tokenInput.value = ""; },
|
|
});
|
|
if (timeoutHandle) { clearTimeout(timeoutHandle); timeoutHandle = null; }
|
|
resetStatus();
|
|
return hcaptchaId;
|
|
}
|
|
|
|
function ensureHcaptcha(attempt = 0) {
|
|
if (hcaptchaId === null) renderHcaptcha();
|
|
if (hcaptchaId !== null) return;
|
|
if (attempt < 50) setTimeout(() => ensureHcaptcha(attempt + 1), 200);
|
|
}
|
|
|
|
function startCaptchaFlow() {
|
|
started = true;
|
|
if (modal) {
|
|
modal.dataset.challenge = "1";
|
|
modal.setAttribute("aria-hidden", "false");
|
|
}
|
|
showModal();
|
|
resetStatus();
|
|
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
timeoutHandle = setTimeout(markTimeout, 30000);
|
|
if (!cfg.enabled) return;
|
|
if (["cloudflare", "turnstile", "cf"].includes(cfg.provider)) return ensureTurnstile();
|
|
if (["hcaptcha", "h"].includes(cfg.provider)) return ensureHcaptcha();
|
|
return ensureRecaptcha();
|
|
}
|
|
|
|
if (form) {
|
|
form.addEventListener("submit", (e) => {
|
|
if (modal && modal.dataset.challenge === "1") {
|
|
e.preventDefault();
|
|
e.stopImmediatePropagation();
|
|
if (cfg.enabled && !tokenInput.value) startCaptchaFlow();
|
|
return false;
|
|
}
|
|
}, true);
|
|
}
|
|
|
|
if (cfg.challengeActive) {
|
|
disableForm();
|
|
if (cfg.enabled && !started) startCaptchaFlow();
|
|
} else if (cfg.enabled && cfg.required && !started) {
|
|
startCaptchaFlow();
|
|
}
|
|
|
|
window.initRecaptcha = function initRecaptcha() {
|
|
if (!cfg.enabled) return;
|
|
ensureRecaptcha();
|
|
};
|
|
|
|
window.initTurnstile = function initTurnstile() {
|
|
if (!cfg.enabled) return;
|
|
ensureTurnstile();
|
|
};
|
|
|
|
window.initHcaptcha = function initHcaptcha() {
|
|
if (!cfg.enabled) return;
|
|
ensureHcaptcha();
|
|
};
|
|
|
|
window.__adCaptchaResolved = (data) => {
|
|
if (data && data.redirect) {
|
|
window.location.href = data.redirect;
|
|
return;
|
|
}
|
|
hideModal();
|
|
};
|
|
window.__adStartCaptchaFlow = startCaptchaFlow;
|
|
})();
|
|
</script>
|
|
<script nonce="<%= cspNonce %>">
|
|
(() => {
|
|
const form = document.querySelector("form.login-form");
|
|
if (!form || !window.fetch) return;
|
|
|
|
const twoFactorField = document.getElementById("loginTwoFactorField");
|
|
const twoFactorInput = document.getElementById("loginTwoFactorCode");
|
|
const csrfInput = form.querySelector('input[name="_csrf"]');
|
|
const submitBtn = form.querySelector('button[type="submit"]');
|
|
const toastHost = document.getElementById("toastHost");
|
|
|
|
function showLoginToast(text, duration = 4200) {
|
|
if (!toastHost || !text) return;
|
|
const toast = document.createElement("div");
|
|
toast.className = "toast";
|
|
toast.innerHTML = '<div class="toast-inner"><div class="toast-msg"></div><div class="toast-bar"></div></div>';
|
|
toast.querySelector(".toast-msg").textContent = text;
|
|
toastHost.appendChild(toast);
|
|
requestAnimationFrame(() => toast.classList.add("toast-show"));
|
|
setTimeout(() => toast.classList.add("toast-hide"), Math.max(0, duration - 320));
|
|
setTimeout(() => toast.remove(), duration + 450);
|
|
}
|
|
|
|
function setTwoFactorRequired(required) {
|
|
form.dataset.requiresTwoFactor = required ? "true" : "false";
|
|
document.body?.classList.toggle("login-has-2fa", !!required);
|
|
if (twoFactorField) {
|
|
twoFactorField.setAttribute("aria-hidden", required ? "false" : "true");
|
|
}
|
|
if (twoFactorInput) {
|
|
twoFactorInput.required = !!required;
|
|
twoFactorInput.disabled = !required;
|
|
if (!required) twoFactorInput.value = "";
|
|
}
|
|
}
|
|
|
|
setTwoFactorRequired(form.dataset.requiresTwoFactor === "true");
|
|
|
|
twoFactorInput?.addEventListener("input", () => {
|
|
twoFactorInput.value = twoFactorInput.value.replace(/\D/g, "").slice(0, 6);
|
|
});
|
|
|
|
form.addEventListener("submit", async (e) => {
|
|
if (e.defaultPrevented) return;
|
|
e.preventDefault();
|
|
|
|
if (submitBtn) submitBtn.disabled = true;
|
|
let keepSubmitDisabled = false;
|
|
|
|
try {
|
|
const body = new URLSearchParams(new FormData(form));
|
|
const res = await fetch(form.action || "/login", {
|
|
method: "POST",
|
|
headers: {
|
|
"Accept": "application/json",
|
|
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
|
"X-Requested-With": "XMLHttpRequest",
|
|
},
|
|
credentials: "same-origin",
|
|
body,
|
|
});
|
|
|
|
const data = await res.json().catch(() => ({}));
|
|
if (data.csrfToken && csrfInput) csrfInput.value = data.csrfToken;
|
|
|
|
if (data.requires2FA) {
|
|
setTwoFactorRequired(true);
|
|
showLoginToast(data.error || "Enter your 2FA code to continue.");
|
|
setTimeout(() => twoFactorInput?.focus(), 40);
|
|
return;
|
|
}
|
|
|
|
if (data.captchaRequired) {
|
|
keepSubmitDisabled = true;
|
|
if (data.useExternalCaptcha && typeof window.__adStartCaptchaFlow === "function") {
|
|
window.__adStartCaptchaFlow();
|
|
} else {
|
|
window.location.reload();
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (res.ok && data.ok) {
|
|
window.location.href = data.redirect || "/";
|
|
return;
|
|
}
|
|
|
|
if (res.status === 403 && !data.error) {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
|
|
showLoginToast(data.error || "Invalid credentials");
|
|
} catch (err) {
|
|
showLoginToast("Network error. Try again.");
|
|
} finally {
|
|
if (submitBtn && !keepSubmitDisabled) submitBtn.disabled = false;
|
|
}
|
|
});
|
|
})();
|
|
</script>
|
|
<% if (loginExternalCaptchaAvailable) { %>
|
|
<% if (["cloudflare","turnstile","cf"].includes((externalCaptchaProvider || "" ).toLowerCase())) { %>
|
|
<script nonce="<%= cspNonce %>"
|
|
src="https://challenges.cloudflare.com/turnstile/v0/api.js?onload=initTurnstile&render=explicit" async
|
|
defer></script>
|
|
<% } else if (["hcaptcha","h"].includes((externalCaptchaProvider || "" ).toLowerCase())) { %>
|
|
<script nonce="<%= cspNonce %>"
|
|
src="https://js.hcaptcha.com/1/api.js?onload=initHcaptcha&render=explicit" async
|
|
defer></script>
|
|
<% } else { %>
|
|
<script nonce="<%= cspNonce %>"
|
|
src="https://www.google.com/recaptcha/api.js?onload=initRecaptcha&render=explicit" async
|
|
defer></script>
|
|
<% } %>
|
|
<% } %>
|
|
|
|
<% if (showLocalCaptcha && captchaQuestion) { %>
|
|
<script nonce="<%= cspNonce %>">
|
|
(function () {
|
|
var grid = document.getElementById("captchaGrid");
|
|
var submitBtn = document.getElementById("captchaSubmitLocal");
|
|
var statusEl = document.getElementById("captchaLocalStatus");
|
|
var localUI = document.getElementById("localCaptchaUI");
|
|
var promptEl = document.getElementById("captchaPrompt");
|
|
var stepEl = document.getElementById("captchaStep");
|
|
if (!grid || !submitBtn || !localUI) return;
|
|
|
|
var selected = new Set();
|
|
|
|
function setLocalStatus(message, state) {
|
|
if (!statusEl) return;
|
|
statusEl.textContent = message || "";
|
|
statusEl.dataset.state = state || "";
|
|
}
|
|
|
|
grid.addEventListener("click", function (e) {
|
|
var cell = e.target.closest(".local-captcha__cell");
|
|
if (!cell) return;
|
|
var idx = parseInt(cell.dataset.idx, 10);
|
|
if (isNaN(idx)) return;
|
|
if (selected.has(idx)) {
|
|
selected.delete(idx);
|
|
cell.classList.remove("selected");
|
|
} else {
|
|
selected.add(idx);
|
|
cell.classList.add("selected");
|
|
}
|
|
});
|
|
|
|
submitBtn.addEventListener("click", function () {
|
|
if (selected.size === 0) {
|
|
setLocalStatus("Select at least one image", "error");
|
|
return;
|
|
}
|
|
|
|
var token = localUI.dataset.token;
|
|
submitBtn.disabled = true;
|
|
setLocalStatus("Verifying...", "muted");
|
|
|
|
fetch("/api/captcha/local", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
credentials: "same-origin",
|
|
body: JSON.stringify({ action: "verify", token: token, selection: Array.from(selected) }),
|
|
})
|
|
.then(function (resp) { return resp.json(); })
|
|
.then(function (data) {
|
|
if (data.ok && data.done) {
|
|
setLocalStatus("Verified!", "success");
|
|
if (typeof window.__adCaptchaResolved === "function") window.__adCaptchaResolved(data);
|
|
return;
|
|
}
|
|
if (data.ok && !data.done && data.question) {
|
|
selected.clear();
|
|
rebuildGrid(data.question);
|
|
setLocalStatus("", "");
|
|
submitBtn.disabled = false;
|
|
return;
|
|
}
|
|
if (!data.ok && data.redirect) {
|
|
window.location.href = data.redirect;
|
|
return;
|
|
}
|
|
setLocalStatus(data.error === "expired" ? "Expired. Reloading..." : "Incorrect selection. Reloading...", "error");
|
|
setTimeout(function () { window.location.reload(); }, 1800);
|
|
})
|
|
.catch(function () {
|
|
setLocalStatus("Network error. Retrying...", "error");
|
|
setTimeout(function () { window.location.reload(); }, 2000);
|
|
});
|
|
});
|
|
|
|
function rebuildGrid(question) {
|
|
localUI.dataset.token = question.token;
|
|
localUI.dataset.step = String(question.step);
|
|
localUI.dataset.total = String(question.total);
|
|
if (promptEl) promptEl.textContent = question.prompt;
|
|
if (stepEl) stepEl.textContent = "Step " + question.step + " of " + question.total;
|
|
grid.innerHTML = "";
|
|
(question.images || []).forEach(function (imgUrl, idx) {
|
|
var cell = document.createElement("div");
|
|
cell.className = "local-captcha__cell";
|
|
cell.dataset.idx = String(idx);
|
|
var img = document.createElement("img");
|
|
img.src = imgUrl;
|
|
img.alt = "captcha image";
|
|
img.draggable = false;
|
|
img.loading = "lazy";
|
|
var check = document.createElement("div");
|
|
check.className = "local-captcha__check";
|
|
check.innerHTML = '<i class="fa-solid fa-check"></i>';
|
|
cell.appendChild(img);
|
|
cell.appendChild(check);
|
|
grid.appendChild(cell);
|
|
});
|
|
}
|
|
})();
|
|
</script>
|
|
<% } %>
|
|
|
|
<script nonce="<%= cspNonce %>">
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
const form = document.querySelector("form");
|
|
const videoEl = document.getElementById("bgVideo");
|
|
if (!videoEl) return;
|
|
|
|
const tryPlay = () => {
|
|
const p = videoEl.play();
|
|
if (p && typeof p.then === "function") {
|
|
p.catch(() => {
|
|
});
|
|
}
|
|
};
|
|
|
|
videoEl.addEventListener(
|
|
"canplay",
|
|
() => {
|
|
tryPlay();
|
|
},
|
|
{ once: true }
|
|
);
|
|
|
|
const resumeOnUserGesture = () => {
|
|
tryPlay();
|
|
window.removeEventListener("click", resumeOnUserGesture);
|
|
window.removeEventListener("keydown", resumeOnUserGesture);
|
|
window.removeEventListener("touchstart", resumeOnUserGesture);
|
|
};
|
|
|
|
window.addEventListener("click", resumeOnUserGesture);
|
|
window.addEventListener("keydown", resumeOnUserGesture);
|
|
window.addEventListener("touchstart", resumeOnUserGesture);
|
|
|
|
videoEl.addEventListener("error", () => {
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<script nonce="<%= cspNonce %>">
|
|
(function () {
|
|
var challengeActive = <%- loginCaptchaChallengeActive ? "true" : "false" %>;
|
|
if (!challengeActive) return;
|
|
|
|
var modal = document.getElementById("captchaModal");
|
|
var form = document.querySelector("form");
|
|
if (!modal) return;
|
|
|
|
if (form) {
|
|
form.addEventListener("submit", function (e) {
|
|
if (modal.dataset.challenge === "1") {
|
|
e.preventDefault();
|
|
e.stopImmediatePropagation();
|
|
return false;
|
|
}
|
|
}, true);
|
|
}
|
|
|
|
var restoring = false;
|
|
var observer = new MutationObserver(function () {
|
|
if (restoring) return;
|
|
var m = document.getElementById("captchaModal");
|
|
if (!m) {
|
|
restoring = true;
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
if (m.dataset.challenge === "0") return;
|
|
if (!m.classList.contains("show")) m.classList.add("show");
|
|
var st = m.getAttribute("style") || "";
|
|
if (st && (st.indexOf("display") !== -1 || st.indexOf("visibility") !== -1 || st.indexOf("opacity") !== -1)) {
|
|
m.removeAttribute("style");
|
|
}
|
|
});
|
|
|
|
observer.observe(document.documentElement, {
|
|
childList: true,
|
|
subtree: true,
|
|
attributes: true,
|
|
attributeFilter: ["class", "style", "hidden"],
|
|
});
|
|
|
|
var integrityInterval = setInterval(function () {
|
|
var m = document.getElementById("captchaModal");
|
|
if (!m) {
|
|
clearInterval(integrityInterval);
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
if (m.dataset.challenge === "0") {
|
|
clearInterval(integrityInterval);
|
|
observer.disconnect();
|
|
return;
|
|
}
|
|
if (!m.classList.contains("show")) m.classList.add("show");
|
|
var cs = getComputedStyle(m);
|
|
if (cs.display === "none" || cs.visibility === "hidden" || parseFloat(cs.opacity) < 0.5) {
|
|
m.removeAttribute("style");
|
|
m.classList.add("show");
|
|
}
|
|
if (form && m.dataset.challenge === "1") {
|
|
form.classList.add("login-form--blocked");
|
|
}
|
|
}, 800);
|
|
|
|
try {
|
|
var origRemove = modal.remove;
|
|
Object.defineProperty(modal, "remove", {
|
|
value: function () {
|
|
if (modal.dataset.challenge === "1") return;
|
|
return origRemove.call(this);
|
|
},
|
|
writable: false,
|
|
configurable: false,
|
|
});
|
|
} catch (ex) { }
|
|
|
|
try {
|
|
var origSetAttr = modal.setAttribute.bind(modal);
|
|
modal.setAttribute = function (name, value) {
|
|
if (modal.dataset.challenge !== "1") return origSetAttr(name, value);
|
|
if (name === "style" && typeof value === "string" && (/display\s*:\s*none|visibility\s*:\s*hidden|opacity\s*:\s*0/i).test(value)) return;
|
|
if (name === "class" && typeof value === "string" && !value.includes("show")) return;
|
|
if (name === "hidden") return;
|
|
return origSetAttr(name, value);
|
|
};
|
|
} catch (ex) { }
|
|
|
|
modal.addEventListener("contextmenu", function (e) { e.preventDefault(); });
|
|
})();
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|