About 1,600 more headings, buttons, table columns, status words, placeholders and short messages are translated. Tables of words built when the app loads are now read when they are drawn, so they follow the language, and a test fails if text is translated at load time. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
120 lines
6.3 KiB
TypeScript
120 lines
6.3 KiB
TypeScript
import { useState, type FormEvent } from "react";
|
|
import { api, type NewDnsZoneInput } from "../api/client";
|
|
import { ErrorNotice } from "./Notice";
|
|
import { readableError } from "../utils/errors";
|
|
import { t } from "../i18n";
|
|
|
|
type Kind = NewDnsZoneInput["type"];
|
|
type Protocol = "Udp" | "Tcp" | "Tls" | "Https" | "Quic";
|
|
|
|
const KINDS: { value: Kind; label: string; hint: string }[] = [
|
|
{ value: "Primary", get label() { return t("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", get label() { return t("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", get label() { return t("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">
|
|
{t("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">
|
|
{t("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">
|
|
{t("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">{t("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">
|
|
{t("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">
|
|
{t("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">{t("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…" : t("Make zone")}
|
|
</button>
|
|
<button type="button" className="btn btn-sm btn-link text-secondary" onClick={onCancel} disabled={busy}>
|
|
{t("Cancel")}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
);
|
|
}
|