This commit is contained in:
Mateusz Gruszczyński committed 2026-11-10 00:15:50 +01:00
1 parent 2789991452
commit e260612ef9
60 files changed
+69 -339

No files matched your search

+28 -28
View File
@@ -65,7 +65,7 @@ function translate() {
}
function toastNode() {
let node = document.getElementById("toast");
if (!node) { // the node lived inside a dialog that was rebuilt; recreate it instead of failing every later toast
if (!node) {
node = document.createElement("div"); node.id = "toast"; node.className = "toast"; node.hidden = true;
node.setAttribute("role", "status"); node.setAttribute("aria-live", "polite"); node.setAttribute("popover", "manual"); document.body.append(node);
}
@@ -291,11 +291,15 @@ function redrawOverviewHistoryCharts() {
}
const httpValues = Object.values(protocolSamples), websocketValues = Object.values(websocketProtocolSamples);
window.rustProxyChartScale.axes("http-protocol-chart", Math.max(1, ...httpValues.flat()), "rate",
protocolSamples.h1.length, { seriesScales: Object.entries(protocolSamples).map(([name, values]) =>
[name.toUpperCase(), Math.max(1, ...values)]) });
protocolSamples.h1.length, {
seriesScales: Object.entries(protocolSamples).map(([name, values]) =>
[name.toUpperCase(), Math.max(1, ...values)])
});
window.rustProxyChartScale.axes("ws-protocol-chart", Math.max(1, ...websocketValues.flat()), "count",
websocketProtocolSamples.h1.length, { seriesScales: Object.entries(websocketProtocolSamples).map(([name, values]) =>
[name.toUpperCase(), Math.max(1, ...values)]) });
websocketProtocolSamples.h1.length, {
seriesScales: Object.entries(websocketProtocolSamples).map(([name, values]) =>
[name.toUpperCase(), Math.max(1, ...values)])
});
$("chart-peak").textContent = `max ${Math.max(0, ...samples).toFixed(1)} req/s`;
}
window.rustProxyOverviewSamples.onChange(() => {
@@ -305,8 +309,7 @@ window.rustProxyOverviewSamples.onChange(() => {
}
redrawOverviewHistoryCharts();
});
// Safari has no CSS scroll anchoring: keep the element under the viewport centre in place
// when a live refresh changes the height of content above it.
const nativeScrollAnchoring = typeof CSS !== "undefined" && CSS.supports?.("overflow-anchor", "auto");
function preserveScrollAnchor(render) {
if (nativeScrollAnchoring || window.scrollY <= 0) return render();
@@ -514,8 +517,6 @@ async function activate(info) {
renderSession();
document.documentElement.classList.remove("app-startup-failed");
rustProxyRefresh.start();
// Keep the startup screen until the account preferences (menu, layout, density)
// are applied, so the panel never appears first with defaults and then changes.
let preferences;
try { preferences = await loadAdminPreferences(); }
finally { document.documentElement.classList.remove("app-loading"); }
@@ -606,8 +607,6 @@ document.addEventListener("click", event => { if (dashboardSidebar?.classList.co
document.addEventListener("keydown", event => { if (event.key === "Escape" && dashboardSidebar?.classList.contains("mobile-nav-open")) { setMobileMenu(false); mobileMenuToggle?.focus(); } });
window.addEventListener("popstate", () => { setPanel(panelFromLocation(), false); setMobileMenu(false); });
$("host-policy-form").addEventListener("submit", async event => { event.preventDefault(); const form = event.currentTarget; if (!envelope || busy) return; try { await withFormSubmitState(form, event.submitter, async () => { const hosts = [...new Set($("policy-hosts").value.split(",").map(h => h.trim().toLowerCase()).filter(Boolean))]; const acl = { default: $("policy-default").value, rules: parseRules($("policy-rules").value, $("policy-rules")) }; const next = structuredClone(envelope.config); next.host_policies = (next.host_policies || []).map(p => ({ ...p, hosts: p.hosts.filter(h => !hosts.includes(h)) })).filter(p => p.hosts.length); next.host_policies.push({ hosts, acl }); if (await saveSection("host-policies", next.host_policies)) { form.reset(); if ($("security-policy-editor")) $("security-policy-editor").open = false; } }); } catch (e) { toast(e.message, true); } });
// Global HTTP controls are a single atomic API section. A header-only save preserves
// the current block rules; a block-only save preserves the current security headers.
const globalLines = id => [...new Set($(id).value.split(/[\n,]+/).map(v => v.trim()).filter(Boolean))];
const globalPatternLines = id => [...new Set($(id).value.split(/\r?\n/).map(v => v.trim()).filter(Boolean))];
function globalSecurityPayload(security, ua) {
@@ -635,10 +634,12 @@ $("global-security-form")?.addEventListener("submit", async event => {
acl,
method_policy: { mode: methodMode, methods },
content_type_policy: { enabled: $("global-content-type-enabled").checked, blocked: contentTypes },
rate_limit: { ...rate, enabled: $("global-rate-enabled").checked,
rate_limit: {
...rate, enabled: $("global-rate-enabled").checked,
requests: Number($("global-rate-requests").value),
window_seconds: Number($("global-rate-window").value),
burst: Number($("global-rate-burst").value) },
burst: Number($("global-rate-burst").value)
},
};
if (await saveSection("global-security", globalSecurityPayload(security, ua))) {
setSettingsDirty("global-security-form", false); renderSettings();
@@ -652,16 +653,20 @@ $("global-security-headers-form")?.addEventListener("submit", async event => {
await withFormSubmitState(form, event.submitter, async () => {
const previous = envelope.config.global_security || {};
const optional = id => $(id).value.trim() || null;
const security = { ...previous, security_headers: {
hsts: { enabled: $("global-hsts-enabled").checked,
max_age_seconds: Number($("global-hsts-age").value),
include_subdomains: $("global-hsts-enabled").checked && $("global-hsts-sub").checked,
preload: $("global-hsts-enabled").checked && $("global-hsts-preload").checked },
nosniff: $("global-nosniff").checked, frame_options: $("global-frame").value,
referrer_policy: optional("global-referrer"),
content_security_policy: optional("global-csp"),
permissions_policy: optional("global-permissions")
}};
const security = {
...previous, security_headers: {
hsts: {
enabled: $("global-hsts-enabled").checked,
max_age_seconds: Number($("global-hsts-age").value),
include_subdomains: $("global-hsts-enabled").checked && $("global-hsts-sub").checked,
preload: $("global-hsts-enabled").checked && $("global-hsts-preload").checked
},
nosniff: $("global-nosniff").checked, frame_options: $("global-frame").value,
referrer_policy: optional("global-referrer"),
content_security_policy: optional("global-csp"),
permissions_policy: optional("global-permissions")
}
};
if (await saveSection("global-security", globalSecurityPayload(security, previous.user_agent_blocking || { enabled: false, patterns: [] }))) {
setSettingsDirty("global-security-headers-form", false); renderSettings();
}
@@ -682,7 +687,6 @@ $("config-editor").addEventListener("input", () => setSettingsDirty("config-edit
$("save-json").addEventListener("click", async event => { const editor = $("config-editor"), page = editor.closest("[data-settings-page]"); if (!envelope || busy) return; try { await withFormSubmitState(page, event.currentTarget, async () => { let config; try { config = JSON.parse(editor.value); } catch { throw fieldError(editor, t("vhJsonInvalid")); } if (await save(config)) setSettingsDirty("config-editor", false); }); } catch (e) { toast(e.message, true); } });
$("export-config").addEventListener("click", () => { const url = URL.createObjectURL(new Blob([JSON.stringify(envelope.config, null, 2) + "\n"], { type: "application/json" })); const a = el("a"); a.href = url; a.download = `RustProxy-config-r${envelope.revision}.json`; a.click(); setTimeout(() => URL.revokeObjectURL(url), 1000); });
// Auto-generated identifiers: a new entry's ID follows its name (or first host) as a unique slug until the user edits the ID by hand.
const rustProxyAutoId = (() => {
const FOLD = { "ł": "l", "đ": "d", "ø": "o", "ß": "ss", "æ": "ae", "œ": "oe", "þ": "th", "ð": "d" };
const states = new WeakMap();
@@ -700,7 +704,6 @@ const rustProxyAutoId = (() => {
}
const locked = input => input.readOnly || input.disabled;
function suggestion(state) { return unique(slugify(state.text()), state.taken()); }
// The ID is shown as a plain value with a "Change" link; the input only appears after the user asks for it (or when validation needs it).
function paint(input, state) {
const isLocked = locked(input), wanted = suggestion(state), value = input.value.trim(), compact = !state.open || isLocked;
state.holder.classList.toggle("is-compact", compact);
@@ -713,7 +716,6 @@ const rustProxyAutoId = (() => {
state.reset.hidden = compact || state.auto || state.resettable === false || !wanted || wanted === value; state.reset.textContent = t("autoIdReset");
}
function regenerate(input, state) { if (!state.auto || locked(input)) return; input.value = suggestion(state); input.setCustomValidity?.(""); paint(input, state); }
// options: { elements: inputs whose changes drive the ID, text: () => source string, taken: () => existing IDs }
function attach(input, options) {
let state = states.get(input);
if (!state) {
@@ -741,7 +743,6 @@ const rustProxyAutoId = (() => {
})();
window.rustProxyAutoId = rustProxyAutoId;
// Automatic certificate choice: for a new entry, pick the stored certificate that covers every host name (exact names beat wildcards); the user can still choose another one.
const rustProxyAutoCertificate = (() => {
const states = new WeakMap();
const covers = (pattern, host) => {
@@ -769,7 +770,6 @@ const rustProxyAutoCertificate = (() => {
}
return best;
}
// options: { hosts: () => host names, certificates: () => certificate objects, auto: boolean, anchor: element after which the hint is placed }
function attach(select, options) {
let state = states.get(select);
if (!state) {