- refactor(api): use audit operation constants and the shared zone not found error in zone handlers - fix(api): return the stored content of rows with check errors - fix(api): return warnings from record deletes, zone creation and import apply - fix(api): allow repairing rows stored with a non canonical zone and invalid SOA sets - fix(check): accept JSON column formatting and an absent SOA serial as canonical content - fix(ui): match audit diff items by identity instead of array index - fix(ui): count the SOA change once, report import warnings and check the request size - fix(ui): edit the selected SOA row, keep the server order, show error rows raw and report write warnings - test(check): cover triggering and clean pairs with exact codes and record ids - test(records): cover SRV port, SOA timer and CAA value boundaries - test(cli): check the exact check output and the exit code of warning-only zones - refactor(import): order current rows with cmp.Compare - test(check): cover malformed stored content and a mailbox stored as an address - test(api): cover zone write failure paths, ambiguous SOA updates and unchanged record detection
132 lines
4.3 KiB
JavaScript
132 lines
4.3 KiB
JavaScript
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
|
|
|
import { $, api, appData, busy, clear, clearErrors, handleError, h, openDialog, parseNumber, plural, setupDialogs, showFlash, toast, zoneLink } from "./common.js";
|
|
|
|
const { isAdmin } = appData();
|
|
const state = { zones: [], counts: null, countsFailed: false, search: "" };
|
|
|
|
function problemCell(zone) {
|
|
const cell = h("td");
|
|
if (state.countsFailed) {
|
|
cell.textContent = "unavailable";
|
|
return cell;
|
|
}
|
|
if (state.counts === null) {
|
|
cell.textContent = "loading...";
|
|
return cell;
|
|
}
|
|
const counts = state.counts.get(zone.name) || { error: 0, warning: 0 };
|
|
if (counts.error === 0 && counts.warning === 0) {
|
|
cell.append(h("span", { class: "badge badge-ok", text: "none" }));
|
|
return cell;
|
|
}
|
|
if (counts.error > 0) cell.append(h("span", { class: "badge badge-error", text: plural(counts.error, "error", "errors") }), " ");
|
|
if (counts.warning > 0) cell.append(h("span", { class: "badge badge-warning", text: plural(counts.warning, "warning", "warnings") }));
|
|
return cell;
|
|
}
|
|
|
|
function render() {
|
|
const body = $("#zones-body");
|
|
const needle = state.search.trim().toLowerCase();
|
|
const zones = state.zones.filter((zone) => zone.name.toLowerCase().includes(needle));
|
|
clear(body);
|
|
for (const zone of zones) {
|
|
const serial = zone.serial === null || zone.serial === undefined ? "dynamic" : String(zone.serial);
|
|
body.append(h("tr", null,
|
|
h("th", { scope: "row" }, zoneLink(zone.name)),
|
|
h("td", { class: "num", text: zone.records }),
|
|
h("td", { class: "mono", text: serial }),
|
|
problemCell(zone)));
|
|
}
|
|
const status = $("#zones-status");
|
|
if (state.zones.length === 0) {
|
|
status.textContent = isAdmin ? "There are no zones yet." : "No zone is delegated to you.";
|
|
} else if (zones.length === 0) {
|
|
status.textContent = "No zone matches the search.";
|
|
} else {
|
|
status.textContent = plural(zones.length, "zone", "zones") + ".";
|
|
}
|
|
}
|
|
|
|
async function loadCounts() {
|
|
try {
|
|
const { data } = await api("GET", "/check");
|
|
const counts = new Map();
|
|
for (const problem of data.problems || []) {
|
|
const entry = counts.get(problem.zone) || { error: 0, warning: 0 };
|
|
if (problem.severity === "error") entry.error += 1;
|
|
else entry.warning += 1;
|
|
counts.set(problem.zone, entry);
|
|
}
|
|
state.counts = counts;
|
|
} catch (err) {
|
|
state.countsFailed = true;
|
|
}
|
|
render();
|
|
}
|
|
|
|
async function load() {
|
|
try {
|
|
const { data } = await api("GET", "/zones");
|
|
state.zones = data.zones || [];
|
|
} catch (err) {
|
|
$("#zones-status").textContent = "The zones could not be loaded.";
|
|
handleError(err);
|
|
return;
|
|
}
|
|
state.counts = null;
|
|
state.countsFailed = false;
|
|
render();
|
|
loadCounts();
|
|
}
|
|
|
|
function zoneBody(form) {
|
|
const el = form.elements;
|
|
return {
|
|
name: el.name.value.trim(),
|
|
ns: el.ns.value.trim(),
|
|
mbox: el.mbox.value.trim(),
|
|
extra_ns: el.extra_ns.value.split("\n").map((line) => line.trim()).filter(Boolean),
|
|
refresh: parseNumber(el.refresh.value),
|
|
retry: parseNumber(el.retry.value),
|
|
expire: parseNumber(el.expire.value),
|
|
minttl: parseNumber(el.minttl.value),
|
|
ttl: parseNumber(el.ttl.value),
|
|
};
|
|
}
|
|
|
|
function setupCreate() {
|
|
const dialog = $("#zone-dialog");
|
|
const form = $("#zone-form");
|
|
$("#new-zone").addEventListener("click", () => openDialog(dialog));
|
|
form.addEventListener("submit", async (event) => {
|
|
event.preventDefault();
|
|
clearErrors(form);
|
|
await busy(form.querySelector("button[type=submit]"), async () => {
|
|
let created;
|
|
try {
|
|
created = await api("POST", "/zones", { body: zoneBody(form) });
|
|
} catch (err) {
|
|
handleError(err, { form });
|
|
return;
|
|
}
|
|
dialog.close();
|
|
form.reset();
|
|
toast("Zone created. The DNS server serves a new zone after its next zone list reload, which happens every 10 minutes by default.");
|
|
const warnings = created.data && Array.isArray(created.data.warnings) ? created.data.warnings : [];
|
|
for (const warning of warnings) toast("Warning: " + warning.message, { kind: "warning" });
|
|
await load();
|
|
});
|
|
});
|
|
}
|
|
|
|
setupDialogs();
|
|
showFlash();
|
|
$("#zone-search").addEventListener("input", (event) => {
|
|
state.search = event.target.value;
|
|
render();
|
|
});
|
|
if (isAdmin) setupCreate();
|
|
load();
|