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:
1 parent
f73704e6ca
commit
0244f5a8ab
12 files changed
+533
-10
No files matched your search
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user