- 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
94 lines
3.4 KiB
JavaScript
94 lines
3.4 KiB
JavaScript
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
|
|
|
export const EDITABLE_TYPES = ["A", "AAAA", "CNAME", "NS", "MX", "TXT", "SRV", "CAA"];
|
|
export const KNOWN_TYPES = [...EDITABLE_TYPES, "SOA"];
|
|
|
|
export const FIELD_SPECS = {
|
|
A: [
|
|
{ key: "ip", label: "IPv4 address", placeholder: "192.0.2.10" },
|
|
],
|
|
AAAA: [
|
|
{ key: "ip", label: "IPv6 address", placeholder: "2001:db8::10" },
|
|
],
|
|
CNAME: [
|
|
{ key: "host", label: "Target host", placeholder: "target.example.org" },
|
|
],
|
|
NS: [
|
|
{ key: "host", label: "Name server host", placeholder: "ns1.example.org" },
|
|
],
|
|
MX: [
|
|
{ key: "preference", label: "Preference", placeholder: "10", numeric: true },
|
|
{ key: "host", label: "Mail host", placeholder: "mail.example.org" },
|
|
],
|
|
TXT: [
|
|
{ key: "text", label: "Text", multiline: true, placeholder: "v=spf1 -all" },
|
|
],
|
|
SRV: [
|
|
{ key: "priority", label: "Priority", placeholder: "10", numeric: true },
|
|
{ key: "weight", label: "Weight", placeholder: "5", numeric: true },
|
|
{ key: "port", label: "Port", placeholder: "443", numeric: true },
|
|
{ key: "target", label: "Target host", placeholder: "host.example.org" },
|
|
],
|
|
CAA: [
|
|
{ key: "flag", label: "Flag", options: [["0", "0 (not critical)"], ["128", "128 (critical)"]] },
|
|
{ key: "tag", label: "Tag", placeholder: "issue" },
|
|
{ key: "value", label: "Value", placeholder: "ca.example.net" },
|
|
],
|
|
};
|
|
|
|
export function presentValue(record) {
|
|
const data = record.data;
|
|
if (!data || typeof data !== "object") return record.raw === null || record.raw === undefined ? "" : String(record.raw);
|
|
switch (record.type) {
|
|
case "A":
|
|
case "AAAA":
|
|
return String(data.ip);
|
|
case "CNAME":
|
|
case "NS":
|
|
return String(data.host);
|
|
case "MX":
|
|
return data.preference + " " + data.host;
|
|
case "TXT":
|
|
return '"' + data.text + '"';
|
|
case "SRV":
|
|
return data.priority + " " + data.weight + " " + data.port + " " + data.target;
|
|
case "CAA":
|
|
return data.flag + " " + data.tag + ' "' + data.value + '"';
|
|
case "SOA":
|
|
return [data.ns, data.MBox !== undefined ? data.MBox : data.mbox, data.serial == null || data.serial === 0 ? "dynamic (Unix time)" : data.serial, data.refresh, data.retry, data.expire, data.minttl].join(" ");
|
|
default:
|
|
return JSON.stringify(data);
|
|
}
|
|
}
|
|
|
|
export function displayName(record) {
|
|
return record.name === "" ? "@" : record.name;
|
|
}
|
|
|
|
export function matchesFilter(record, type, text) {
|
|
if (type && record.type !== type) return false;
|
|
if (!text) return true;
|
|
const needle = text.toLowerCase();
|
|
const haystack = [displayName(record), record.fqdn || "", record.type, presentValue(record)].join(" ").toLowerCase();
|
|
return haystack.includes(needle);
|
|
}
|
|
|
|
export function stripDot(name) {
|
|
return name.endsWith(".") ? name.slice(0, -1) : name;
|
|
}
|
|
|
|
export function previewName(input, zone) {
|
|
const apex = zone.endsWith(".") ? zone : zone + ".";
|
|
let text = input.trim().toLowerCase();
|
|
if (text === "" || text === "@") return { name: "", fqdn: apex, error: "" };
|
|
if (text.endsWith("." + apex)) {
|
|
text = text.slice(0, -(apex.length + 1));
|
|
} else if (text === apex) {
|
|
return { name: "", fqdn: apex, error: "" };
|
|
} else if (text.endsWith(".")) {
|
|
return { name: "", fqdn: "", error: "The name ends with a dot and is outside " + apex };
|
|
}
|
|
return { name: text, fqdn: text + "." + apex, error: "" };
|
|
}
|