From 42f33840a5366dfa4c84d73e05219c00fc8295e7 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Wed, 9 Sep 2026 07:20:24 +0200 Subject: [PATCH] Add opt-in connection logging (LOG_CONNECTIONS env var) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Off by default — this is an open-source, self-hostable image, so other instances shouldn't get connection logging just because it's in the codebase. Set LOG_CONNECTIONS=1 in an instance's .env to log a single line per TS3/TeaSpeak connect and disconnect (host, server name, timestamp — no nickname, no IP). --- gateway/src/index.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/gateway/src/index.ts b/gateway/src/index.ts index 536f56a..16db992 100644 --- a/gateway/src/index.ts +++ b/gateway/src/index.ts @@ -22,6 +22,12 @@ function parsePrivilegeKey(msg: { privilegeKey?: unknown; token?: unknown }): st const PORT = Number(process.env.PORT ?? 8080); +// Opt-in only, off by default: this is an open-source, self-hostable image, +// and other instances shouldn't get connection logging just because it's in +// the codebase. Set LOG_CONNECTIONS=1 in the .env of the instance you want it +// on. Logs only host/server-name/timestamp — no nickname, no IP. +const LOG_CONNECTIONS = process.env.LOG_CONNECTIONS === "1"; + // In production (Docker), the built web app lives alongside the gateway and // is served from the same port as the WebSocket endpoint, so a single // reverse-proxied origin (e.g. a Zoraxy subdomain) is enough for everything. @@ -164,7 +170,18 @@ wss.on("connection", (socket: WebSocket) => { privilegeKey: parsePrivilegeKey(msg), }; connection = new Ts3Connection(options); - connection.onEvent((event) => socket.send(JSON.stringify(event))); + connection.onEvent((event) => { + if (LOG_CONNECTIONS) { + if (event.type === "connected") { + console.log( + `[connections] connected host=${options.host} server=${event.serverName} at=${new Date().toISOString()}` + ); + } else if (event.type === "disconnected") { + console.log(`[connections] disconnected host=${options.host} at=${new Date().toISOString()}`); + } + } + socket.send(JSON.stringify(event)); + }); await connection.connect(); break; }