This commit is contained in:
Mateusz Gruszczyński committed 2026-11-14 17:24:12 +01:00
1 parent 78dbb31487
commit f48843e934
83 files changed
+7304 -1203

No files matched your search

+21 -46
View File
@@ -71,16 +71,6 @@
const target = $("api-tokens-card");
if (target) { target.scrollIntoView({ block: "start" }); target.focus({ preventScroll: true }); }
}
$("api-tokens-security-link")?.addEventListener("click", event => {
if (event.defaultPrevented || event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
event.preventDefault();
select("security");
if (typeof location !== "undefined" && ["http:", "https:"].includes(location.protocol)) {
const url = new URL($("api-tokens-security-link").href);
history.replaceState({ ...(history.state || {}), panel: "settings", settingsTab: "security" }, "", `${url.pathname}${url.search}${url.hash}`);
}
scrollToApiTokens();
});
const policyTabs = [...document.querySelectorAll("[data-policy-settings-tab]")].filter(button => typeof button.addEventListener === "function" && typeof button.setAttribute === "function");
function selectPolicyTab(name, focus = false) {
if (!policyTabs.some(button => button.dataset.policySettingsTab === name)) return;
@@ -170,7 +160,7 @@
if (!envelope) return; const p = { ...defaults, ...envelope.config.prometheus };
if (!settingsDirty.has("prometheus-form")) {
$("prom-enabled").checked = p.enabled; $("prom-listen").value = p.listen; $("prom-path").value = p.path;
$("prom-cidrs").value = p.allowed_cidrs.join("\n"); $("prom-trusted-no-token").checked = !!p.allow_trusted_network_without_token;
$("prom-cidrs").replaceChildren(window.rustProxyChipInput.create({ className: "prom-cidr-editor", values: p.allowed_cidrs, placeholder: "127.0.0.0/8 / 10.0.0.0/24", label: t("prometheusCidrs"), limit: 64, validate: value => window.rustProxyChipInput.validCidr(value) && (value.includes("/") ? value : value.includes(":") ? `${value}/128` : `${value}/32`), invalidMessage: t("apiTokenCidrInvalid") })); $("prom-trusted-no-token").checked = !!p.allow_trusted_network_without_token;
for (const [id, key] of [["system", "include_system"], ["vhosts", "include_vhosts"], ["traffic", "include_traffic"], ["backends", "include_backends"], ["docker-vhosts", "include_docker_vhosts"], ["domains", "include_cache_domains"], ["streams", "include_streams"], ["logging", "include_logging"]]) $(`prom-${id}`).checked = p[key];
}
const status = latestStatus?.prometheus;
@@ -209,40 +199,7 @@
$("admin-listen").disabled = listenLocked; $("admin-listen-lock-note").hidden = !listenLocked;
const syncAdminTls = () => { $("admin-certificate").disabled = !$("admin-tls").checked; }; syncAdminTls();
$("admin-status").textContent = adminStatus?.restart_required ? t("restartPending") : adminStatus?.active?.tls ? `${t("administrationActiveHttps")}: ${adminStatus.active.listen}` : `${t("administrationActiveHttp")}: ${adminStatus?.active?.listen || latestStatus?.admin_listen || "-"}`;
const runtime = latestStatus?.runtime || {};
const system = latestStatus?.system || {};
const hasMetric = value => value !== null && value !== undefined && Number.isFinite(Number(value));
const humanCount = value => hasMetric(value) ? Number(value).toLocaleString(locale()) : t("unavailable");
const humanBytes = value => hasMetric(value) ? bytes(Number(value)) : t("unavailable");
const humanUptime = value => hasMetric(value) ? uptime(Number(value)) : t("unavailable");
const percent = value => hasMetric(value) ? `${Number(value).toLocaleString(locale(), { maximumFractionDigits: 1 })}%` : t("unavailable");
const ram = hasMetric(system.memory_used_bytes) || hasMetric(system.memory_total_bytes)
? `${humanBytes(system.memory_used_bytes)} / ${humanBytes(system.memory_total_bytes)}` : t("unavailable");
for (const [id, value] of [
["runtime-platform", runtime.platform],
["runtime-operating-system", runtime.operating_system],
["runtime-kernel-version", runtime.kernel_version],
["runtime-architecture", runtime.architecture],
["runtime-logical-cpus", humanCount(system.logical_cpus)],
["runtime-cpu-usage", percent(system.cpu_percent)],
["runtime-system-memory", ram],
["runtime-system-uptime", humanUptime(system.system_uptime_seconds)],
["runtime-statistics-source", runtime.statistics_source],
["runtime-data-directory", runtime.data_directory],
["runtime-database-path", runtime.database_path]
]) { const node = $(id); if (node) node.textContent = value ?? t("unavailable"); }
const certificateRuntime = runtime.certificate_runtime || {};
const availability = flag => flag === true ? t("runtimeAvailable") : flag === false ? t("runtimeUnavailable") : t("unavailable");
const modeLabel = certificateRuntime.status === "unavailable" ? t("certificateRuntimeUnavailable") : certificateRuntime.status === "ready" && certificateRuntime.mode === "managed" ? t("certificateRuntimeManaged") : certificateRuntime.status === "ready" && certificateRuntime.mode === "system" ? t("certificateRuntimeSystem") : t("certificateRuntimePreparing");
const versioned = (flag, version) => version && flag === true ? `${availability(flag)} · ${version}` : availability(flag);
for (const [id, value] of [
["runtime-acme-mode", modeLabel],
["runtime-acme-status", certificateRuntime.message ? t(certificateRuntime.message) : t("unavailable")],
["runtime-python", versioned(certificateRuntime.python, certificateRuntime.python_version)],
["runtime-pip", versioned(certificateRuntime.pip, certificateRuntime.pip_version)],
["runtime-certbot", versioned(certificateRuntime.certbot, certificateRuntime.certbot_version)],
["runtime-acme-directory", certificateRuntime.managed_directory]
]) { const node = $(id); if (node) node.textContent = value || t("unavailable"); }
window.rustProxySystemInfo?.render(latestStatus);
const policy = envelope.config.tls?.policy || { tls12: true, tls13: true, cipher_suites: [] };
if (!settingsDirty.has("tls-policy-form")) { $("tls-policy-12").checked = policy.tls12 !== false; $("tls-policy-13").checked = policy.tls13 !== false; $("tls-policy-ciphers").value = (policy.cipher_suites || []).join("\n"); $("tls-policy-pqc").checked = policy.post_quantum === true; }
@@ -281,7 +238,7 @@
});
bindSettingsForm("prometheus-form", next => {
next.prometheus = {
enabled: $("prom-enabled").checked, listen: $("prom-listen").value.trim(), path: $("prom-path").value.trim(), allowed_cidrs: $("prom-cidrs").value.split(/[\n,]/).map(v => v.trim()).filter(Boolean), bearer_token_env: envelope?.config?.prometheus?.bearer_token_env || null, allow_trusted_network_without_token: $("prom-trusted-no-token").checked,
enabled: $("prom-enabled").checked, listen: $("prom-listen").value.trim(), path: $("prom-path").value.trim(), allowed_cidrs: $("prom-cidrs").firstElementChild?.read?.() || [], bearer_token_env: envelope?.config?.prometheus?.bearer_token_env || null, allow_trusted_network_without_token: $("prom-trusted-no-token").checked,
include_system: $("prom-system").checked, include_vhosts: $("prom-vhosts").checked, include_traffic: $("prom-traffic").checked, include_backends: $("prom-backends").checked, include_docker_vhosts: $("prom-docker-vhosts").checked, include_cache_domains: $("prom-domains").checked, include_streams: $("prom-streams").checked, include_logging: $("prom-logging").checked
};
}, "prometheus");
@@ -303,6 +260,24 @@
const text = await response.text(); if (epoch !== authEpoch || !authenticated) return; $("prom-preview-output").textContent = text.slice(0, 262144); $("prom-preview-output").hidden = false;
} catch (error) { if (epoch === authEpoch) toast(error.message, true); } finally { button.disabled = false; }
});
const HELP_CLAMP_LENGTH = 220;
function decorateSettings() {
const panel = $("panel-settings"); if (!panel) return;
const restart = t("restartFieldBadge");
panel.querySelectorAll("[data-restart]").forEach(node => { const span = node.querySelector(":scope > span"); if (span && span.dataset.restartBadge !== restart) span.dataset.restartBadge = restart; node.title = t("restartFieldHelp"); });
panel.querySelectorAll(".settings-page .fine:not([role=status]):not(.help-clamp)").forEach(node => {
if (node.id?.endsWith("-status") || node.closest(".certificate-api-credential-item, .acl-picker, .docker-container-state, dialog")) return;
if ((node.textContent || "").trim().length < HELP_CLAMP_LENGTH) return;
node.classList.add("help-clamp"); node.tabIndex = 0; node.setAttribute("aria-expanded", "false");
const toggle = () => { const open = !node.classList.contains("is-open"); node.classList.toggle("is-open", open); node.setAttribute("aria-expanded", String(open)); };
node.addEventListener("click", event => { if (event.target.closest("a, button")) return; toggle(); });
node.addEventListener("keydown", event => { if (event.key === "Enter" || event.key === " ") { event.preventDefault(); toggle(); } });
});
}
let decorateQueued = false;
const queueDecorate = () => { if (decorateQueued) return; decorateQueued = true; requestAnimationFrame(() => { decorateQueued = false; decorateSettings(); }); };
if (typeof MutationObserver === "function" && $("panel-settings")) new MutationObserver(queueDecorate).observe($("panel-settings"), { childList: true, subtree: true });
queueDecorate();
window.rustProxySettings = { select, selectHttpTab, syncLocation, render, refreshSearch: applySettingsSearch, current: () => active, scrollToApiTokens, reset() { if (search) search.value = ""; applySettingsSearch(); select(validTab(rememberedTab) ? rememberedTab : "appearance", false, false); selectPolicyTab("block-allow"); selectCacheTab("general"); selectLoggingTab("outputs"); selectHttpTab("http2"); window.rustProxyCertificateApi?.reset(); window.rustProxyApiTokens?.reset?.(); window.rustProxyPrometheusToken?.reset?.(); $("prom-preview-output").textContent = ""; $("prom-preview-output").hidden = true; } };
select(active); render();
})();