About: name the webmail node and the mail server node
ci / version (pull_request) Skipped
ci / node (pull_request) Successful in 2m26s
ci / publish (pull_request) Skipped
ci / docker-build (pull_request) Successful in 53s

Settings > About shows which webmail node answered (NODE_NAME, else the
container hostname) and which inbuxa node it talks to: the address the
server's name resolves to from the webmail, named by its PTR record. The
server only tells administrators its node name, so the webmail works it
out itself. Fetched from /api/about/nodes on every visit, cached for a
minute server-side, for troubleshooting a cluster.

Fork-only: upstream ihasmail runs one webmail against one server.
4 new strings, translated in all 9 catalogues.
This commit is contained in:
jcoffey-dev committed 2026-09-25 20:46:04 -07:00
1 parent 119548090e
commit 6b44705bfd
14 files changed
+189 -1

No files matched your search

+7
View File
@@ -44,6 +44,7 @@ import { imageProxyHandler } from "./imageproxy.js";
import { SignInError, finish as finishSignIn, needsRefresh, oauthEnabled, refreshTokens, singleServer, start as startSignIn, type TokenSet } from "./oauth.js";
import { icsProxyHandler } from "./icsproxy.js";
import { staticHandler } from "./static.js";
import { mailNode, webmailNode } from "./nodes.js";
type Env = { Variables: { session: LiveSession } };
@@ -609,6 +610,12 @@ export function createApp(basePath = config.basePath): Hono<Env> {
return c.json({ ok: true });
});
/* ihasmail-inbuxa: which webmail node this is, and which mail node it talks to (nodes.ts). */
api.get("/about/nodes", requireSession, async (c) => {
const session = c.get("session");
return c.json({ webmail: webmailNode(), mailServer: await mailNode(upstreamFor(session.username)) });
});
api.get("/auth/sessions", requireSession, (c) => {
const session = c.get("session");
return c.json({ current: session.id, sessions: sessions.listForUser(session.account) });
+6
View File
@@ -296,6 +296,12 @@ export const config = {
* such a tree, so the default is INBUXA's fork.
*/
sourceUrl: env("SOURCE_URL", "https://git.coffeylabs.org/inbuxa/ihasmail-inbuxa"),
/**
* ihasmail-inbuxa: this webmail's own name, shown in Settings > About next
* to the mail node it talks to. Set per host by the deploy; empty means the
* container's hostname. See nodes.ts.
*/
nodeName: env("NODE_NAME", ""),
host: env("HOST", "0.0.0.0"),
port: int("PORT", 8080),
/**
+40
View File
@@ -0,0 +1,40 @@
import { test, beforeEach } from "node:test";
import assert from "node:assert/strict";
import { clearNodeCache, mailNode } from "./nodes.js";
/**
* About names the mail node by the PTR of the address the server's name
* resolves to from the webmail -- the local node, where a host entry pins it.
*/
beforeEach(() => clearNodeCache());
const lookup = (address: string) => async () => ({ address });
test("the node is named by its address's PTR, without the trailing dot", async () => {
const n = await mailNode("https://mail.example.com", lookup("192.0.2.2"), async () => ["mx2.example.com."]);
assert.deepEqual(n, { host: "mail.example.com", address: "192.0.2.2", name: "mx2.example.com" });
});
test("an address without a PTR still shows the address", async () => {
const n = await mailNode("https://mail.example.com", lookup("192.0.2.3"), async () => { throw new Error("ENOTFOUND"); });
assert.deepEqual(n, { host: "mail.example.com", address: "192.0.2.3", name: null });
});
test("a name that doesn't resolve says so instead of failing", async () => {
let reversed = false;
const n = await mailNode("https://mail.example.com", async () => { throw new Error("ENOTFOUND"); }, async () => { reversed = true; return []; });
assert.deepEqual(n, { host: "mail.example.com", address: null, name: null });
assert.equal(reversed, false);
});
test("the answer is cached for a minute, then looked up again", async () => {
let calls = 0;
const count = async () => { calls++; return { address: "192.0.2.1" }; };
const rev = async () => ["mail.example.com"];
await mailNode("https://mail.example.com", count, rev, 0);
await mailNode("https://mail.example.com", count, rev, 59_000);
assert.equal(calls, 1);
await mailNode("https://mail.example.com", count, rev, 61_000);
assert.equal(calls, 2);
});
+68
View File
@@ -0,0 +1,68 @@
/**
* ihasmail-inbuxa: which webmail node answered, and which inbuxa node it talks
* to -- shown in Settings > About, for troubleshooting a cluster.
*
* Not for upstream ihasmail: it only makes sense where one webmail runs per
* host, each pinned to its own host's mail node.
*
* The webmail node is NODE_NAME, set per host by the deploy; without it, the
* container's hostname, which is at least distinct. The mail node is worked
* out from the address the server's name resolves to *here*, where the host
* entry pins it to the local node, named by that address's PTR record (every
* node has one: mail/mx2/mx3). The server offers its node name only to
* administrators, so asking it would leave everyone else with nothing.
*/
import { lookup as dnsLookup, reverse as dnsReverse } from "node:dns/promises";
import { hostname } from "node:os";
import { config } from "./config.js";
export interface MailNode {
/** The server name the webmail connects to, from its configured URL. */
host: string;
/** What that name resolves to from this container, or null if it doesn't. */
address: string | null;
/** The address's PTR name: the node's own name. Null without a PTR. */
name: string | null;
}
export interface Nodes {
webmail: string;
mailServer: MailNode;
}
type Lookup = (host: string) => Promise<{ address: string }>;
type Reverse = (address: string) => Promise<string[]>;
const CACHE_MS = 60_000;
const cache = new Map<string, { node: MailNode; at: number }>();
export function webmailNode(): string {
return config.nodeName || hostname();
}
export async function mailNode(base: string, lookup: Lookup = dnsLookup, reverse: Reverse = dnsReverse, now = Date.now()): Promise<MailNode> {
const host = new URL(base).hostname;
const hit = cache.get(host);
if (hit && now - hit.at < CACHE_MS) return hit.node;
let address: string | null = null;
let name: string | null = null;
try {
address = (await lookup(host)).address;
} catch {
/* unresolvable: say so rather than fail the page */
}
if (address) {
try {
name = (await reverse(address))[0]?.replace(/\.$/, "") ?? null;
} catch {
/* no PTR */
}
}
const node = { host, address, name };
cache.set(host, { node, at: now });
return node;
}
export function clearNodeCache(): void {
cache.clear();
}