Files
housecarl/internal/web/static/assets/pages/zones.js
T
abrown38andClaude Opus 5.5 34292eeebb Build Housecarl 0.1.0: the nftables firewall manager
Zones, address sets (IPv4 and IPv6 mixed, dynamic sets with timeouts) and
services, ordered rules in the early, input, forward and output chains,
port forwards with hairpin NAT and IPv6 pinholes, source NAT, redirects,
and switchable built-ins (loopback, conntrack, ICMPv6, antispoofing, MSS
clamping, DHCPv6 client, flowtable). Every change is validated, checked
with nft -c and applied in one transaction to Housecarl's own table,
inet housecarl; changes made over the network roll back unless
confirmed, and the confirmed ruleset is loaded at boot by
housecarl-ruleset.service. An empty configuration applies nothing.

Also: hit counters and the drop log (nflog), 'hc import' of an existing
nftables ruleset and 'hc takeover', the hc CLI, the REST API and the web
UI, users, scoped tokens (sets:write:NAME), the audit log, the web UI's
certificate through Jarl, Debian packages, docs, unit tests with real
nft 1.1.3, and an e2e test with real traffic (71 checks).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 07:57:14 +01:00

56 lines
3.4 KiB
JavaScript

// Zones: groups of interfaces, and the machine's interfaces.
import { h, mount, table, modal, errorBox, field, input, checkbox, confirmDialog, badge } from "../ui.js";
import { get, change, can } from "../api.js";
import { rerender } from "../app.js";
import { listEditor } from "../widgets.js";
export async function render(el) {
const [zones, ifs] = await Promise.all([get("/zones"), get("/interfaces")]);
const write = can("config", true);
mount(el,
h("div", { class: "page-head" },
h("div", { class: "grow" }, h("h1", null, "Zones"), h("div", { class: "muted" }, "Groups of interfaces that rules name. External zones face the internet: antispoofing, MSS clamping and port forwards apply there.")),
write ? h("div", { class: "actions" }, h("button", { class: "primary", onclick: () => zoneDialog(null, ifs) }, "Add zone")) : null),
h("div", { class: "panel" }, table([
{ label: "Name", render: (z) => h("strong", null, z.name) },
{ label: "Interfaces", render: (z) => h("span", { class: "mono" }, z.interfaces.join(", ")) },
{ label: "", render: (z) => z.external ? badge("external", "warn") : badge("internal", "") },
{ label: "Comment", render: (z) => z.comment },
write ? { label: "", tdClass: "actions-cell", render: (z) => [
h("button", { class: "small reveal", onclick: () => zoneDialog(z, ifs) }, "Edit"), " ",
h("button", { class: "small reveal", onclick: () => del(z) }, "Delete")] } : null,
].filter(Boolean), zones, { empty: "No zones yet: add one per network (wan, lan, guest…)." })),
h("div", { class: "panel" }, h("h2", null, "This machine's interfaces"), table([
{ label: "Interface", render: (i) => h("span", { class: "mono" }, i.name) },
{ label: "State", render: (i) => badge(i.up ? "up" : "down", i.up ? "ok" : "") },
{ label: "Zone", render: (i) => i.zone || h("span", { class: "muted" }, "none") },
{ label: "Addresses", render: (i) => h("span", { class: "mono small" }, i.addresses.join(", ")) },
], ifs)));
}
async function del(z) {
if (!await confirmDialog("Delete zone", "Delete zone " + z.name + "?", "Delete", "danger")) return;
try { await change("DELETE", "/zones/" + z.id); rerender(); } catch (e) { modal("Not deleted", errorBox(e)); }
}
async function zoneDialog(z, ifs) {
z = z || { interfaces: [] };
const name = input({ value: z.name || "", placeholder: "wan, lan, guest" });
const list = listEditor(z.interfaces, { suggestions: ifs.map((i) => i.name), placeholder: "eth0, or incusbr* for many", addLabel: "Add interface" });
const ext = checkbox("external: faces the internet", z.external);
const comment = input({ value: z.comment || "" });
const err = h("div");
await modal(z.id ? "Edit zone " + z.name : "Add zone", h("div", null, h("div", { class: "form-grid" },
field("Name", name), field("Interfaces", list, "A trailing * matches many (incusbr*)."), h("label"), ext, field("Comment", comment)), err), [
{ label: "Cancel", value: null },
{ label: z.id ? "Save" : "Add zone", kind: "primary", onclick: async () => {
mount(err);
try {
await change(z.id ? "PATCH" : "POST", z.id ? "/zones/" + z.id : "/zones", { name: name.value.trim(), interfaces: list.value(), external: ext.input.checked, comment: comment.value.trim() });
rerender();
return true;
} catch (e) { mount(err, errorBox(e)); return false; }
} },
], { sticky: true });
}