v0.42.1
This commit is contained in:
1 parent
167861fc16
commit
aa0a271a1c
38 files changed
+3642
-1058
No files matched your search
@@ -23,7 +23,7 @@ const field = (parent, name, key, value, type = "text", options = {}) => {
|
||||
};
|
||||
const group = (key, advanced = false) => {
|
||||
const box = el(advanced ? "details" : "fieldset", undefined, "vh-group");
|
||||
box.dataset.tab = ({ vhEditor: "details", vhFrontends: "details", vhBackendPool: "backends", vhBackendDiagnostics: "headers", vhProxyTimeouts: "backends", vhBalancing: "backends", vhSticky: "backends", vhHealth: "health", vhPassiveHealth: "health", vhSecurity: "security", vhTrafficPolicy: "security", vhTinyauth: "auth", vhResponsePolicy: "headers", vhHeaders: "headers", policyTitle: "headers", vhHeadersPreview: "headers", vhAdvanced: "advanced", vhLocations: "locations", vhSsl: "ssl", vhSslSettings: "ssl", vhCache: "cache", vhCompression: "compression", vhTransform: "transform", vhPages: "pages" })[key] || "advanced"; box.append(text(advanced ? "summary" : "legend", key));
|
||||
box.dataset.tab = ({ vhEditor: "details", vhFrontends: "details", vhBackendPool: "backends", vhBackendDiagnostics: "headers", vhProxyTimeouts: "backends", vhBalancing: "backends", vhSticky: "backends", vhHealth: "health", vhPassiveHealth: "health", vhSecurity: "security", vhTrafficPolicy: "security", vhTinyauth: "auth", vhResponsePolicy: "headers", vhHeaders: "headers", policyTitle: "headers", vhHeadersPreview: "headers", vhLocations: "locations", vhSsl: "ssl", vhSslSettings: "ssl", vhCache: "cache", vhCompression: "compression", vhTransform: "transform", vhPages: "pages" })[key] || "details"; box.append(text(advanced ? "summary" : "legend", key));
|
||||
const body = el("div", undefined, "vh-grid"); box.append(body); container.append(box); return body;
|
||||
};
|
||||
const note = (parent, key) => { const node = text("p", key, "fine vh-wide"); parent.append(node); return node; };
|
||||
@@ -60,7 +60,53 @@ const defaults = () => ({
|
||||
});
|
||||
|
||||
function activateTab(name) { document.querySelectorAll("#vhost-tabs button").forEach(b => { const active = b.dataset.tab === name; b.classList.toggle("active", active); b.setAttribute("aria-pressed", String(active)); b.setAttribute("aria-selected", String(active)); b.tabIndex = active ? 0 : -1; }); container.querySelectorAll(".vh-group").forEach(g => g.hidden = g.dataset.tab !== name); }
|
||||
function initTabs() { const tabs = $("vhost-tabs"); tabs.replaceChildren(); tabs.setAttribute("role", "tablist"); for (const [name, key] of [["details", "vhDetailsTab"], ["backends", "vhBackendPool"], ["health", "vhHealth"], ["locations", "vhLocations"], ["auth", "vhTabAuth"], ["ssl", "vhSsl"], ["cache", "vhCache"], ["compression", "vhCompression"], ["transform", "vhTransform"], ["security", "vhSecurity"], ["headers", "vhTabHeaders"], ["pages", "vhPages"], ["advanced", "advanced"]]) { const b = button(key, () => activateTab(name)); b.dataset.tab = name; b.setAttribute("role", "tab"); b.addEventListener("keydown", event => { const buttons = [...tabs.querySelectorAll("button")], index = buttons.indexOf(b); let next; if (event.key === "ArrowRight" || event.key === "ArrowDown") next = (index + 1) % buttons.length; else if (event.key === "ArrowLeft" || event.key === "ArrowUp") next = (index + buttons.length - 1) % buttons.length; else if (event.key === "Home") next = 0; else if (event.key === "End") next = buttons.length - 1; else return; event.preventDefault(); activateTab(buttons[next].dataset.tab); buttons[next].focus(); }); tabs.append(b); } activateTab("details"); }
|
||||
function initTabs() { const tabs = $("vhost-tabs"); tabs.replaceChildren(); tabs.setAttribute("role", "tablist"); for (const [name, key] of [["details", "vhDetailsTab"], ["backends", "vhBackendPool"], ["health", "vhHealth"], ["locations", "vhLocations"], ["auth", "vhTabAuth"], ["ssl", "vhSsl"], ["cache", "vhCache"], ["compression", "vhCompression"], ["transform", "vhTransform"], ["security", "vhSecurity"], ["headers", "vhTabHeaders"], ["pages", "vhPages"]]) { const b = button(key, () => activateTab(name)); b.dataset.tab = name; b.setAttribute("role", "tab"); b.addEventListener("keydown", event => { const buttons = [...tabs.querySelectorAll("button")], index = buttons.indexOf(b); let next; if (event.key === "ArrowRight" || event.key === "ArrowDown") next = (index + 1) % buttons.length; else if (event.key === "ArrowLeft" || event.key === "ArrowUp") next = (index + buttons.length - 1) % buttons.length; else if (event.key === "Home") next = 0; else if (event.key === "End") next = buttons.length - 1; else return; event.preventDefault(); activateTab(buttons[next].dataset.tab); buttons[next].focus(); }); tabs.append(b); } activateTab("details"); }
|
||||
function jsonDrawer(parent, { name, titleKey, helpKey, value, maxLength, validate = value => value, apply }) {
|
||||
const node = el("details", undefined, "vh-wide vh-json-editor"), summary = el("summary"), status = el("span", undefined, "vh-json-status");
|
||||
node.dataset.jsonSection = name; summary.append(text("span", titleKey), status); node.append(summary);
|
||||
const body = el("div", undefined, "vh-grid vh-json-body"); node.append(body); parent.append(node); note(body, helpKey);
|
||||
const target = document.createElement("textarea"); target.name = name; target.hidden = true; target.value = JSON.stringify(value, null, 2); body.append(target);
|
||||
const source = field(body, `${name}-json-draft`, titleKey, target.value, "textarea", { rows: 10, maxLength }); source.classList.add("vh-json-source"); source.setAttribute("aria-label", t(titleKey));
|
||||
const toolbar = el("div", undefined, "vh-wide vh-json-toolbar"), message = el("p", undefined, "fine vh-wide vh-json-message"); message.hidden = true; message.setAttribute("role", "status");
|
||||
let baseline = target.value, pending = false;
|
||||
const parse = () => validate(JSON.parse(source.value));
|
||||
const fail = error => { message.textContent = error.message || t("vhJsonInvalid"); message.hidden = false; message.classList.add("is-error"); source.setCustomValidity(message.textContent); };
|
||||
const update = () => {
|
||||
pending = source.value !== baseline; status.textContent = t(pending ? "vhJsonDraft" : "vhJsonSynced"); node.classList.toggle("has-json-draft", pending);
|
||||
applyButton.disabled = !pending; source.setCustomValidity(pending ? t("vhJsonPending") : "");
|
||||
};
|
||||
const refresh = () => { if (pending) return; baseline = target.value; source.value = baseline; update(); };
|
||||
const applyButton = button("vhJsonApply", () => {
|
||||
try {
|
||||
if (target.value !== baseline) throw Error(t("vhJsonConflict"));
|
||||
const next = parse(); apply(next); target.value = JSON.stringify(next, null, 2);
|
||||
pending = false; refresh(); message.classList.remove("is-error"); message.textContent = t("vhJsonApplied"); message.hidden = false;
|
||||
target.dispatchEvent(new Event("change", { bubbles: true })); changed();
|
||||
} catch (error) { fail(error); }
|
||||
}, "primary");
|
||||
const formatButton = button("vhJsonFormat", () => { try { const next = parse(); source.value = JSON.stringify(next, null, 2); message.hidden = true; update(); if (pending) changed(); } catch (error) { fail(error); } });
|
||||
const reloadButton = button("vhJsonReload", async () => {
|
||||
if (pending && !(await appConfirm(t("vhJsonReloadConfirm"), { danger: true, confirmLabel: t("discardAction") }))) return;
|
||||
pending = false; refresh(); message.hidden = true;
|
||||
});
|
||||
toolbar.append(applyButton, formatButton, reloadButton); body.append(toolbar, message);
|
||||
source.addEventListener("input", () => { message.hidden = true; update(); if (pending) { try { parse(); } catch (error) { fail(error); } } });
|
||||
source.addEventListener("invalid", () => { node.open = true; activateTab(node.closest(".vh-group")?.dataset.tab || "details"); });
|
||||
node.addEventListener("toggle", () => { if (node.open) refresh(); }); update();
|
||||
return { node, target, refresh };
|
||||
}
|
||||
function validateInlineAcl(value) {
|
||||
if (value === null) return value;
|
||||
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).some(key => !["default", "rules"].includes(key))
|
||||
|| (value.default !== undefined && !["allow", "deny"].includes(value.default))
|
||||
|| (value.rules !== undefined && (!Array.isArray(value.rules) || value.rules.length > 128 || value.rules.some(rule => !rule || typeof rule !== "object" || Array.isArray(rule)
|
||||
|| Object.keys(rule).some(key => !["network", "action"].includes(key)) || typeof rule.network !== "string" || !rule.network.trim() || rule.network.length > 254 || !["allow", "deny"].includes(rule.action))))) throw Error(t("vhJsonInvalidAcl"));
|
||||
return value;
|
||||
}
|
||||
function validateLocations(value) {
|
||||
if (!Array.isArray(value) || value.length > 64 || value.some(route => !route || typeof route !== "object" || Array.isArray(route))) throw Error(t("vhJsonInvalidPaths"));
|
||||
return value;
|
||||
}
|
||||
function collectCache() { const tri = name => str(name) === "" ? null : str(name) === "on", number = (name, mul = 1) => { if (str(name) === "") return null; const value = Number(str(name)) * mul; if (!Number.isSafeInteger(value)) throw new Error(t("vhJsonInvalid")); return value; }; return { enabled: tri("vh-cache-enabled"), max_ttl_seconds: number("vh-cache-ttl"), default_ttl_seconds: number("vh-cache-default"), max_object_bytes: number("vh-cache-object", 1024), bypass_query: tri("vh-cache-query"), static_ignore_cookies: tri("vh-cache-static-cookie"), static_ignore_vary_cookie: tri("vh-cache-static-vary-cookie"), static_extensions: yes("vh-cache-static-custom") ? lines(str("vh-cache-static-extensions")).map(v => v.replace(/^\./, "").toLowerCase()) : null, expose_status: tri("vh-cache-status"), expose_hits: tri("vh-cache-hits"), expose_cache_status: tri("vh-cache-rfc"), expose_resident_age: tri("vh-cache-resident-age"), expose_only_hits: tri("vh-cache-only-hits"), expose_detailed_status: tri("vh-cache-detailed-status"), bypass_prefixes: yes("vh-cache-prefix-custom") ? lines(str("vh-cache-prefixes")) : null, unsafe_force: { enabled: yes("vh-cache-force-enabled"), targets: lines(str("vh-cache-force-targets")) }, rules: vhostCacheRulesEditor ? vhostCacheRulesEditor.read() : [], ignore_global_rules: vhostCacheRulesEditor ? vhostCacheRulesEditor.ignoreGlobal() : false }; }
|
||||
function collectCompression() { const tri = name => str(name) === "" ? null : str(name) === "on"; return { enabled: tri("vh-compression-enabled"), zstd: tri("vh-compression-zstd"), br: tri("vh-compression-br"), gzip: tri("vh-compression-gzip"), deflate: tri("vh-compression-deflate") }; }
|
||||
function collectTransform() {
|
||||
@@ -80,14 +126,14 @@ function validateHeaders(value) {
|
||||
const fail = () => { throw new Error(t("headersInvalid")); };
|
||||
if (!value || Array.isArray(value) || typeof value !== "object" || Object.keys(value).some(k => !["request", "response"].includes(k))) fail();
|
||||
for (const direction of ["request", "response"]) {
|
||||
const rules = value[direction] || []; if (!Array.isArray(rules) || rules.length > 32) fail(); for (const rule of rules) {
|
||||
const rules = Object.hasOwn(value, direction) ? value[direction] : []; if (!Array.isArray(rules) || rules.length > 32) fail(); for (const rule of rules) {
|
||||
if (!rule || typeof rule !== "object" || Object.keys(rule).some(k => !["op", "name", "value"].includes(k)) || !["set", "append", "remove"].includes(rule.op) || typeof rule.name !== "string" || rule.name.length > 128 || !/^[-!#$%&'*+.^_`|~0-9A-Za-z]+$/.test(rule.name)) fail();
|
||||
const name = rule.name.toLowerCase(); if (["host", "connection", "content-length", "transfer-encoding", "te", "trailer", "content-encoding", "content-range", "upgrade", "keep-alive", "proxy-connection", "proxy-authorization", "proxy-authenticate", "forwarded", "x-real-ip", "x-request-id", "x-rust-proxy-backend", "x-rust-proxy-backend-time", "x-rustproxy-backend-time"].includes(name) || name.startsWith("x-forwarded-") || name.startsWith("sec-websocket-")) throw new Error(t("headersProtected"));
|
||||
if (rule.op === "remove") { if (Object.hasOwn(rule, "value") && rule.value !== null) fail(); } else if (typeof rule.value !== "string" || rule.value.length > 8192 || /[\r\n\0]/.test(rule.value)) fail();
|
||||
}
|
||||
} return value;
|
||||
}
|
||||
// Header value variables (src/headers/mod.rs Var::ALL); true = response rules only.
|
||||
|
||||
const HEADER_VARIABLES = [["srv_id", false], ["srv_url", false], ["location", false], ["vhost", false], ["lb_algorithm", false], ["hash_key", false], ["client_ip", false], ["country", false], ["req_id", false], ["method", false], ["host", false], ["path", false], ["cache_status", true], ["backend_time", true]];
|
||||
const DIAGNOSTIC_PRESETS = [
|
||||
{ key: "hdrPresetServedBy", direction: "response", rule: { op: "set", name: "X-Served-By", value: "%[srv_id]" } },
|
||||
@@ -119,8 +165,6 @@ function headerEditors(parent, initial, target = read("headers"), onChange = cha
|
||||
const rows = el("div", undefined, "vh-header-rows"); holders[direction] = rows; block.append(rows); parent.append(block);
|
||||
const add = (value = { op: "set", name: "", value: "" }) => {
|
||||
if (rows.children.length >= 32) { toast(t("headerLimit"), true); return; }
|
||||
// Compact one-line rule: operation · name · value · remove, with a live check of
|
||||
// %[variables] (example value or error) underneath.
|
||||
const row = el("article", undefined, "vh-header-row hdr-row");
|
||||
const fields = el("div", undefined, "vh-header-rule-fields hdr-row-fields");
|
||||
field(fields, "rule-op", "headerOperation", value.op, "select", { values: [["set", "header_set"], ["append", "header_append"], ["remove", "header_remove"]] });
|
||||
@@ -140,7 +184,6 @@ function headerEditors(parent, initial, target = read("headers"), onChange = cha
|
||||
};
|
||||
adders[direction] = add; for (const rule of initial[direction] || []) add(rule); renumber(direction);
|
||||
block.append(button("addHeader", () => { add(); sync(); }, "quiet location-add-header"));
|
||||
// %[variable] chips insert into the last focused value field of this direction.
|
||||
const chips = el("div", undefined, "hdr-vars"); chips.append(text("span", "hdrVariables", "hdr-vars-label"));
|
||||
let lastValue = null; rows.addEventListener("focusin", event => { if (event.target.name === "rule-value") lastValue = event.target; });
|
||||
for (const [name, responseOnly] of HEADER_VARIABLES) {
|
||||
@@ -155,19 +198,25 @@ function headerEditors(parent, initial, target = read("headers"), onChange = cha
|
||||
}
|
||||
block.append(chips);
|
||||
}
|
||||
const set = data => {
|
||||
const value = validateHeaders(data);
|
||||
for (const direction of ["request", "response"]) for (const rule of value[direction] || []) {
|
||||
const result = rule.op === "remove" ? {} : headerValueCheck(rule.value, direction);
|
||||
if (result.error) throw Error(result.error);
|
||||
}
|
||||
for (const direction of ["request", "response"]) {
|
||||
holders[direction].replaceChildren();
|
||||
for (const rule of value[direction] || []) adders[direction](rule);
|
||||
renumber(direction);
|
||||
}
|
||||
target.value = JSON.stringify(value, null, 2); target.setCustomValidity(""); onChange();
|
||||
};
|
||||
target.addEventListener("input", () => {
|
||||
try {
|
||||
const value = validateHeaders(JSON.parse(target.value));
|
||||
for (const direction of ["request", "response"]) {
|
||||
holders[direction].replaceChildren();
|
||||
for (const rule of value[direction] || []) adders[direction](rule);
|
||||
renumber(direction);
|
||||
}
|
||||
target.setCustomValidity(""); onChange();
|
||||
} catch (error) { target.setCustomValidity(error.message || t("headersInvalid")); }
|
||||
try { set(JSON.parse(target.value)); }
|
||||
catch (error) { target.setCustomValidity(error.message || t("headersInvalid")); }
|
||||
});
|
||||
note(parent, "locationHeadersHelp"); note(parent, "hdrVariablesHelp");
|
||||
return { read: () => validateHeaders(JSON.parse(target.value)), add: (direction, rule) => { adders[direction](rule); renumber(direction); sync(); } };
|
||||
return { read: () => validateHeaders(JSON.parse(target.value)), set, add: (direction, rule) => { adders[direction](rule); renumber(direction); sync(); } };
|
||||
}
|
||||
function suspendDraft() {
|
||||
const state = {
|
||||
@@ -185,7 +234,7 @@ function restoreDraft(state) {
|
||||
editing = state.editing; revision = state.revision; basicEditor = state.basicEditor; locationsReader = state.locationsReader; aclControl = state.aclControl;
|
||||
readBindings = state.readBindings; readHosts = state.readHosts; countryRatesReader = state.countryRatesReader; uaRatesReader = state.uaRatesReader || (() => []); pagesEditor = state.pagesEditor; backendHealthEditorControl = state.backendHealthEditorControl || null;
|
||||
vhostPolicyEditor = state.vhostPolicyEditor || null; vhostCacheRulesEditor = state.vhostCacheRulesEditor || null;
|
||||
vhostHeadersControl = state.vhostHeadersControl || null; headersPreviewControl = state.headersPreviewControl || null; presetsRefresh = state.presetsRefresh || (() => {});
|
||||
vhostHeadersControl = state.vhostHeadersControl || null; headersPreviewControl = state.headersPreviewControl || null; presetsRefresh = state.presetsRefresh || (() => { });
|
||||
stagedCertificates = state.stagedCertificates || []; uploading = state.uploading === true; initialized = true; dirty = true; $("vhost-editing").textContent = state.label;
|
||||
if (!dialog.open) dialog.showModal(); if (latestStatus) renderStatus(latestStatus);
|
||||
}
|
||||
@@ -342,10 +391,13 @@ function debugOriginIssues(members) {
|
||||
function aclEditor(parent, initial, onChange = () => { }) {
|
||||
const enabled = field(parent, "acl-use", "aclUse", !!initial, "checkbox", { switch: true }), body = el("div", undefined, "vh-wide vh-grid"); parent.append(body);
|
||||
const policy = field(body, "acl-default", "aclDefault", initial?.default || "deny", "select", { values: [["deny", "vhDeny"], ["allow", "aclAllow"]] }), rows = el("div", undefined, "vh-wide"); body.append(rows);
|
||||
function add(value = { network: "", action: "allow" }) { const row = el("div", undefined, "acl-rule"); field(row, "network", "aclNetwork", value.network, "text", { maxLength: 64 }); field(row, "action", "aclAction", value.action, "select", { values: [["allow", "aclAllow"], ["deny", "vhDeny"]] }); row.append(button("remove", () => { row.remove(); onChange(); })); rows.append(row); }
|
||||
function add(value = { network: "", action: "allow" }) { const row = el("div", undefined, "acl-rule"); field(row, "network", "aclNetwork", value.network, "text", { maxLength: 254 }); field(row, "action", "aclAction", value.action, "select", { values: [["allow", "aclAllow"], ["deny", "vhDeny"]] }); row.append(button("remove", () => { row.remove(); onChange(); })); rows.append(row); }
|
||||
body.append(button("aclAdd", () => { add(); onChange(); })); for (const rule of initial?.rules || []) add(rule);
|
||||
const sync = () => { body.hidden = !enabled.checked; onChange(); }; enabled.addEventListener("change", sync); body.addEventListener("input", onChange); body.addEventListener("change", onChange); body.hidden = !enabled.checked;
|
||||
note(parent, "aclHelp"); return { read: () => enabled.checked ? { default: policy.value, rules: [...rows.children].map(r => ({ network: str("network", r), action: str("action", r) })) } : null };
|
||||
note(parent, "aclHelp"); return {
|
||||
read: () => enabled.checked ? { default: policy.value, rules: [...rows.children].map(r => ({ network: str("network", r), action: str("action", r) })) } : null,
|
||||
set: value => { validateInlineAcl(value); enabled.checked = value !== null; policy.value = value?.default || "deny"; rows.replaceChildren(); for (const rule of value?.rules || []) add(rule); body.hidden = !enabled.checked; onChange(); }
|
||||
};
|
||||
}
|
||||
function openLocationHelp(topic = "locations") {
|
||||
const dialog = $("location-help-dialog"), title = $("location-help-title"), body = $("location-help-body");
|
||||
@@ -375,7 +427,7 @@ function openLocationHelp(topic = "locations") {
|
||||
dialog.showModal();
|
||||
}
|
||||
const LOCATION_GROUP = "__group__";
|
||||
function locationsEditor(parent, values) {
|
||||
function locationsEditor(parent, values, onChange = changed) {
|
||||
const toolbar = el("div", undefined, "vh-wide location-toolbar"), rows = el("div", undefined, "vh-wide vh-locations");
|
||||
const addTop = button("locationAdd", () => { add(); sync(); }, "primary");
|
||||
const addHostRule = button("rtAddHostRule", () => { add({ id: nextId("host-rule"), match_type: "any", conditions: [{ source: "header", name: "", operator: "equals", values: [] }] }, true); sync(); });
|
||||
@@ -412,7 +464,7 @@ function locationsEditor(parent, values) {
|
||||
};
|
||||
});
|
||||
}
|
||||
function sync() { if (reloading) return; try { read("paths").value = JSON.stringify(readRows(), null, 2); changed(); } catch { } tester?.run(); }
|
||||
function sync() { if (reloading) return; try { read("paths").value = JSON.stringify(readRows(), null, 2); onChange(); } catch { } tester?.run(); }
|
||||
function memberOptions(select, chosen = select.value) { const base = text("option", "locationPool"); base.value = ""; const groupOption = text("option", "locationBackendGroup"); groupOption.value = LOCATION_GROUP; select.replaceChildren(base, groupOption, ...[...form.querySelectorAll(".vh-member")].map(m => { const id = str("member-id", m), o = el("option", `${id} / ${str("member-url", m)}`); o.value = id; return o; })); if (chosen && !Array.from(select.options).some(o => o.value === chosen)) { const o = el("option", `${chosen} / ${t("locationMissing")}`); o.value = chosen; select.append(o); } select.value = chosen; }
|
||||
function add(value = {}, openConditions = false) {
|
||||
if (rows.children.length >= 64) { toast(t("locationLimit"), true); return; }
|
||||
@@ -588,6 +640,11 @@ function locationsEditor(parent, values) {
|
||||
const bottom = el("div", undefined, "vh-wide location-toolbar location-toolbar-bottom"); bottom.append(button("locationAdd", () => { add(); sync(); }, "primary")); parent.append(bottom);
|
||||
const refreshMembers = () => { for (const select of rows.querySelectorAll('[name="location-backend"]')) memberOptions(select); for (const row of rows.children) row.refreshBalancing?.(); };
|
||||
form.querySelector(".vh-members").addEventListener("input", refreshMembers); form.querySelector(".vh-members").addEventListener("change", refreshMembers);
|
||||
read("paths").addEventListener("change", () => { try { const data = JSON.parse(str("paths")); if (!Array.isArray(data) || data.length > 64) return; reloading = true; rows.replaceChildren(); for (const value of data) add(value); } catch { } finally { reloading = false; } });
|
||||
readRows.set = data => {
|
||||
validateLocations(data); const previous = [...rows.childNodes]; reloading = true;
|
||||
try { rows.replaceChildren(); for (const value of data) add(value); readRows(); tester?.run(); }
|
||||
catch (error) { rows.replaceChildren(...previous); throw error; }
|
||||
finally { reloading = false; }
|
||||
};
|
||||
sync(); return readRows;
|
||||
}
|
||||
@@ -207,10 +207,12 @@ function load(value = defaults(), migrationIds = [], show = true) {
|
||||
g = group("vhHeadersPreview"); headersPreviewControl = headersPreview(g);
|
||||
g = group("vhBackendDiagnostics");
|
||||
const diagnosticCards = el("div", undefined, "vh-wide hdr-cards"); g.append(diagnosticCards);
|
||||
diagnosticCard(diagnosticCards, { name: "timing-headers", key: "vhTimingHeaders", checked: value.timing_headers === true, header: "Server-Timing", example: "proxy;dur=1.8, upstream;dur=12.4", help: "hdrCardTimingHelp", extra: body => {
|
||||
field(body, "timing-header-names", "vhTimingHeaderNames", value.timing_header_names || "standard", "select", { values: [["standard", "vhTimingHeaderNamesStandard"], ["cdn", "vhTimingHeaderNamesCdn"], ["legacy", "vhTimingHeaderNamesLegacy"]] });
|
||||
field(body, "timing-allow-origin", "vhTimingAllowOrigin", (value.timing_allow_origin || []).join(", "), "text", { maxLength: 2048 }).placeholder = "https://app.example.com";
|
||||
} });
|
||||
diagnosticCard(diagnosticCards, {
|
||||
name: "timing-headers", key: "vhTimingHeaders", checked: value.timing_headers === true, header: "Server-Timing", example: "proxy;dur=1.8, upstream;dur=12.4", help: "hdrCardTimingHelp", extra: body => {
|
||||
field(body, "timing-header-names", "vhTimingHeaderNames", value.timing_header_names || "standard", "select", { values: [["standard", "vhTimingHeaderNamesStandard"], ["cdn", "vhTimingHeaderNamesCdn"], ["legacy", "vhTimingHeaderNamesLegacy"]] });
|
||||
field(body, "timing-allow-origin", "vhTimingAllowOrigin", (value.timing_allow_origin || []).join(", "), "text", { maxLength: 2048 }).placeholder = "https://app.example.com";
|
||||
}
|
||||
});
|
||||
diagnosticCard(diagnosticCards, { name: "backend-header", key: "vhBackendHeader", checked: value.backend_header === true, header: "X-Rust-Proxy-Backend", example: `${value.id || "vhost"}/${(value.backends || [])[0]?.id || "origin-1"}`, help: "hdrCardBackendHelp" });
|
||||
diagnosticCard(diagnosticCards, { name: "backend-timing-header", key: "vhBackendTimingHeader", checked: value.backend_timing_header === true, header: "X-RustProxy-Backend-Time", example: "12.40ms", help: "hdrCardBackendTimeHelp" });
|
||||
note(g, "vhBackendDiagnosticsHelp");
|
||||
@@ -306,8 +308,10 @@ function load(value = defaults(), migrationIds = [], show = true) {
|
||||
profileBox.append(multiWarning); aclFields.append(profileBox); note(aclFields, "vhAclProfileHelp");
|
||||
|
||||
const inlineAclFields = subsection(g, "vhIpAccess");
|
||||
aclControl = aclEditor(inlineAclFields, value.acl, () => { if (aclControl) read("acl").value = JSON.stringify(aclControl.read(), null, 2); });
|
||||
const aclJson = jsonDrawer(inlineAclFields, { name: "acl", titleKey: "vhAclJson", helpKey: "vhAclJsonHelp", value: value.acl ?? null, maxLength: 32768, validate: validateInlineAcl, apply: data => aclControl.set(data) });
|
||||
aclControl = aclEditor(inlineAclFields, value.acl, () => { if (aclControl) { aclJson.target.value = JSON.stringify(aclControl.read(), null, 2); aclJson.refresh(); changed(); } });
|
||||
note(inlineAclFields, "vhInlineAclHelp");
|
||||
inlineAclFields.append(aclJson.node);
|
||||
|
||||
const methodFields = subsection(g, "vhTrafficMethodsSection");
|
||||
field(methodFields, "method-mode", "vhMethodMode", methodPolicy.mode || "off", "select", { values: [["off", "vhOff"], ["allow", "locationMethodAllow"], ["block", "locationMethodBlock"]] });
|
||||
@@ -360,14 +364,13 @@ function load(value = defaults(), migrationIds = [], show = true) {
|
||||
field(uaBlockingFields, "ua-block-enabled", "vhUaBlockEnabled", uaBlock.enabled === true, "checkbox", { switch: true });
|
||||
field(uaBlockingFields, "ua-block-patterns", "vhUaBlockPatterns", (uaBlock.patterns || []).join("\n"), "textarea", { rows: 4, maxLength: 32768 });
|
||||
note(uaBlockingFields, "vhUaBlockHelp");
|
||||
g = group("vhAdvanced", true); field(g, "paths", "vhPaths", JSON.stringify(value.routes || [], null, 2), "textarea", { rows: 5, maxLength: 131072 });
|
||||
field(g, "acl", "vhAcl", JSON.stringify(value.acl ?? null, null, 2), "textarea", { rows: 5, maxLength: 32768 });
|
||||
field(g, "headers", "vhHeaders", JSON.stringify(value.headers || {}, null, 2), "textarea", { rows: 5, maxLength: 65536 });
|
||||
g = group("vhLocations");
|
||||
field(g, "main-error-target", "vhErrorFallbackTarget", value.error_fallback?.target || "", "text", { maxLength: 64, pattern: "[A-Za-z0-9_\\-]{0,64}" });
|
||||
field(g, "main-error-statuses", "vhErrorFallbackStatuses", (value.error_fallback?.statuses || [404]).join(", "), "text", { maxLength: 64 });
|
||||
note(g, "vhErrorFallbackHelp");
|
||||
locationsReader = locationsEditor(g, value.routes || []);
|
||||
const pathsJson = jsonDrawer(g, { name: "paths", titleKey: "vhLocationsJson", helpKey: "vhLocationsJsonHelp", value: value.routes || [], maxLength: 131072, validate: validateLocations, apply: data => locationsReader.set(data) });
|
||||
locationsReader = locationsEditor(g, value.routes || [], () => { changed(); pathsJson.refresh(); });
|
||||
g.append(pathsJson.node);
|
||||
g = group("vhSsl");
|
||||
const certificateRow = el("div", undefined, "vh-wide vh-certificate-select-row"); g.append(certificateRow);
|
||||
const selector = field(certificateRow, "certificate-id", "vhCertificate", value.certificate_id || "", "select");
|
||||
@@ -578,7 +581,10 @@ function load(value = defaults(), migrationIds = [], show = true) {
|
||||
};
|
||||
transformEnabled.addEventListener("change", syncTransform); customTransformExtensions.addEventListener("change", syncTransform); syncTransform();
|
||||
note(transformOptions, "vhTransformHelp");
|
||||
g = group("vhHeaders"); g.parentElement.classList.add("hdr-rules-anchor"); vhostHeadersControl = headerEditors(g, value.headers || {});
|
||||
g = group("vhHeaders"); g.parentElement.classList.add("hdr-rules-anchor");
|
||||
const headersJson = jsonDrawer(g, { name: "headers", titleKey: "vhHeadersJson", helpKey: "vhHeadersJsonHelp", value: value.headers || {}, maxLength: 65536, validate: validateHeaders, apply: data => vhostHeadersControl.set(data) });
|
||||
vhostHeadersControl = headerEditors(g, value.headers || {}, headersJson.target, () => { changed(); headersJson.refresh(); });
|
||||
g.append(headersJson.node);
|
||||
g = group("policyTitle"); vhostPolicyEditor = window.rustProxyPolicy.create({ value: value.policy || {}, scope: "vhost", onChange: changed }); g.append(vhostPolicyEditor.node);
|
||||
g = group("vhPages"); g.classList.add("vh-pages-grid"); pagesEditor = window.rustProxyPages.vhostEditor(g, value.pages || {});
|
||||
initTabs(); dirty = false; if (latestStatus) renderStatus(latestStatus); if (show && !dialog.open) dialog.showModal();
|
||||
@@ -657,12 +663,14 @@ function collect() {
|
||||
authentication: selectedAuthentication().provider === "none" ? null : selectedAuthentication(),
|
||||
tinyauth: { enabled: selectedAuthentication().provider === "tinyauth" && selectedAuthentication().method === "forward_auth", url: str("auth-url"), login_url: str("auth-login"), allow_private: yes("auth-private"), redirect_forbidden: yes("auth-redirect-forbidden"), connect_timeout_seconds: num("auth-connect"), timeout_seconds: num("auth-timeout"), request_headers: lines(str("auth-request-headers")), response_headers: lines(str("auth-response-headers")), address_allowlist: lines(str("auth-allowlist")), tls_ca_pem: nullable("auth-ca") },
|
||||
authelia: readForwardProvider("authelia"), authentik: readForwardProvider("authentik"),
|
||||
oidc: { enabled: selectedAuthentication().method === "oidc", issuer_url: str("oidc-issuer"), backend_url: str("oidc-backend"),
|
||||
oidc: {
|
||||
enabled: selectedAuthentication().method === "oidc", issuer_url: str("oidc-issuer"), backend_url: str("oidc-backend"),
|
||||
redirect_url: str("oidc-redirect"), client_id: str("oidc-client"),
|
||||
client_secret: str("oidc-secret"), session_secret: str("oidc-session"), scopes: str("oidc-scopes"),
|
||||
allow_private: yes("oidc-private"), address_allowlist: lines(str("oidc-allowlist")),
|
||||
tls_ca_pem: nullable("oidc-ca"), connect_timeout_seconds: num("oidc-connect"),
|
||||
timeout_seconds: num("oidc-timeout"), session_ttl_seconds: num("oidc-ttl") },
|
||||
timeout_seconds: num("oidc-timeout"), session_ttl_seconds: num("oidc-ttl")
|
||||
},
|
||||
backends: members, routes: paths, acl, headers, policy: vhostPolicyEditor ? vhostPolicyEditor.read() : {},
|
||||
load_balancing: {
|
||||
algorithm: str("algorithm"), ...(vhostBalancingControl?.hash() ? { hash: vhostBalancingControl.hash() } : {}), slow_start_seconds: num("slow-start"), keepalive: { enabled: yes("keepalive"), idle_timeout_seconds: num("idle-timeout"), max_idle_per_host: num("max-idle"), tcp_keepalive_seconds: num("tcp-keepalive"), pool_recycle_requests: num("pool-recycle-requests"), pool_recycle_seconds: num("pool-recycle-seconds"), http1_max_buffer_bytes: num("http1-max-buffer") },
|
||||
|
||||
@@ -92,7 +92,7 @@ function refreshVhostBackendPopup(status = latestStatus) {
|
||||
scheme = url.protocol.replace(":", "").toUpperCase();
|
||||
const port = url.port || (scheme === "HTTPS" ? "443" : scheme === "HTTP" ? "80" : "");
|
||||
address = `${url.hostname}${port ? `:${port}` : ""}`;
|
||||
} catch { }
|
||||
} catch { }
|
||||
const upstream = upstreamProtocolBadgeText(backend, member);
|
||||
const protocol = `${scheme} · ${upstream.mode}${upstream.observed ? ` → ${upstream.observed}` : ""}`;
|
||||
const statusCode = Number(member?.last_status);
|
||||
@@ -225,9 +225,7 @@ function syncPoolSortDirection() {
|
||||
control.setAttribute("aria-label", t(poolTablePrefs.descending ? "backendSortDescending" : "backendSortAscending"));
|
||||
}
|
||||
}
|
||||
// The backend pool and backend overview tables live on Overview. Rebuilding
|
||||
// them on every live snapshot while another panel is shown cost tens of
|
||||
// milliseconds per update; defer them until Overview is shown again.
|
||||
|
||||
let overviewViewsPending = false;
|
||||
const overviewViewsHidden = () => typeof currentPanel !== "undefined" && currentPanel !== "overview";
|
||||
function flushOverviewViews() { if (!overviewViewsPending) return; overviewViewsPending = false; if (latestStatus) renderStatus(latestStatus); else applyPoolTableView(); }
|
||||
@@ -913,7 +911,7 @@ form.addEventListener("submit", async event => {
|
||||
const healthPanel = invalid.closest(".vh-backend-health-panel");
|
||||
if (healthPanel) backendHealthEditorControl?.reveal([...form.querySelector(".vh-members").children].find(row => row.memberHealthPanel === healthPanel));
|
||||
activateTab(invalid.closest(".vh-group")?.dataset.tab || "details");
|
||||
const details = invalid.closest("details"); if (details) details.open = true;
|
||||
for (let parent = invalid.parentElement; parent && parent !== form; parent = parent.parentElement) if (parent.tagName === "DETAILS") parent.open = true;
|
||||
invalid.reportValidity(); return;
|
||||
}
|
||||
if (revision !== envelope.revision) { toast(t("stale"), true); return; }
|
||||
|
||||
Reference in new issue
Block a user