Port presets: Network services and Tailscale

Two more ready-made presets, added once to installs that already have presets.
Later batches now each have their own flag (LATER_BATCHES), so the next one is
a list entry rather than new seeding code.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-16 23:47:28 +01:00
1 parent 94288afcbd
commit b8ce337dfb
4 files changed
+58 -21

No files matched your search

+34 -9
View File
@@ -25,7 +25,6 @@ export interface PortPreset {
export const MAX_PRESET_PORTS = 60;
const SEEDED_FLAG = "portPresetsSeeded";
const OS_SEEDED_FLAG = "portPresetsOsSeeded";
const tcp = (port: number, label: string): PresetPort => ({ port, protocol: "tcp", label });
const udp = (port: number, label: string): PresetPort => ({ port, protocol: "udp", label });
@@ -73,6 +72,29 @@ export const OS_PRESETS: { name: string; ports: PresetPort[] }[] = [
},
];
/**
* The network's own services, and Tailscale. Tailscale makes few ports of its own that a scan can find — it talks out, and on a port picked at run time — so what is named here is the direct
* WireGuard port an agent reports and the ports Serve and Funnel answer on. 8443 keeps the name the Web preset gives it: a name given here would be given to it on every host.
*/
export const NETWORK_PRESETS: { name: string; ports: PresetPort[] }[] = [
{
name: "Network services",
ports: [
tcp(22, "SSH"), tcp(23, "Telnet"), tcp(53, "DNS"), tcp(179, "BGP"), tcp(853, "DNS over TLS"), tcp(1723, "PPTP"), tcp(5201, "iperf3"), tcp(8291, "MikroTik Winbox"), tcp(8728, "MikroTik API"), tcp(8729, "MikroTik API (SSL)"),
udp(53, "DNS"), udp(67, "DHCP server"), udp(68, "DHCP client"), udp(69, "TFTP"), udp(123, "NTP"), udp(161, "SNMP"), udp(162, "SNMP trap"), udp(500, "IPsec (IKE)"), udp(514, "Syslog"), udp(520, "RIP"),
udp(546, "DHCPv6 client"), udp(547, "DHCPv6 server"), udp(1194, "OpenVPN"), udp(1701, "L2TP"), udp(1812, "RADIUS"), udp(1813, "RADIUS accounting"), udp(1900, "SSDP (UPnP discovery)"), udp(3478, "STUN"),
udp(4500, "IPsec (NAT traversal)"), udp(5201, "iperf3"), udp(5353, "mDNS"), udp(51820, "WireGuard"),
],
},
{ name: "Tailscale", ports: [tcp(22, "SSH"), tcp(443, "HTTPS"), tcp(8443, "HTTPS (alternate)"), udp(3478, "STUN"), udp(41641, "Tailscale")] },
];
/** The presets that came after the first five, each batch with the flag that says it has been put there. */
const LATER_BATCHES: { flag: string; presets: { name: string; ports: PresetPort[] }[] }[] = [
{ flag: "portPresetsOsSeeded", presets: OS_PRESETS },
{ flag: "portPresetsNetworkSeeded", presets: NETWORK_PRESETS },
];
function parsePorts(stored: string): PresetPort[] {
try {
const v = JSON.parse(stored);
@@ -88,25 +110,28 @@ function parsePorts(stored: string): PresetPort[] {
const rowToPreset = (r: typeof portPresets.$inferSelect): PortPreset => ({ id: r.id, name: r.name, ports: parsePorts(r.ports), updatedAt: r.updatedAt });
/**
* Puts the ready-made presets there, once: the first time, and only into an empty list. The operating-system ones are put there once as well, and in a list that is already in use
* only the ones whose name is not taken (whatever its case) — an empty list stays empty, since somebody cleared it — so a preset deleted afterwards is not put back.
* Puts the ready-made presets there, once: the first time, and only into an empty list. The ones that came later (LATER_BATCHES) are put there once as well, and in a list that is already
* in use only those whose name is not taken (whatever its case) — an empty list stays empty, since somebody cleared it — so a preset deleted afterwards is not put back.
*/
async function ensureStarters(): Promise<void> {
const first = (await getInternalFlag(SEEDED_FLAG)) === null;
const osDone = (await getInternalFlag(OS_SEEDED_FLAG)) !== null;
if (!first && osDone) return;
const due = [];
for (const b of LATER_BATCHES) if ((await getInternalFlag(b.flag)) === null) due.push(b);
if (!first && due.length === 0) return;
const now = new Date().toISOString();
const add = (p: { name: string; ports: PresetPort[] }) => db.insert(portPresets).values({ name: p.name, ports: JSON.stringify(p.ports), createdAt: now, updatedAt: now });
const existing = await db.select({ name: portPresets.name }).from(portPresets);
if (first) {
if (existing.length === 0) for (const p of [...STARTER_PRESETS, ...OS_PRESETS]) await add(p);
if (existing.length === 0) for (const p of [...STARTER_PRESETS, ...LATER_BATCHES.flatMap((b) => b.presets)]) await add(p);
await setInternalFlag(SEEDED_FLAG, now);
await setInternalFlag(OS_SEEDED_FLAG, now);
for (const b of LATER_BATCHES) await setInternalFlag(b.flag, now);
return;
}
const taken = new Set(existing.map((e) => e.name.toLowerCase()));
if (existing.length > 0) for (const p of OS_PRESETS) if (!taken.has(p.name.toLowerCase())) await add(p);
await setInternalFlag(OS_SEEDED_FLAG, now);
for (const b of due) {
if (existing.length > 0) for (const p of b.presets) if (!taken.has(p.name.toLowerCase())) await add(p);
await setInternalFlag(b.flag, now);
}
}
/** Every preset, by name. */