manual optimizations

This commit is contained in:
zefie
2025-08-11 14:48:01 -04:00
parent 8f0d815009
commit 1ddae93b07
3 changed files with 20 additions and 18 deletions

View File

@@ -910,7 +910,7 @@ async function processURL(socket, request_headers, pc_services = false) {
request_headers.query = {}; request_headers.query = {};
if (request_headers.request_url) { 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]) { if (minisrv_config.services[service_name]) {
allow_double_slash = minisrv_config.services[service_name].allow_double_slash || false; allow_double_slash = minisrv_config.services[service_name].allow_double_slash || false;
enable_multi_query = minisrv_config.services[service_name].enable_multi_query || 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("="); const qraw_split = param.split("=");
if (qraw_split.length === 2) { if (qraw_split.length === 2) {
const k = qraw_split[0]; 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) { if (request_headers.query[k] && enable_multi_query) {
console.log("yes") console.log("yes")
if (typeof request_headers.query[k] === 'string') { if (typeof request_headers.query[k] === 'string') {
@@ -944,7 +944,7 @@ async function processURL(socket, request_headers, pc_services = false) {
}); });
} }
} else { } 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']; 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 // 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 // this way we can pull up client info such as wtv-client-rom-type or wtv-system-sysconfig
Object.keys(headers).forEach(function (k) { 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) { if (k === "wtv-incarnation" && socket_sessions[socket.id].wtvsec) {
socket_sessions[socket.id].wtvsec.set_incarnation(headers[k]); 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) { } else if (skipSecure) {
if (headers) { if (headers) {
if (headers['request']) { 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; if (socket_sessions[socket.id].secure_buffer) delete socket_sessions[socket.id].secure_buffer;
} else { } else {
return headers; return headers;
@@ -1992,7 +1992,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
} }
// handle POST // handle POST
if (headers['request'] && !socket_sessions[socket.id].expecting_post_data) { 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); socket.setTimeout(minisrv_config.config.post_data_socket_timeout * 1000);
if (typeof socket_sessions[socket.id].post_data == "undefined") { 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; 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]; headers[k] = secure_headers[k];
}); });
if (headers['request']) { if (headers['request']) {
if (headers['request'].substring(0, 4) == "POST") { if (headers['request'].slice(0, 4) == "POST") {
if (!socket_sessions[socket.id].post_data) { 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_length = headers['Content-length'] || headers['Content-Length'] || 0;
socket_sessions[socket.id].post_data = ""; socket_sessions[socket.id].post_data = "";
@@ -2244,7 +2244,7 @@ function getSocketRandomID(socket) {
crypto.createHash('sha256') crypto.createHash('sha256')
.update(String(socket.remoteAddress) + String(socket.remotePort)) .update(String(socket.remoteAddress) + String(socket.remotePort))
.digest('hex') .digest('hex')
.substring(0, 8), 16 .slice(0, 8), 16
) % 100000000; ) % 100000000;
} }
@@ -2302,9 +2302,9 @@ function getGitRevision() {
try { try {
const rev = fs.readFileSync(__dirname + path.sep + ".." + path.sep + ".git" + path.sep + "HEAD").toString().trim(); const rev = fs.readFileSync(__dirname + path.sep + ".." + path.sep + ".git" + path.sep + "HEAD").toString().trim();
if (!rev.includes(':')) { if (!rev.includes(':')) {
return rev; return rev.slice(0, 8);
} else { } 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) { } catch (e) {
return null; return null;

View File

@@ -1,5 +1,7 @@
var minisrv_service_file = true; var minisrv_service_file = true;
if (request_headers.query.machine && request_headers.query.port) { if (request_headers.query.machine && request_headers.query.port) {
headers = `200 OK headers = `200 OK
Content-Type: text/html Content-Type: text/html

View File

@@ -252,7 +252,7 @@ class WTVIRC {
data = data.toString('ascii'); data = data.toString('ascii');
} }
if (data.length > this.max_message_len) { 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}`); 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) { switch (type) {
case 'nickname': case 'nickname':
// IRC nicknames: A-Z a-z 0-9 [ ] \ ` _ ^ { | } // 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': case 'channel':
// Channel names: start with #, no spaces, commas, or control chars // Channel names: start with #, no spaces, commas, or control chars
if (!input.startsWith('#')) return ''; 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': case 'message':
// Messages: no control chars, reasonable length // Messages: no control chars, reasonable length
return input.substring(0, 512); return input.slice(0, 512);
case 'username': case 'username':
// Usernames: alphanumeric and some special chars // 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: 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 var gitPath = __dirname + path.sep + ".." + path.sep + ".." + path.sep + ".." + path.sep + ".git" + path.sep
const rev = fs.readFileSync(gitPath + "HEAD").toString().trim(); const rev = fs.readFileSync(gitPath + "HEAD").toString().trim();
if (rev.indexOf(':') === -1) { if (rev.indexOf(':') === -1) {
return rev; return rev.slice(0, 8);
} else { } 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) { } catch (e) {
return null; return null;