From 4296ad20c8ab16d65222be050ae8dcb97b033e4a Mon Sep 17 00:00:00 2001 From: ari melody Date: Fri, 19 Jan 2024 04:22:18 +0000 Subject: [PATCH 1/2] fixed real address grabbing --- server/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/main.js b/server/main.js index ba992ce..30ddba1 100644 --- a/server/main.js +++ b/server/main.js @@ -130,10 +130,10 @@ function log_request(req, res, time) { } function get_real_address(req) { - if (TRUSTED_PROXIES.indexOf(req.socket.localAddress) !== -1 && req.headers['x-forwarded-for']) { + if (TRUSTED_PROXIES.indexOf(req.connection.remoteAddress) !== -1 && req.headers['x-forwarded-for']) { return req.headers['x-forwarded-for']; } - return req.socket.localAddress; + return req.connection.remoteAddress; } const wss = new Websocket.Server({ server }); From a85199c9709a0b46ed501cba785c9717277d73ed Mon Sep 17 00:00:00 2001 From: ari melody Date: Fri, 19 Jan 2024 04:26:57 +0000 Subject: [PATCH 2/2] fixed cosmetic server url not reflecting actual server --- public/scripts/terminal.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/public/scripts/terminal.js b/public/scripts/terminal.js index 31b6c17..5445ab7 100644 --- a/public/scripts/terminal.js +++ b/public/scripts/terminal.js @@ -91,7 +91,7 @@ to help you feel a little more comfortable, i've prepared some commands for you: * closes any existing websocket connection and attempts to create a new one. * @param {string} server_url - the server websocket url to connect to. */ -export async function connect(server_url) { +export async function connect(url) { if (client && client.readyState == 1) { // OPEN client.close(); @@ -140,9 +140,18 @@ export async function connect(server_url) { */ function add_client_events(client) { client.addEventListener('open', async () => { - console.log(`Successfully connected to ${client.url}.`); + server_url = client.url; + console.log(`Successfully connected to ${server_url}.`); + + server_indicator.innerText = function() { + if (client.url.startsWith("ws://")) + return client.url.slice(5, -1); + else if (client.url.startsWith("wss://")) + return client.url.slice(6, -1); + else + return client.url; + }(); - server_indicator.innerText = server_url; add_system_message(`Connection successful.\n\n`); add_system_message(`=== BEGIN SESSION ===\n\n`);