Make Technitium zones from the DNS page

A New zone form on a Technitium DNS provider makes a Primary zone (a domain
name, or an address or network for a reverse zone), a Secondary zone (from the
servers that hold it) or a Forwarder zone (where to pass questions, the
protocol, DNSSEC). Names are written lower case, ASCII, without the trailing
dot and refused before Technitium is asked if they are not zone names;
Technitium's own refusal (a zone that exists) is shown as it was said.
Administrators only, audited, and only for providers that can (the adapter
gets an optional createZone). The new zone opens when it is made.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-01 22:19:16 +01:00
1 parent f73704e6ca
commit 0244f5a8ab
12 files changed
+533 -10

No files matched your search

+9
View File
@@ -675,8 +675,16 @@ export interface DnsProviderSummary {
name: string;
enabled: boolean;
createdAt: string;
/** Whether zones can be made on it from here (Technitium). */
canCreateZones: boolean;
}
/** A zone to be made: a Primary one, a Secondary one from the servers that hold it, or a Forwarder one that passes questions on. */
export type NewDnsZoneInput =
| { type: "Primary"; name: string }
| { type: "Secondary"; name: string; primaryNameServers: string[] }
| { type: "Forwarder"; name: string; forwarder: string; protocol: "Udp" | "Tcp" | "Tls" | "Https" | "Quic"; dnssecValidation: boolean };
export interface DnsZone {
id: string;
name: string;
@@ -3917,6 +3925,7 @@ export const api = {
},
zones: {
list: (providerId: number) => request<{ zones: DnsZone[] }>(`/api/dns/providers/${providerId}/zones`),
create: (providerId: number, body: NewDnsZoneInput) => request<{ zone: { id: string; name: string } }>(`/api/dns/providers/${providerId}/zones`, { method: "POST", body: JSON.stringify(body) }),
},
records: {
list: (providerId: number, zoneId: string) =>
+118
View File
@@ -0,0 +1,118 @@
import { useState, type FormEvent } from "react";
import { api, type NewDnsZoneInput } from "../api/client";
import { ErrorNotice } from "./Notice";
import { readableError } from "../utils/errors";
type Kind = NewDnsZoneInput["type"];
type Protocol = "Udp" | "Tcp" | "Tls" | "Https" | "Quic";
const KINDS: { value: Kind; label: string; hint: string }[] = [
{ value: "Primary", label: "Primary zone", hint: "This server holds the zone: its records are made and changed here. It starts with the records Technitium makes for it; the rest are added under Records." },
{ value: "Secondary", label: "Secondary zone", hint: "A copy of a zone another server holds. This server fetches it from there and keeps it up to date; it can only be read here." },
{ value: "Forwarder", label: "Forwarder zone", hint: "Questions about this name (and under it) are passed on to another DNS server — for a domain another server answers, such as a company network." },
];
/** The servers a person typed, one to a line or separated by commas or spaces. */
const serversOf = (text: string) => text.split(/[\s,]+/).map((s) => s.trim()).filter(Boolean);
/**
* Making a zone on a DNS provider that can: Technitium. A name (a domain such as home.lan, or an address or network such as 192.168.1.0/24 for a reverse zone) and what kind. What the provider says
* when it won't — a zone that is there already — is shown as it was said. An administrator's alone, as it makes the server an authority for the name.
*/
export default function DnsNewZone({ providerId, providerName, onCreated, onCancel }: { providerId: number; providerName: string; onCreated: (zone: { id: string; name: string }) => void; onCancel: () => void }) {
const [kind, setKind] = useState<Kind>("Primary");
const [name, setName] = useState("");
const [primaries, setPrimaries] = useState("");
const [forwarder, setForwarder] = useState("");
const [protocol, setProtocol] = useState<Protocol>("Udp");
const [dnssec, setDnssec] = useState(false);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
async function submit(e: FormEvent) {
e.preventDefault();
if (busy) return;
setBusy(true);
setError(null);
try {
const body: NewDnsZoneInput = kind === "Primary" ? { type: "Primary", name } : kind === "Secondary" ? { type: "Secondary", name, primaryNameServers: serversOf(primaries) } : { type: "Forwarder", name, forwarder: forwarder.trim(), protocol, dnssecValidation: dnssec };
const { zone } = await api.dns.zones.create(providerId, body);
onCreated(zone);
} catch (err) {
setError(readableError(err));
setBusy(false);
}
}
return (
<form onSubmit={submit}>
<h4 className="mb-2">New zone on {providerName}</h4>
<ErrorNotice error={error} />
<div className="mb-2">
<label className="form-label" htmlFor="newzone-kind">
Kind
</label>
<select id="newzone-kind" className="form-select form-select-sm" value={kind} onChange={(e) => setKind(e.target.value as Kind)}>
{KINDS.map((k) => (
<option key={k.value} value={k.value}>
{k.label}
</option>
))}
</select>
<div className="text-secondary small mt-1">{KINDS.find((k) => k.value === kind)!.hint}</div>
</div>
<div className="mb-2">
<label className="form-label" htmlFor="newzone-name">
Name
</label>
<input id="newzone-name" className="form-control form-control-sm" required autoFocus maxLength={300} autoComplete="off" placeholder="home.lan — or 192.168.1.0/24 for a reverse zone" value={name} onChange={(e) => setName(e.target.value)} />
<div className="text-secondary small mt-1">Written in lower case, ASCII (a name with other letters in its xn-- form), with no dot at the end.</div>
</div>
{kind === "Secondary" && (
<div className="mb-2">
<label className="form-label" htmlFor="newzone-primaries">
Servers that hold it
</label>
<input id="newzone-primaries" className="form-control form-control-sm" required maxLength={600} autoComplete="off" placeholder="10.0.0.2, ns1.example.lan" value={primaries} onChange={(e) => setPrimaries(e.target.value)} />
<div className="text-secondary small mt-1">Addresses or host names, separated by commas.</div>
</div>
)}
{kind === "Forwarder" && (
<div className="row g-2 mb-2">
<div className="col-md-6">
<label className="form-label" htmlFor="newzone-forwarder">
Pass questions to
</label>
<input id="newzone-forwarder" className="form-control form-control-sm" required maxLength={255} autoComplete="off" placeholder="10.1.1.1 — or this-server" value={forwarder} onChange={(e) => setForwarder(e.target.value)} />
</div>
<div className="col-md-3">
<label className="form-label" htmlFor="newzone-protocol">
Protocol
</label>
<select id="newzone-protocol" className="form-select form-select-sm" value={protocol} onChange={(e) => setProtocol(e.target.value as Protocol)}>
{(["Udp", "Tcp", "Tls", "Https", "Quic"] as Protocol[]).map((p) => (
<option key={p} value={p}>
{p === "Udp" ? "UDP" : p === "Tcp" ? "TCP" : p === "Tls" ? "TLS" : p === "Https" ? "HTTPS" : "QUIC"}
</option>
))}
</select>
</div>
<div className="col-md-3 d-flex align-items-end">
<label className="form-check mb-1">
<input type="checkbox" className="form-check-input" checked={dnssec} onChange={(e) => setDnssec(e.target.checked)} />
<span className="form-check-label">Check DNSSEC</span>
</label>
</div>
</div>
)}
<div className="d-flex gap-2 mt-3">
<button type="submit" className="btn btn-sm btn-primary" disabled={busy || name.trim() === ""}>
{busy ? "Making…" : "Make zone"}
</button>
<button type="button" className="btn btn-sm btn-link text-secondary" onClick={onCancel} disabled={busy}>
Cancel
</button>
</div>
</form>
);
}
+25 -2
View File
@@ -13,6 +13,7 @@ import {
type DnsZone,
} from "../api/client";
import DnsProviderForm from "../components/DnsProviderForm";
import DnsNewZone from "../components/DnsNewZone";
import { formatDateTime } from "../utils/date";
import { useSortable } from "../hooks/useSortable";
import SortableTh from "../components/SortableTh";
@@ -86,6 +87,7 @@ function DnsRecords({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
const [zones, setZones] = useState<DnsZone[] | null>(null);
const [zonesError, setZonesError] = useState<string | null>(null);
const [selectedZone, setSelectedZone] = useState<DnsZone | null>(null);
const [creatingZone, setCreatingZone] = useState(false);
const [records, setRecords] = useState<DnsRecord[] | null>(null);
const [syncedAt, setSyncedAt] = useState<string | null>(null);
@@ -111,7 +113,8 @@ function DnsRecords({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
useEffect(loadProviders, []);
function loadZones(providerId: number) {
/** `selectId`: a zone to open once the list is read (the one just made). */
function loadZones(providerId: number, selectId?: string) {
setZonesError(null);
setZones(null);
setSelectedZone(null);
@@ -121,7 +124,7 @@ function DnsRecords({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
.then((res) => {
setZones(res.zones);
// Deep-link from global search (?providerId=&zoneId=) — auto-open the linked zone once its records load.
const linkedZoneId = searchParams.get("zoneId");
const linkedZoneId = selectId ?? searchParams.get("zoneId");
const linkedZone = linkedZoneId ? res.zones.find((z) => z.id === linkedZoneId) : undefined;
if (linkedZone) selectZone(linkedZone);
})
@@ -129,6 +132,7 @@ function DnsRecords({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
}
useEffect(() => {
setCreatingZone(false);
if (selectedProviderId && !managingProviders) loadZones(selectedProviderId);
}, [selectedProviderId, managingProviders]);
@@ -427,6 +431,11 @@ function DnsRecords({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
<div className="card-header">
<h3 className="card-title">Zones</h3>
<div className="card-actions">
{isAdmin && selectedProvider?.canCreateZones && selectedProvider.enabled && (
<button className="btn btn-sm btn-primary me-2" onClick={() => setCreatingZone((v) => !v)} aria-expanded={creatingZone}>
New zone
</button>
)}
<button
className="btn btn-sm btn-outline-secondary"
onClick={exportZonesCsv}
@@ -436,6 +445,20 @@ function DnsRecords({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
</button>
</div>
</div>
{creatingZone && selectedProvider && selectedProviderId && (
<div className="card-body border-bottom">
<DnsNewZone
providerId={selectedProviderId}
providerName={selectedProvider.name}
onCancel={() => setCreatingZone(false)}
onCreated={(zone) => {
setCreatingZone(false);
toast.success(`Made the zone ${zone.name}.`);
loadZones(selectedProviderId, zone.id);
}}
/>
</div>
)}
<ErrorNotice error={zonesError} className="m-3 mb-0" />
<div className="table-responsive">
<table className="table table-vcenter card-table">