This commit is contained in:
Mateusz Gruszczyński committed 2026-10-07 13:40:21 +02:00
1 parent 3a2eb4fe79
commit e0194fbaff
63 files changed
+1553 -379

No files matched your search

+25 -8
View File
@@ -1,6 +1,6 @@
"use strict";
(() => {
let job = null, pending = false, loading = false, renewalLogs = {}, resetIssueFormJob = null;
let job = null, pending = false, loading = false, renewalLogs = {}, resetIssueFormJob = null, runtimeAvailable = true;
const picker = $("certificate-provider");
const secrets = ["acme-secret", "acme-cf-token", "acme-ovh-application-key", "acme-ovh-application-secret", "acme-ovh-consumer-key"];
const tabs = [...document.querySelectorAll("[data-certificate-tab]")];
@@ -44,6 +44,9 @@
clearSecrets();
syncProvider();
}
function syncSubmitState() {
$("acme-submit").disabled = pending || job?.status === "running" || !runtimeAvailable;
}
function syncProvider() {
const provider = picker.value, acme = !["import", "existing"].includes(provider);
$("certificate-acme-editor").hidden = !acme;
@@ -56,6 +59,7 @@
for (const input of node.querySelectorAll("input,select")) input.disabled = !visible;
}
$("acme-domains").placeholder = provider === "http01" ? "example.org, www.example.org" : "example.org, *.example.org";
syncSubmitState();
}
function open(provider = "http01") {
selectTab("generate"); picker.value = provider;
@@ -67,6 +71,19 @@
$("certificate-new").addEventListener("click", () => open());
const stateKey = value => ({ running: "certificateStateRunning", ready: "certificateStateReady", complete: "certificateStateComplete", failed: "certificateStateFailed" }[value?.status] || "certificateStateIdle");
function renderRuntime(value) {
const status = value?.status || "checking", mode = value?.mode || "none";
runtimeAvailable = status !== "unavailable";
$("acme-runtime-card").dataset.state = status;
$("acme-runtime-message").textContent = t(value?.message || "acme.runtime_checking");
$("acme-runtime-state").textContent = t(status === "unavailable" ? "certificateRuntimeUnavailable" : status === "ready" && mode === "managed" ? "certificateRuntimeManaged" : status === "ready" && mode === "system" ? "certificateRuntimeSystem" : "certificateRuntimePreparing");
const path = value?.managed_directory;
$("acme-runtime-path").hidden = !path;
$("acme-runtime-path").textContent = path ? `${t("certificateRuntimePath")}: ${path}` : "";
const availability = flag => t(flag === true ? "runtimeAvailable" : flag === false ? "runtimeUnavailable" : "certificateRuntimePreparing");
$("acme-runtime-components").textContent = `${t("runtimePython")}: ${availability(value?.python)} · ${t("runtimePip")}: ${availability(value?.pip)} · ${t("runtimeCertbot")}: ${availability(value?.certbot)}`;
syncSubmitState();
}
function renderOperation(cardId, messageId, stateId, logId, value, idleKey) {
const card = $(cardId), message = $(messageId), state = $(stateId), log = $(logId);
card.dataset.state = value?.status || "idle";
@@ -83,7 +100,7 @@
if (value.status === "ready") { resetIssueForm(); resetIssueFormJob = null; }
else if (value.status === "failed") resetIssueFormJob = null;
}
$("acme-submit").disabled = pending || value?.status === "running";
syncSubmitState();
const issue = value?.kind === "issue" ? value : null;
const renewal = value?.kind?.startsWith("renewal") ? value : null;
renderOperation("acme-issue-status-card", "acme-job", "acme-issue-state", "acme-log-path", issue, "acmeIdle");
@@ -131,7 +148,7 @@
if (epoch === authEpoch) toast(error.message, true);
} finally { node.disabled = false; }
});
node.disabled = job?.status === "running";
node.disabled = job?.status === "running" || !runtimeAvailable;
}
entry.append(controls); list.append(entry);
}
@@ -142,14 +159,14 @@
if (!authenticated || currentPanel !== "tls" || loading) return; loading = true; const epoch = authEpoch;
try {
const data = await api("/api/acme");
if (authenticated && epoch === authEpoch) { render(data.job); renderRenewals(data.renewals, data.log_directories); }
if (authenticated && epoch === authEpoch) { renderRuntime(data.runtime); render(data.job); renderRenewals(data.renewals, data.log_directories); }
} catch (error) {
if (epoch === authEpoch) { toast(error.message, true); if (error.status === 401) lock(); }
} finally { loading = false; }
}
$("acme-environment").addEventListener("change", () => { $("acme-confirm-production").required = $("acme-environment").value === "production"; });
$("acme-form").addEventListener("submit", async event => {
event.preventDefault(); if (!authenticated || pending || job?.status === "running") return;
event.preventDefault(); if (!authenticated || pending || job?.status === "running" || !runtimeAvailable) return;
const provider = picker.value, input = {
provider, certificate_id: $("acme-name").value.trim(), email: $("acme-email").value.trim(), domains: $("acme-domains").value.split(/[,\n]/).map(v => v.trim()).filter(Boolean), environment: $("acme-environment").value,
agree_tos: $("acme-tos").checked, confirm_production: $("acme-confirm-production").checked
@@ -168,7 +185,7 @@
} catch (error) { if (epoch === authEpoch) toast(error.message, true); }
finally {
for (const key of ["key_secret", "api_token", "application_key", "application_secret", "consumer_key"]) delete input[key];
clearSecrets(); pending = false; $("acme-submit").disabled = job?.status === "running";
clearSecrets(); pending = false; syncSubmitState();
}
});
$("acme-refresh").addEventListener("click", () => void refresh());
@@ -187,8 +204,8 @@
syncLocation,
current: () => activeTab,
reset() {
job = null; renewalLogs = {}; resetIssueFormJob = null; $("renewal-list").replaceChildren(); resetIssueForm();
render(null); selectTab("installed", false, false);
job = null; renewalLogs = {}; resetIssueFormJob = null; runtimeAvailable = true; $("renewal-list").replaceChildren(); resetIssueForm();
renderRuntime(null); render(null); selectTab("installed", false, false);
}
};
window.rustProxyCertificates = { open, close, select: selectTab, reset() { clearSecrets(); picker.value = "http01"; syncProvider(); selectTab("installed", false, false); } };