Files
db9979andClaude Opus 5.5 938a3db14d Styled operator mails: console look with tables, links and a text part
Every mail to the admin now goes out as multipart text + HTML in the same
phosphor-console look as the player mails: watchdog alert, recovery and
daily report, the host health-check alert (scripts/alert.ts), the nightly
bot-arena report and the weekly backup restore test. Status banner by tone,
data blocks as tables (per mission, every game, row counts per table),
command output as colored log blocks, buttons to the admin area and
/api/health. Subjects are unchanged so mail filters keep working.

- mail-frame.ts: shared frame (strip, sonar header, VON/AN/BETR, footer),
  used by the player mails too; their text part now shows callsigns
  unescaped
- admin-mail.ts: renderer for operator reports; every value is escaped,
  links must be http(s), only the origin of PUBLIC_URL is linked
- admin-mails.ts: the concrete reports, parsing the arena and restore
  output into tables
- Watchdog SendFn now takes the rendered mail content
- scripts/mail-preview.ts renders every mail with sample data to HTML
- Tests for escaping, link safety, multipart and all fields of each mail

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 10:23:06 +01:00

34 lines
1.4 KiB
TypeScript

/**
* Send one operator mail with the game server's mail settings (SMTP_* in .env).
* Recipient: ALERT_TO, else MAIL_FROM, else SMTP_USER. Used by scripts/healthcheck.sh on the
* host, in a fresh container, so it works even when the game container is down:
* docker compose run --rm --no-deps -T -w /app tiefenkontakt node --import tsx scripts/alert.ts "Betreff" "Text"
* Without a text argument the body is read from stdin. Exit code 1 if the mail could not be sent.
*/
import { alertRecipient } from '../apps/server/src/alerts.js';
import { adminMail } from '../apps/server/src/admin-mail.js';
import { operatorAlert } from '../apps/server/src/admin-mails.js';
import { createMailer } from '../apps/server/src/mailer.js';
const [subject, bodyArg] = process.argv.slice(2);
if (!subject) {
console.error('Aufruf: alert.ts "Betreff" ["Text"] (ohne Text: von stdin)');
process.exit(2);
}
let text = bodyArg ?? '';
if (bodyArg === undefined && !process.stdin.isTTY) {
for await (const c of process.stdin) text += String(c);
}
const to = alertRecipient();
if (!to) {
console.log(`Kein Empfänger (ALERT_TO / MAIL_FROM): ${subject}\n${text}`);
process.exit(0);
}
try {
await createMailer().send(adminMail(to, operatorAlert(subject, text || subject, process.env.PUBLIC_URL)));
console.log(`Alarm-Mail an ${to}: ${subject}`);
} catch (e) {
console.error(`Alarm-Mail fehlgeschlagen: ${(e as Error).message}`);
process.exit(1);
}