forked from svrjs/svrjs
Fix or ignore all ESLint errors
This commit is contained in:
parent
2872be5b5b
commit
fae1b661ed
19 changed files with 76 additions and 15 deletions
|
@ -45,6 +45,7 @@ function clientErrorHandler(err, socket) {
|
|||
socket.end(x, function () {
|
||||
try {
|
||||
socket.destroy();
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Socket is probably already destroyed
|
||||
}
|
||||
|
@ -61,7 +62,9 @@ function clientErrorHandler(err, socket) {
|
|||
if (headername.toLowerCase() == "set-cookie") {
|
||||
headers[headername].forEach(function (headerValueS) {
|
||||
if (
|
||||
// eslint-disable-next-line no-control-regex
|
||||
headername.match(/[^\x09\x20-\x7e\x80-\xff]|.:/) ||
|
||||
// eslint-disable-next-line no-control-regex
|
||||
headerValueS.match(/[^\x09\x20-\x7e\x80-\xff]/)
|
||||
)
|
||||
throw new Error(`Invalid header!!! (${headername})`);
|
||||
|
@ -69,7 +72,9 @@ function clientErrorHandler(err, socket) {
|
|||
});
|
||||
} else {
|
||||
if (
|
||||
// eslint-disable-next-line no-control-regex
|
||||
headername.match(/[^\x09\x20-\x7e\x80-\xff]|.:/) ||
|
||||
// eslint-disable-next-line no-control-regex
|
||||
headers[headername].match(/[^\x09\x20-\x7e\x80-\xff]/)
|
||||
)
|
||||
throw new Error(`Invalid header!!! (${headername})`);
|
||||
|
@ -546,7 +551,7 @@ function clientErrorHandler(err, socket) {
|
|||
if (packetLine1.length != 1) {
|
||||
logFacilities.errmessage("The head of request is invalid.");
|
||||
callServerError(400); // Malformed Packet
|
||||
} else if (!httpVersion.toString().match(/^HTTP[\/]/i)) {
|
||||
} else if (!httpVersion.toString().match(/^HTTP[/]/i)) {
|
||||
logFacilities.errmessage("Invalid protocol.");
|
||||
callServerError(400); // bad protocol version
|
||||
} else if (http.METHODS.indexOf(method) == -1) {
|
||||
|
@ -562,6 +567,7 @@ function clientErrorHandler(err, socket) {
|
|||
callServerError(400); // Also malformed Packet
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
logFacilities.errmessage(
|
||||
"There was an error while determining type of malformed request.",
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
// eslint-disable-next-line no-unused-vars
|
||||
const svrjsInfo = require("../../svrjs.json");
|
||||
|
||||
let serverconsole = {};
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function noproxyHandler(req, socket, head) {
|
||||
let reqIdInt = Math.floor(Math.random() * 16777216);
|
||||
if (reqIdInt == 16777216) reqIdInt = 0;
|
||||
|
|
|
@ -246,6 +246,7 @@ function requestHandler(req, res) {
|
|||
res.socket.realRemoteAddress = reqip;
|
||||
res.socket.originalRemotePort = oldport;
|
||||
res.socket.originalRemoteAddress = oldip;
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Address setting failed
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ function serverErrorHandler(err, isRedirect, server, start) {
|
|||
process.send(
|
||||
"\x12ERRLIST" + (isRedirect ? attmtsRedir : attmts) + err.code,
|
||||
);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Probably main process exited
|
||||
}
|
||||
|
@ -33,6 +34,7 @@ function serverErrorHandler(err, isRedirect, server, start) {
|
|||
try {
|
||||
if (cluster.isPrimary !== undefined)
|
||||
process.send("\x12ERRCRASH" + err.code);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Probably main process exited
|
||||
}
|
||||
|
|
40
src/index.js
40
src/index.js
|
@ -12,6 +12,7 @@ const { name, version } = svrjsInfo;
|
|||
let inspector = undefined;
|
||||
try {
|
||||
inspector = require("inspector");
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Don't use inspector
|
||||
}
|
||||
|
@ -39,6 +40,7 @@ try {
|
|||
throw err;
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
http2.__disabled__ = null;
|
||||
http2.createServer = () => {
|
||||
|
@ -71,6 +73,7 @@ let https = {
|
|||
try {
|
||||
crypto = require("crypto");
|
||||
https = require("https");
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
http2.createSecureServer = () => {
|
||||
throw new Error("Crypto support is not present");
|
||||
|
@ -94,6 +97,7 @@ process.filename = __filename;
|
|||
let hexstrbase64 = undefined;
|
||||
try {
|
||||
hexstrbase64 = require(process.dirname + "/hexstrbase64/index.js");
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Don't use hexstrbase64
|
||||
}
|
||||
|
@ -345,7 +349,7 @@ if (typeof process.serverConfig.port === "string") {
|
|||
process.serverConfig.port = parseInt(process.serverConfig.port);
|
||||
} else {
|
||||
const portLMatch = process.serverConfig.port.match(
|
||||
/^(\[[^ \]@\/\\]+\]|[^ \]\[:@\/\\]+):([0-9]+)$/,
|
||||
/^(\[[^ \]@/\\]+\]|[^ \][:@/\\]+):([0-9]+)$/,
|
||||
);
|
||||
if (portLMatch) {
|
||||
listenAddress = portLMatch[1]
|
||||
|
@ -360,7 +364,7 @@ if (typeof process.serverConfig.sport === "string") {
|
|||
process.serverConfig.sport = parseInt(process.serverConfig.sport);
|
||||
} else {
|
||||
const sportLMatch = process.serverConfig.sport.match(
|
||||
/^(\[[^ \]@\/\\]+\]|[^ \]\[:@\/\\]+):([0-9]+)$/,
|
||||
/^(\[[^ \]@/\\]+\]|[^ \][:@/\\]+):([0-9]+)$/,
|
||||
);
|
||||
if (sportLMatch) {
|
||||
sListenAddress = sportLMatch[1]
|
||||
|
@ -384,6 +388,7 @@ try {
|
|||
if (inspector) {
|
||||
inspectorURL = inspector.url();
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Failed to get inspector URL
|
||||
}
|
||||
|
@ -494,6 +499,7 @@ function doIpRequest(isHTTPS, options) {
|
|||
ipRequestCompleted = true;
|
||||
process.emit("ipRequestCompleted");
|
||||
});
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
clearTimeout(dnsTimeout);
|
||||
callbackDone = true;
|
||||
|
@ -629,6 +635,7 @@ if (process.serverConfig.secure) {
|
|||
let vnum = 0;
|
||||
try {
|
||||
vnum = process.config.variables.node_module_version;
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Version number not retrieved
|
||||
}
|
||||
|
@ -813,7 +820,7 @@ if (!disableMods) {
|
|||
crypto.__disabled__ === undefined
|
||||
? "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 =
|
||||
"\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
|
||||
|
@ -1042,6 +1049,7 @@ try {
|
|||
server2 = http.createServer({
|
||||
requireHostHeader: false,
|
||||
});
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
server2 = http.createServer();
|
||||
}
|
||||
|
@ -1107,6 +1115,7 @@ if (process.serverConfig.enableHTTP2 == true) {
|
|||
server = http.createServer({
|
||||
requireHostHeader: false,
|
||||
});
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
server = http.createServer();
|
||||
}
|
||||
|
@ -1144,10 +1153,12 @@ if (process.serverConfig.secure) {
|
|||
"$",
|
||||
"i",
|
||||
);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Can't replace regex, ignoring...
|
||||
}
|
||||
});
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// SNI error
|
||||
}
|
||||
|
@ -1201,6 +1212,7 @@ if (process.serverConfig.secure) {
|
|||
try {
|
||||
sock._parent.destroy(a, b, c);
|
||||
sock.destroyed = sock._parent.destroyed;
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Socket is probably already destroyed.
|
||||
}
|
||||
|
@ -1209,6 +1221,7 @@ if (process.serverConfig.secure) {
|
|||
sock._parent.destroy = sock._parent.reallyDestroy;
|
||||
try {
|
||||
if (sock._parent.toDestroy) sock._parent.destroy();
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Socket is probably already destroyed.
|
||||
}
|
||||
|
@ -1302,9 +1315,13 @@ let commands = {
|
|||
log("No mods installed.");
|
||||
}
|
||||
},
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
clear: (args, log) => {
|
||||
console.clear();
|
||||
},
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
stop: (args, log) => {
|
||||
let retcode = args[0];
|
||||
if (
|
||||
|
@ -1325,6 +1342,7 @@ let commands = {
|
|||
}
|
||||
}
|
||||
});
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
if (!process.removeFakeIPC) {
|
||||
if (typeof retcode == "number") {
|
||||
|
@ -1344,6 +1362,7 @@ let commands = {
|
|||
}
|
||||
}
|
||||
});
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
if (typeof retcode == "number") {
|
||||
process.exit(retcode);
|
||||
|
@ -1491,6 +1510,7 @@ function getWorkerCountToFork() {
|
|||
try {
|
||||
const useAvailableCores = Math.round(os.freemem() / 50000000) - 1; // 1 core deleted for safety...
|
||||
if (workersToFork > useAvailableCores) workersToFork = useAvailableCores;
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// 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
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
process.messageEventListeners.push((worker, serverconsole) => {
|
||||
return (message) => {
|
||||
if (message == "\x12LISTEN") {
|
||||
|
@ -1972,6 +1994,7 @@ function start(init) {
|
|||
} else {
|
||||
checkWorker(callback, _id + 1);
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
if (cluster.workers[allWorkers[_id]]) {
|
||||
cluster.workers[allWorkers[_id]].removeAllListeners("message");
|
||||
|
@ -2045,9 +2068,10 @@ function start(init) {
|
|||
process.send(`Unrecognized command "${line.split(" ")[0]}".`);
|
||||
process.send("\x12END");
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
if (line != "") {
|
||||
process.send(`Can't execute command \"${line.split(" ")[0]}".`);
|
||||
process.send(`Can't execute command "${line.split(" ")[0]}".`);
|
||||
process.send("\x12END");
|
||||
}
|
||||
}
|
||||
|
@ -2078,6 +2102,7 @@ function start(init) {
|
|||
if (cluster.workers[allWorkers[i]]) {
|
||||
cluster.workers[allWorkers[i]].kill();
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
stopError = true;
|
||||
}
|
||||
|
@ -2108,6 +2133,7 @@ function start(init) {
|
|||
cluster.workers[clusterID].on("message", msgListener);
|
||||
cluster.workers[clusterID].send(line);
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
if (cluster.workers[clusterID]) {
|
||||
cluster.workers[clusterID].removeAllListeners("message");
|
||||
|
@ -2124,6 +2150,7 @@ function start(init) {
|
|||
} else {
|
||||
try {
|
||||
commands[command](argss, serverconsole.climessage);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
serverconsole.climessage(
|
||||
'Unrecognized command "' + command + '".',
|
||||
|
@ -2325,6 +2352,7 @@ function start(init) {
|
|||
} else {
|
||||
checkWorker(callback, _id + 1);
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
if (cluster.workers[allWorkers[_id]]) {
|
||||
cluster.workers[allWorkers[_id]].removeAllListeners(
|
||||
|
@ -2397,11 +2425,13 @@ if (cluster.isPrimary || cluster.isPrimary === undefined) {
|
|||
}
|
||||
try {
|
||||
deleteFolderRecursive(process.dirname + "/temp");
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Error!
|
||||
}
|
||||
try {
|
||||
fs.mkdirSync(process.dirname + "/temp");
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Error!
|
||||
}
|
||||
|
@ -2415,6 +2445,7 @@ if (cluster.isPrimary || cluster.isPrimary === undefined) {
|
|||
process.dirname + "/temp/serverSideScript.js",
|
||||
"// Placeholder server-side JavaScript to workaround Bun bug.\r\n",
|
||||
);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Error!
|
||||
}
|
||||
|
@ -2437,6 +2468,7 @@ if (cluster.isPrimary || cluster.isPrimary === undefined) {
|
|||
if (cluster.workers[allWorkers[i]]) {
|
||||
cluster.workers[allWorkers[i]].send("stop");
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Worker will crash with EPIPE anyway.
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
decodedHrefWithoutDuplicateSlashes = decodeURIComponent(
|
||||
req.parsedURL.pathname,
|
||||
).replace(/\/+/g, "/");
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
res.error(400);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ let crypto = {
|
|||
};
|
||||
try {
|
||||
crypto = require("crypto");
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Crypto is disabled
|
||||
}
|
||||
|
@ -415,6 +416,8 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
};
|
||||
|
||||
// IPC listener for brute force protection
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
process.messageEventListeners.push((worker, serverconsole) => {
|
||||
return (message) => {
|
||||
let ip = "";
|
||||
|
|
|
@ -4,6 +4,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
Object.keys(hkh).forEach((hkS) => {
|
||||
try {
|
||||
res.setHeader(hkS, hkh[hkS]);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Headers will not be set.
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ const matchHostname = require("../utils/matchHostname.js");
|
|||
module.exports = (req, res, logFacilities, config, next) => {
|
||||
try {
|
||||
decodeURIComponent(req.parsedURL.pathname);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
res.error(400);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ const generateETag = (filePath, stat) => {
|
|||
return ETagDB[filePath + "-" + stat.size + "-" + stat.mtime];
|
||||
};
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
module.exports = (req, res, logFacilities, config, next) => {
|
||||
const checkPathLevel = (path) => {
|
||||
// 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 origHref = req.originalParsedURL.pathname;
|
||||
let ext = href.match(/[^\/]\.([^.]+)$/);
|
||||
let ext = href.match(/[^/]\.([^.]+)$/);
|
||||
if (!ext) ext = "";
|
||||
else ext = ext[1].toLowerCase();
|
||||
let dHref = "";
|
||||
try {
|
||||
dHref = decodeURIComponent(href);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
res.error(400);
|
||||
return;
|
||||
|
@ -381,6 +383,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
if (process.isBun && useBrotli && isCompressable) {
|
||||
try {
|
||||
zlib.createBrotliCompress();
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
useBrotli = false;
|
||||
}
|
||||
|
@ -574,7 +577,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
getCustomDirListingFooter(() => {
|
||||
// Check if custom header has HTML tag
|
||||
const headerHasHTMLTag = customDirListingHeader
|
||||
.replace(/<!--(?:(?:(?!--\>)[\s\S])*|)(?:-->|$)/g, "")
|
||||
.replace(/<!--(?:(?:(?!-->)[\s\S])*|)(?:-->|$)/g, "")
|
||||
.match(
|
||||
/<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
|
||||
? ""
|
||||
: '<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>'
|
||||
}`;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ if (!process.singleThreaded) {
|
|||
try {
|
||||
// Import cluster module
|
||||
cluster = require("cluster");
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Clustering is not supported!
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const os = require("os");
|
||||
|
||||
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);
|
||||
const searchString = regexStrMatch[1];
|
||||
let modifiers = regexStrMatch[2];
|
||||
|
|
|
@ -17,7 +17,7 @@ module.exports = (legacyMod) => {
|
|||
if (!req[legacyParsedURLSymbol])
|
||||
req[legacyParsedURLSymbol] = parseURL(req.url);
|
||||
|
||||
let ext = req[legacyParsedURLSymbol].pathname.match(/[^\/]\.([^.]+)$/);
|
||||
let ext = req[legacyParsedURLSymbol].pathname.match(/[^/]\.([^.]+)$/);
|
||||
if (!ext) ext = "";
|
||||
|
||||
// Function to parse incoming POST data from the request
|
||||
|
|
|
@ -17,8 +17,10 @@ let https = {
|
|||
},
|
||||
};
|
||||
try {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
crypto = require("crypto");
|
||||
https = require("https");
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Can't load HTTPS
|
||||
}
|
||||
|
@ -51,6 +53,7 @@ function sendStatistics(modInfos, callback) {
|
|||
let parsedJson = {};
|
||||
try {
|
||||
parsedJson = JSON.parse(data);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
throw new Error("JSON parse error (response parsing failed).");
|
||||
}
|
||||
|
|
|
@ -260,6 +260,7 @@ process.exit = (code) => {
|
|||
logSync = true;
|
||||
process.unsafeExit(code);
|
||||
}, 10000); // timeout
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
logFile = undefined;
|
||||
logSync = true;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
let crypto = { __disabled__: null };
|
||||
try {
|
||||
crypto = require("crypto");
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (err) {
|
||||
// Crypto support is disabled.
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ function parseURL(uri, prepend) {
|
|||
|
||||
// Parse the URL using regular expression
|
||||
let parsedURI = uri.match(
|
||||
/^(?:([^:]+:)(\/\/)?)?(?:([^@\/?#\*]+)@)?([^:\/?#\*]+|\[[^\*]\/]\])?(?::([0-9]+))?(\*|\/[^?#]*)?(\?[^#]*)?(#[\S\s]*)?/,
|
||||
/^(?:([^:]+:)(\/\/)?)?(?:([^@/?#*]+)@)?([^:/?#*]+|\[[^*]\/]\])?(?::([0-9]+))?(\*|\/[^?#]*)?(\?[^#]*)?(#[\S\s]*)?/,
|
||||
);
|
||||
// Match 1: protocol
|
||||
// Match 2: slashes after protocol
|
||||
|
@ -34,7 +34,7 @@ function parseURL(uri, prepend) {
|
|||
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 (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]);
|
||||
if (!parsedURI[4]) throw new Error("Invalid URL: " + uri);
|
||||
}
|
||||
|
|
|
@ -28,10 +28,10 @@ function sanitizeURL(resource, allowDoubleSlashes) {
|
|||
// Handle relative navigation (e.g., "/./", "/../", "../", "./"), also remove trailing dots in paths
|
||||
sanitizedResource = sanitizedResource
|
||||
.replace(/\/\.(?:\.{2,})?(?=\/|$)/g, "")
|
||||
.replace(/([^.\/])\.+(?=\/|$)/g, "$1");
|
||||
while (sanitizedResource.match(/\/(?!\.\.\/)[^\/]+\/\.\.(?=\/|$)/)) {
|
||||
.replace(/([^./])\.+(?=\/|$)/g, "$1");
|
||||
while (sanitizedResource.match(/\/(?!\.\.\/)[^/]+\/\.\.(?=\/|$)/)) {
|
||||
sanitizedResource = sanitizedResource.replace(
|
||||
/\/(?!\.\.\/)[^\/]+\/\.\.(?=\/|$)/g,
|
||||
/\/(?!\.\.\/)[^/]+\/\.\.(?=\/|$)/g,
|
||||
"",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ const fs = require("fs");
|
|||
let crypto = {};
|
||||
try {
|
||||
crypto = require("crypto");
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (ex) {
|
||||
crypto = {};
|
||||
crypto.__disabled__ = null;
|
||||
|
@ -259,11 +260,13 @@ if (fs.existsSync(__dirname + "/config.json")) {
|
|||
let configJSONf = "";
|
||||
try {
|
||||
configJSONf = fs.readFileSync(__dirname + "/config.json"); //Read JSON File
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (ex) {
|
||||
throw new Error("Cannot read JSON file.");
|
||||
}
|
||||
try {
|
||||
configJSON = JSON.parse(configJSONf); //Parse JSON
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (ex) {
|
||||
throw new Error("JSON Parse error.");
|
||||
}
|
||||
|
|
Reference in a new issue