Sortable record columns, filters and sort kept in the URL on the zones, zone and audit pages, a Show action that filters the records table to a problem's owner, Save and add another, a highlight of the saved row, an Audit history link on the zone page, and dialogs that keep typed input on a backdrop click.
102 lines
4.0 KiB
JavaScript
102 lines
4.0 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", "TLSA"];
|
|
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" },
|
|
],
|
|
TLSA: [
|
|
{ key: "usage", label: "Certificate usage", options: [["0", "0 (PKIX-TA)"], ["1", "1 (PKIX-EE)"], ["2", "2 (DANE-TA)"], ["3", "3 (DANE-EE)"]] },
|
|
{ key: "selector", label: "Selector", options: [["0", "0 (full certificate)"], ["1", "1 (SubjectPublicKeyInfo)"]] },
|
|
{ key: "matching_type", label: "Matching type", options: [["0", "0 (exact match)"], ["1", "1 (SHA-256)"], ["2", "2 (SHA-512)"]] },
|
|
{ key: "certificate", label: "Certificate association data (hex)", multiline: true, hex: true, placeholder: "0123456789abcdef..." },
|
|
],
|
|
};
|
|
|
|
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 "TLSA":
|
|
return data.usage + " " + data.selector + " " + data.matching_type + " " + data.certificate;
|
|
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;
|
|
const needle = text.trim().toLowerCase();
|
|
if (!needle) return true;
|
|
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: "" };
|
|
}
|