Port presets: Windows client, Windows server and Debian / Ubuntu
Ready-made presets for what each OS has open out of the box. They are added once to installs that already have presets (same-name presets untouched, emptied list stays empty); a test checks no port is given two names across presets. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
06ac120a1d
commit
94288afcbd
4 files changed
+100
-10
No files matched your search
@@ -25,8 +25,12 @@ 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 });
|
||||
/** A run of ports with one name: the dynamic RPC ports Windows listens on, 49664–49670. */
|
||||
const run = (from: number, to: number, label: string): PresetPort[] => Array.from({ length: to - from + 1 }, (_, i) => tcp(from + i, label));
|
||||
|
||||
/** What is there to begin with. */
|
||||
export const STARTER_PRESETS: { name: string; ports: PresetPort[] }[] = [
|
||||
@@ -37,6 +41,38 @@ export const STARTER_PRESETS: { name: string; ports: PresetPort[] }[] = [
|
||||
{ name: "Homelab tools", ports: [tcp(3000, "Grafana"), tcp(5000, "Synology DSM"), tcp(5001, "Synology DSM (HTTPS)"), tcp(8006, "Proxmox VE"), tcp(8007, "Proxmox Backup Server"), tcp(9090, "Prometheus")] },
|
||||
];
|
||||
|
||||
/**
|
||||
* What a machine has open out of the box, by operating system. These came later than the five above, so they are put there once more (see ensureStarters), into a list that is already in use.
|
||||
* A port that other presets name too is called the same thing here, so it is never called two names; the ones named only here are what is new.
|
||||
*/
|
||||
export const OS_PRESETS: { name: string; ports: PresetPort[] }[] = [
|
||||
{
|
||||
name: "Windows client",
|
||||
ports: [
|
||||
tcp(135, "RPC endpoint mapper"), tcp(139, "NetBIOS"), tcp(445, "SMB"), tcp(2869, "UPnP device host"), tcp(3389, "RDP"), tcp(5040, "Device association (CDPSvc)"), tcp(5357, "Web Services for Devices"),
|
||||
tcp(5985, "WinRM (HTTP)"), tcp(5986, "WinRM (HTTPS)"), tcp(7680, "Delivery Optimization"), ...run(49664, 49670, "RPC (dynamic)"),
|
||||
udp(137, "NetBIOS name"), udp(138, "NetBIOS datagram"), udp(1900, "SSDP (UPnP discovery)"), udp(3702, "WS-Discovery"), udp(5353, "mDNS"), udp(5355, "LLMNR"),
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Windows server",
|
||||
ports: [
|
||||
tcp(53, "DNS"), tcp(80, "HTTP"), tcp(88, "Kerberos"), tcp(135, "RPC endpoint mapper"), tcp(139, "NetBIOS"), tcp(389, "LDAP"), tcp(443, "HTTPS"), tcp(445, "SMB"), tcp(464, "Kerberos password change"),
|
||||
tcp(593, "RPC over HTTP"), tcp(636, "LDAPS"), tcp(1688, "KMS activation"), tcp(2179, "Hyper-V VM console"), tcp(3268, "Global Catalog"), tcp(3269, "Global Catalog (SSL)"), tcp(3389, "RDP"),
|
||||
tcp(5722, "DFS Replication"), tcp(5985, "WinRM (HTTP)"), tcp(5986, "WinRM (HTTPS)"), tcp(8530, "WSUS"), tcp(8531, "WSUS (HTTPS)"), tcp(9389, "AD Web Services"), tcp(47001, "WinRM (HTTP.sys)"),
|
||||
...run(49664, 49670, "RPC (dynamic)"),
|
||||
udp(53, "DNS"), udp(67, "DHCP server"), udp(88, "Kerberos"), udp(123, "NTP"), udp(137, "NetBIOS name"), udp(138, "NetBIOS datagram"), udp(389, "LDAP"), udp(464, "Kerberos password change"), udp(5355, "LLMNR"),
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Debian / Ubuntu",
|
||||
ports: [
|
||||
tcp(22, "SSH"), tcp(25, "SMTP"), tcp(53, "DNS"), tcp(111, "rpcbind"), tcp(631, "CUPS (printing)"), tcp(5355, "LLMNR"),
|
||||
udp(53, "DNS"), udp(68, "DHCP client"), udp(111, "rpcbind"), udp(123, "NTP"), udp(161, "SNMP"), udp(323, "NTP (chrony)"), udp(5353, "mDNS"), udp(5355, "LLMNR"), udp(41641, "Tailscale"),
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
function parsePorts(stored: string): PresetPort[] {
|
||||
try {
|
||||
const v = JSON.parse(stored);
|
||||
@@ -51,15 +87,26 @@ 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. */
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
async function ensureStarters(): Promise<void> {
|
||||
if ((await getInternalFlag(SEEDED_FLAG)) !== null) return;
|
||||
const existing = await db.select({ id: portPresets.id }).from(portPresets).limit(1);
|
||||
if (existing.length === 0) {
|
||||
const now = new Date().toISOString();
|
||||
for (const p of STARTER_PRESETS) await db.insert(portPresets).values({ name: p.name, ports: JSON.stringify(p.ports), createdAt: now, updatedAt: now });
|
||||
const first = (await getInternalFlag(SEEDED_FLAG)) === null;
|
||||
const osDone = (await getInternalFlag(OS_SEEDED_FLAG)) !== null;
|
||||
if (!first && osDone) 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);
|
||||
await setInternalFlag(SEEDED_FLAG, now);
|
||||
await setInternalFlag(OS_SEEDED_FLAG, now);
|
||||
return;
|
||||
}
|
||||
await setInternalFlag(SEEDED_FLAG, new Date().toISOString());
|
||||
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);
|
||||
}
|
||||
|
||||
/** Every preset, by name. */
|
||||
|
||||
Reference in new issue
Block a user