import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import ReadNowButton from "../components/ReadNowButton"; import { api, type CurrentUser, type TechnitiumInstance } from "../api/client"; import EmptyState from "../components/EmptyState"; import TimeAgo from "../components/TimeAgo"; import { BlockSkeleton } from "../components/Skeleton"; import { ErrorNotice } from "../components/Notice"; import { formatAgo } from "../utils/duration"; import { readableError } from "../utils/errors"; import PageIntro from "../components/PageIntro"; function Badge({ a }: { a: TechnitiumInstance }) { if (!a.enabled) return Off; if (!a.state) return Not read yet; if (!a.fresh) return Can’t be read; if (a.problems.some((x) => x.severity === "critical")) return Needs a look; if (a.problems.length > 0) return Needs a look; return In order; } function Tile({ label, value, sub, tone }: { label: string; value: string; sub?: string | null; tone?: "bad" | "warn" }) { return (
{label}
{value}
{sub &&
{sub}
}
); } function Counted({ title, items, empty }: { title: string; items: { name: string; count: number }[]; empty: string }) { const top = items[0]?.count ?? 0; return (

{title}

{items.length === 0 &&
{empty}
} {items.slice(0, 7).map((i) => (
{i.name} {i.count.toLocaleString()}
0 ? Math.max(2, (i.count / top) * 100) : 0}%` }} />
))}
); } /** "12 d 3 h", "5 h 20 min", "40 min": how long since a moment. */ function upFor(startedAt: string, now: number = Date.now()): string { const minutes = Math.max(0, Math.floor((now - Date.parse(startedAt)) / 60_000)); if (minutes < 60) return `${minutes} min`; const hours = Math.floor(minutes / 60); if (hours < 24) return minutes % 60 ? `${hours} h ${minutes % 60} min` : `${hours} h`; const days = Math.floor(hours / 24); return hours % 24 ? `${days} d ${hours % 24} h` : `${days} d`; } const NODE_STATE: Record = { self: { className: "bg-blue-lt", label: "this node" }, connected: { className: "bg-green-lt", label: "connected" }, unreachable: { className: "bg-red-lt", label: "unreachable" }, }; /** The cluster the server belongs to: its nodes and whether this one can reach them, and (for a secondary) when it last took the configuration from the primary. Nothing when it is in none. */ function ClusterSection({ cluster }: { cluster: NonNullable["cluster"] }) { if (!cluster || (!cluster.info && !cluster.note)) return null; const info = cluster.info; return (

Cluster{info?.domain ? — {info.domain} : null}

{cluster.note &&
{cluster.note}
} {info && ( <>
{info.nodes.map((n) => { const st = NODE_STATE[n.state.toLowerCase()] ?? { className: "bg-secondary-lt", label: n.state }; return ( ); })}
Node Role State Version Last seen
{n.url ? ( {n.name} ) : ( n.name )} {n.type} {st.label} {n.version ?? "—"} {n.state.toLowerCase() === "self" ? "—" : n.lastSeen ? : "—"}
{info.configLastSynced && (
This node last took the configuration from the primary {info.configRefreshSeconds ? ` (it asks every ${Math.round(info.configRefreshSeconds / 60)} min)` : ""}.
)} )}
); } /** How the last day's queries were answered, as one bar: from the cache, resolved by the server, from its own zones, blocked, dropped. */ const HOW: { key: "cached" | "recursive" | "authoritative" | "blocked" | "dropped"; label: string; className: string }[] = [ { key: "cached", label: "from the cache", className: "bg-blue" }, { key: "recursive", label: "resolved", className: "bg-azure" }, { key: "authoritative", label: "from its own zones", className: "bg-green" }, { key: "blocked", label: "blocked", className: "bg-orange" }, { key: "dropped", label: "dropped", className: "bg-red" }, ]; function Card({ a, canRead, onRead }: { a: TechnitiumInstance; canRead: boolean; onRead: () => void }) { const s = a.state; const st = s?.stats ?? null; const cacheMax = s?.settings.cacheMaximumEntries ?? null; const cacheFill = st && st.cachedEntries !== null && cacheMax !== null && cacheMax > 0 ? Math.min(100, Math.round((st.cachedEntries / cacheMax) * 100)) : null; return (

{a.name} {s?.version ? `v${s.version}` : ""}

{a.status ? <>read : "not read yet"} {canRead && a.enabled && }
{a.status && !a.status.ok &&
The last attempt to read it failed: {a.status.error ?? "no answer"}.
} {a.problems.length > 0 && (
    {a.problems.map((x) => (
  • {x.message}
  • ))}
)} {s && ( <>
0 ? "warn" : undefined} /> = 200 && st.failurePercent >= 20 ? "warn" : undefined} /> = 95 ? "warn" : undefined} />
{st && st.queries > 0 && (

How the queries were answered

{HOW.map((h) => (
))}
{HOW.map((h) => (   {h.label} {st[h.key].toLocaleString()} ))}
)} {st && (st.topBlocked.length > 0 || st.topClients.length > 0 || st.topDomains.length > 0) && (
)}

Zones

{s.zones === null ? (
They could not be read.
) : (
{s.zones.total} zone{s.zones.total === 1 ? "" : "s"} {s.zones.disabled > 0 ? `, ${s.zones.disabled} switched off` : ""} {s.zones.issues.length === 0 ? " — none with a problem." : "."}
{s.zones.issues.length > 0 && (
    {s.zones.issues.map((z) => (
  • {z.name} — {z.problem === "expired" ? "expired: it no longer answers" : "cannot sync with its primary"}
  • ))}
)}
)}

Block lists and the rest

  • {s.settings.blockLists.count === 0 ? ( "No block lists are set up." ) : ( <> {s.settings.blockLists.count} block list{s.settings.blockLists.count === 1 ? "" : "s"} {st && st.blockListZones !== null ? `, ${st.blockListZones.toLocaleString()} names on them` : ""} {s.settings.blockLists.nextUpdate ? ( s.blockListsOverdueMs !== null ? ( {" "} — update was due ) : ( — next update {new Date(s.settings.blockLists.nextUpdate).toLocaleString()} ) ) : ( "" )} )}
  • {st && (st.allowedZones !== null || st.blockedZones !== null) && (
  • Allowed by hand: {(st.allowedZones ?? 0).toLocaleString()} · blocked by hand: {(st.blockedZones ?? 0).toLocaleString()}
  • )}
  • Recursion: {s.settings.recursion ?? "—"} · DNSSEC validation: {s.settings.dnssecValidation === null ? "—" : s.settings.dnssecValidation ? "on" : "off"}
  • {s.dhcp && (
  • DHCP: {s.dhcp.scopes} scope{s.dhcp.scopes === 1 ? "" : "s"} ({s.dhcp.enabledScopes} on), {s.dhcp.leases.toLocaleString()} lease{s.dhcp.leases === 1 ? "" : "s"}
  • )}
)}
); } /** Technitium DNS Server: whether DNS really answers, whether it blocks, what it has done in the last day, how its zones and block lists are, and how it is doing. */ export default function TechnitiumDns({ user }: { user: CurrentUser }) { const canRead = user.role === "admin" || user.role === "operator"; const [tick, setTick] = useState(0); const [data, setData] = useState(null); const [error, setError] = useState(null); useEffect(() => { const load = () => api.technitium .list() .then((r) => { setData(r.instances); setError(null); }) .catch((err) => setError(readableError(err))); void load(); const t = setInterval(load, 60_000); return () => clearInterval(t); }, [tick]); return ( <>

Technitium DNS

Read every two minutes (see Integrations), with a real DNS question put to it each time — its web console can be up while DNS is not. Nothing is changed. DNS that stops answering, blocking left off for an hour,{" "} block lists that stopped updating and an expired or unsynced zone, a cluster node that cannot be reached and a secondary that has stopped taking the primary's configuration are alerts — see Alerts. Technitium does not report the CPU, memory or disk of the machine it runs on: put a server agent there for that. {!data && !error && } {data && data.length === 0 && (
)} {data?.map((a) => setTick((n) => n + 1)} />)} ); }