From fcc95414e6a60d696a8cb0ff733f82b46468ff11 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Mon, 23 Mar 2026 13:53:05 +0100 Subject: [PATCH] now? --- server/helpers.js | 21 ++++++++++----------- server/index.js | 5 ++--- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/server/helpers.js b/server/helpers.js index fcb6876..eb1431f 100644 --- a/server/helpers.js +++ b/server/helpers.js @@ -143,20 +143,20 @@ function handleConnect(clientIp, currentUsers, ws, callback) { consoleCmd.logWarn('geoip-lite is not installed; location will be Unknown.'); } - const inFlightPromise = fetchIpWhoisInfo(normalizedClientIp) + const inFlightPromise = fetchIpWhoisInfo(clientIp) .then((whoisInfo) => { const merged = { ...locationInfo, ...whoisInfo }; - ipCache.set(normalizedClientIp, merged); - ipInfoInFlight.delete(normalizedClientIp); + ipCache.set(clientIp, merged); + ipInfoInFlight.delete(clientIp); return merged; }) .catch(() => { - ipCache.set(normalizedClientIp, locationInfo); - ipInfoInFlight.delete(normalizedClientIp); + ipCache.set(clientIp, locationInfo); + ipInfoInFlight.delete(clientIp); return locationInfo; }); - ipInfoInFlight.set(normalizedClientIp, inFlightPromise); + ipInfoInFlight.set(clientIp, inFlightPromise); inFlightPromise.then((info) => processConnection(clientIp, info, currentUsers, ws, callback)); } @@ -332,11 +332,10 @@ function antispamProtection(message, clientIp, ws, userCommands, lastWarn, userC const rawCommand = message.toString(); const command = rawCommand.replace(/[\r\n]+/g, ''); const now = Date.now(); - const normalizedClientIp = clientIp?.replace(/^::ffff:/, ''); if (endpointName === 'text') consoleCmd.logDebug(`Command received from \x1b[90m${clientIp}\x1b[0m: ${command}`); if (command.length > maxPayloadSize) { - consoleCmd.logWarn(`Command from \x1b[90m${normalizedClientIp}\x1b[0m on \x1b[90m/${endpointName}\x1b[0m exceeded maximum payload size (${parseInt(command.length / 1024)} KB / ${parseInt(maxPayloadSize / 1024)} KB).`); + consoleCmd.logWarn(`Command from \x1b[90m${clientIp}\x1b[0m on \x1b[90m/${endpointName}\x1b[0m exceeded maximum payload size (${parseInt(command.length / 1024)} KB / ${parseInt(maxPayloadSize / 1024)} KB).`); return ""; } @@ -354,12 +353,12 @@ function antispamProtection(message, clientIp, ws, userCommands, lastWarn, userC consoleCmd.logWarn(`User \x1b[90m${clientIp}\x1b[0m is spamming with rapid commands. Connection will be terminated and user will be banned.`); // Check if the normalized IP is already in the banlist - const isAlreadyBanned = serverConfig.webserver.banlist.some(banEntry => banEntry[0] === normalizedClientIp); + const isAlreadyBanned = serverConfig.webserver.banlist.some(banEntry => banEntry[0] === clientIp); if (!isAlreadyBanned) { // Add the normalized IP to the banlist - serverConfig.webserver.banlist.push([normalizedClientIp, 'Unknown', Date.now(), '[Auto ban] Spam']); - consoleCmd.logInfo(`User \x1b[90m${normalizedClientIp}\x1b[0m has been added to the banlist due to extreme spam.`); + serverConfig.webserver.banlist.push([clientIp, 'Unknown', Date.now(), '[Auto ban] Spam']); + consoleCmd.logInfo(`User \x1b[90m${clientIp}\x1b[0m has been added to the banlist due to extreme spam.`); configSave(); } diff --git a/server/index.js b/server/index.js index ab4b026..64b12b3 100644 --- a/server/index.js +++ b/server/index.js @@ -306,7 +306,6 @@ wss.on('connection', (ws, request) => { const output = serverConfig.xdrd.wirelessConnection ? client : serialport; let clientIp = helpers.getIpAddress(request); const userCommandHistory = {}; - const normalizedClientIp = clientIp?.replace(/^::ffff:/, ''); if (clientIp && serverConfig.webserver.banlist?.includes(clientIp)) { ws.close(1008, 'Banned IP'); @@ -328,7 +327,7 @@ wss.on('connection', (ws, request) => { const lastLogTime = ipLogTimestamps.get(clientIp) || 0; const now = Date.now(); if (now - lastLogTime > IP_LOG_INTERVAL_MS) { - logWarn(`Web client \x1b[31mclosed: limit exceeded\x1b[0m (${normalizedClientIp}) \x1b[90m[${currentUsers}]`); + logWarn(`Web client \x1b[31mclosed: limit exceeded\x1b[0m (${clientIp}) \x1b[90m[${currentUsers}]`); ipLogTimestamps.set(clientIp, now); } return; @@ -481,7 +480,7 @@ wss.on('connection', (ws, request) => { if (currentUsers === 0 && serverConfig.autoShutdown === true && serverConfig.xdrd.wirelessConnection === true) client.write('X\n'); - if (code !== 1008) logInfo(`Web client \x1b[31mdisconnected\x1b[0m (${normalizedClientIp}) \x1b[90m[${currentUsers}]`); + if (code !== 1008) logInfo(`Web client \x1b[31mdisconnected\x1b[0m (${clientIp}) \x1b[90m[${currentUsers}]`); }); ws.on('error', console.error);