1
0
Fork 0
forked from svrjs/svrjs

Fix or ignore all ESLint errors

This commit is contained in:
Dorian Niemiec 2024-08-27 11:28:24 +02:00
parent 2872be5b5b
commit fae1b661ed
19 changed files with 76 additions and 15 deletions

View file

@ -45,6 +45,7 @@ function clientErrorHandler(err, socket) {
socket.end(x, function () { socket.end(x, function () {
try { try {
socket.destroy(); socket.destroy();
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Socket is probably already destroyed // Socket is probably already destroyed
} }
@ -61,7 +62,9 @@ function clientErrorHandler(err, socket) {
if (headername.toLowerCase() == "set-cookie") { if (headername.toLowerCase() == "set-cookie") {
headers[headername].forEach(function (headerValueS) { headers[headername].forEach(function (headerValueS) {
if ( if (
// eslint-disable-next-line no-control-regex
headername.match(/[^\x09\x20-\x7e\x80-\xff]|.:/) || headername.match(/[^\x09\x20-\x7e\x80-\xff]|.:/) ||
// eslint-disable-next-line no-control-regex
headerValueS.match(/[^\x09\x20-\x7e\x80-\xff]/) headerValueS.match(/[^\x09\x20-\x7e\x80-\xff]/)
) )
throw new Error(`Invalid header!!! (${headername})`); throw new Error(`Invalid header!!! (${headername})`);
@ -69,7 +72,9 @@ function clientErrorHandler(err, socket) {
}); });
} else { } else {
if ( if (
// eslint-disable-next-line no-control-regex
headername.match(/[^\x09\x20-\x7e\x80-\xff]|.:/) || headername.match(/[^\x09\x20-\x7e\x80-\xff]|.:/) ||
// eslint-disable-next-line no-control-regex
headers[headername].match(/[^\x09\x20-\x7e\x80-\xff]/) headers[headername].match(/[^\x09\x20-\x7e\x80-\xff]/)
) )
throw new Error(`Invalid header!!! (${headername})`); throw new Error(`Invalid header!!! (${headername})`);
@ -546,7 +551,7 @@ function clientErrorHandler(err, socket) {
if (packetLine1.length != 1) { if (packetLine1.length != 1) {
logFacilities.errmessage("The head of request is invalid."); logFacilities.errmessage("The head of request is invalid.");
callServerError(400); // Malformed Packet callServerError(400); // Malformed Packet
} else if (!httpVersion.toString().match(/^HTTP[\/]/i)) { } else if (!httpVersion.toString().match(/^HTTP[/]/i)) {
logFacilities.errmessage("Invalid protocol."); logFacilities.errmessage("Invalid protocol.");
callServerError(400); // bad protocol version callServerError(400); // bad protocol version
} else if (http.METHODS.indexOf(method) == -1) { } else if (http.METHODS.indexOf(method) == -1) {
@ -562,6 +567,7 @@ function clientErrorHandler(err, socket) {
callServerError(400); // Also malformed Packet callServerError(400); // Also malformed Packet
} }
} }
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
logFacilities.errmessage( logFacilities.errmessage(
"There was an error while determining type of malformed request.", "There was an error while determining type of malformed request.",

View file

@ -1,7 +1,9 @@
// eslint-disable-next-line no-unused-vars
const svrjsInfo = require("../../svrjs.json"); const svrjsInfo = require("../../svrjs.json");
let serverconsole = {}; let serverconsole = {};
// eslint-disable-next-line no-unused-vars
function noproxyHandler(req, socket, head) { function noproxyHandler(req, socket, head) {
let reqIdInt = Math.floor(Math.random() * 16777216); let reqIdInt = Math.floor(Math.random() * 16777216);
if (reqIdInt == 16777216) reqIdInt = 0; if (reqIdInt == 16777216) reqIdInt = 0;

View file

@ -246,6 +246,7 @@ function requestHandler(req, res) {
res.socket.realRemoteAddress = reqip; res.socket.realRemoteAddress = reqip;
res.socket.originalRemotePort = oldport; res.socket.originalRemotePort = oldport;
res.socket.originalRemoteAddress = oldip; res.socket.originalRemoteAddress = oldip;
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Address setting failed // Address setting failed
} }

View file

@ -22,6 +22,7 @@ function serverErrorHandler(err, isRedirect, server, start) {
process.send( process.send(
"\x12ERRLIST" + (isRedirect ? attmtsRedir : attmts) + err.code, "\x12ERRLIST" + (isRedirect ? attmtsRedir : attmts) + err.code,
); );
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Probably main process exited // Probably main process exited
} }
@ -33,6 +34,7 @@ function serverErrorHandler(err, isRedirect, server, start) {
try { try {
if (cluster.isPrimary !== undefined) if (cluster.isPrimary !== undefined)
process.send("\x12ERRCRASH" + err.code); process.send("\x12ERRCRASH" + err.code);
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Probably main process exited // Probably main process exited
} }

View file

@ -12,6 +12,7 @@ const { name, version } = svrjsInfo;
let inspector = undefined; let inspector = undefined;
try { try {
inspector = require("inspector"); inspector = require("inspector");
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Don't use inspector // Don't use inspector
} }
@ -39,6 +40,7 @@ try {
throw err; throw err;
} }
} }
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
http2.__disabled__ = null; http2.__disabled__ = null;
http2.createServer = () => { http2.createServer = () => {
@ -71,6 +73,7 @@ let https = {
try { try {
crypto = require("crypto"); crypto = require("crypto");
https = require("https"); https = require("https");
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
http2.createSecureServer = () => { http2.createSecureServer = () => {
throw new Error("Crypto support is not present"); throw new Error("Crypto support is not present");
@ -94,6 +97,7 @@ process.filename = __filename;
let hexstrbase64 = undefined; let hexstrbase64 = undefined;
try { try {
hexstrbase64 = require(process.dirname + "/hexstrbase64/index.js"); hexstrbase64 = require(process.dirname + "/hexstrbase64/index.js");
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Don't use hexstrbase64 // Don't use hexstrbase64
} }
@ -345,7 +349,7 @@ if (typeof process.serverConfig.port === "string") {
process.serverConfig.port = parseInt(process.serverConfig.port); process.serverConfig.port = parseInt(process.serverConfig.port);
} else { } else {
const portLMatch = process.serverConfig.port.match( const portLMatch = process.serverConfig.port.match(
/^(\[[^ \]@\/\\]+\]|[^ \]\[:@\/\\]+):([0-9]+)$/, /^(\[[^ \]@/\\]+\]|[^ \][:@/\\]+):([0-9]+)$/,
); );
if (portLMatch) { if (portLMatch) {
listenAddress = portLMatch[1] listenAddress = portLMatch[1]
@ -360,7 +364,7 @@ if (typeof process.serverConfig.sport === "string") {
process.serverConfig.sport = parseInt(process.serverConfig.sport); process.serverConfig.sport = parseInt(process.serverConfig.sport);
} else { } else {
const sportLMatch = process.serverConfig.sport.match( const sportLMatch = process.serverConfig.sport.match(
/^(\[[^ \]@\/\\]+\]|[^ \]\[:@\/\\]+):([0-9]+)$/, /^(\[[^ \]@/\\]+\]|[^ \][:@/\\]+):([0-9]+)$/,
); );
if (sportLMatch) { if (sportLMatch) {
sListenAddress = sportLMatch[1] sListenAddress = sportLMatch[1]
@ -384,6 +388,7 @@ try {
if (inspector) { if (inspector) {
inspectorURL = inspector.url(); inspectorURL = inspector.url();
} }
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Failed to get inspector URL // Failed to get inspector URL
} }
@ -494,6 +499,7 @@ function doIpRequest(isHTTPS, options) {
ipRequestCompleted = true; ipRequestCompleted = true;
process.emit("ipRequestCompleted"); process.emit("ipRequestCompleted");
}); });
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
clearTimeout(dnsTimeout); clearTimeout(dnsTimeout);
callbackDone = true; callbackDone = true;
@ -629,6 +635,7 @@ if (process.serverConfig.secure) {
let vnum = 0; let vnum = 0;
try { try {
vnum = process.config.variables.node_module_version; vnum = process.config.variables.node_module_version;
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Version number not retrieved // Version number not retrieved
} }
@ -813,7 +820,7 @@ if (!disableMods) {
crypto.__disabled__ === undefined crypto.__disabled__ === undefined
? "var crypto = require('crypto');\r\nvar https = require('https');\r\n" ? "var crypto = require('crypto');\r\nvar https = require('https');\r\n"
: "" : ""
}var stream = require(\'stream\');\r\nvar customvar1;\r\nvar customvar2;\r\nvar customvar3;\r\nvar customvar4;\r\n\r\nfunction Mod() {}\r\nMod.prototype.callback = function callback(req, res, serverconsole, responseEnd, href, ext, uobject, search, defaultpage, users, page404, head, foot, fd, elseCallback, configJSON, callServerError, getCustomHeaders, origHref, redirect, parsePostData, authUser) {\r\nreturn () => {\r\nvar disableEndElseCallbackExecute = false;\r\nfunction filterHeaders(e){var r={};return Object.keys(e).forEach(((t) => {null!==e[t]&&void 0!==e[t]&&("object"==typeof e[t]?r[t]=JSON.parse(JSON.stringify(e[t])):r[t]=e[t])})),r}\r\nfunction checkHostname(e){if(void 0===e||"*"==e)return!0;if(req.headers.host&&0==e.indexOf("*.")&&"*."!=e){var r=e.substring(2);if(req.headers.host==r||req.headers.host.indexOf("."+r)==req.headers.host.length-r.length-1)return!0}else if(req.headers.host&&req.headers.host==e)return!0;return!1}\r\nfunction checkHref(e){return href==e||"win32"==os.platform()&&href.toLowerCase()==e.toLowerCase()}\r\n`; }var stream = require('stream');\r\nvar customvar1;\r\nvar customvar2;\r\nvar customvar3;\r\nvar customvar4;\r\n\r\nfunction Mod() {}\r\nMod.prototype.callback = function callback(req, res, serverconsole, responseEnd, href, ext, uobject, search, defaultpage, users, page404, head, foot, fd, elseCallback, configJSON, callServerError, getCustomHeaders, origHref, redirect, parsePostData, authUser) {\r\nreturn () => {\r\nvar disableEndElseCallbackExecute = false;\r\nfunction filterHeaders(e){var r={};return Object.keys(e).forEach(((t) => {null!==e[t]&&void 0!==e[t]&&("object"==typeof e[t]?r[t]=JSON.parse(JSON.stringify(e[t])):r[t]=e[t])})),r}\r\nfunction checkHostname(e){if(void 0===e||"*"==e)return!0;if(req.headers.host&&0==e.indexOf("*.")&&"*."!=e){var r=e.substring(2);if(req.headers.host==r||req.headers.host.indexOf("."+r)==req.headers.host.length-r.length-1)return!0}else if(req.headers.host&&req.headers.host==e)return!0;return!1}\r\nfunction checkHref(e){return href==e||"win32"==os.platform()&&href.toLowerCase()==e.toLowerCase()}\r\n`;
const modfoot = const modfoot =
"\r\nif(!disableEndElseCallbackExecute) {\r\ntry{\r\nelseCallback();\r\n} catch(err) {\r\n}\r\n}\r\n}\r\n}\r\nmodule.exports = Mod;"; "\r\nif(!disableEndElseCallbackExecute) {\r\ntry{\r\nelseCallback();\r\n} catch(err) {\r\n}\r\n}\r\n}\r\n}\r\nmodule.exports = Mod;";
// Write the modified server side script to the temp folder // Write the modified server side script to the temp folder
@ -1042,6 +1049,7 @@ try {
server2 = http.createServer({ server2 = http.createServer({
requireHostHeader: false, requireHostHeader: false,
}); });
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
server2 = http.createServer(); server2 = http.createServer();
} }
@ -1107,6 +1115,7 @@ if (process.serverConfig.enableHTTP2 == true) {
server = http.createServer({ server = http.createServer({
requireHostHeader: false, requireHostHeader: false,
}); });
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
server = http.createServer(); server = http.createServer();
} }
@ -1144,10 +1153,12 @@ if (process.serverConfig.secure) {
"$", "$",
"i", "i",
); );
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Can't replace regex, ignoring... // Can't replace regex, ignoring...
} }
}); });
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// SNI error // SNI error
} }
@ -1201,6 +1212,7 @@ if (process.serverConfig.secure) {
try { try {
sock._parent.destroy(a, b, c); sock._parent.destroy(a, b, c);
sock.destroyed = sock._parent.destroyed; sock.destroyed = sock._parent.destroyed;
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Socket is probably already destroyed. // Socket is probably already destroyed.
} }
@ -1209,6 +1221,7 @@ if (process.serverConfig.secure) {
sock._parent.destroy = sock._parent.reallyDestroy; sock._parent.destroy = sock._parent.reallyDestroy;
try { try {
if (sock._parent.toDestroy) sock._parent.destroy(); if (sock._parent.toDestroy) sock._parent.destroy();
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Socket is probably already destroyed. // Socket is probably already destroyed.
} }
@ -1302,9 +1315,13 @@ let commands = {
log("No mods installed."); log("No mods installed.");
} }
}, },
// eslint-disable-next-line no-unused-vars
clear: (args, log) => { clear: (args, log) => {
console.clear(); console.clear();
}, },
// eslint-disable-next-line no-unused-vars
stop: (args, log) => { stop: (args, log) => {
let retcode = args[0]; let retcode = args[0];
if ( if (
@ -1325,6 +1342,7 @@ let commands = {
} }
} }
}); });
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
if (!process.removeFakeIPC) { if (!process.removeFakeIPC) {
if (typeof retcode == "number") { if (typeof retcode == "number") {
@ -1344,6 +1362,7 @@ let commands = {
} }
} }
}); });
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
if (typeof retcode == "number") { if (typeof retcode == "number") {
process.exit(retcode); process.exit(retcode);
@ -1491,6 +1510,7 @@ function getWorkerCountToFork() {
try { try {
const useAvailableCores = Math.round(os.freemem() / 50000000) - 1; // 1 core deleted for safety... const useAvailableCores = Math.round(os.freemem() / 50000000) - 1; // 1 core deleted for safety...
if (workersToFork > useAvailableCores) workersToFork = useAvailableCores; if (workersToFork > useAvailableCores) workersToFork = useAvailableCores;
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Nevermind... Don't want SVR.JS to fail starting, because os.freemem function is not working. // Nevermind... Don't want SVR.JS to fail starting, because os.freemem function is not working.
} }
@ -1517,6 +1537,8 @@ function forkWorkers(workersToFork, callback) {
} }
// Listening message event listener // Listening message event listener
// eslint-disable-next-line no-unused-vars
process.messageEventListeners.push((worker, serverconsole) => { process.messageEventListeners.push((worker, serverconsole) => {
return (message) => { return (message) => {
if (message == "\x12LISTEN") { if (message == "\x12LISTEN") {
@ -1972,6 +1994,7 @@ function start(init) {
} else { } else {
checkWorker(callback, _id + 1); checkWorker(callback, _id + 1);
} }
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
if (cluster.workers[allWorkers[_id]]) { if (cluster.workers[allWorkers[_id]]) {
cluster.workers[allWorkers[_id]].removeAllListeners("message"); cluster.workers[allWorkers[_id]].removeAllListeners("message");
@ -2045,9 +2068,10 @@ function start(init) {
process.send(`Unrecognized command "${line.split(" ")[0]}".`); process.send(`Unrecognized command "${line.split(" ")[0]}".`);
process.send("\x12END"); process.send("\x12END");
} }
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
if (line != "") { if (line != "") {
process.send(`Can't execute command \"${line.split(" ")[0]}".`); process.send(`Can't execute command "${line.split(" ")[0]}".`);
process.send("\x12END"); process.send("\x12END");
} }
} }
@ -2078,6 +2102,7 @@ function start(init) {
if (cluster.workers[allWorkers[i]]) { if (cluster.workers[allWorkers[i]]) {
cluster.workers[allWorkers[i]].kill(); cluster.workers[allWorkers[i]].kill();
} }
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
stopError = true; stopError = true;
} }
@ -2108,6 +2133,7 @@ function start(init) {
cluster.workers[clusterID].on("message", msgListener); cluster.workers[clusterID].on("message", msgListener);
cluster.workers[clusterID].send(line); cluster.workers[clusterID].send(line);
} }
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
if (cluster.workers[clusterID]) { if (cluster.workers[clusterID]) {
cluster.workers[clusterID].removeAllListeners("message"); cluster.workers[clusterID].removeAllListeners("message");
@ -2124,6 +2150,7 @@ function start(init) {
} else { } else {
try { try {
commands[command](argss, serverconsole.climessage); commands[command](argss, serverconsole.climessage);
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
serverconsole.climessage( serverconsole.climessage(
'Unrecognized command "' + command + '".', 'Unrecognized command "' + command + '".',
@ -2325,6 +2352,7 @@ function start(init) {
} else { } else {
checkWorker(callback, _id + 1); checkWorker(callback, _id + 1);
} }
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
if (cluster.workers[allWorkers[_id]]) { if (cluster.workers[allWorkers[_id]]) {
cluster.workers[allWorkers[_id]].removeAllListeners( cluster.workers[allWorkers[_id]].removeAllListeners(
@ -2397,11 +2425,13 @@ if (cluster.isPrimary || cluster.isPrimary === undefined) {
} }
try { try {
deleteFolderRecursive(process.dirname + "/temp"); deleteFolderRecursive(process.dirname + "/temp");
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Error! // Error!
} }
try { try {
fs.mkdirSync(process.dirname + "/temp"); fs.mkdirSync(process.dirname + "/temp");
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Error! // Error!
} }
@ -2415,6 +2445,7 @@ if (cluster.isPrimary || cluster.isPrimary === undefined) {
process.dirname + "/temp/serverSideScript.js", process.dirname + "/temp/serverSideScript.js",
"// Placeholder server-side JavaScript to workaround Bun bug.\r\n", "// Placeholder server-side JavaScript to workaround Bun bug.\r\n",
); );
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Error! // Error!
} }
@ -2437,6 +2468,7 @@ if (cluster.isPrimary || cluster.isPrimary === undefined) {
if (cluster.workers[allWorkers[i]]) { if (cluster.workers[allWorkers[i]]) {
cluster.workers[allWorkers[i]].send("stop"); cluster.workers[allWorkers[i]].send("stop");
} }
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Worker will crash with EPIPE anyway. // Worker will crash with EPIPE anyway.
} }

View file

@ -53,6 +53,7 @@ module.exports = (req, res, logFacilities, config, next) => {
decodedHrefWithoutDuplicateSlashes = decodeURIComponent( decodedHrefWithoutDuplicateSlashes = decodeURIComponent(
req.parsedURL.pathname, req.parsedURL.pathname,
).replace(/\/+/g, "/"); ).replace(/\/+/g, "/");
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
res.error(400); res.error(400);
} }

View file

@ -13,6 +13,7 @@ let crypto = {
}; };
try { try {
crypto = require("crypto"); crypto = require("crypto");
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Crypto is disabled // Crypto is disabled
} }
@ -415,6 +416,8 @@ module.exports = (req, res, logFacilities, config, next) => {
}; };
// IPC listener for brute force protection // IPC listener for brute force protection
// eslint-disable-next-line no-unused-vars
process.messageEventListeners.push((worker, serverconsole) => { process.messageEventListeners.push((worker, serverconsole) => {
return (message) => { return (message) => {
let ip = ""; let ip = "";

View file

@ -4,6 +4,7 @@ module.exports = (req, res, logFacilities, config, next) => {
Object.keys(hkh).forEach((hkS) => { Object.keys(hkh).forEach((hkS) => {
try { try {
res.setHeader(hkS, hkh[hkS]); res.setHeader(hkS, hkh[hkS]);
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Headers will not be set. // Headers will not be set.
} }

View file

@ -7,6 +7,7 @@ const matchHostname = require("../utils/matchHostname.js");
module.exports = (req, res, logFacilities, config, next) => { module.exports = (req, res, logFacilities, config, next) => {
try { try {
decodeURIComponent(req.parsedURL.pathname); decodeURIComponent(req.parsedURL.pathname);
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
res.error(400); res.error(400);
} }

View file

@ -23,6 +23,7 @@ const generateETag = (filePath, stat) => {
return ETagDB[filePath + "-" + stat.size + "-" + stat.mtime]; return ETagDB[filePath + "-" + stat.size + "-" + stat.mtime];
}; };
// eslint-disable-next-line no-unused-vars
module.exports = (req, res, logFacilities, config, next) => { module.exports = (req, res, logFacilities, config, next) => {
const checkPathLevel = (path) => { const checkPathLevel = (path) => {
// Split the path into an array of components based on "/" // Split the path into an array of components based on "/"
@ -74,12 +75,13 @@ module.exports = (req, res, logFacilities, config, next) => {
let href = req.parsedURL.pathname; let href = req.parsedURL.pathname;
let origHref = req.originalParsedURL.pathname; let origHref = req.originalParsedURL.pathname;
let ext = href.match(/[^\/]\.([^.]+)$/); let ext = href.match(/[^/]\.([^.]+)$/);
if (!ext) ext = ""; if (!ext) ext = "";
else ext = ext[1].toLowerCase(); else ext = ext[1].toLowerCase();
let dHref = ""; let dHref = "";
try { try {
dHref = decodeURIComponent(href); dHref = decodeURIComponent(href);
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
res.error(400); res.error(400);
return; return;
@ -381,6 +383,7 @@ module.exports = (req, res, logFacilities, config, next) => {
if (process.isBun && useBrotli && isCompressable) { if (process.isBun && useBrotli && isCompressable) {
try { try {
zlib.createBrotliCompress(); zlib.createBrotliCompress();
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
useBrotli = false; useBrotli = false;
} }
@ -574,7 +577,7 @@ module.exports = (req, res, logFacilities, config, next) => {
getCustomDirListingFooter(() => { getCustomDirListingFooter(() => {
// Check if custom header has HTML tag // Check if custom header has HTML tag
const headerHasHTMLTag = customDirListingHeader const headerHasHTMLTag = customDirListingHeader
.replace(/<!--(?:(?:(?!--\>)[\s\S])*|)(?:-->|$)/g, "") .replace(/<!--(?:(?:(?!-->)[\s\S])*|)(?:-->|$)/g, "")
.match( .match(
/<html(?![a-zA-Z0-9])(?:"(?:\\(?:[\s\S]|$)|[^\\"])*(?:"|$)|'(?:\\(?:[\s\S]|$)|[^\\'])*(?:'|$)|[^'">])*(?:>|$)/i, /<html(?![a-zA-Z0-9])(?:"(?:\\(?:[\s\S]|$)|[^\\"])*(?:"|$)|'(?:\\(?:[\s\S]|$)|[^\\'])*(?:'|$)|[^'">])*(?:>|$)/i,
); );
@ -619,7 +622,7 @@ module.exports = (req, res, logFacilities, config, next) => {
checkPathLevel(decodeURIComponent(origHref)) < 1 checkPathLevel(decodeURIComponent(origHref)) < 1
? "" ? ""
: '<tr><td style="width: 24px;"><img src="/.dirimages/return.png" width="24px" height="24px" alt="[RET]" /></td><td style="word-wrap: break-word; word-break: break-word; overflow-wrap: break-word;"><a href="' + : '<tr><td style="width: 24px;"><img src="/.dirimages/return.png" width="24px" height="24px" alt="[RET]" /></td><td style="word-wrap: break-word; word-break: break-word; overflow-wrap: break-word;"><a href="' +
origHref.replace(/\/+/g, "/").replace(/\/[^\/]*\/?$/, "/") + origHref.replace(/\/+/g, "/").replace(/\/[^/]*\/?$/, "/") +
'">Return</a></td><td></td><td></td></tr>' '">Return</a></td><td></td><td></td></tr>'
}`; }`;

View file

@ -8,6 +8,7 @@ if (!process.singleThreaded) {
try { try {
// Import cluster module // Import cluster module
cluster = require("cluster"); cluster = require("cluster");
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Clustering is not supported! // Clustering is not supported!
} }

View file

@ -1,7 +1,7 @@
const os = require("os"); const os = require("os");
function createRegex(regex, isPath) { function createRegex(regex, isPath) {
const regexStrMatch = regex.match(/^\/((?:\\.|[^\/\\])*)\/([a-zA-Z0-9]*)$/); const regexStrMatch = regex.match(/^\/((?:\\.|[^/\\])*)\/([a-zA-Z0-9]*)$/);
if (!regexStrMatch) throw new Error("Invalid regular expression: " + regex); if (!regexStrMatch) throw new Error("Invalid regular expression: " + regex);
const searchString = regexStrMatch[1]; const searchString = regexStrMatch[1];
let modifiers = regexStrMatch[2]; let modifiers = regexStrMatch[2];

View file

@ -17,7 +17,7 @@ module.exports = (legacyMod) => {
if (!req[legacyParsedURLSymbol]) if (!req[legacyParsedURLSymbol])
req[legacyParsedURLSymbol] = parseURL(req.url); req[legacyParsedURLSymbol] = parseURL(req.url);
let ext = req[legacyParsedURLSymbol].pathname.match(/[^\/]\.([^.]+)$/); let ext = req[legacyParsedURLSymbol].pathname.match(/[^/]\.([^.]+)$/);
if (!ext) ext = ""; if (!ext) ext = "";
// Function to parse incoming POST data from the request // Function to parse incoming POST data from the request

View file

@ -17,8 +17,10 @@ let https = {
}, },
}; };
try { try {
// eslint-disable-next-line no-unused-vars
crypto = require("crypto"); crypto = require("crypto");
https = require("https"); https = require("https");
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Can't load HTTPS // Can't load HTTPS
} }
@ -51,6 +53,7 @@ function sendStatistics(modInfos, callback) {
let parsedJson = {}; let parsedJson = {};
try { try {
parsedJson = JSON.parse(data); parsedJson = JSON.parse(data);
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
throw new Error("JSON parse error (response parsing failed)."); throw new Error("JSON parse error (response parsing failed).");
} }

View file

@ -260,6 +260,7 @@ process.exit = (code) => {
logSync = true; logSync = true;
process.unsafeExit(code); process.unsafeExit(code);
}, 10000); // timeout }, 10000); // timeout
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
logFile = undefined; logFile = undefined;
logSync = true; logSync = true;

View file

@ -1,6 +1,7 @@
let crypto = { __disabled__: null }; let crypto = { __disabled__: null };
try { try {
crypto = require("crypto"); crypto = require("crypto");
// eslint-disable-next-line no-unused-vars
} catch (err) { } catch (err) {
// Crypto support is disabled. // Crypto support is disabled.
} }

View file

@ -13,7 +13,7 @@ function parseURL(uri, prepend) {
// Parse the URL using regular expression // Parse the URL using regular expression
let parsedURI = uri.match( let parsedURI = uri.match(
/^(?:([^:]+:)(\/\/)?)?(?:([^@\/?#\*]+)@)?([^:\/?#\*]+|\[[^\*]\/]\])?(?::([0-9]+))?(\*|\/[^?#]*)?(\?[^#]*)?(#[\S\s]*)?/, /^(?:([^:]+:)(\/\/)?)?(?:([^@/?#*]+)@)?([^:/?#*]+|\[[^*]\/]\])?(?::([0-9]+))?(\*|\/[^?#]*)?(\?[^#]*)?(#[\S\s]*)?/,
); );
// Match 1: protocol // Match 1: protocol
// Match 2: slashes after protocol // Match 2: slashes after protocol
@ -34,7 +34,7 @@ function parseURL(uri, prepend) {
if (hasSlashes && !parsedURI[6]) parsedURI[6] = "/"; if (hasSlashes && !parsedURI[6]) parsedURI[6] = "/";
// If match 4 contains Unicode characters, convert it to Punycode. If the result is an empty string, throw an error // If match 4 contains Unicode characters, convert it to Punycode. If the result is an empty string, throw an error
if (parsedURI[4] && !parsedURI[4].match(/^[a-zA-Z0-9\.\-]+$/)) { if (parsedURI[4] && !parsedURI[4].match(/^[a-zA-Z0-9.-]+$/)) {
parsedURI[4] = url.domainToASCII(parsedURI[4]); parsedURI[4] = url.domainToASCII(parsedURI[4]);
if (!parsedURI[4]) throw new Error("Invalid URL: " + uri); if (!parsedURI[4]) throw new Error("Invalid URL: " + uri);
} }

View file

@ -28,10 +28,10 @@ function sanitizeURL(resource, allowDoubleSlashes) {
// Handle relative navigation (e.g., "/./", "/../", "../", "./"), also remove trailing dots in paths // Handle relative navigation (e.g., "/./", "/../", "../", "./"), also remove trailing dots in paths
sanitizedResource = sanitizedResource sanitizedResource = sanitizedResource
.replace(/\/\.(?:\.{2,})?(?=\/|$)/g, "") .replace(/\/\.(?:\.{2,})?(?=\/|$)/g, "")
.replace(/([^.\/])\.+(?=\/|$)/g, "$1"); .replace(/([^./])\.+(?=\/|$)/g, "$1");
while (sanitizedResource.match(/\/(?!\.\.\/)[^\/]+\/\.\.(?=\/|$)/)) { while (sanitizedResource.match(/\/(?!\.\.\/)[^/]+\/\.\.(?=\/|$)/)) {
sanitizedResource = sanitizedResource.replace( sanitizedResource = sanitizedResource.replace(
/\/(?!\.\.\/)[^\/]+\/\.\.(?=\/|$)/g, /\/(?!\.\.\/)[^/]+\/\.\.(?=\/|$)/g,
"", "",
); );
} }

View file

@ -4,6 +4,7 @@ const fs = require("fs");
let crypto = {}; let crypto = {};
try { try {
crypto = require("crypto"); crypto = require("crypto");
// eslint-disable-next-line no-unused-vars
} catch (ex) { } catch (ex) {
crypto = {}; crypto = {};
crypto.__disabled__ = null; crypto.__disabled__ = null;
@ -259,11 +260,13 @@ if (fs.existsSync(__dirname + "/config.json")) {
let configJSONf = ""; let configJSONf = "";
try { try {
configJSONf = fs.readFileSync(__dirname + "/config.json"); //Read JSON File configJSONf = fs.readFileSync(__dirname + "/config.json"); //Read JSON File
// eslint-disable-next-line no-unused-vars
} catch (ex) { } catch (ex) {
throw new Error("Cannot read JSON file."); throw new Error("Cannot read JSON file.");
} }
try { try {
configJSON = JSON.parse(configJSONf); //Parse JSON configJSON = JSON.parse(configJSONf); //Parse JSON
// eslint-disable-next-line no-unused-vars
} catch (ex) { } catch (ex) {
throw new Error("JSON Parse error."); throw new Error("JSON Parse error.");
} }