Hub 2.20.0: port list labels; frps allow_ports checked against it

- GET /api/admin/ports names each port's install (church, product, web/API, domain); the port
  list shows it, linked to the install, and says which ports are held for a port check.
- A church server's hand-written frpc tunnels are listed as taken (note: frpc tunnel "<name>" on
  <server>) on each frp-read/frp-write, and taken off when they leave the file.
- Central servers: allow_ports must cover the port range and every listed port outside it. An
  allow_ports alert names what's missing and the value to set; the frp card warns, and Edit has
  "Use the Hub's allow_ports" (INI or TOML).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 13:45:30 +02:00
co-authored by Claude Opus 5.5
parent 11c3259dab
commit 308d4e42ba
13 changed files with 391 additions and 12 deletions
+50
View File
@@ -1115,3 +1115,53 @@ describe('a second product while another is being uninstalled (2.12.0)', () => {
expect(mockMails.some(m => m.subject.includes('Uninstalled: hope') && m.text.includes('folder and app user'))).toBe(true);
});
});
describe('frps allow_ports and port labels (Hub 2.20.0)', () => {
const frpcIni = [
'[common]', 'server_port = 7000', 'token = ••••••', '',
'[events-frontend]', 'type = tcp', 'local_port = 3000', 'remote_port = 3000', '',
'[games-night]', 'type = tcp', 'local_port = 3201', 'remote_port = 3201', '',
'# >>> crosscode:hope:events', '[hope-events-web]', 'type = tcp', 'local_port = 20000', 'remote_port = 20000', '# <<< crosscode:hope:events', '',
].join('\n');
const read = content => ({ service: 'frpc', path: '/etc/frp/frpc.ini', source: 'systemd', found: true, format: 'ini', content, hidden: ['token'], proxyBindAddr: null, allowPorts: null, serviceRunning: true, readAt: NOW.toISOString() });
test("a church server's hand-written tunnels are listed as taken, and taken off when they go", async () => {
const { server } = await joinServer();
await db.port.create({ data: { port: 20000, serverId: server.id, role: 'web', deploymentId: 'dep-1' } });
await db.port.create({ data: { port: 3201, role: 'taken', note: 'mine' } });
await jobs.listFrpcTunnels(server.id, read(frpcIni), NOW);
const rows = Object.fromEntries((await db.port.findMany({})).map(r => [r.port, r]));
expect(rows[3000]).toMatchObject({ role: 'taken', serverId: server.id, note: 'frpc tunnel "events-frontend" on church-1' });
expect(rows[3201].note).toBe('mine'); // marked by hand: left as it is
expect(rows[20000]).toMatchObject({ role: 'web', deploymentId: 'dep-1' }); // an install's
await jobs.listFrpcTunnels(server.id, read(frpcIni.replace('remote_port = 3000', 'remote_port = 3005')), NOW);
const after = (await db.port.findMany({})).map(r => r.port).sort((a, b) => a - b);
expect(after).toEqual([3005, 3201, 20000]);
// A central server's frps config lists nothing.
const central = (await joinServer('central', 'central-1')).server;
await jobs.listFrpcTunnels(central.id, read('[common]\n[x]\nremote_port = 4444\n'), NOW);
expect(await db.port.findUnique({ where: { port: 4444 } })).toBeNull();
});
test('the central server is warned when allow_ports leaves out the range or a listed port', async () => {
const central = (await joinServer('central', 'central-1')).server;
await db.port.create({ data: { port: 3000, role: 'taken', note: 'frpc tunnel "events-frontend" on church-1' } });
await db.port.create({ data: { port: 5000, role: 'taken', releasedAt: NOW } });
const check = await servers.allowPortsCheck('3000,20000-20007');
expect(check).toMatchObject({ needed: '3000,20000-29999', missing: '20008-29999', suggested: '3000,20000-29999' });
expect((await servers.allowPortsCheck('3000,20000-29999')).missing).toBe('');
expect((await servers.allowPortsCheck(null)).missing).toBe('');
await db.server.update({ where: { id: central.id }, data: { lastSeenAt: NOW, lastStats: { disks: [], frpConfigPath: '/etc/frp/frps.ini', central: { proxyBindAddr: '127.0.0.1', allowPorts: '20000-29999', frpsRunning: true } } } });
await servers.runServerAlerts(NOW);
const alert = await db.serverAlert.findFirst({ where: { serverId: central.id, type: 'allow_ports' } });
expect(alert.message).toContain("doesn't allow 3000");
expect(alert.message).toContain('Set it to 3000,20000-29999');
await db.server.update({ where: { id: central.id }, data: { lastStats: { disks: [], frpConfigPath: '/etc/frp/frps.ini', central: { proxyBindAddr: '127.0.0.1', allowPorts: '3000,20000-29999', frpsRunning: true } } } });
await servers.runServerAlerts(NOW);
expect((await db.serverAlert.findFirst({ where: { serverId: central.id, type: 'allow_ports' } })).resolvedAt).toEqual(NOW);
});
});