diff --git a/frontend/src/plugins/serverkit-crowdsec/components/CrowdSecPage.jsx b/frontend/src/plugins/serverkit-crowdsec/components/CrowdSecPage.jsx new file mode 100644 index 00000000..3e0c9379 --- /dev/null +++ b/frontend/src/plugins/serverkit-crowdsec/components/CrowdSecPage.jsx @@ -0,0 +1,566 @@ +import { useCallback, useEffect, useState } from 'react'; +import { ShieldCheck, RefreshCw, Ban, ListChecks, Activity, Plus } from 'lucide-react'; +import api from '@/services/api'; +import { PageTopbar, Pill, MetricCard } from '@/components/ds'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue } from '@/components/ui/select'; +import Modal from '@/components/Modal'; +import ConfirmDialog from '@/components/ConfirmDialog'; +import EmptyState from '@/components/EmptyState'; +import { useToast } from '@/contexts/ToastContext'; + +const DURATIONS = ['1h', '4h', '12h', '24h', '7d']; + +const formatDate = (d) => (d ? new Date(d).toLocaleString() : '—'); + +// Best-effort: pull a headline number out of `cscli metrics -o json`, whose +// shape varies across CrowdSec versions. Null when nothing recognizable. +function parsedEventsTotal(metrics) { + try { + const acq = metrics?.acquisition; + if (!acq || typeof acq !== 'object') return null; + let total = 0; + for (const source of Object.values(acq)) { + const n = source?.parsed ?? source?.lines_parsed; + if (typeof n === 'number') total += n; + } + return total > 0 ? total : null; + } catch { + return null; + } +} + +const CrowdSecPage = () => { + const toast = useToast(); + + const [status, setStatus] = useState(null); + const [decisions, setDecisions] = useState([]); + const [alerts, setAlerts] = useState([]); + const [allowlists, setAllowlists] = useState({ supported: false, allowlists: [], message: null }); + const [metrics, setMetrics] = useState(null); + const [loading, setLoading] = useState(true); + const [actionLoading, setActionLoading] = useState(false); + const [confirmDialog, setConfirmDialog] = useState(null); + + // Ban modal + const [showBanModal, setShowBanModal] = useState(false); + const [banForm, setBanForm] = useState({ ip: '', duration: '4h', reason: '' }); + + // Allowlist manager + const [showListModal, setShowListModal] = useState(false); + const [listForm, setListForm] = useState({ name: '', description: '' }); + const [selectedList, setSelectedList] = useState(null); + const [listItems, setListItems] = useState([]); + const [entryForm, setEntryForm] = useState({ value: '', comment: '' }); + + const loadData = useCallback(async () => { + setLoading(true); + try { + const statusData = await api.request('/crowdsec/status'); + setStatus(statusData); + if (statusData?.installed) { + const [d, a, al, m] = await Promise.all([ + api.request('/crowdsec/decisions').catch(() => ({ decisions: [] })), + api.request('/crowdsec/alerts').catch(() => ({ alerts: [] })), + api.request('/crowdsec/allowlists').catch(() => ({ supported: false, allowlists: [] })), + api.request('/crowdsec/metrics').catch(() => null), + ]); + setDecisions(d.decisions || []); + setAlerts(a.alerts || []); + setAllowlists(al || { supported: false, allowlists: [] }); + setMetrics(m?.metrics ?? null); + } + } catch (error) { + toast.error(`Failed to load CrowdSec data: ${error.message}`); + } finally { + setLoading(false); + } + }, [toast]); + + useEffect(() => { + loadData(); + }, [loadData]); + + const handleBan = async () => { + if (!banForm.ip.trim()) return; + setActionLoading(true); + try { + await api.request('/crowdsec/decisions', { + method: 'POST', + body: { + ip: banForm.ip.trim(), + duration: banForm.duration, + reason: banForm.reason.trim() || undefined, + }, + }); + toast.success(`Decision added for ${banForm.ip}`); + setShowBanModal(false); + setBanForm({ ip: '', duration: '4h', reason: '' }); + await loadData(); + } catch (error) { + toast.error(`Failed to ban IP: ${error.message}`); + } finally { + setActionLoading(false); + } + }; + + const handleDeleteDecision = (value) => { + setConfirmDialog({ + title: 'Remove decision', + message: `Remove all active decisions for ${value}?`, + confirmText: 'Remove', + variant: 'warning', + onConfirm: async () => { + try { + await api.request(`/crowdsec/decisions/${encodeURIComponent(value)}`, { method: 'DELETE' }); + toast.success(`Decisions removed for ${value}`); + await loadData(); + } catch (error) { + toast.error(`Failed to remove decision: ${error.message}`); + } + setConfirmDialog(null); + }, + onCancel: () => setConfirmDialog(null), + }); + }; + + const handleCreateList = async () => { + if (!listForm.name.trim()) return; + setActionLoading(true); + try { + await api.request('/crowdsec/allowlists', { + method: 'POST', + body: { name: listForm.name.trim(), description: listForm.description.trim() }, + }); + toast.success(`Allowlist ${listForm.name} created`); + setShowListModal(false); + setListForm({ name: '', description: '' }); + await loadData(); + } catch (error) { + toast.error(`Failed to create allowlist: ${error.message}`); + } finally { + setActionLoading(false); + } + }; + + const openList = async (name) => { + setSelectedList(name); + setListItems([]); + try { + const res = await api.request(`/crowdsec/allowlists/${encodeURIComponent(name)}`); + setListItems(res?.allowlist?.items || []); + } catch (error) { + toast.error(`Failed to load allowlist: ${error.message}`); + } + }; + + const handleAddEntry = async () => { + if (!selectedList || !entryForm.value.trim()) return; + setActionLoading(true); + try { + await api.request(`/crowdsec/allowlists/${encodeURIComponent(selectedList)}/items`, { + method: 'POST', + body: { value: entryForm.value.trim(), comment: entryForm.comment.trim() || undefined }, + }); + toast.success(`Added ${entryForm.value} to ${selectedList}`); + setEntryForm({ value: '', comment: '' }); + await openList(selectedList); + } catch (error) { + toast.error(`Failed to add entry: ${error.message}`); + } finally { + setActionLoading(false); + } + }; + + const handleRemoveEntry = async (value) => { + try { + await api.request( + `/crowdsec/allowlists/${encodeURIComponent(selectedList)}/items?value=${encodeURIComponent(value)}`, + { method: 'DELETE' } + ); + toast.success(`Removed ${value} from ${selectedList}`); + await openList(selectedList); + } catch (error) { + toast.error(`Failed to remove entry: ${error.message}`); + } + }; + + if (loading) { + return ( +
+ } title="CrowdSec" /> + +
+ ); + } + + // ── Not installed: guidance, never auto-install ── + if (!status?.installed) { + return ( +
+ } title="CrowdSec" /> +
+ +

CrowdSec Is Not Installed

+

+ CrowdSec is a collaborative security engine that detects attacks in your + logs and shares blocklists across its community. Install it on this host + and this page will surface its decisions, alerts, and allowlists. +

+

+ ServerKit does not install it for you — follow the official guide, then + refresh this page. +

+
+ + +
+
+
+ ); + } + + const parsedEvents = parsedEventsTotal(metrics); + + return ( +
+ } + title="CrowdSec" + actions={ + <> + + + + } + /> + + {/* ── Status ── */} +
+
+

Engine Status

+
+
+
+
+ Service + + {status.running ? 'Running' : 'Stopped'} + +
+
+ Local API + + {status.lapi_ok ? 'Reachable' : 'Unreachable'} + +
+
+ Version + {status.version || 'Unknown'} +
+
+ Allowlists + + {status.allowlists_supported + ? 'Supported' + : 'Not supported by this CrowdSec version'} + +
+
+ AppSec / WAF + + In-line request filtering needs the CrowdSec AppSec component and a + bouncer on your reverse proxy — configured outside the panel. + +
+
+
+
+ + {/* ── Metric cards (best-effort) ── */} +
+ } tone="red" value={decisions.length} label="Active decisions" /> + } tone="amber" value={alerts.length} label="Recent alerts" /> + } + tone="green" + value={allowlists.supported ? (allowlists.allowlists || []).length : '—'} + label="Allowlists" + /> + {parsedEvents != null && ( + } tone="cyan" value={parsedEvents} label="Parsed log lines" /> + )} +
+ + {/* ── Decisions ── */} +
+
+

Decisions {decisions.length > 0 && · {decisions.length}}

+
+ {decisions.length === 0 ? ( +
+

No active decisions — nothing is currently banned.

+
+ ) : ( + + + + + + + + + + + + + + {decisions.map((d, i) => ( + + + + + + + + + + ))} + +
ValueScopeTypeOriginReasonExpiresActions
{d.value}{d.scope || '—'}{d.type || '—'}{d.origin || '—'}{d.reason || '—'}{d.until ? formatDate(d.until) : (d.duration || '—')} + +
+ )} +
+ + {/* ── Alerts ── */} +
+
+

Alerts {alerts.length > 0 && · {alerts.length}}

+
+ {alerts.length === 0 ? ( +
+

No recent alerts.

+
+ ) : ( + + + + + + + + + + + + + {alerts.map((a, i) => ( + + + + + + + + + ))} + +
ScenarioSourceCountryEventsDecisionsCreated
{a.scenario || '—'}{a.source || '—'}{a.country || '—'}{a.events_count ?? '—'}{a.decisions ?? '—'}{formatDate(a.created_at)}
+ )} +
+ + {/* ── Allowlists ── */} +
+
+

Allowlists

+ {allowlists.supported && ( +
+ +
+ )} +
+
+ {!allowlists.supported ? ( +

+ {allowlists.message + || 'The installed CrowdSec version does not support centralized allowlists. Upgrade CrowdSec to manage allowlists from the panel.'} +

+ ) : (allowlists.allowlists || []).length === 0 ? ( +

No allowlists yet. Create one to exempt trusted IPs from remediation.

+ ) : ( +
+
+ {(allowlists.allowlists || []).map((l, i) => ( + + ))} +
+ {selectedList && ( +
+

{selectedList}

+ {listItems.length === 0 ? ( +

No entries in this allowlist.

+ ) : ( + + + + + + + + + + {listItems.map((it, i) => { + const value = typeof it === 'string' ? it : it.value; + return ( + + + + + + ); + })} + +
ValueCommentActions
{value}{(typeof it === 'object' && (it.description || it.comment)) || '—'} + +
+ )} +
+ setEntryForm((f) => ({ ...f, value: e.target.value }))} + placeholder="IP or CIDR, e.g. 203.0.113.7 or 10.0.0.0/8" + /> + setEntryForm((f) => ({ ...f, comment: e.target.value }))} + placeholder="Comment (optional)" + /> + +
+
+ )} +
+ )} +
+
+ + {/* ── Ban modal ── */} + setShowBanModal(false)} title="Ban an IP"> +
+ + setBanForm((f) => ({ ...f, ip: e.target.value }))} + placeholder="203.0.113.7 or 203.0.113.0/24" + /> +
+
+ + +
+
+ + setBanForm((f) => ({ ...f, reason: e.target.value }))} + placeholder="Manual ban from ServerKit" + /> +
+
+ + +
+
+ + {/* ── New allowlist modal ── */} + setShowListModal(false)} title="New Allowlist"> +
+ + setListForm((f) => ({ ...f, name: e.target.value }))} + placeholder="trusted-ips" + /> +
+
+ + setListForm((f) => ({ ...f, description: e.target.value }))} + placeholder="Office and monitoring IPs" + /> +
+
+ + +
+
+ + {confirmDialog && ( + + )} +
+ ); +}; + +export default CrowdSecPage; diff --git a/frontend/src/plugins/serverkit-crowdsec/index.jsx b/frontend/src/plugins/serverkit-crowdsec/index.jsx new file mode 100644 index 00000000..09905699 --- /dev/null +++ b/frontend/src/plugins/serverkit-crowdsec/index.jsx @@ -0,0 +1,8 @@ +// CrowdSec integration UI, contributed through the extension system. Unlike the +// re-export builtins (ftp/status/email…), this page is fully self-contained in +// the extension — no core page to wrap. After sync this folder lives at +// frontend/src/plugins/serverkit-crowdsec/, so '@/…' host aliases resolve. +export { default as CrowdSecPage } from './components/CrowdSecPage.jsx'; + +// No default export on purpose: PluginLoader legacy-auto-renders any plugin +// default export globally. The route contribution resolves the NAMED export. diff --git a/frontend/src/plugins/serverkit-crowdsec/plugin.json b/frontend/src/plugins/serverkit-crowdsec/plugin.json new file mode 100644 index 00000000..8a2c213d --- /dev/null +++ b/frontend/src/plugins/serverkit-crowdsec/plugin.json @@ -0,0 +1,45 @@ +{ + "name": "serverkit-crowdsec", + "display_name": "CrowdSec", + "version": "1.0.0", + "description": "CrowdSec security engine integration — surface active decisions and alerts, ban/unban IPs, and manage allowlists straight from the panel. Read/write via cscli on the host; shows install guidance when CrowdSec is absent (never auto-installs).", + "author": "ServerKit", + "license": "MIT", + "category": "security", + "homepage": "https://github.com/jhd3197/ServerKit", + "permissions": [ + "shell" + ], + "min_panel_version": "1.7.0", + "entry_point": "crowdsec:crowdsec_bp", + "url_prefix": "/api/v1/crowdsec", + "icon": "", + "contributions": { + "nav": [ + { + "id": "crowdsec", + "label": "CrowdSec", + "route": "/crowdsec", + "category": "operations", + "icon": "" + } + ], + "routes": [ + { + "path": "crowdsec", + "component": "CrowdSecPage" + } + ], + "page_titles": { + "/crowdsec": "CrowdSec" + }, + "command_palette": [ + { + "label": "CrowdSec", + "path": "/crowdsec", + "category": "Pages", + "keywords": "crowdsec decisions alerts bans ips allowlist security waf appsec" + } + ] + } +} diff --git a/frontend/src/plugins/serverkit-crowdsec/styles/crowdsec.css b/frontend/src/plugins/serverkit-crowdsec/styles/crowdsec.css new file mode 100644 index 00000000..0d110e6c --- /dev/null +++ b/frontend/src/plugins/serverkit-crowdsec/styles/crowdsec.css @@ -0,0 +1,53 @@ +/* CrowdSec extension — layout-only styles; colors/typography inherit from the + host design system (card, sk-dtable, sk-info-row, sk-kpi, empty-state…). */ + +.crowdsec-page .cs-kpis { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); + gap: 12px; + margin: 12px 0; +} + +.crowdsec-page .cs-empty-actions { + display: flex; + gap: 8px; + justify-content: center; + margin-top: 12px; +} + +.crowdsec-page .cs-allowlists { + display: flex; + flex-direction: column; + gap: 12px; +} + +.crowdsec-page .cs-allowlists__names { + display: flex; + flex-wrap: wrap; + gap: 8px; +} + +.crowdsec-page .cs-allowlists__name { + background: none; + border: none; + padding: 2px 4px; + cursor: pointer; + text-align: left; + border-radius: 6px; +} + +.crowdsec-page .cs-allowlists__name.is-active { + outline: 1px solid currentColor; + outline-offset: 2px; +} + +.crowdsec-page .cs-entry-form { + display: flex; + gap: 8px; + margin-top: 12px; + align-items: center; +} + +.crowdsec-page .cs-entry-form input { + max-width: 320px; +} diff --git a/frontend/src/plugins/serverkit-dns-server/components/DnsServerPage.jsx b/frontend/src/plugins/serverkit-dns-server/components/DnsServerPage.jsx new file mode 100644 index 00000000..ef0a4caa --- /dev/null +++ b/frontend/src/plugins/serverkit-dns-server/components/DnsServerPage.jsx @@ -0,0 +1,381 @@ +import { useCallback, useEffect, useState } from 'react'; +import { Globe, RefreshCw, Plus, Trash2, Server } from 'lucide-react'; +import api from '@/services/api'; +import { PageTopbar, Pill } from '@/components/ds'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import Modal from '@/components/Modal'; +import ConfirmDialog from '@/components/ConfirmDialog'; +import EmptyState from '@/components/EmptyState'; +import { useToast } from '@/contexts/ToastContext'; +import ZoneDetail from './ZoneDetail.jsx'; + +const DnsServerPage = () => { + const toast = useToast(); + + const [status, setStatus] = useState(null); + const [zones, setZones] = useState([]); + const [loading, setLoading] = useState(true); + const [actionLoading, setActionLoading] = useState(false); + const [confirmDialog, setConfirmDialog] = useState(null); + const [selectedZone, setSelectedZone] = useState(null); + + // Install form + const [installForm, setInstallForm] = useState({ ns_hostname: '', admin_email: '' }); + + // New zone modal + const [showZoneModal, setShowZoneModal] = useState(false); + const [zoneName, setZoneName] = useState(''); + + const loadData = useCallback(async () => { + setLoading(true); + try { + const statusData = await api.request('/dns-server/status'); + setStatus(statusData); + if (statusData?.installed) { + const z = await api.request('/dns-server/zones').catch(() => ({ zones: [] })); + setZones(z.zones || []); + } + } catch (error) { + toast.error(`Failed to load DNS server status: ${error.message}`); + } finally { + setLoading(false); + } + }, [toast]); + + useEffect(() => { + loadData(); + }, [loadData]); + + const handleInstall = async () => { + if (!installForm.ns_hostname.trim() || !installForm.admin_email.trim()) return; + setActionLoading(true); + try { + await api.request('/dns-server/install', { + method: 'POST', + body: { + ns_hostname: installForm.ns_hostname.trim(), + admin_email: installForm.admin_email.trim(), + }, + }); + toast.success('PowerDNS authoritative server installed'); + await loadData(); + } catch (error) { + toast.error(`Install failed: ${error.message}`); + } finally { + setActionLoading(false); + } + }; + + const handleUninstall = (keepData) => { + setConfirmDialog({ + title: 'Remove DNS server', + message: keepData + ? 'Remove the PowerDNS container? Zone data stays on disk and a reinstall picks it back up.' + : 'Remove the PowerDNS container AND delete all zone data? This cannot be undone.', + confirmText: 'Remove', + variant: 'danger', + onConfirm: async () => { + try { + await api.request(`/dns-server/install?keep_data=${keepData}`, { method: 'DELETE' }); + toast.success('DNS server removed'); + setSelectedZone(null); + await loadData(); + } catch (error) { + toast.error(`Uninstall failed: ${error.message}`); + } + setConfirmDialog(null); + }, + onCancel: () => setConfirmDialog(null), + }); + }; + + const handleCreateZone = async () => { + if (!zoneName.trim()) return; + setActionLoading(true); + try { + await api.request('/dns-server/zones', { + method: 'POST', + body: { name: zoneName.trim() }, + }); + toast.success(`Zone ${zoneName} created`); + setShowZoneModal(false); + setZoneName(''); + await loadData(); + } catch (error) { + toast.error(`Failed to create zone: ${error.message}`); + } finally { + setActionLoading(false); + } + }; + + const handleDeleteZone = (name) => { + setConfirmDialog({ + title: 'Delete zone', + message: `Delete zone ${name} and all of its records?`, + confirmText: 'Delete', + variant: 'danger', + onConfirm: async () => { + try { + await api.request(`/dns-server/zones/${encodeURIComponent(name)}`, { method: 'DELETE' }); + toast.success(`Zone ${name} deleted`); + if (selectedZone === name) setSelectedZone(null); + await loadData(); + } catch (error) { + toast.error(`Failed to delete zone: ${error.message}`); + } + setConfirmDialog(null); + }, + onCancel: () => setConfirmDialog(null), + }); + }; + + if (loading) { + return ( +
+ } title="DNS Server" /> + +
+ ); + } + + // ── Not installed: explainer + install form ── + if (!status?.installed) { + return ( +
+ } title="DNS Server" /> +
+
+

Host Your Own Nameserver

+
+
+

+ Run PowerDNS (authoritative, SQLite backend) in a managed Docker + container so this box answers DNS for your domains directly — + handy for homelabs and air-gapped networks where a hosted DNS + provider is not an option. +

+
    +
  • + Authoritative only. This serves the zones you + create; it never resolves other names for clients. Keep using + your normal resolver. +
  • +
  • + Port 53 must be free on this host (tcp + udp). + systemd-resolved or another DNS service will conflict. +
  • +
  • + Delegation happens at your registrar. Point the + domain's NS (and glue) records at this box's nameserver + hostname so the world finds it. +
  • +
  • + This complements provider integrations (Cloudflare etc.) — it + does not replace them. +
  • +
+
+
+ + setInstallForm((f) => ({ ...f, ns_hostname: e.target.value }))} + placeholder="ns1.example.com" + /> +

+ The hostname other resolvers will use to reach this server. + It should resolve (via glue records) to this box's public IP. +

+
+
+ + setInstallForm((f) => ({ ...f, admin_email: e.target.value }))} + placeholder="hostmaster@example.com" + /> +

Used in each zone's SOA record.

+
+
+ + +
+
+
+
+
+ ); + } + + return ( +
+ } + title="DNS Server" + actions={ + <> + + + + } + /> + + {/* ── Status ── */} +
+
+

Server Status

+
+ + +
+
+
+
+
+ Container + + {status.running ? 'Running' : 'Stopped'} + +
+
+ Engine + + PowerDNS Authoritative {status.version ? `v${status.version}` : '(version unavailable)'} + +
+
+ Nameserver + {status.ns_hostname || '—'} +
+
+ Mode + Authoritative only — no recursion, by design. +
+
+
+
+ + {/* ── Zones ── */} +
+
+

Zones {zones.length > 0 && · {zones.length}}

+
+ {zones.length === 0 ? ( +
+

+ No zones yet. Create one, then point the domain's nameservers here + at your registrar. +

+
+ ) : ( + + + + + + + + + + + + {zones.map((z) => ( + + + + + + + + ))} + +
ZoneKindSerialDNSSECActions
+ + {z.kind || '—'}{z.serial ?? '—'} + + {z.dnssec ? 'Signed' : 'Off'} + + + {' '} + +
+ )} +
+ + {/* ── Zone detail ── */} + {selectedZone && ( + setSelectedZone(null)} + onChanged={loadData} + /> + )} + + {/* ── New zone modal ── */} + setShowZoneModal(false)} title="New Zone"> +
+ + setZoneName(e.target.value)} + placeholder="example.com" + /> +

+ SOA and NS records are bootstrapped from the nameserver hostname and + hostmaster email you provided at install. +

+
+
+ + +
+
+ + {confirmDialog && ( + + )} +
+ ); +}; + +export default DnsServerPage; diff --git a/frontend/src/plugins/serverkit-dns-server/components/ZoneDetail.jsx b/frontend/src/plugins/serverkit-dns-server/components/ZoneDetail.jsx new file mode 100644 index 00000000..4d9a1fb3 --- /dev/null +++ b/frontend/src/plugins/serverkit-dns-server/components/ZoneDetail.jsx @@ -0,0 +1,333 @@ +import { useCallback, useEffect, useState } from 'react'; +import { RefreshCw, Plus, ShieldCheck, X } from 'lucide-react'; +import api from '@/services/api'; +import { Pill } from '@/components/ds'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue } from '@/components/ui/select'; +import Modal from '@/components/Modal'; +import ConfirmDialog from '@/components/ConfirmDialog'; +import { useToast } from '@/contexts/ToastContext'; + +const RECORD_TYPES = ['A', 'AAAA', 'CNAME', 'MX', 'TXT', 'NS', 'SRV', 'CAA', 'PTR']; +const EMPTY_FORM = { name: '', type: 'A', ttl: 3600, records: '' }; + +const ZoneDetail = ({ zoneName, onClose, onChanged }) => { + const toast = useToast(); + + const [zone, setZone] = useState(null); + const [dsRecords, setDsRecords] = useState([]); + const [delegation, setDelegation] = useState(null); + const [loading, setLoading] = useState(true); + const [actionLoading, setActionLoading] = useState(false); + const [confirmDialog, setConfirmDialog] = useState(null); + + // Record editor modal (add or edit — edit pre-fills, save is an upsert) + const [showRecordModal, setShowRecordModal] = useState(false); + const [recordForm, setRecordForm] = useState(EMPTY_FORM); + + const loadZone = useCallback(async () => { + setLoading(true); + try { + const data = await api.request(`/dns-server/zones/${encodeURIComponent(zoneName)}`); + setZone(data.zone || null); + setDsRecords(data.ds_records || []); + setDelegation(data.delegation || null); + } catch (error) { + toast.error(`Failed to load zone: ${error.message}`); + } finally { + setLoading(false); + } + }, [zoneName, toast]); + + useEffect(() => { + loadZone(); + }, [loadZone]); + + const openAdd = () => { + setRecordForm(EMPTY_FORM); + setShowRecordModal(true); + }; + + const openEdit = (rrset) => { + setRecordForm({ + name: rrset.name, + type: rrset.type, + ttl: rrset.ttl ?? 3600, + records: (rrset.records || []).join('\n'), + }); + setShowRecordModal(true); + }; + + const handleSaveRecord = async () => { + const values = recordForm.records.split('\n').map((v) => v.trim()).filter(Boolean); + if (!values.length) return; + setActionLoading(true); + try { + await api.request(`/dns-server/zones/${encodeURIComponent(zoneName)}/rrsets`, { + method: 'POST', + body: { + name: recordForm.name.trim(), + type: recordForm.type, + ttl: Number(recordForm.ttl) || 3600, + records: values, + }, + }); + toast.success(`${recordForm.type} record set saved`); + setShowRecordModal(false); + await loadZone(); + onChanged?.(); + } catch (error) { + toast.error(`Failed to save record set: ${error.message}`); + } finally { + setActionLoading(false); + } + }; + + const handleDeleteRecord = (rrset) => { + setConfirmDialog({ + title: 'Delete record set', + message: `Delete the ${rrset.type} record set for ${rrset.name}?`, + confirmText: 'Delete', + variant: 'danger', + onConfirm: async () => { + try { + const qs = `name=${encodeURIComponent(rrset.name)}&type=${encodeURIComponent(rrset.type)}`; + await api.request( + `/dns-server/zones/${encodeURIComponent(zoneName)}/rrsets?${qs}`, + { method: 'DELETE' } + ); + toast.success(`${rrset.type} record set deleted`); + await loadZone(); + onChanged?.(); + } catch (error) { + toast.error(`Failed to delete record set: ${error.message}`); + } + setConfirmDialog(null); + }, + onCancel: () => setConfirmDialog(null), + }); + }; + + const handleDnssec = async (enable) => { + setActionLoading(true); + try { + const res = await api.request(`/dns-server/zones/${encodeURIComponent(zoneName)}/dnssec`, { + method: 'POST', + body: { action: enable ? 'enable' : 'disable' }, + }); + toast.success(res.message || `DNSSEC ${enable ? 'enabled' : 'disabled'}`); + await loadZone(); + onChanged?.(); + } catch (error) { + toast.error(`DNSSEC update failed: ${error.message}`); + } finally { + setActionLoading(false); + } + }; + + return ( +
+
+

{zoneName}

+
+ + + +
+
+
+ {loading ? ( +

Loading zone...

+ ) : !zone ? ( +

Zone could not be loaded.

+ ) : ( + <> + {/* ── Delegation banner ── */} + {delegation && ( +
+ {delegation.checked === false ? ( + Delegation check unavailable: {delegation.note} + ) : delegation.delegated ? ( + + Delegation looks correct — the public NS set matches this + zone ({(delegation.public_ns || []).join(', ')}). + + ) : ( + + {delegation.note}{' '} + {delegation.public_ns?.length > 0 && ( + <>Public: {delegation.public_ns.join(', ')} · Zone:{' '} + {(delegation.zone_ns || []).join(', ') || 'none'} + )} + + )} +
+ )} + + {/* ── Records ── */} + + + + + + + + + + + + {(zone.rrsets || []).map((r) => ( + + + + + + + + ))} + +
NameTypeTTLValuesActions
{r.name}{r.type}{r.ttl ?? '—'} + {(r.records || []).map((v) =>
{v}
)} +
+ {' '} + {r.type !== 'SOA' && ( + + )} +
+ + {/* ── DNSSEC ── */} +
+
+

DNSSEC

+ + {zone.dnssec ? 'Enabled' : 'Disabled'} + + +
+ {zone.dnssec && ( + dsRecords.length > 0 ? ( +
+

+ Publish these DS records at your registrar (the parent + zone) to complete the chain of trust: +

+ {dsRecords.map((ds) => ( + {ds} + ))} +
+ ) : ( +

+ DNSSEC is enabled but no DS records were returned yet — + refresh in a moment. +

+ ) + )} +
+ + )} +
+ + {/* ── Record editor ── */} + setShowRecordModal(false)} + title={`${recordForm.name ? 'Edit' : 'Add'} Record Set`} + > +
+ + setRecordForm((f) => ({ ...f, name: e.target.value }))} + placeholder={`@ or www (relative to ${zoneName})`} + /> +
+
+ + +
+
+ + setRecordForm((f) => ({ ...f, ttl: e.target.value }))} + /> +
+
+ +