v0.43.1
This commit is contained in:
1 parent
5b6d4a7903
commit
4d1087e357
160 files changed
+2407
-1933
No files matched your search
+244
-69
@@ -63,90 +63,187 @@ for (const id of ["certificate-file", "certificate-key"]) {
|
||||
$(id).addEventListener("input", syncCertificatePermissions);
|
||||
$(id).addEventListener("change", syncCertificatePermissions);
|
||||
}
|
||||
function certificateUsage(cert) {
|
||||
const config = envelope?.config || {}, settings = config.tls || {};
|
||||
const hostsOf = item => item?.frontend?.hosts || [];
|
||||
const groups = {
|
||||
vhosts: (config.vhosts || []).filter(item => item.certificate_id === cert.id).map(item => ({ id: item.id, hosts: hostsOf(item), mismatch: item.allow_certificate_mismatch === true, open: () => { setPanel("vhosts"); window.rustProxyVhosts?.edit(item.id); } })),
|
||||
redirects: (config.redirects || []).filter(item => item.certificate_id === cert.id).map(item => ({ id: item.id, hosts: hostsOf(item), open: () => { setPanel("redirects"); window.rustProxyRedirects?.edit(item.id); } })),
|
||||
notfound: (config.not_found_hosts || []).filter(item => item.certificate_id === cert.id).map(item => ({ id: item.id, hosts: hostsOf(item), open: () => { setPanel("notfound"); window.rustProxyNotFound?.edit(item.id); } })),
|
||||
docker: (config.docker_agents?.agents || []).filter(agent => [agent.certificate_id, ...(agent.certificate_ids || [])].includes(cert.id)).map(agent => ({ id: agent.id, hosts: agent.domains || [], open: () => setPanel("settings") }))
|
||||
};
|
||||
const legacy = [];
|
||||
for (const item of config.vhosts || []) if (item.certificate_id === cert.id) legacy.push(`vhost:${item.id}`);
|
||||
for (const item of config.redirects || []) if (item.certificate_id === cert.id) legacy.push(`redirect:${item.id}`);
|
||||
for (const item of config.not_found_hosts || []) if (item.certificate_id === cert.id) legacy.push(`404:${item.id}`);
|
||||
const admin = config.administration?.certificate_id === cert.id, isDefault = settings.default_certificate === cert.id;
|
||||
if (admin) legacy.push(t("administration"));
|
||||
if (isDefault) legacy.push(t("defaultLabel"));
|
||||
const count = groups.vhosts.length + groups.redirects.length + groups.notfound.length + (admin ? 1 : 0) + (isDefault ? 1 : 0);
|
||||
return { groups, admin, isDefault, legacy, count, inUse: legacy.length > 0 };
|
||||
}
|
||||
function certificateCoverage(cert) {
|
||||
const inventory = certificateInventory.get(cert.id);
|
||||
return inventory?.covered_hosts?.length ? inventory.covered_hosts : (cert.covered_hosts || []);
|
||||
}
|
||||
function certificateCovers(coverage, host) { return coverage.some(pattern => window.rustProxyAutoCertificate.covers(pattern, host)); }
|
||||
function certificateCoverageState(coverage, hosts) {
|
||||
if (!hosts.length || !coverage.length) return { state: "unknown", missing: [] };
|
||||
const missing = hosts.filter(host => !certificateCovers(coverage, host));
|
||||
return { state: missing.length === 0 ? "full" : missing.length === hosts.length ? "none" : "partial", missing };
|
||||
}
|
||||
let certificateFilter = "all";
|
||||
const certificateOpenRows = new Set();
|
||||
function certificateTimeline(inventory) {
|
||||
const days = inventory?.days_remaining, to = Number(inventory?.not_after_unix);
|
||||
const box = el("div", undefined, "certificate-validity");
|
||||
const tone = inventory?.expiry_status === "expired" ? "bad" : inventory?.expiry_status === "warning" ? "warn" : "ok";
|
||||
box.dataset.tone = days == null ? "unknown" : tone;
|
||||
const text = days == null ? t("certificateValidityUnknown") : `${t("certificateDaysLeft").replace("{days}", days)} · ${t("certificateUntil")} ${formatDate(to * 1000)}`;
|
||||
const bar = el("span", undefined, "certificate-validity-bar"), fill = el("i");
|
||||
const ratio = days == null ? 0 : Math.max(0, Math.min(1, Number(days) / 90));
|
||||
fill.style.width = `${Math.round(ratio * 100)}%`; bar.append(fill);
|
||||
box.append(el("span", text, "certificate-validity-text"), bar);
|
||||
return box;
|
||||
}
|
||||
function formatDate(ms) { try { return new Date(ms).toLocaleDateString(typeof language !== "undefined" ? language.replace("_", "-") : undefined); } catch { return new Date(ms).toISOString().slice(0, 10); } }
|
||||
function renderCertificateSummary(certificates) {
|
||||
const box = $("certificate-summary"); if (!box) return;
|
||||
const settings = envelope?.config.tls || {};
|
||||
let acme = 0, external = 0, managedFiles = 0, expiring = [], assignments = 0, vhostCount = 0, redirectCount = 0, notfoundCount = 0;
|
||||
for (const cert of certificates) {
|
||||
if (cert.issuer) acme++; else if (certificateUsesExternalFiles(cert)) external++; else managedFiles++;
|
||||
const inventory = certificateInventory.get(cert.id);
|
||||
if (["warning", "expired"].includes(inventory?.expiry_status)) expiring.push(`${cert.id} · ${inventory?.days_remaining ?? "-"} ${t("certificateDaysShort")}`);
|
||||
const usage = certificateUsage(cert); assignments += usage.count; vhostCount += usage.groups.vhosts.length; redirectCount += usage.groups.redirects.length; notfoundCount += usage.groups.notfound.length;
|
||||
}
|
||||
const tile = (value, titleKey, line, tone, filter) => {
|
||||
const node = el(filter ? "button" : "div", undefined, `cert-summary-tile${tone ? ` is-${tone}` : ""}`);
|
||||
if (filter) { node.type = "button"; node.dataset.uiIconName = "none"; node.addEventListener("click", () => { window.rustProxyAcme?.select("installed"); setCertificateFilter(filter); }); }
|
||||
const title = el("span", t(titleKey)); title.dataset.i18n = titleKey;
|
||||
node.append(el("b", value), title, el("small", line)); return node;
|
||||
};
|
||||
const runtime = $("acme-runtime-state")?.textContent || "";
|
||||
box.replaceChildren(
|
||||
tile(String(certificates.length), "certificateSummaryCount", `${acme} ACME · ${external} ${t("certificateSummaryExternal")} · ${managedFiles} ${t("certificateSummaryManaged")}`, certificates.length ? "ok" : "", "all"),
|
||||
tile(String(expiring.length), "certificateSummaryExpiring", expiring.length ? expiring.slice(0, 2).join(", ") : t("certificateSummaryNothingExpiring"), expiring.length ? "warn" : "ok", "expiring"),
|
||||
tile(String(assignments), "certificateSummaryAssignments", `${vhostCount} vhost · ${redirectCount} ${t("certificateSummaryRedirects")} · ${notfoundCount} 404${settings.default_certificate ? ` · ${t("defaultLabel")}: ${settings.default_certificate}` : ""}`, "", "unassigned"),
|
||||
tile(runtime || "-", "certificateSummaryRuntime", $("acme-runtime-components")?.textContent || "", $("acme-runtime-card")?.dataset.state === "ready" ? "ok" : $("acme-runtime-card")?.dataset.state === "unavailable" ? "bad" : "")
|
||||
);
|
||||
}
|
||||
function setCertificateFilter(value) {
|
||||
certificateFilter = value;
|
||||
for (const button of document.querySelectorAll("[data-certificate-filter]")) button.setAttribute("aria-pressed", String(button.dataset.certificateFilter === value));
|
||||
applyCertificateFilter();
|
||||
}
|
||||
function applyCertificateFilter() {
|
||||
const query = ($("certificate-search")?.value || "").trim().toLowerCase();
|
||||
let shown = 0;
|
||||
for (const row of document.querySelectorAll("#certificate-list > .certificate-row")) {
|
||||
const matchesQuery = !query || row.dataset.search.includes(query);
|
||||
const matchesFilter = certificateFilter === "all" || (certificateFilter === "expiring" && row.dataset.expiring === "true") || (certificateFilter === "unassigned" && row.dataset.assigned === "false");
|
||||
row.hidden = !(matchesQuery && matchesFilter); if (!row.hidden) shown++;
|
||||
}
|
||||
const empty = $("certificate-list-filtered-empty");
|
||||
if (empty) empty.hidden = shown > 0 || !document.querySelector("#certificate-list > .certificate-row");
|
||||
}
|
||||
function renderCertificates() {
|
||||
if (!envelope) return;
|
||||
const settings = envelope.config.tls || {};
|
||||
const entries = (settings.certificates || []).map(cert => {
|
||||
const certificates = settings.certificates || [];
|
||||
const entries = certificates.map(cert => {
|
||||
const inventory = certificateInventory.get(cert.id);
|
||||
const coverage = (inventory?.covered_hosts?.length ? inventory.covered_hosts : (cert.covered_hosts || []));
|
||||
const coverage = certificateCoverage(cert);
|
||||
const bindings = cert.hosts || [];
|
||||
const used = [];
|
||||
for (const vhost of envelope.config.vhosts || []) if (vhost.certificate_id === cert.id) used.push(`vhost:${vhost.id}`);
|
||||
for (const redirect of envelope.config.redirects || []) if (redirect.certificate_id === cert.id) used.push(`redirect:${redirect.id}`);
|
||||
for (const host of envelope.config.not_found_hosts || []) if (host.certificate_id === cert.id) used.push(`404:${host.id}`);
|
||||
if (envelope.config.administration?.certificate_id === cert.id) used.push(t("administration"));
|
||||
if (settings.default_certificate === cert.id) used.push(t("defaultLabel"));
|
||||
const managed = !!cert.issuer, inUse = used.length > 0;
|
||||
const box = el("div", undefined, "entity certificate-card");
|
||||
const head = el("div", undefined, "certificate-card-head");
|
||||
const usage = certificateUsage(cert), used = usage.legacy;
|
||||
const managed = !!cert.issuer, inUse = usage.inUse;
|
||||
const box = el("details", undefined, "entity certificate-card certificate-row");
|
||||
box.dataset.certificateId = cert.id;
|
||||
box.dataset.expiring = String(["warning", "expired"].includes(inventory?.expiry_status));
|
||||
box.dataset.assigned = String(usage.count > 0);
|
||||
box.dataset.search = [cert.id, ...coverage, ...bindings, ...usage.groups.vhosts.map(item => item.id), ...usage.groups.redirects.map(item => item.id), ...usage.groups.notfound.map(item => item.id)].join(" ").toLowerCase();
|
||||
box.open = certificateOpenRows.has(cert.id);
|
||||
box.addEventListener("toggle", () => { if (box.open) certificateOpenRows.add(cert.id); else certificateOpenRows.delete(cert.id); });
|
||||
const summary = el("summary", undefined, "certificate-row-summary");
|
||||
const dot = el("span", undefined, "certificate-state-dot"); dot.dataset.tone = inventory?.expiry_status === "expired" ? "bad" : inventory?.expiry_status === "warning" ? "warn" : inventory ? "ok" : "unknown";
|
||||
const identity = el("div", undefined, "certificate-card-identity");
|
||||
identity.append(el("span", cert.id, "entity-title"));
|
||||
const statePills = el("div", undefined, "vhost-policy-pills certificate-state-pills");
|
||||
if (managed) statePills.append(el("small", `${t("certificateManaged")} · ${cert.issuer.provider} / ${cert.issuer.environment}`, "pill"));
|
||||
if (managed) statePills.append(el("small", `${t("certificateManaged")} · ${cert.issuer.provider} / ${cert.issuer.environment}`, "pill live"));
|
||||
else if (certificateUsesExternalFiles(cert)) statePills.append(el("small", t("certificateExternalFiles"), "pill"));
|
||||
if (settings.default_certificate === cert.id) statePills.append(el("small", t("defaultLabel"), "pill"));
|
||||
else statePills.append(el("small", t("certificateManagedFiles"), "pill"));
|
||||
if (settings.default_certificate === cert.id) statePills.append(el("small", t("defaultLabel"), "pill live"));
|
||||
if (inventory?.expiry_status === "expired") statePills.append(el("small", t("certificateExpired"), "pill status-error"));
|
||||
else if (inventory?.expiry_status === "warning") statePills.append(el("small", t("certificateExpiresSoon"), "pill status-error"));
|
||||
if (statePills.children.length) identity.append(statePills);
|
||||
head.append(identity);
|
||||
box.append(head);
|
||||
|
||||
identity.append(statePills);
|
||||
const coverageBlock = el("div", undefined, "certificate-coverage");
|
||||
coverageBlock.append(el("span", t("certificateCovers"), "small-label"));
|
||||
const domainPills = el("div", undefined, "vhost-policy-pills certificate-domain-pills");
|
||||
if (coverage.length) {
|
||||
for (const host of coverage) domainPills.append(el("small", host, "pill"));
|
||||
} else {
|
||||
domainPills.append(el("small", t("certificateCoverageUnknown"), "certificate-coverage-unknown"));
|
||||
}
|
||||
for (const host of coverage.slice(0, 3)) domainPills.append(el("small", host, "pill"));
|
||||
if (coverage.length > 3) domainPills.append(el("small", `+${coverage.length - 3}`, "pill"));
|
||||
} else domainPills.append(el("small", t("certificateCoverageUnknown"), "certificate-coverage-unknown"));
|
||||
coverageBlock.append(domainPills);
|
||||
box.append(coverageBlock);
|
||||
const usageCell = el("div", undefined, "certificate-usage-cell");
|
||||
const usageParts = [];
|
||||
if (usage.groups.vhosts.length) usageParts.push(`${usage.groups.vhosts.length} vhost`);
|
||||
if (usage.groups.redirects.length) usageParts.push(`${usage.groups.redirects.length} ${t("certificateSummaryRedirects")}`);
|
||||
if (usage.groups.notfound.length) usageParts.push(`${usage.groups.notfound.length} 404`);
|
||||
if (usage.admin) usageParts.push(t("administration"));
|
||||
if (usage.isDefault) usageParts.push(t("defaultLabel"));
|
||||
usageCell.append(el("b", String(usage.count)), el("span", usageParts.join(" · ") || t("certUnassigned"), "fine"));
|
||||
summary.append(dot, identity, coverageBlock, certificateTimeline(inventory), usageCell, el("span", "", "certificate-row-chevron"));
|
||||
box.append(summary);
|
||||
|
||||
const details = el("details", undefined, "certificate-details");
|
||||
details.append(el("summary", t("certificateDetails")));
|
||||
const detailBody = el("div", undefined, "certificate-details-body");
|
||||
const stamp = value => Number(value) ? formatDateTime(Number(value) * 1000) : "-";
|
||||
detailBody.append(
|
||||
el("p", `${t("certificateBindings")}: ${bindings.join(", ") || "-"}`, "entity-details"),
|
||||
el("p", `${t("certificateFiles")}: ${cert.cert_file} / ${cert.key_file}`, "entity-details"),
|
||||
el("p", `${t("certAssigned")}: ${used.join(", ") || t("certUnassigned")}`, "entity-details"),
|
||||
el("p", `${t("certificateIssuerName")}: ${inventory?.certificate_issuer || "-"}`, "entity-details"),
|
||||
el("p", `${t("certificateValidFrom")}: ${stamp(inventory?.not_before_unix)}`, "entity-details"),
|
||||
el("p", `${t("renewalExpires")}: ${stamp(inventory?.not_after_unix)}`, "entity-details"),
|
||||
el("p", `${t("certificateDaysRemaining")}: ${inventory?.days_remaining ?? "-"}`, "entity-details"),
|
||||
el("p", `${t("certificateRenewalStatus")}: ${inventory?.renewal_status || "-"}`, "entity-details"),
|
||||
el("p", `${t("renewalLast")}: ${stamp(inventory?.last_renewal_attempt)}`, "entity-details"),
|
||||
el("p", `${t("certificateRenewalError")}: ${inventory?.last_renewal_error ? t(inventory.last_renewal_error) : "-"}`, "entity-details"),
|
||||
);
|
||||
details.append(detailBody);
|
||||
box.append(details);
|
||||
|
||||
const buttons = el("div", undefined, "entity-actions");
|
||||
const assignPane = el("div", undefined, "certificate-bulk-assign");
|
||||
assignPane.hidden = true;
|
||||
const assignmentList = el("div", undefined, "certificate-bulk-list");
|
||||
for (const host of envelope.config.vhosts || []) {
|
||||
const label = el("label", undefined, "check");
|
||||
const check = document.createElement("input");
|
||||
check.type = "checkbox"; check.value = host.id;
|
||||
check.checked = host.certificate_id === cert.id;
|
||||
label.append(check, el("span", `${host.id} · ${(host.frontend?.hosts || []).join(", ")}`));
|
||||
assignmentList.append(label);
|
||||
}
|
||||
const applyBindings = action(t("certAssignApply"), async () => {
|
||||
if (busy) return;
|
||||
const selected = new Set([...assignmentList.querySelectorAll('input:checked')].map(input => input.value));
|
||||
const next = structuredClone(envelope.config);
|
||||
for (const host of next.vhosts) {
|
||||
if (selected.has(host.id)) host.certificate_id = cert.id;
|
||||
else if (host.certificate_id === cert.id) host.certificate_id = null;
|
||||
const body = el("div", undefined, "certificate-row-body");
|
||||
const usageSection = el("section", undefined, "certificate-section certificate-usage");
|
||||
const usageHead = el("h4"); usageHead.append(el("span", t("certificateWhereUsed")), el("span", String(usage.count), "pill"));
|
||||
usageSection.append(usageHead);
|
||||
const groupDefs = [["vhosts", "certificateGroupVhosts"], ["redirects", "certificateGroupRedirects"], ["notfound", "certificateGroupNotFound"], ["docker", "certificateGroupDocker"]];
|
||||
let anyUsage = false;
|
||||
for (const [key, labelKey] of groupDefs) {
|
||||
const items = usage.groups[key]; if (!items.length) continue; anyUsage = true;
|
||||
const group = el("div", undefined, "certificate-usage-group");
|
||||
group.append(el("span", `${t(labelKey)} · ${items.length}`, "small-label"));
|
||||
for (const item of items) {
|
||||
const row = el("div", undefined, "certificate-usage-row");
|
||||
const cover = certificateCoverageState(coverage, item.hosts);
|
||||
const pillText = cover.state === "full" ? t("certificateCovered") : cover.state === "unknown" ? t("certificateCoverageUnknownShort") : `${t("certificateNotCovered")}: ${cover.missing.join(", ")}${item.mismatch ? ` · ${t("certificateMismatchAccepted")}` : ""}`;
|
||||
const open = el("button", t("certificateOpen"), "quiet certificate-usage-open"); open.type = "button"; open.dataset.uiIconName = "none"; open.addEventListener("click", item.open);
|
||||
row.append(el("span", item.id, "mono"), el("span", item.hosts.join(", ") || "-", "fine"), el("span", pillText, `pill${cover.state === "full" ? " live" : cover.state === "unknown" ? "" : " warn"}`), open);
|
||||
group.append(row);
|
||||
}
|
||||
await saveSection("vhosts", next.vhosts);
|
||||
});
|
||||
assignPane.append(el("p", t("certAssignHelp"), "fine"), assignmentList, applyBindings);
|
||||
const assignButton = action(t("certAssignVhosts"), () => {
|
||||
assignPane.hidden = !assignPane.hidden;
|
||||
});
|
||||
usageSection.append(group);
|
||||
}
|
||||
const extra = [];
|
||||
if (usage.admin) extra.push(t("administration"));
|
||||
if (usage.isDefault) extra.push(t("certificateDefaultSni"));
|
||||
if (extra.length) { anyUsage = true; usageSection.append(el("p", `${t("certificateAlsoUsedBy")}: ${extra.join(", ")}`, "fine")); }
|
||||
if (!anyUsage) usageSection.append(el("p", t("certUnassigned"), "fine"));
|
||||
usageSection.append(el("p", t("certificateUsageHelp"), "fine certificate-usage-help"));
|
||||
|
||||
const side = el("div", undefined, "certificate-row-side");
|
||||
const stamp = value => Number(value) ? formatDateTime(Number(value) * 1000) : "-";
|
||||
const kv = (rows) => { const list = el("dl", undefined, "certificate-kv"); for (const [key, value] of rows) list.append(el("dt", t(key)), el("dd", value)); return list; };
|
||||
const details = el("section", undefined, "certificate-section certificate-details");
|
||||
details.append(el("h4", t("certificateDetails")), kv([
|
||||
["certificateIssuerName", inventory?.certificate_issuer || "-"],
|
||||
["certificateValidFrom", stamp(inventory?.not_before_unix)],
|
||||
["renewalExpires", stamp(inventory?.not_after_unix)],
|
||||
["certificateDaysRemaining", String(inventory?.days_remaining ?? "-")],
|
||||
["certificateBindings", bindings.join(", ") || "-"],
|
||||
["certAssigned", used.join(", ") || t("certUnassigned")]
|
||||
]));
|
||||
const renewal = el("section", undefined, "certificate-section certificate-renewal-summary");
|
||||
renewal.append(el("h4", t("certificateRenewalStatus")), kv([
|
||||
["certificateRenewalStatus", inventory?.renewal_status || "-"],
|
||||
["renewalLast", stamp(inventory?.last_renewal_attempt)],
|
||||
["certificateRenewalError", inventory?.last_renewal_error ? t(inventory.last_renewal_error) : "-"]
|
||||
]));
|
||||
if (managed) { const link = el("button", t("certificateRenewalActionsLink"), "quiet"); link.type = "button"; link.dataset.uiIconName = "none"; link.addEventListener("click", () => window.rustProxyAcme?.select("renewal")); renewal.append(link); }
|
||||
const files = el("section", undefined, "certificate-section certificate-files");
|
||||
files.append(el("h4", t("certificateFiles")), el("p", `${cert.cert_file}\n${cert.key_file}`, "mono certificate-file-paths"));
|
||||
const buttons = el("div", undefined, "entity-actions");
|
||||
const assignButton = action(t("certAssignVhosts"), () => openCertificateAssign(cert));
|
||||
assignButton.disabled = !(envelope.config.vhosts || []).length;
|
||||
buttons.append(assignButton);
|
||||
if (!managed) {
|
||||
@@ -173,13 +270,91 @@ function renderCertificates() {
|
||||
}
|
||||
const remove = action(t("remove"), async () => { if (inUse) { toast(t("certInUse"), true); return; } if (!(await appConfirm(t("confirmDelete"), { danger: true }))) return; const next = structuredClone(envelope.config); next.tls.certificates = next.tls.certificates.filter(v => v.id !== cert.id); await saveSection("tls", next.tls); });
|
||||
remove.disabled = inUse; remove.title = inUse ? t("certInUse") : ""; buttons.append(remove);
|
||||
box.append(buttons, assignPane);
|
||||
side.append(details, renewal, files, buttons);
|
||||
body.append(usageSection, side);
|
||||
box.append(body);
|
||||
return box;
|
||||
});
|
||||
$("certificate-list").replaceChildren(...entries);
|
||||
const filteredEmpty = el("p", t("certificateFilterEmpty"), "empty"); filteredEmpty.id = "certificate-list-filtered-empty"; filteredEmpty.hidden = true;
|
||||
$("certificate-list").replaceChildren(...entries, filteredEmpty);
|
||||
if (!entries.length) $("certificate-list").append(el("p", t("emptyCertificates"), "empty"));
|
||||
renderCertificateSummary(certificates);
|
||||
applyCertificateFilter();
|
||||
window.rustProxyCertificates?.syncSource?.();
|
||||
syncCertificatePermissions();
|
||||
}
|
||||
let certificateAssignState = null;
|
||||
function openCertificateAssign(cert) {
|
||||
const dialog = $("certificate-assign-dialog"); if (!dialog || !envelope) return;
|
||||
const coverage = certificateCoverage(cert);
|
||||
const rows = (envelope.config.vhosts || []).map(host => {
|
||||
const hosts = host.frontend?.hosts || [], cover = certificateCoverageState(coverage, hosts);
|
||||
const selectable = cover.state === "full" || cover.state === "unknown" || host.allow_certificate_mismatch === true || host.certificate_id === cert.id;
|
||||
return { host, hosts, cover, selectable, initial: host.certificate_id === cert.id, checked: host.certificate_id === cert.id };
|
||||
});
|
||||
certificateAssignState = { cert, rows, filter: "matching", query: "" };
|
||||
$("certificate-assign-title").textContent = `${t("certAssignVhosts")} · ${cert.id}`;
|
||||
$("certificate-assign-domains").replaceChildren(...coverage.slice(0, 4).map(host => el("span", host, "pill")), ...(coverage.length > 4 ? [el("span", `+${coverage.length - 4}`, "pill")] : []));
|
||||
$("certificate-assign-search").value = "";
|
||||
renderCertificateAssign();
|
||||
if (!dialog.open) dialog.showModal();
|
||||
}
|
||||
function renderCertificateAssign() {
|
||||
const state = certificateAssignState; if (!state) return;
|
||||
const counts = { matching: state.rows.filter(row => row.cover.state === "full").length, assigned: state.rows.filter(row => row.checked).length, all: state.rows.length };
|
||||
const filters = $("certificate-assign-filters");
|
||||
filters.replaceChildren(...[["matching", "certificateAssignMatching"], ["assigned", "certificateAssignAssigned"], ["all", "certificateFilterAll"]].map(([key, labelKey]) => {
|
||||
const button = el("button", `${t(labelKey)} · ${counts[key]}`); button.type = "button"; button.dataset.uiIconName = "none";
|
||||
button.setAttribute("aria-pressed", String(state.filter === key));
|
||||
button.addEventListener("click", () => { state.filter = key; renderCertificateAssign(); });
|
||||
return button;
|
||||
}));
|
||||
const query = state.query.toLowerCase(), list = $("certificate-assign-list");
|
||||
const head = el("div", undefined, "certificate-assign-row certificate-assign-head");
|
||||
for (const key of ["", "certificateAssignColVhost", "certificateAssignColHosts", "certificateAssignColCoverage", "certificateAssignColNow"]) head.append(el("span", key ? t(key) : ""));
|
||||
const visible = state.rows.filter(row => (state.filter === "all" || (state.filter === "matching" && row.cover.state === "full") || (state.filter === "assigned" && row.checked))
|
||||
&& (!query || `${row.host.id} ${row.hosts.join(" ")}`.toLowerCase().includes(query)));
|
||||
const items = visible.map(row => {
|
||||
const line = el("label", undefined, "certificate-assign-row");
|
||||
const check = document.createElement("input"); check.type = "checkbox"; check.checked = row.checked; check.disabled = !row.selectable && !row.checked;
|
||||
check.addEventListener("change", () => { row.checked = check.checked; renderCertificateAssign(); });
|
||||
const coverText = row.cover.state === "full" ? t("certificateCoveredAll") : row.cover.state === "unknown" ? t("certificateCoverageUnknownShort") : row.cover.state === "none" ? t("certificateCoverageNone") : `${t("certificateCoveragePartial").replace("{covered}", row.hosts.length - row.cover.missing.length).replace("{total}", row.hosts.length)}`;
|
||||
const coverExtra = row.cover.state !== "full" && row.cover.state !== "unknown" ? (row.host.allow_certificate_mismatch ? ` · ${t("certificateMismatchAccepted")}` : ` · ${t("certificateMismatchRequired")}`) : "";
|
||||
const now = el("span", undefined, "certificate-assign-now");
|
||||
if (row.checked !== row.initial) now.append(el("span", t(row.checked ? "certificateAssignAdd" : "certificateAssignRemove"), `pill ${row.checked ? "warn" : "status-error"}`), " ");
|
||||
now.append(el("span", row.host.certificate_id ? (row.host.certificate_id === state.cert.id ? t("certificateAssignThis") : row.host.certificate_id) : t("certificateAssignDefault"), "fine"));
|
||||
line.classList.toggle("is-changed", row.checked !== row.initial);
|
||||
line.classList.toggle("is-disabled", check.disabled);
|
||||
line.append(check, el("b", row.host.id, "mono"), el("span", row.hosts.join(", ") || "-", "fine"), el("span", coverText + coverExtra, `pill${row.cover.state === "full" ? " live" : row.cover.state === "unknown" ? "" : " warn"}`), now);
|
||||
return line;
|
||||
});
|
||||
list.replaceChildren(head, ...(items.length ? items : [el("p", t("certificateFilterEmpty"), "empty")]));
|
||||
const added = state.rows.filter(row => row.checked && !row.initial).length, removed = state.rows.filter(row => !row.checked && row.initial).length;
|
||||
const changes = $("certificate-assign-changes"); changes.replaceChildren();
|
||||
if (added || removed) {
|
||||
changes.append(el("b", `${t("certificateAssignChanges")}: `));
|
||||
if (added) changes.append(el("span", `+${added} ${t("certificateAssignAdded")}`, "pill live"), " ");
|
||||
if (removed) changes.append(el("span", `−${removed} ${t("certificateAssignRemoved")}`, "pill status-error"));
|
||||
} else changes.append(el("span", t("certificateAssignNoChanges"), "fine"));
|
||||
$("certificate-assign-apply").disabled = !(added || removed);
|
||||
}
|
||||
$("certificate-assign-search")?.addEventListener("input", event => { if (certificateAssignState) { certificateAssignState.query = event.target.value; renderCertificateAssign(); } });
|
||||
$("certificate-assign-all")?.addEventListener("click", () => { if (!certificateAssignState) return; for (const row of certificateAssignState.rows) if (row.cover.state === "full") row.checked = true; renderCertificateAssign(); });
|
||||
$("certificate-assign-none")?.addEventListener("click", () => { if (!certificateAssignState) return; for (const row of certificateAssignState.rows) row.checked = false; renderCertificateAssign(); });
|
||||
for (const id of ["certificate-assign-close", "certificate-assign-cancel"]) $(id)?.addEventListener("click", () => { $("certificate-assign-dialog").close(); });
|
||||
$("certificate-assign-dialog")?.addEventListener("close", () => { certificateAssignState = null; });
|
||||
$("certificate-assign-apply")?.addEventListener("click", async () => {
|
||||
const state = certificateAssignState; if (!state || busy || !envelope) return;
|
||||
const selected = new Set(state.rows.filter(row => row.checked).map(row => row.host.id));
|
||||
const next = structuredClone(envelope.config);
|
||||
for (const host of next.vhosts) {
|
||||
if (selected.has(host.id)) host.certificate_id = state.cert.id;
|
||||
else if (host.certificate_id === state.cert.id) host.certificate_id = null;
|
||||
}
|
||||
if (await saveSection("vhosts", next.vhosts)) $("certificate-assign-dialog").close();
|
||||
});
|
||||
$("certificate-search")?.addEventListener("input", applyCertificateFilter);
|
||||
for (const button of document.querySelectorAll("[data-certificate-filter]")) button.addEventListener("click", () => setCertificateFilter(button.dataset.certificateFilter));
|
||||
$("certificate-form").addEventListener("submit", async event => {
|
||||
event.preventDefault(); const form = event.currentTarget;
|
||||
if (!envelope || busy) return;
|
||||
|
||||
Reference in new issue
Block a user