initial commit
build-and-push / build (aarch64, linux/arm64) (push) Has been cancelled
build-and-push / build (amd64, linux/amd64) (push) Has been cancelled
build-and-push / build (armhf, linux/arm/v6) (push) Has been cancelled
build-and-push / build (armv7, linux/arm/v7) (push) Has been cancelled
build-and-push / build (i386, linux/386) (push) Has been cancelled
build-and-push / build (aarch64, linux/arm64) (push) Has been cancelled
build-and-push / build (amd64, linux/amd64) (push) Has been cancelled
build-and-push / build (armhf, linux/arm/v6) (push) Has been cancelled
build-and-push / build (armv7, linux/arm/v7) (push) Has been cancelled
build-and-push / build (i386, linux/386) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
async function refreshPending() {
|
||||
const res = await fetch("api/pending");
|
||||
const data = await res.json();
|
||||
const tbody = document.querySelector("#pending-table tbody");
|
||||
const empty = document.getElementById("pending-empty");
|
||||
tbody.innerHTML = "";
|
||||
const ids = Object.keys(data);
|
||||
empty.style.display = ids.length ? "none" : "block";
|
||||
|
||||
for (const deviceId of ids) {
|
||||
const entry = data[deviceId];
|
||||
const row = document.createElement("tr");
|
||||
const requested = new Date(entry.requested_at * 1000).toLocaleString();
|
||||
const meta = Object.entries(entry.meta || {}).map(([k, v]) => `${k}: ${v}`).join(", ");
|
||||
row.innerHTML = `
|
||||
<td>${deviceId}</td>
|
||||
<td>${requested}</td>
|
||||
<td>${meta || "-"}</td>
|
||||
<td>
|
||||
<button class="approve" data-id="${deviceId}">Approve</button>
|
||||
<button class="reject" data-id="${deviceId}">Reject</button>
|
||||
</td>`;
|
||||
tbody.appendChild(row);
|
||||
}
|
||||
|
||||
tbody.querySelectorAll(".approve").forEach((btn) =>
|
||||
btn.addEventListener("click", () => approve(btn.dataset.id))
|
||||
);
|
||||
tbody.querySelectorAll(".reject").forEach((btn) =>
|
||||
btn.addEventListener("click", () => reject(btn.dataset.id))
|
||||
);
|
||||
}
|
||||
|
||||
async function refreshIssued() {
|
||||
const [issuedRes, revokedRes] = await Promise.all([fetch("api/issued"), fetch("api/revoked")]);
|
||||
const data = await issuedRes.json();
|
||||
const revoked = await revokedRes.json();
|
||||
const tbody = document.querySelector("#issued-table tbody");
|
||||
const empty = document.getElementById("issued-empty");
|
||||
tbody.innerHTML = "";
|
||||
const ids = Object.keys(data);
|
||||
empty.style.display = ids.length ? "none" : "block";
|
||||
|
||||
for (const deviceId of ids) {
|
||||
const entry = data[deviceId];
|
||||
const row = document.createElement("tr");
|
||||
const issued = new Date(entry.issued_at * 1000).toLocaleString();
|
||||
const expires = new Date(entry.not_after).toLocaleDateString();
|
||||
const isRevoked = Object.prototype.hasOwnProperty.call(revoked, deviceId);
|
||||
const action = isRevoked
|
||||
? `<span class="empty">revoked</span>`
|
||||
: `<button class="revoke" data-id="${deviceId}">Revoke</button>`;
|
||||
row.innerHTML = `<td>${deviceId}</td><td>${issued}</td><td>${expires}</td><td>${action}</td>`;
|
||||
tbody.appendChild(row);
|
||||
}
|
||||
|
||||
tbody.querySelectorAll(".revoke").forEach((btn) =>
|
||||
btn.addEventListener("click", () => revoke(btn.dataset.id))
|
||||
);
|
||||
}
|
||||
|
||||
async function refreshRevoked() {
|
||||
const res = await fetch("api/revoked");
|
||||
const data = await res.json();
|
||||
const tbody = document.querySelector("#revoked-table tbody");
|
||||
const empty = document.getElementById("revoked-empty");
|
||||
tbody.innerHTML = "";
|
||||
const ids = Object.keys(data);
|
||||
empty.style.display = ids.length ? "none" : "block";
|
||||
|
||||
for (const deviceId of ids) {
|
||||
const entry = data[deviceId];
|
||||
const row = document.createElement("tr");
|
||||
const revokedAt = new Date(entry.revoked_at * 1000).toLocaleString();
|
||||
row.innerHTML = `<td>${deviceId}</td><td>${revokedAt}</td><td>${entry.reason}</td>`;
|
||||
tbody.appendChild(row);
|
||||
}
|
||||
}
|
||||
|
||||
async function approve(deviceId) {
|
||||
const res = await fetch(`api/approve/${encodeURIComponent(deviceId)}`, { method: "POST" });
|
||||
if (!res.ok) {
|
||||
const err = await res.json();
|
||||
alert(`Could not issue certificate: ${err.error}`);
|
||||
}
|
||||
await refresh();
|
||||
}
|
||||
|
||||
async function reject(deviceId) {
|
||||
await fetch(`api/reject/${encodeURIComponent(deviceId)}`, { method: "POST" });
|
||||
await refresh();
|
||||
}
|
||||
|
||||
async function revoke(deviceId) {
|
||||
if (!confirm(`Revoke the certificate for "${deviceId}"? This can't be undone, and requires a Mosquitto restart to take effect.`)) return;
|
||||
const res = await fetch(`api/revoke/${encodeURIComponent(deviceId)}`, { method: "POST" });
|
||||
if (!res.ok) {
|
||||
const err = await res.json();
|
||||
alert(`Could not revoke: ${err.error}`);
|
||||
}
|
||||
await refresh();
|
||||
}
|
||||
|
||||
async function refreshBrokerCert() {
|
||||
const res = await fetch("api/broker-cert");
|
||||
const data = await res.json();
|
||||
const statusEl = document.getElementById("broker-cert-status");
|
||||
const configEl = document.getElementById("broker-cert-config");
|
||||
|
||||
if (!data.info) {
|
||||
statusEl.textContent = "Not yet issued.";
|
||||
} else {
|
||||
const expires = new Date(data.info.not_after).toLocaleDateString();
|
||||
statusEl.textContent = `Covers: ${data.info.hostnames.join(", ")} — expires ${expires}`;
|
||||
}
|
||||
|
||||
configEl.textContent =
|
||||
`certfile: ${data.cert_filename}\n` +
|
||||
`keyfile: ${data.key_filename}\n` +
|
||||
`require_certificate: true\n` +
|
||||
`cafile: ${data.ca_filename}`;
|
||||
}
|
||||
|
||||
document.getElementById("reissue-broker-cert").addEventListener("click", async () => {
|
||||
if (!confirm("Reissue the broker's TLS certificate? Mosquitto will need a restart to pick up the new files.")) return;
|
||||
const res = await fetch("api/broker-cert/reissue", { method: "POST" });
|
||||
if (!res.ok) {
|
||||
const err = await res.json();
|
||||
alert(`Could not reissue: ${err.error}`);
|
||||
}
|
||||
await refreshBrokerCert();
|
||||
});
|
||||
|
||||
async function refresh() {
|
||||
await refreshPending();
|
||||
await refreshIssued();
|
||||
await refreshRevoked();
|
||||
await refreshBrokerCert();
|
||||
}
|
||||
|
||||
refresh();
|
||||
setInterval(refresh, 5000);
|
||||
@@ -0,0 +1,19 @@
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 2rem auto;
|
||||
padding: 0 1rem;
|
||||
color: #212121;
|
||||
}
|
||||
h1 { font-size: 1.4rem; font-weight: 500; }
|
||||
h2 { font-size: 1.1rem; font-weight: 500; margin-top: 2rem; }
|
||||
table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; }
|
||||
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid #e0e0e0; font-size: 0.9rem; }
|
||||
th { color: #757575; font-weight: 500; }
|
||||
button { padding: 0.35rem 0.8rem; border-radius: 6px; border: none; cursor: pointer; font-size: 0.85rem; margin-right: 0.4rem; }
|
||||
.approve { background: #43a047; color: white; }
|
||||
.reject { background: #e53935; color: white; }
|
||||
.empty { color: #757575; font-size: 0.9rem; }
|
||||
.note { color: #757575; font-size: 0.85rem; margin-top: 0.25rem; }
|
||||
pre { background: #f5f5f5; padding: 0.75rem; border-radius: 6px; font-size: 0.85rem; overflow-x: auto; }
|
||||
code { background: #f5f5f5; padding: 0.1rem 0.3rem; border-radius: 4px; }
|
||||
Reference in New Issue
Block a user