This commit is contained in:
Mateusz Gruszczyński committed 2026-11-28 20:38:38 +01:00
1 parent 4d1087e357
commit 7514227b3b
40 files changed
+502 -260

No files matched your search

+40 -36
View File
@@ -573,12 +573,12 @@
rules.placeholder = custom ? "allow 10.0.0.0/8\ndeny 10.21.0.0/16" : "10.0.0.0/8\n203.0.113.5";
syncRuleRows(convertRules); renderPreview();
}
function attachAclProfileId() { window.rustProxyAutoId.attach($("acl-profile-id"), { elements: [$("acl-profile-name")], taken: () => (envelope?.config.acl_profiles || []).map(value => value.id) }); }
function attachAclProfileId() { window.rustProxyAutoId.attach($("acl-profile-id"), { elements: [$("acl-profile-name")], taken: () => (envelope?.config.acl_profiles || []).map(value => value.id).filter(value => value !== editing), original: editing, inUse: id => configReferences(id, ["acl_profile_id", "acl_profile_ids"]), renameKey: "idRenameHelpAclProfile" }); }
function clear() {
editing = null; dirty = false; form.reset(); setMode("allow_exceptions"); aclDefault.value = "deny"; countryMode.value = "off"; countryEnabled.checked = false; countriesInput.value = ""; $("acl-profile-id").readOnly = false; attachAclProfileId(); $("acl-profile-editing").textContent = t("aclProfileNew"); renderRuleRows([]); rules.value = ""; syncPolicy();
}
function edit(profile) {
editing = profile.id; dirty = false; $("acl-profile-id").value = profile.id; $("acl-profile-id").readOnly = true; $("acl-profile-name").value = profile.name || profile.id; attachAclProfileId();
editing = profile.id; dirty = false; $("acl-profile-id").value = profile.id; $("acl-profile-id").readOnly = false; $("acl-profile-name").value = profile.name || profile.id; attachAclProfileId();
const cMode = profile.country_access?.mode || "off"; aclDefault.value = profile.acl?.default || (cMode === "allow" ? "deny" : "allow"); countryMode.value = cMode;
countryEnabled.checked = cMode !== "off"; countriesInput.value = (profile.country_access?.countries || []).join("\n");
setMode(inferMode(profile)); renderRuleRows(profile.acl?.rules || []); $("acl-profile-editing").textContent = t("aclProfileEdit"); dirty = false; syncPolicy();
@@ -587,16 +587,6 @@
edit(profile); editing = null; $("acl-profile-id").readOnly = false; $("acl-profile-id").value = ""; $("acl-profile-name").value = ""; attachAclProfileId();
$("acl-profile-editing").textContent = t("aclProfileNew"); dirty = true; $("acl-profile-name").focus();
}
function friendlySummary(profile) {
const mode = inferMode(profile), countries = profile.country_access?.countries || [], rulesList = profile.acl?.rules || [];
if (mode === "allow_exceptions" || mode === "block_exceptions") {
const allowMode = mode === "allow_exceptions", parts = [];
if (countries.length && profile.country_access?.mode !== "off") parts.push(`${t(allowMode ? "aclProfileCountriesShortAllow" : "aclProfileCountriesShortBlock")}: ${countries.join(", ")}`);
if (rulesList.length) parts.push(`${t(allowMode ? "aclProfileIpsShortAllow" : "aclProfileIpsShortBlock")}: ${rulesList.map(rule => rule.network).join(", ")}`);
return [`${t(allowMode ? "aclProfileModeAllowExceptions" : "aclProfileModeBlockExceptions")}`, parts.join(" · ") || t("aclProfilePreviewNoExceptions")];
}
return [`${t("aclProfileModeCustom")}: ${t("aclDefault")} ${t(profile.acl?.default || "allow")}`, `${rulesList.length} ${t("aclProfileIpRulesShort")} · ${t("vhCountryMode")}: ${t(profile.country_access?.mode === "block" ? "vhCountryBlock" : profile.country_access?.mode === "allow" ? "vhCountryAllow" : "vhOff")}`];
}
function refreshTranslations() {
$("acl-profile-editing").textContent = t(editing ? "aclProfileEdit" : "aclProfileNew");
for (const row of ruleRows.children) {
@@ -617,28 +607,32 @@
function render() {
if (!envelope) return;
const profiles = envelope.config.acl_profiles || [], list = $("acl-profile-list");
const cards = profiles.map(profile => {
const box = el("div", undefined, "entity acl-profile-card");
const top = el("div", undefined, "entity-top"); top.append(el("span", profile.name || profile.id, "entity-title"), el("small", profile.id)); box.append(top);
const pieces = friendlySummary(profile);
const usesProfile = value => value.acl_profile_id === profile.id || (value.acl_profile_ids || []).includes(profile.id);
const users = (envelope.config.vhosts || []).filter(usesProfile).map(v => v.id);
for (const agent of envelope.config.docker_agents?.agents || []) {
if (usesProfile(agent)) users.push(`docker-agent:${agent.id}`);
for (const assignment of agent.assignments || []) if (usesProfile(assignment)) users.push(`docker:${agent.id}/${assignment.hostname || assignment.service_key}`);
}
box.append(el("p", pieces.filter(Boolean).join("\n"), "entity-details"));
if (users.length) {
const attached = el("details", undefined, "acl-profile-attached");
attached.append(el("summary", `${t("aclProfileAttached")} (${users.length})`), el("p", users.join(", "), "entity-details"));
box.append(attached);
}
const actions = el("div", undefined, "entity-actions"); actions.append(action(t("edit"), () => edit(profile)), action(t("copyEntry"), () => copyProfile(profile)), action(t("remove"), async () => {
const query = ($("acl-profile-search")?.value || "").trim().toLowerCase();
const usersOf = profile => window.rustProxyConfigReferences(profile.id, ["acl_profile_id", "acl_profile_ids"]);
const shown = profiles.filter(profile => !query || [profile.id, profile.name, ...(profile.acl?.rules || []).map(rule => rule.network), ...(profile.country_access?.countries || []), ...usersOf(profile)].join(" ").toLowerCase().includes(query));
const cards = shown.map(profile => {
const box = el("article", undefined, "vhost-card acl-profile-card acl-profile-row"); box.dataset.aclProfile = profile.id;
const mode = inferMode(profile), users = usersOf(profile), rulesList = profile.acl?.rules || [], countries = profile.country_access?.countries || [];
const head = el("div", undefined, "vhost-card-head"), identity = el("div", undefined, "vhost-card-identity"), title = el("div", undefined, "vhost-title-line");
const modePill = el("span", t(mode === "allow_exceptions" ? "aclProfileModeAllowExceptions" : mode === "block_exceptions" ? "aclProfileModeBlockExceptions" : "aclProfileModeCustom"), `pill${profile.acl?.default === "deny" ? " warn" : " live"}`);
title.append(el("strong", profile.name || profile.id, "entity-title"), modePill, el("span", users.length ? `${t("aclProfileAttached")}: ${users.length}` : t("aclProfileNotUsed"), users.length ? "pill live" : "pill"));
identity.append(title, el("div", profile.id, "vhost-hosts")); head.append(identity);
const actions = el("div", undefined, "entity-actions"); actions.append(action(t("edit"), () => { edit(profile); openEditor(); }), action(t("copyEntry"), () => { copyProfile(profile); openEditor(); }), action(t("remove"), async () => {
if (users.length) { toast(`${t("aclProfileInUse")}: ${users.join(", ")}`, true); return; }
if (!(await appConfirm(t("confirmDelete"), { danger: true }))) return; const next = structuredClone(envelope.config); next.acl_profiles = (next.acl_profiles || []).filter(item => item.id !== profile.id); if (await saveSection("acl-profiles", next.acl_profiles || [])) clear();
})); box.append(actions); return box;
if (!(await appConfirm(t("confirmDelete"), { danger: true }))) return; const next = structuredClone(envelope.config); next.acl_profiles = (next.acl_profiles || []).filter(item => item.id !== profile.id); if (await saveSection("acl-profiles", next.acl_profiles || [])) { if (editing === profile.id && aclDialog?.open) aclDialog.close(); clear(); }
}));
head.append(actions); box.append(head);
const details = el("div", undefined, "vhost-detail-strip");
const countryMode = profile.country_access?.mode || "off";
for (const [key, value] of [
["aclDefault", t(profile.acl?.default === "deny" ? "deny" : "allow")],
["aclProfileIpRulesShort", rulesList.length ? rulesList.map(rule => `${t(rule.action === "deny" ? "aclDeny" : "aclAllow")} ${rule.network}`).join(", ") : "-"],
["vhCountryMode", countryMode === "off" || !countries.length ? "-" : `${t(countryMode === "block" ? "vhCountryBlock" : "vhCountryAllow")}: ${countries.join(", ")}`],
["aclProfileAttached", users.join(", ") || "-"]
]) { const cell = el("div", undefined, "vhost-detail"); const valueNode = el("b", value); valueNode.title = value; cell.append(el("span", t(key), "small-label"), valueNode); details.append(cell); }
box.append(details); return box;
});
list.replaceChildren(...(cards.length ? cards : [el("p", t("aclProfilesEmpty"), "empty")]));
list.replaceChildren(...(cards.length ? cards : [el("p", t(query && profiles.length ? "aclProfileSearchEmpty" : "aclProfilesEmpty"), "empty")]));
if (!dirty && editing) { const current = profiles.find(p => p.id === editing); if (current) edit(current); else clear(); }
}
form.addEventListener("input", event => { dirty = true; if (event.target !== rules) { syncRulesText(); syncPolicy(); } });
@@ -676,12 +670,22 @@
const profile = { id, name, acl: { default: finalDefault, rules: aclRules }, country_access: { mode: finalCountryMode, countries } };
const next = structuredClone(envelope.config); next.acl_profiles ||= [];
const index = next.acl_profiles.findIndex(item => item.id === editing);
if (index < 0) { if (next.acl_profiles.some(item => item.id === id)) throw fieldError($("acl-profile-id"), t("aclProfileDuplicate")); next.acl_profiles.push(profile); } else next.acl_profiles[index] = profile;
if (await saveSection("acl-profiles", next.acl_profiles || [])) { editing = id; dirty = false; render(); }
if (next.acl_profiles.some(item => item.id === id && item.id !== editing)) throw fieldError($("acl-profile-id"), t("aclProfileDuplicate")); if (index < 0) next.acl_profiles.push(profile); else next.acl_profiles[index] = profile;
if (await saveSection("acl-profiles", next.acl_profiles || [])) { dirty = false; editing = null; if (aclDialog?.open) aclDialog.close(); clear(); render(); }
});
} catch (error) { toast(error.message, true); if (error.fieldTarget?.focus) error.fieldTarget.focus(); }
});
$("acl-profile-new").addEventListener("click", clear); $("acl-profile-reset").addEventListener("click", clear);
window.rustProxyAclProfiles = { render, reset: clear, refreshTranslations };
const aclDialog = $("acl-profile-dialog");
function openEditor() { if (aclDialog && !aclDialog.open) aclDialog.showModal(); }
async function closeEditor() {
if (dirty && !(await appConfirm(t("aclProfileUnsaved"), { danger: true, confirmLabel: t("discardAction") }))) return;
dirty = false; if (aclDialog?.open) aclDialog.close(); clear();
}
$("acl-profile-new").addEventListener("click", () => { clear(); openEditor(); $("acl-profile-name").focus(); });
$("acl-profile-search")?.addEventListener("input", () => render());
$("acl-profile-reset").addEventListener("click", () => void closeEditor());
$("acl-profile-close")?.addEventListener("click", () => void closeEditor());
aclDialog?.addEventListener("cancel", event => { event.preventDefault(); void closeEditor(); });
window.rustProxyAclProfiles = { render, reset: () => { dirty = false; if (aclDialog?.open) aclDialog.close(); clear(); }, refreshTranslations };
clear(); if (envelope) render();
})();