From 1ddae93b07d60cdc66e0434a46c8aeb584c29d5f Mon Sep 17 00:00:00 2001 From: zefie Date: Mon, 11 Aug 2025 14:48:01 -0400 Subject: [PATCH] manual optimizations --- zefie_wtvp_minisrv/app.js | 20 +++++++++---------- .../ServiceVault/wtv-tricks/cSetup.js | 2 ++ zefie_wtvp_minisrv/includes/classes/WTVIRC.js | 16 +++++++-------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/zefie_wtvp_minisrv/app.js b/zefie_wtvp_minisrv/app.js index 0d2ddce1..cdc14fa3 100644 --- a/zefie_wtvp_minisrv/app.js +++ b/zefie_wtvp_minisrv/app.js @@ -910,7 +910,7 @@ async function processURL(socket, request_headers, pc_services = false) { request_headers.query = {}; if (request_headers.request_url) { - service_name = socket.service_name || verifyServicePort(unescape(request_headers.request_url).split(':/')[0], socket); + service_name = socket.service_name || verifyServicePort(decodeURIComponent(request_headers.request_url).split(':/')[0], socket); if (minisrv_config.services[service_name]) { allow_double_slash = minisrv_config.services[service_name].allow_double_slash || false; enable_multi_query = minisrv_config.services[service_name].enable_multi_query || false; @@ -928,7 +928,7 @@ async function processURL(socket, request_headers, pc_services = false) { const qraw_split = param.split("="); if (qraw_split.length === 2) { const k = qraw_split[0]; - const value = unescape(qraw_split[1].replace(/\+/g, "%20")); + const value = decodeURIComponent(qraw_split[1].replace(/\+/g, "%20")); if (request_headers.query[k] && enable_multi_query) { console.log("yes") if (typeof request_headers.query[k] === 'string') { @@ -944,7 +944,7 @@ async function processURL(socket, request_headers, pc_services = false) { }); } } else { - shortURL = unescape(request_headers.request_url); + shortURL = decodeURIComponent(request_headers.request_url); } if (request_headers['wtv-request-type']) socket_sessions[socket.id].wtv_request_type = request_headers['wtv-request-type']; @@ -1866,7 +1866,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq // log all client wtv- headers to the SessionData for that SSID // this way we can pull up client info such as wtv-client-rom-type or wtv-system-sysconfig Object.keys(headers).forEach(function (k) { - if (k.substr(0, 4) === "wtv-") { + if (k.slice(0, 4) === "wtv-") { if (k === "wtv-incarnation" && socket_sessions[socket.id].wtvsec) { socket_sessions[socket.id].wtvsec.set_incarnation(headers[k]); } @@ -1978,7 +1978,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq } else if (skipSecure) { if (headers) { if (headers['request']) { - if (headers['request'].substring(0, 4) == "POST") { + if (headers['request'].slice(0, 4) == "POST") { if (socket_sessions[socket.id].secure_buffer) delete socket_sessions[socket.id].secure_buffer; } else { return headers; @@ -1992,7 +1992,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq } // handle POST if (headers['request'] && !socket_sessions[socket.id].expecting_post_data) { - if (headers['request'].substring(0, 4) == "POST") { + if (headers['request'].slice(0, 4) == "POST") { socket.setTimeout(minisrv_config.config.post_data_socket_timeout * 1000); if (typeof socket_sessions[socket.id].post_data == "undefined") { if (socket_sessions[socket.id].post_data_percents_shown) delete socket_sessions[socket.id].post_data_percents_shown; @@ -2172,7 +2172,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq headers[k] = secure_headers[k]; }); if (headers['request']) { - if (headers['request'].substring(0, 4) == "POST") { + if (headers['request'].slice(0, 4) == "POST") { if (!socket_sessions[socket.id].post_data) { socket_sessions[socket.id].post_data_length = headers['Content-length'] || headers['Content-Length'] || 0; socket_sessions[socket.id].post_data = ""; @@ -2244,7 +2244,7 @@ function getSocketRandomID(socket) { crypto.createHash('sha256') .update(String(socket.remoteAddress) + String(socket.remotePort)) .digest('hex') - .substring(0, 8), 16 + .slice(0, 8), 16 ) % 100000000; } @@ -2302,9 +2302,9 @@ function getGitRevision() { try { const rev = fs.readFileSync(__dirname + path.sep + ".." + path.sep + ".git" + path.sep + "HEAD").toString().trim(); if (!rev.includes(':')) { - return rev; + return rev.slice(0, 8); } else { - return fs.readFileSync(__dirname + path.sep + ".." + path.sep + ".git" + path.sep + rev.substring(5)).toString().trim().substring(0, 8) + "-" + rev.split('/').pop(); + return fs.readFileSync(__dirname + path.sep + ".." + path.sep + ".git" + path.sep + rev.slice(5)).toString().trim().slice(0, 8) + "-" + rev.split('/').pop(); } } catch (e) { return null; diff --git a/zefie_wtvp_minisrv/includes/ServiceVault/wtv-tricks/cSetup.js b/zefie_wtvp_minisrv/includes/ServiceVault/wtv-tricks/cSetup.js index ea2600fa..33db87ca 100644 --- a/zefie_wtvp_minisrv/includes/ServiceVault/wtv-tricks/cSetup.js +++ b/zefie_wtvp_minisrv/includes/ServiceVault/wtv-tricks/cSetup.js @@ -1,5 +1,7 @@ var minisrv_service_file = true; + + if (request_headers.query.machine && request_headers.query.port) { headers = `200 OK Content-Type: text/html diff --git a/zefie_wtvp_minisrv/includes/classes/WTVIRC.js b/zefie_wtvp_minisrv/includes/classes/WTVIRC.js index d68fbcc9..3f23d555 100644 --- a/zefie_wtvp_minisrv/includes/classes/WTVIRC.js +++ b/zefie_wtvp_minisrv/includes/classes/WTVIRC.js @@ -252,7 +252,7 @@ class WTVIRC { data = data.toString('ascii'); } if (data.length > this.max_message_len) { - data = data.substring(0, this.max_message_len - 2) + '\r\n'; + data = data.alice(0, this.max_message_len - 2) + '\r\n'; this.debugLog('warn', `Data length exceeds max_message_len (${this.max_message_len}), truncating: ${data.length} > ${this.max_message_len}`); } @@ -351,23 +351,23 @@ class WTVIRC { switch (type) { case 'nickname': // IRC nicknames: A-Z a-z 0-9 [ ] \ ` _ ^ { | } - return input.replace(/[^A-Za-z0-9\[\]\\`_^{|}]/g, '').substring(0, this.nicklen); + return input.replace(/[^A-Za-z0-9\[\]\\`_^{|}]/g, '').slice(0, this.nicklen); case 'channel': // Channel names: start with #, no spaces, commas, or control chars if (!input.startsWith('#')) return ''; - return input.replace(/[^A-Za-z0-9#\-_.]/g, '').substring(0, this.channellen); + return input.replace(/[^A-Za-z0-9#\-_.]/g, '').slice(0, this.channellen); case 'message': // Messages: no control chars, reasonable length - return input.substring(0, 512); + return input.slice(0, 512); case 'username': // Usernames: alphanumeric and some special chars - return input.replace(/[^A-Za-z0-9\-_.]/g, '').substring(0, 32); + return input.replace(/[^A-Za-z0-9\-_.]/g, '').slice(0, 32); default: - return input.substring(0, 512); + return input.slice(0, 512); } } @@ -4141,9 +4141,9 @@ class WTVIRC { var gitPath = __dirname + path.sep + ".." + path.sep + ".." + path.sep + ".." + path.sep + ".git" + path.sep const rev = fs.readFileSync(gitPath + "HEAD").toString().trim(); if (rev.indexOf(':') === -1) { - return rev; + return rev.slice(0, 8); } else { - return fs.readFileSync(gitPath + rev.substring(5)).toString().trim().substring(0, 8) + "-" + rev.split('/').pop(); + return fs.readFileSync(gitPath + rev.slice(5)).toString().trim().slice(0, 8) + "-" + rev.split('/').pop(); } } catch (e) { return null;