// A server's lines as Java's server windows write them (ServerAnwendung, // ServerMitarbeiter, TCPSocket's failures), and the generic client's as its // window writes them (ClientBaustein, Socket, TCPSocket), in the person's // language: one line each (a failed connection two), as Java appends them to // its window's text area. And a computer's firewall's log as its window // writes it (Firewall.benachrichtigeBeobachter, GUIApplicationFirewallWindow). import { firewallRuleText, PORT_RULE_PROTOCOL_NAMES, type FirewallLogEntry, type ServerLogEntry, type SimpleClientLogEntry } from '@mdg-filius/core'; import type { Translate } from '../i18n/i18n.js'; export function serverLine(entry: ServerLogEntry, t: Translate): string { switch (entry.kind) { case 'acceptingStarted': case 'acceptingStopped': case 'serverSocketClosed': case 'serverSocketFailed': return t(`server.${entry.kind}`); case 'connectionAccepted': case 'connectionClosed': return t(`server.${entry.kind}`, { address: `${entry.address}:${entry.port}` }); case 'received': return `>>${entry.text}`; case 'sent': return `<<${entry.text}`; case 'sendFailed': return t(`server.sendFailed.${entry.failure}`); } } export function simpleClientLine(entry: SimpleClientLogEntry, t: Translate): string { switch (entry.kind) { case 'connected': case 'disconnected': case 'notConnected': case 'receiveFailed': return t(`simpleClient.${entry.kind}`); case 'connectFailed': return `${t('simpleClient.notConnected')}\n${t(`simpleClient.failure.${entry.failure}`)}`; case 'connectionClosed': return t('simpleClient.connectionClosed', { address: `${entry.address}:${entry.port}` }); case 'received': return `>>${entry.text}`; case 'sent': return `<<${entry.text}`; case 'sendFailed': return t(`server.sendFailed.${entry.failure}`); } } export function firewallLine(entry: FirewallLogEntry, t: Translate): string { switch (entry.kind) { case 'ruleMatched': return t('personalFirewall.ruleMatched', { number: entry.ruleNumber, rule: firewallRuleText(entry.rule, entry.firstInterface), action: t(entry.accepted ? 'firewall.accept' : 'firewall.drop'), }); case 'icmpDropped': return t('personalFirewall.icmpDropped', { sender: entry.senderIPAddress, receiver: entry.receiverIPAddress, code: entry.code, type: entry.type }); case 'portRuleAdded': return t('personalFirewall.portRuleAdded', { port: entry.port, protocol: PORT_RULE_PROTOCOL_NAMES[entry.protocol] }); case 'portRuleRemoved': return t('personalFirewall.portRuleRemoved'); } }