An Edit zone panel on the open zone of a Technitium provider switches the zone off and on (its records stay) and edits who may ask it (query access), who may copy it (zone transfer, with the TSIG keys the server has) and who is told when it changes (notify). Only the groups that apply to the kind of zone are shown, a mode that goes by a list needs it, and entries must be addresses or networks; only groups that differ are sent, each whole, and the zone is read again afterwards so anything else that moved is named on the page and in the audit log. The server's own zones are not touched. Administrators only, audited. Zones in the list show when they are off and what kind they are. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
737 lines
32 KiB
TypeScript
737 lines
32 KiB
TypeScript
import { useEffect, useState, type CSSProperties, type ReactNode } from "react";
|
|
import ViewTabs from "../components/ViewTabs";
|
|
import DomainsView from "../views/DomainsView";
|
|
import TimeAgo from "../components/TimeAgo";
|
|
import { useSearchParams } from "react-router-dom";
|
|
import {
|
|
api,
|
|
type CurrentUser,
|
|
type DnsProviderSummary,
|
|
type DnsProviderType,
|
|
type DnsRecord,
|
|
type DnsRecordInput,
|
|
type DnsZone,
|
|
} from "../api/client";
|
|
import DnsProviderForm from "../components/DnsProviderForm";
|
|
import DnsNewZone from "../components/DnsNewZone";
|
|
import DnsZoneEditor from "../components/DnsZoneEditor";
|
|
import { formatDateTime } from "../utils/date";
|
|
import { useSortable } from "../hooks/useSortable";
|
|
import SortableTh from "../components/SortableTh";
|
|
import { usePagination } from "../hooks/usePagination";
|
|
import Pagination from "../components/Pagination";
|
|
import { downloadCsv } from "../utils/csv";
|
|
import { confirmDialog, promptDialog } from "../utils/dialogs";
|
|
import { ErrorNotice } from "../components/Notice";
|
|
import { toast } from "../utils/toast";
|
|
import { readableError } from "../utils/errors";
|
|
import { EmptyRow, LoadingRow } from "../components/EmptyState";
|
|
|
|
const PROVIDER_LABELS: Record<DnsProviderType, string> = {
|
|
cloudflare: "Cloudflare",
|
|
loopia: "Loopia",
|
|
pihole: "Pi-hole",
|
|
azure: "Azure DNS",
|
|
cpanel: "cPanel",
|
|
technitium: "Technitium",
|
|
};
|
|
|
|
const emptyRecordForm: DnsRecordInput = { type: "A", name: "", content: "", ttl: 3600, priority: undefined, proxied: undefined };
|
|
|
|
function providerBadgeStyle(colors: Record<string, string>, providerType: DnsProviderType): CSSProperties {
|
|
const color = colors[providerType];
|
|
if (!color) return {};
|
|
return { backgroundColor: `${color}22`, color, border: `1px solid ${color}55` };
|
|
}
|
|
|
|
const dnsTabs = (view: "records" | "domains") => (
|
|
<ViewTabs
|
|
label="DNS view"
|
|
tabs={[
|
|
{ to: "/dns", label: "Zones and records", active: view === "records" },
|
|
{ to: "/dns?view=domains", label: "Domain names", active: view === "domains" },
|
|
]}
|
|
/>
|
|
);
|
|
|
|
/** Zones and records from the DNS providers, and the registration expiry of the domain names (`?view=domains`). */
|
|
export default function Dns({ user }: { user: CurrentUser }) {
|
|
const [params] = useSearchParams();
|
|
if (params.get("view") === "domains") {
|
|
return (
|
|
<>
|
|
<div className="d-flex align-items-center mb-2">
|
|
<h2 className="page-title mb-0">DNS</h2>
|
|
</div>
|
|
{dnsTabs("domains")}
|
|
<DomainsView user={user} />
|
|
</>
|
|
);
|
|
}
|
|
return <DnsRecords user={user} tabs={dnsTabs("records")} />;
|
|
}
|
|
|
|
function DnsRecords({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
|
|
const isAdmin = user.role === "admin";
|
|
const canEdit = user.role === "admin" || user.role === "operator";
|
|
|
|
const [searchParams] = useSearchParams();
|
|
const [providers, setProviders] = useState<DnsProviderSummary[] | null>(null);
|
|
const [managingProviders, setManagingProviders] = useState(false);
|
|
const [selectedProviderId, setSelectedProviderId] = useState<number | null>(null);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [providerColors, setProviderColors] = useState<Record<string, string>>({});
|
|
|
|
useEffect(() => {
|
|
api.settings.providerColors().then((res) => setProviderColors(res.providerColors)).catch(() => {});
|
|
}, []);
|
|
|
|
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 [editingZone, setEditingZone] = useState(false);
|
|
|
|
const [records, setRecords] = useState<DnsRecord[] | null>(null);
|
|
const [syncedAt, setSyncedAt] = useState<string | null>(null);
|
|
const [syncing, setSyncing] = useState(false);
|
|
|
|
const [recordForm, setRecordForm] = useState<DnsRecordInput | null>(null);
|
|
const [editingRecordId, setEditingRecordId] = useState<string | null>(null);
|
|
const [savingRecord, setSavingRecord] = useState(false);
|
|
|
|
function loadProviders() {
|
|
api.dns.providers
|
|
.list()
|
|
.then((res) => {
|
|
setProviders(res.providers);
|
|
if (!selectedProviderId && res.providers.length > 0) {
|
|
const linkedId = Number(searchParams.get("providerId"));
|
|
const target = res.providers.find((p) => p.id === linkedId) ?? res.providers[0];
|
|
setSelectedProviderId(target.id);
|
|
}
|
|
})
|
|
.catch((err) => setError(String(err)));
|
|
}
|
|
|
|
useEffect(loadProviders, []);
|
|
|
|
/** `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);
|
|
setRecords(null);
|
|
api.dns.zones
|
|
.list(providerId)
|
|
.then((res) => {
|
|
setZones(res.zones);
|
|
// Deep-link from global search (?providerId=&zoneId=) — auto-open the linked zone once its records load.
|
|
const linkedZoneId = selectId ?? searchParams.get("zoneId");
|
|
const linkedZone = linkedZoneId ? res.zones.find((z) => z.id === linkedZoneId) : undefined;
|
|
if (linkedZone) selectZone(linkedZone);
|
|
})
|
|
.catch((err) => setZonesError(err instanceof Error ? err.message : String(err)));
|
|
}
|
|
|
|
useEffect(() => {
|
|
setCreatingZone(false);
|
|
if (selectedProviderId && !managingProviders) loadZones(selectedProviderId);
|
|
}, [selectedProviderId, managingProviders]);
|
|
|
|
/** Reads the zones again without closing anything: the open zone is kept, with what the provider now says of it (switched off, say). */
|
|
function refreshZones(providerId: number) {
|
|
api.dns.zones
|
|
.list(providerId)
|
|
.then((res) => {
|
|
setZones(res.zones);
|
|
setSelectedZone((current) => (current ? (res.zones.find((z) => z.id === current.id) ?? current) : current));
|
|
})
|
|
.catch(() => {});
|
|
}
|
|
|
|
function loadRecords(providerId: number, zone: DnsZone) {
|
|
api.dns.records
|
|
.list(providerId, zone.id)
|
|
.then((res) => {
|
|
setRecords(res.records);
|
|
setSyncedAt(res.syncedAt);
|
|
// Deep-link from global search (?recordType=&recordName=&recordContent=) — jump
|
|
// straight to that record's edit form. Matched by (type, name, content) rather
|
|
// than an id, since a record's identifier isn't reliably exposed to the frontend
|
|
// for this purpose, but that triple is unambiguous within one zone.
|
|
const linkedType = searchParams.get("recordType");
|
|
const linkedName = searchParams.get("recordName");
|
|
const linkedContent = searchParams.get("recordContent");
|
|
if (linkedType && linkedName && linkedContent && canEdit) {
|
|
const match = res.records.find((r) => r.type === linkedType && r.name === linkedName && r.content === linkedContent);
|
|
if (match) startEditRecord(match);
|
|
}
|
|
})
|
|
.catch((err) => setError(err instanceof Error ? err.message : String(err)));
|
|
}
|
|
|
|
function selectZone(zone: DnsZone) {
|
|
setSelectedZone(zone);
|
|
setEditingZone(false);
|
|
setRecordForm(null);
|
|
setEditingRecordId(null);
|
|
if (selectedProviderId) loadRecords(selectedProviderId, zone);
|
|
}
|
|
|
|
async function syncZone() {
|
|
if (!selectedProviderId || !selectedZone) return;
|
|
setSyncing(true);
|
|
setError(null);
|
|
try {
|
|
const res = await api.dns.records.sync(selectedProviderId, selectedZone.id, selectedZone.name);
|
|
setRecords(res.records);
|
|
setSyncedAt(res.syncedAt);
|
|
loadZones(selectedProviderId);
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : String(err));
|
|
} finally {
|
|
setSyncing(false);
|
|
}
|
|
}
|
|
|
|
function startAddRecord() {
|
|
setEditingRecordId(null);
|
|
setRecordForm({ ...emptyRecordForm });
|
|
}
|
|
|
|
function startEditRecord(r: DnsRecord) {
|
|
setEditingRecordId(r.id);
|
|
setRecordForm({
|
|
type: r.type,
|
|
name: r.name,
|
|
content: r.content,
|
|
ttl: r.ttl ?? undefined,
|
|
priority: r.priority ?? undefined,
|
|
proxied: r.proxied ?? undefined,
|
|
});
|
|
}
|
|
|
|
async function submitRecord(e: React.FormEvent) {
|
|
e.preventDefault();
|
|
if (!selectedProviderId || !selectedZone || !recordForm) return;
|
|
setSavingRecord(true);
|
|
setError(null);
|
|
try {
|
|
if (editingRecordId) {
|
|
await api.dns.records.update(selectedProviderId, selectedZone.id, editingRecordId, recordForm);
|
|
toast.success("Record updated.");
|
|
} else {
|
|
await api.dns.records.create(selectedProviderId, selectedZone.id, recordForm);
|
|
toast.success("Record added.");
|
|
}
|
|
setRecordForm(null);
|
|
setEditingRecordId(null);
|
|
loadRecords(selectedProviderId, selectedZone);
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : String(err));
|
|
} finally {
|
|
setSavingRecord(false);
|
|
}
|
|
}
|
|
|
|
async function removeRecord(r: DnsRecord) {
|
|
if (!selectedProviderId || !selectedZone) return;
|
|
if (!(await confirmDialog({ title: "Delete DNS record", message: `Delete ${r.type} record "${r.name}"?`, confirmLabel: "Delete", danger: true }))) return;
|
|
setError(null);
|
|
try {
|
|
await api.dns.records.remove(selectedProviderId, selectedZone.id, r.id);
|
|
toast.success(`Deleted ${r.type} record ${r.name}.`);
|
|
loadRecords(selectedProviderId, selectedZone);
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : String(err));
|
|
}
|
|
}
|
|
|
|
async function toggleProviderEnabled(p: DnsProviderSummary) {
|
|
try {
|
|
await api.dns.providers.update(p.id, { enabled: !p.enabled });
|
|
loadProviders();
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : String(err));
|
|
}
|
|
}
|
|
|
|
/** Deletes the open zone, and every record in it, on the provider. The name of the zone has to be typed. */
|
|
async function deleteZone() {
|
|
if (!selectedProviderId || !selectedZone || !selectedProvider) return;
|
|
const zone = selectedZone;
|
|
const cached = zone.recordCount > 0 ? ` (${zone.recordCount} record${zone.recordCount === 1 ? " is" : "s are"} cached here)` : "";
|
|
const typed = await promptDialog({
|
|
title: "Delete zone",
|
|
message: `This deletes the zone "${zone.name}" on ${selectedProvider.name}, and every record in it${cached}, for good. It cannot be undone, and what uses this server stops finding the names in it. Type the name of the zone to confirm.`,
|
|
label: "Zone name",
|
|
confirmLabel: "Delete",
|
|
required: true,
|
|
});
|
|
if (typed === null) return;
|
|
if (typed.trim() !== zone.name) {
|
|
toast.error("That is not the name of the zone, so nothing was deleted.");
|
|
return;
|
|
}
|
|
try {
|
|
await api.dns.zones.remove(selectedProviderId, zone.id, zone.name);
|
|
toast.success(`Deleted the zone ${zone.name}.`);
|
|
loadZones(selectedProviderId);
|
|
} catch (err) {
|
|
toast.error(readableError(err));
|
|
}
|
|
}
|
|
|
|
async function removeProvider(p: DnsProviderSummary) {
|
|
if (!(await confirmDialog({ title: "Delete DNS provider", message: `Delete provider "${p.name}"? This removes its cached zones and records too.`, confirmLabel: "Delete", danger: true }))) return;
|
|
try {
|
|
await api.dns.providers.remove(p.id);
|
|
if (selectedProviderId === p.id) setSelectedProviderId(null);
|
|
loadProviders();
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : String(err));
|
|
}
|
|
}
|
|
|
|
const selectedProvider = providers?.find((p) => p.id === selectedProviderId) ?? null;
|
|
|
|
const { sorted: sortedProviders, sortKey: providerSortKey, sortDir: providerSortDir, requestSort: requestProviderSort } = useSortable(
|
|
providers,
|
|
);
|
|
const { sorted: sortedZones, sortKey: zoneSortKey, sortDir: zoneSortDir, requestSort: requestZoneSort } = useSortable(zones);
|
|
const { sorted: sortedRecords, sortKey: recordSortKey, sortDir: recordSortDir, requestSort: requestRecordSort } = useSortable(records);
|
|
const { pageItems: zonePageItems, page: zonePage, setPage: setZonePage, pageCount: zonePageCount, totalCount: zoneTotalCount } =
|
|
usePagination(sortedZones);
|
|
const {
|
|
pageItems: recordPageItems,
|
|
page: recordPage,
|
|
setPage: setRecordPage,
|
|
pageCount: recordPageCount,
|
|
totalCount: recordTotalCount,
|
|
} = usePagination(sortedRecords);
|
|
|
|
function exportProvidersCsv() {
|
|
if (!sortedProviders) return;
|
|
downloadCsv(
|
|
"dns-providers.csv",
|
|
["Name", "Provider", "Status"],
|
|
sortedProviders.map((p) => [p.name, PROVIDER_LABELS[p.providerType], p.enabled ? "Enabled" : "Disabled"]),
|
|
);
|
|
}
|
|
|
|
function exportZonesCsv() {
|
|
if (!sortedZones) return;
|
|
downloadCsv(
|
|
"dns-zones.csv",
|
|
["Zone", "Records", "Synced"],
|
|
sortedZones.map((z) => [z.name, z.recordCount, z.syncedAt ? formatDateTime(new Date(z.syncedAt)) : "never"]),
|
|
);
|
|
}
|
|
|
|
function exportRecordsCsv() {
|
|
if (!sortedRecords) return;
|
|
downloadCsv(
|
|
`dns-records${selectedZone ? `-${selectedZone.name}` : ""}.csv`,
|
|
["Type", "Name", "Content", "TTL"],
|
|
sortedRecords.map((r) => [r.type, r.name, r.content, r.ttl ?? ""]),
|
|
);
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className="d-flex align-items-center mb-3">
|
|
<h2 className="page-title mb-0">DNS</h2>
|
|
{isAdmin && (
|
|
<button
|
|
className="btn btn-outline-secondary ms-auto"
|
|
onClick={() => setManagingProviders((v) => !v)}
|
|
>
|
|
{managingProviders ? "Back to browsing" : "Manage providers"}
|
|
</button>
|
|
)}
|
|
</div>
|
|
{tabs}
|
|
<ErrorNotice error={error} />
|
|
|
|
{managingProviders ? (
|
|
<>
|
|
<DnsProviderForm
|
|
onCreated={() => {
|
|
loadProviders();
|
|
}}
|
|
onCancel={() => setManagingProviders(false)}
|
|
/>
|
|
<div className="card">
|
|
<div className="card-header justify-content-end">
|
|
<button
|
|
className="btn btn-outline-secondary btn-sm"
|
|
onClick={exportProvidersCsv}
|
|
disabled={!providers || providers.length === 0}
|
|
>
|
|
Export CSV
|
|
</button>
|
|
</div>
|
|
<div className="table-responsive">
|
|
<table className="table table-vcenter card-table">
|
|
<thead>
|
|
<tr>
|
|
<SortableTh<DnsProviderSummary>
|
|
label="Name"
|
|
sortKeyName="name"
|
|
activeKey={providerSortKey}
|
|
direction={providerSortDir}
|
|
onSort={requestProviderSort}
|
|
/>
|
|
<SortableTh<DnsProviderSummary>
|
|
label="Provider"
|
|
sortKeyName="providerType"
|
|
activeKey={providerSortKey}
|
|
direction={providerSortDir}
|
|
onSort={requestProviderSort}
|
|
/>
|
|
<SortableTh<DnsProviderSummary>
|
|
label="Status"
|
|
sortKeyName="enabled"
|
|
activeKey={providerSortKey}
|
|
direction={providerSortDir}
|
|
onSort={requestProviderSort}
|
|
/>
|
|
<th className="w-1">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{sortedProviders?.map((p) => (
|
|
<tr key={p.id}>
|
|
<td>{p.name}</td>
|
|
<td>
|
|
<span className="badge" style={providerBadgeStyle(providerColors, p.providerType)}>
|
|
{PROVIDER_LABELS[p.providerType]}
|
|
</span>
|
|
</td>
|
|
<td>
|
|
<button
|
|
className={`badge ${p.enabled ? "bg-green-lt text-green" : "bg-secondary-lt text-secondary"} border-0`}
|
|
onClick={() => toggleProviderEnabled(p)}
|
|
>
|
|
{p.enabled ? "Enabled" : "Disabled"}
|
|
</button>
|
|
</td>
|
|
<td>
|
|
<button className="btn btn-sm btn-outline-danger" onClick={() => removeProvider(p)}>
|
|
Delete
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
{providers === null && <LoadingRow colSpan={4} />}
|
|
{sortedProviders?.length === 0 && (
|
|
<EmptyRow colSpan={4} title="No DNS providers yet" hint="Connect Cloudflare, Loopia, Pi-hole, Azure DNS, cPanel or Technitium to see its zones and records here, and to have names matched to your servers." />
|
|
)}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</>
|
|
) : (
|
|
<>
|
|
{providers?.length === 0 ? (
|
|
<div className="card">
|
|
<div className="card-body text-secondary">
|
|
No DNS providers configured yet.
|
|
{isAdmin && (
|
|
<>
|
|
{" "}
|
|
<button className="btn btn-link p-0 align-baseline" onClick={() => setManagingProviders(true)}>
|
|
Add one
|
|
</button>
|
|
.
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<>
|
|
<div className="mb-3" style={{ maxWidth: 320 }}>
|
|
<select
|
|
className="form-select"
|
|
value={selectedProviderId ?? ""}
|
|
onChange={(e) => setSelectedProviderId(Number(e.target.value))}
|
|
>
|
|
{providers?.map((p) => (
|
|
<option key={p.id} value={p.id} disabled={!p.enabled}>
|
|
{p.name} ({PROVIDER_LABELS[p.providerType]}){!p.enabled ? " — disabled" : ""}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
|
|
<div className="row g-3">
|
|
<div className="col-md-5">
|
|
<div className="card">
|
|
<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}
|
|
disabled={!sortedZones || sortedZones.length === 0}
|
|
>
|
|
Export CSV
|
|
</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">
|
|
<thead>
|
|
<tr>
|
|
<SortableTh<DnsZone> label="Zone" sortKeyName="name" activeKey={zoneSortKey} direction={zoneSortDir} onSort={requestZoneSort} />
|
|
<SortableTh<DnsZone>
|
|
label="Records"
|
|
sortKeyName="recordCount"
|
|
activeKey={zoneSortKey}
|
|
direction={zoneSortDir}
|
|
onSort={requestZoneSort}
|
|
/>
|
|
<SortableTh<DnsZone>
|
|
label="Synced"
|
|
sortKeyName="syncedAt"
|
|
activeKey={zoneSortKey}
|
|
direction={zoneSortDir}
|
|
onSort={requestZoneSort}
|
|
/>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{zonePageItems?.map((z) => (
|
|
<tr
|
|
key={z.id}
|
|
role="button"
|
|
className={selectedZone?.id === z.id ? "table-active" : ""}
|
|
onClick={() => selectZone(z)}
|
|
>
|
|
<td>
|
|
{z.name}
|
|
{z.disabled && <span className="badge bg-yellow-lt text-yellow ms-2">off</span>}
|
|
{z.type && z.type !== "Primary" && <span className="badge bg-secondary-lt text-secondary ms-1">{z.type}</span>}
|
|
</td>
|
|
<td>{z.recordCount}</td>
|
|
<td className="text-secondary">
|
|
{z.syncedAt ? <TimeAgo value={z.syncedAt} /> : "never"}
|
|
</td>
|
|
</tr>
|
|
))}
|
|
{sortedZones && sortedZones.length === 0 && (
|
|
<EmptyRow colSpan={3} title="No zones found" hint="The provider answered with none. Check that its credentials can see the zones, or sync it again." />
|
|
)}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<Pagination page={zonePage} pageCount={zonePageCount} totalCount={zoneTotalCount} onPageChange={setZonePage} />
|
|
</div>
|
|
</div>
|
|
|
|
<div className="col-md-7">
|
|
{selectedZone ? (
|
|
<div className="card">
|
|
<div className="card-header">
|
|
<h3 className="card-title">{selectedZone.name}</h3>
|
|
<div className="card-actions">
|
|
<button
|
|
className="btn btn-sm btn-outline-secondary me-2"
|
|
onClick={exportRecordsCsv}
|
|
disabled={!sortedRecords || sortedRecords.length === 0}
|
|
>
|
|
Export CSV
|
|
</button>
|
|
{canEdit && (
|
|
<button className="btn btn-sm btn-outline-secondary me-2" onClick={syncZone} disabled={syncing}>
|
|
{syncing ? "Syncing…" : "Sync now"}
|
|
</button>
|
|
)}
|
|
{canEdit && !recordForm && (
|
|
<button className="btn btn-sm btn-primary" onClick={startAddRecord}>
|
|
Add record
|
|
</button>
|
|
)}
|
|
{isAdmin && selectedProvider?.canEditZones && selectedProvider.enabled && (
|
|
<button className="btn btn-sm btn-outline-secondary ms-2" onClick={() => setEditingZone((v) => !v)} aria-expanded={editingZone}>
|
|
Edit zone
|
|
</button>
|
|
)}
|
|
{isAdmin && selectedProvider?.canDeleteZones && selectedProvider.enabled && (
|
|
<button className="btn btn-sm btn-outline-danger ms-2" onClick={() => void deleteZone()}>
|
|
Delete zone
|
|
</button>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{editingZone && selectedProviderId && (
|
|
<DnsZoneEditor providerId={selectedProviderId} zone={selectedZone} onChanged={() => refreshZones(selectedProviderId)} onClose={() => setEditingZone(false)} />
|
|
)}
|
|
|
|
{recordForm && (
|
|
<form onSubmit={submitRecord}>
|
|
<div className="card-body row g-2">
|
|
<div className="col-2">
|
|
<label className="form-label">Type</label>
|
|
<input
|
|
className="form-control"
|
|
required
|
|
list="dns-record-types"
|
|
value={recordForm.type}
|
|
onChange={(e) => setRecordForm({ ...recordForm, type: e.target.value.toUpperCase() })}
|
|
/>
|
|
<datalist id="dns-record-types">
|
|
{["A", "AAAA", "CNAME", "MX", "TXT", "NS", "PTR"].map((t) => (
|
|
<option key={t} value={t} />
|
|
))}
|
|
</datalist>
|
|
</div>
|
|
<div className="col-3">
|
|
<label className="form-label">Name</label>
|
|
<input
|
|
className="form-control"
|
|
required
|
|
value={recordForm.name}
|
|
onChange={(e) => setRecordForm({ ...recordForm, name: e.target.value })}
|
|
/>
|
|
</div>
|
|
<div className="col-3">
|
|
<label className="form-label">Content</label>
|
|
<input
|
|
className="form-control"
|
|
required
|
|
value={recordForm.content}
|
|
onChange={(e) => setRecordForm({ ...recordForm, content: e.target.value })}
|
|
/>
|
|
</div>
|
|
<div className="col-2">
|
|
<label className="form-label">TTL</label>
|
|
<input
|
|
type="number"
|
|
className="form-control"
|
|
value={recordForm.ttl ?? ""}
|
|
onChange={(e) => setRecordForm({ ...recordForm, ttl: Number(e.target.value) || undefined })}
|
|
/>
|
|
</div>
|
|
<div className="col-2">
|
|
<label className="form-label">Priority</label>
|
|
<input
|
|
type="number"
|
|
className="form-control"
|
|
value={recordForm.priority ?? ""}
|
|
onChange={(e) =>
|
|
setRecordForm({ ...recordForm, priority: e.target.value === "" ? undefined : Number(e.target.value) })
|
|
}
|
|
/>
|
|
</div>
|
|
{selectedProvider?.providerType === "cloudflare" && (
|
|
<div className="col-12">
|
|
<label className="form-check">
|
|
<input
|
|
type="checkbox"
|
|
className="form-check-input"
|
|
checked={Boolean(recordForm.proxied)}
|
|
onChange={(e) => setRecordForm({ ...recordForm, proxied: e.target.checked })}
|
|
/>
|
|
<span className="form-check-label">Proxied through Cloudflare</span>
|
|
</label>
|
|
</div>
|
|
)}
|
|
</div>
|
|
<div className="card-footer d-flex gap-2">
|
|
<button type="submit" className="btn btn-primary" disabled={savingRecord}>
|
|
{editingRecordId ? "Save changes" : "Add record"}
|
|
</button>
|
|
<button type="button" className="btn" onClick={() => setRecordForm(null)}>
|
|
Cancel
|
|
</button>
|
|
</div>
|
|
</form>
|
|
)}
|
|
|
|
<div className="table-responsive">
|
|
<table className="table table-vcenter card-table">
|
|
<thead>
|
|
<tr>
|
|
<SortableTh<DnsRecord> label="Type" sortKeyName="type" activeKey={recordSortKey} direction={recordSortDir} onSort={requestRecordSort} />
|
|
<SortableTh<DnsRecord> label="Name" sortKeyName="name" activeKey={recordSortKey} direction={recordSortDir} onSort={requestRecordSort} />
|
|
<SortableTh<DnsRecord>
|
|
label="Content"
|
|
sortKeyName="content"
|
|
activeKey={recordSortKey}
|
|
direction={recordSortDir}
|
|
onSort={requestRecordSort}
|
|
/>
|
|
<SortableTh<DnsRecord> label="TTL" sortKeyName="ttl" activeKey={recordSortKey} direction={recordSortDir} onSort={requestRecordSort} />
|
|
{canEdit && <th className="w-1">Actions</th>}
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{recordPageItems?.map((r) => (
|
|
<tr key={r.id}>
|
|
<td>
|
|
<span className="badge bg-blue-lt">{r.type}</span>
|
|
</td>
|
|
<td>{r.name}</td>
|
|
<td className="text-secondary">{r.content}</td>
|
|
<td>{r.ttl ?? "—"}</td>
|
|
{canEdit && (
|
|
<td>
|
|
<div className="btn-list flex-nowrap">
|
|
<button className="btn btn-sm" onClick={() => startEditRecord(r)}>
|
|
Edit
|
|
</button>
|
|
<button className="btn btn-sm btn-outline-danger" onClick={() => removeRecord(r)}>
|
|
Delete
|
|
</button>
|
|
</div>
|
|
</td>
|
|
)}
|
|
</tr>
|
|
))}
|
|
{sortedRecords?.length === 0 && (
|
|
<EmptyRow colSpan={canEdit ? 5 : 4} title="No records cached" hint={syncedAt === null ? "Sync this zone to fetch its records from the provider." : "This zone has no records."} action={canEdit ? { label: "Add a record", onClick: startAddRecord } : undefined} />
|
|
)}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<Pagination page={recordPage} pageCount={recordPageCount} totalCount={recordTotalCount} onPageChange={setRecordPage} />
|
|
</div>
|
|
) : (
|
|
<div className="card">
|
|
<div className="card-body text-secondary">Select a zone to view its records.</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</>
|
|
)}
|
|
</>
|
|
)}
|
|
</>
|
|
);
|
|
}
|