Let an administrator set a server's hostname by hand

A Change link on the Identity card sets the hostname (a host name or an
address, written lower case without the trailing dot). It is then kept even
when the agent reports another — marked "set by hand", with what the agent
reports shown beside it — until "Use what the agent reports" gives it up. The
agent's own hostname is always remembered (reported_hostname). PUT and DELETE
/api/servers/:id/hostname, administrators only, audited with from and to.
Migration 0082 adds hostname_pinned and reported_hostname and fills the latter
for servers that have reported. It changes this app's name for the server, not
the machine's.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-01 23:30:31 +01:00
1 parent 6f144b4e36
commit 672c7f2f66
14 files changed
+9020 -7

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
/**
* The hostname a server is given by hand. It is how this app names the machine to the rest of the world — to match it to a DNS name or a monitor, and to reach it — so it is a host name
* (letters, digits, `-` and `_`, in labels of up to 63 characters, a name of up to 253) or an address, written the way names are compared: lower case, no dot at the end.
*/
import * as net from "node:net";
const LABEL = /^[a-z0-9_]([a-z0-9_-]{0,61}[a-z0-9_])?$/;
/** The hostname as it is to be kept, or null when it is not one. */
export function normaliseHostname(input: string): string | null {
const s = input.trim().toLowerCase().replace(/\.$/, "");
if (s === "" || s.length > 253) return null;
if (net.isIP(s) !== 0) return s;
return s.split(".").every((label) => LABEL.test(label)) ? s : null;
}