From 5a3e6765f1540c0e3f25ca2e5a0e9e6af9542d33 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Tue, 27 Aug 2024 10:54:08 +0200 Subject: [PATCH] Replace ES5-style functions with ES6-style ones --- src/index.js | 144 +++++++++--------- src/middleware/checkForbiddenPaths.js | 2 +- .../nonStandardCodesAndHttpAuthentication.js | 20 +-- src/middleware/redirectTrailingSlashes.js | 2 +- src/middleware/responseHeaders.js | 2 +- src/middleware/rewriteURL.js | 4 +- .../staticFileServingAndDirectoryListings.js | 2 +- src/middleware/webRootPostfixes.js | 4 +- src/utils/deleteFolderRecursive.js | 2 +- src/utils/forbiddenPaths.js | 4 +- src/utils/generateErrorStack.js | 4 +- src/utils/legacyModWrapper.js | 2 +- src/utils/sendStatistics.js | 6 +- src/utils/serverconsole.js | 10 +- src/utils/urlMojibakeFixer.js | 4 +- src/utils/urlParserLegacy.js | 2 +- 16 files changed, 107 insertions(+), 107 deletions(-) diff --git a/src/index.js b/src/index.js index b747bd2..f3406f9 100644 --- a/src/index.js +++ b/src/index.js @@ -41,16 +41,16 @@ try { } } catch (err) { http2.__disabled__ = null; - http2.createServer = function () { + http2.createServer = () => { throw new Error("HTTP/2 support is not present"); }; - http2.createSecureServer = function () { + http2.createSecureServer = () => { throw new Error("HTTP/2 support is not present"); }; - http2.connect = function () { + http2.connect = () => { throw new Error("HTTP/2 support is not present"); }; - http2.get = function () { + http2.get = () => { throw new Error("HTTP/2 support is not present"); }; } @@ -58,13 +58,13 @@ let crypto = { __disabled__: null, }; let https = { - createServer: function () { + createServer: () => { throw new Error("Crypto support is not present"); }, - connect: function () { + connect: () => { throw new Error("Crypto support is not present"); }, - get: function () { + get: () => { throw new Error("Crypto support is not present"); }, }; @@ -72,7 +72,7 @@ try { crypto = require("crypto"); https = require("https"); } catch (err) { - http2.createSecureServer = function () { + http2.createSecureServer = () => { throw new Error("Crypto support is not present"); }; } @@ -390,10 +390,10 @@ try { if (!process.stdout.isTTY && !inspectorURL) { // When stdout is not a terminal and not attached to an Node.JS inspector, disable it to improve performance of SVR.JS - console.log = function () {}; - process.stdout.write = function () {}; - process.stdout._write = function () {}; - process.stdout._writev = function () {}; + console.log = () => {}; + process.stdout.write = () => {}; + process.stdout._write = () => {}; + process.stdout._writev = () => {}; } let wwwrootError = null; @@ -467,7 +467,7 @@ let pubip = ""; function doIpRequest(isHTTPS, options) { const ipRequest = (isHTTPS ? https : http).get(options, (res) => { ipRequest.removeAllListeners("timeout"); - res.on("data", function (d) { + res.on("data", (d) => { if (res.statusCode != 200) { ipRequestCompleted = true; process.emit("ipRequestCompleted"); @@ -480,14 +480,14 @@ function doIpRequest(isHTTPS, options) { } else { let callbackDone = false; - const dnsTimeout = setTimeout(function () { + const dnsTimeout = setTimeout(() => { callbackDone = true; ipRequestCompleted = true; process.emit("ipRequestCompleted"); }, 3000); try { - dns.reverse(pubip, function (err, hostnames) { + dns.reverse(pubip, (err, hostnames) => { if (callbackDone) return; clearTimeout(dnsTimeout); if (!err && hostnames.length > 0) domain = hostnames[0]; @@ -503,7 +503,7 @@ function doIpRequest(isHTTPS, options) { } }); }); - ipRequest.on("error", function () { + ipRequest.on("error", () => { if (crypto.__disabled__ || ipRequestGotError) { ipRequestCompleted = true; process.emit("ipRequestCompleted"); @@ -511,7 +511,7 @@ function doIpRequest(isHTTPS, options) { ipRequestGotError = true; } }); - ipRequest.on("timeout", function () { + ipRequest.on("timeout", () => { if (crypto.__disabled__ || ipRequestGotError) { ipRequestCompleted = true; process.emit("ipRequestCompleted"); @@ -594,7 +594,7 @@ if (process.serverConfig.secure) { ) .toString(); const sniNames = Object.keys(process.serverConfig.sni); - sniNames.forEach(function (sniName) { + sniNames.forEach((sniName) => { if ( typeof sniName === "string" && sniName.match(/\*[^*.:]*\*[^*.:]*(?:\.|:|$)/) @@ -697,7 +697,7 @@ if (!disableMods) { // Create a subfolder for the current mod within the modloader folder fs.mkdirSync(process.dirname + "/temp/" + modloaderFolderName + "/" + modFileRaw); - + } catch (err) { // If there was an error creating the folder, ignore it if it's a known error if (err.code != "EEXIST" && err.code != "ENOENT") throw err; @@ -806,7 +806,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 function () {\r\nvar disableEndElseCallbackExecute = false;\r\nfunction filterHeaders(e){var r={};return Object.keys(e).forEach((function(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 @@ -1109,7 +1109,7 @@ if (process.serverConfig.enableHTTP2 == true) { // Load SNI contexts into HTTP server if (process.serverConfig.secure) { try { - sniCredentials.forEach(function (sniCredentialsSingle) { + sniCredentials.forEach((sniCredentialsSingle) => { server.addContext(sniCredentialsSingle.name, { cert: sniCredentialsSingle.cert, key: sniCredentialsSingle.key, @@ -1151,7 +1151,7 @@ server.on("request", requestHandler); server.on("checkExpectation", requestHandler); server.on("connect", proxyHandler); server.on("clientError", clientErrorHandler); -server.on("error", function (err) { +server.on("error", (err) => { serverErrorHandler(err, false, server, start); }); server.on("listening", () => { @@ -1160,14 +1160,14 @@ server.on("listening", () => { }); if (process.serverConfig.secure) { - server.prependListener("connection", function (sock) { + server.prependListener("connection", (sock) => { sock.reallyDestroy = sock.destroy; - sock.destroy = function () { + sock.destroy = () => { sock.toDestroy = true; }; }); - server.prependListener("tlsClientError", function (err, sock) { + server.prependListener("tlsClientError", (err, sock) => { if ( err.code == "ERR_SSL_HTTP_REQUEST" || err.message.indexOf("http request") != -1 @@ -1176,13 +1176,13 @@ if (process.serverConfig.secure) { sock._readableState = sock._parent._readableState; sock._writableState = sock._parent._writableState; sock._parent.toDestroy = false; - sock.pipe = function (a, b, c) { + sock.pipe = (a, b, c) => { sock._parent.pipe(a, b, c); }; - sock.write = function (a, b, c) { + sock.write = (a, b, c) => { sock._parent.write(a, b, c); }; - sock.end = function (a, b, c) { + sock.end = (a, b, c) => { sock._parent.end(a, b, c); }; sock.destroyed = sock._parent.destroyed; @@ -1190,7 +1190,7 @@ if (process.serverConfig.secure) { sock.writable = sock._parent.writable; sock.remoteAddress = sock._parent.remoteAddress; sock.remotePort = sock._parent.remoteAddress; - sock.destroy = function (a, b, c) { + sock.destroy = (a, b, c) => { try { sock._parent.destroy(a, b, c); sock.destroyed = sock._parent.destroyed; @@ -1208,14 +1208,14 @@ if (process.serverConfig.secure) { } }); - server.prependListener("secureConnection", function (sock) { + server.prependListener("secureConnection", (sock) => { sock._parent.destroy = sock._parent.reallyDestroy; delete sock._parent.reallyDestroy; }); if (process.serverConfig.enableOCSPStapling && !ocsp._errored) { - server.on("OCSPRequest", function (cert, issuer, callback) { - ocsp.getOCSPURI(cert, function (err, uri) { + server.on("OCSPRequest", (cert, issuer, callback) => { + ocsp.getOCSPURI(cert, (err, uri) => { if (err) return callback(err); const req = ocsp.request.generate(cert, issuer); @@ -1306,10 +1306,10 @@ let commands = { server.listening ) { try { - server.close(function () { + server.close(() => { if (server2.listening) { try { - server2.close(function () { + server2.close(() => { if (!process.removeFakeIPC) { if (typeof retcode == "number") { process.exit(retcode); @@ -1458,7 +1458,7 @@ function SVRJSFork() { // Add event listeners if (newWorker.on) { - newWorker.on("error", function (err) { + newWorker.on("error", (err) => { if (!exiting) serverconsole.locwarnmessage( "There was a problem when handling " + @@ -1467,7 +1467,7 @@ function SVRJSFork() { err.message, ); }); - newWorker.on("exit", function () { + newWorker.on("exit", () => { if (!exiting && Object.keys(cluster.workers).length == 0) { crashed = true; SVRJSFork(); @@ -1497,8 +1497,8 @@ function forkWorkers(workersToFork, callback) { SVRJSFork(); } else { setTimeout( - (function (i) { - return function () { + ((i) => { + return () => { SVRJSFork(); if (i >= workersToFork - 1) callback(); }; @@ -1690,7 +1690,7 @@ function start(init) { /^(?:0\.|1\.0\.|1\.1\.[0-9](?![0-9])|1\.1\.1[0-2](?![0-9]))/, ) ) && - process.serverConfig.users.some(function (entry) { + process.serverConfig.users.some((entry) => { return entry.pbkdf2; }) ) @@ -1769,7 +1769,7 @@ function start(init) { // Display mod and server-side JavaScript errors if (process.isPrimary || process.isPrimary === undefined) { - modLoadingErrors.forEach(function (modLoadingError) { + modLoadingErrors.forEach((modLoadingError) => { serverconsole.locwarnmessage( `There was a problem while loading a "${String(modLoadingError.modName).replace(/[\r\n]/g, "")}" mod.`, ); @@ -1930,7 +1930,7 @@ function start(init) { let workersToFork = 1; if (cluster.isPrimary === undefined) { - setInterval(function () { + setInterval(() => { try { saveConfig(); serverconsole.locmessage("Configuration saved."); @@ -1939,7 +1939,7 @@ function start(init) { } }, 300000); } else if (cluster.isPrimary) { - setInterval(function () { + setInterval(() => { var allWorkers = Object.keys(cluster.workers); var goodWorkers = []; @@ -1954,7 +1954,7 @@ function start(init) { isWorkerHungUpBuff2 = true; cluster.workers[allWorkers[_id]].on("message", msgListener); cluster.workers[allWorkers[_id]].send("\x14PINGPING"); - setTimeout(function () { + setTimeout(() => { if (isWorkerHungUpBuff2) { checkWorker(callback, _id + 1); } else { @@ -1973,7 +1973,7 @@ function start(init) { checkWorker(callback, _id + 1); } }; - checkWorker(function () { + checkWorker(() => { const wN = Math.floor(Math.random() * goodWorkers.length); //Send a configuration saving message to a random worker. try { if (cluster.workers[goodWorkers[wN]]) { @@ -1995,7 +1995,7 @@ function start(init) { } if (!cluster.isPrimary && cluster.isPrimary !== undefined) { - process.on("message", function (line) { + process.on("message", (line) => { try { if (line == "") { // Does Nothing @@ -2052,7 +2052,7 @@ function start(init) { prompt: "", }); rla.prompt(); - rla.on("line", function (line) { + rla.on("line", (line) => { line = line.trim(); const argss = line.split(" "); const command = argss.shift(); @@ -2083,7 +2083,7 @@ function start(init) { closedMaster = true; workersToFork = getWorkerCountToFork(); - forkWorkers(workersToFork, function () { + forkWorkers(workersToFork, () => { SVRJSInitialized = true; exiting = false; serverconsole.climessage(`${name} workers restarted.`); @@ -2110,7 +2110,7 @@ function start(init) { } }); if (command == "stop") { - setTimeout(function () { + setTimeout(() => { commands[command](argss, serverconsole.climessage); }, 50); } @@ -2132,12 +2132,12 @@ function start(init) { // Cluster forking code if (cluster.isPrimary !== undefined && init) { workersToFork = getWorkerCountToFork(); - forkWorkers(workersToFork, function () { + forkWorkers(workersToFork, () => { SVRJSInitialized = true; }); // Hangup check and restart - setInterval(function () { + setInterval(() => { if (!closedMaster && !exiting) { let chksocket = {}; if ( @@ -2167,21 +2167,21 @@ function start(init) { timeout: 1620, rejectUnauthorized: false, }, - function (res) { + (res) => { chksocket.removeAllListeners("timeout"); res.destroy(); - res.on("data", function () {}); - res.on("end", function () {}); + res.on("data", () => {}); + res.on("end", () => {}); crashed = false; }, ) - .on("error", function () { + .on("error", () => { if (!exiting) { if (!crashed) SVRJSFork(); else crashed = false; } }) - .on("timeout", function () { + .on("timeout", () => { if (!exiting) SVRJSFork(); crashed = true; }); @@ -2206,13 +2206,13 @@ function start(init) { ":" + process.serverConfig.port.toString(), ); - connection.on("error", function () { + connection.on("error", () => { if (!exiting) { if (!crashed) SVRJSFork(); else crashed = false; } }); - connection.setTimeout(1620, function () { + connection.setTimeout(1620, () => { if (!exiting) SVRJSFork(); crashed = true; }); @@ -2221,11 +2221,11 @@ function start(init) { "x-svr-js-from-main-thread": "true", "user-agent": generateServerString(true), }); - chksocket.on("response", function () { + chksocket.on("response", () => { connection.close(); crashed = false; }); - chksocket.on("error", function () { + chksocket.on("error", () => { if (!exiting) { if (!crashed) SVRJSFork(); else crashed = false; @@ -2254,21 +2254,21 @@ function start(init) { }, timeout: 1620, }, - function (res) { + (res) => { chksocket.removeAllListeners("timeout"); res.destroy(); - res.on("data", function () {}); - res.on("end", function () {}); + res.on("data", () => {}); + res.on("end", () => {}); crashed = false; }, ) - .on("error", function () { + .on("error", () => { if (!exiting) { if (!crashed) SVRJSFork(); else crashed = false; } }) - .on("timeout", function () { + .on("timeout", () => { if (!exiting) SVRJSFork(); crashed = true; }); @@ -2281,8 +2281,8 @@ function start(init) { !process.serverConfig.disableUnusedWorkerTermination && cluster.isPrimary !== undefined ) { - setTimeout(function () { - setInterval(function () { + setTimeout(() => { + setInterval(() => { if (!closedMaster && !exiting) { const allWorkers = Object.keys(cluster.workers); @@ -2307,7 +2307,7 @@ function start(init) { msgListener, ); cluster.workers[allWorkers[_id]].send("\x14KILLPING"); - setTimeout(function () { + setTimeout(() => { if (isWorkerHungUpBuff) { checkWorker(callback, _id + 1); } else { @@ -2378,7 +2378,7 @@ if (cluster.isPrimary || cluster.isPrimary === undefined) { process.on("uncaughtException", crashHandlerMaster); process.on("unhandledRejection", crashHandlerMaster); - process.on("exit", function (code) { + process.on("exit", (code) => { try { if (!configJSONRErr && !configJSONPErr) { saveConfig(); @@ -2414,14 +2414,14 @@ if (cluster.isPrimary || cluster.isPrimary === undefined) { } serverconsole.locmessage("Server closed with exit code: " + code); }); - process.on("warning", function (warning) { + process.on("warning", (warning) => { serverconsole.locwarnmessage(warning.message); if (generateErrorStack(warning)) { serverconsole.locwarnmessage("Stack:"); serverconsole.locwarnmessage(generateErrorStack(warning)); } }); - process.on("SIGINT", function () { + process.on("SIGINT", () => { if (cluster.isPrimary !== undefined) { exiting = true; const allWorkers = Object.keys(cluster.workers); @@ -2453,7 +2453,7 @@ if (cluster.isPrimary || cluster.isPrimary === undefined) { process.on("unhandledRejection", crashHandler); // Warning handler - process.on("warning", function (warning) { + process.on("warning", (warning) => { serverconsole.locwarnmessage(warning.message); if (warning.stack) { serverconsole.locwarnmessage("Stack:"); @@ -2469,7 +2469,7 @@ try { serverconsole.locerrmessage(`There was a problem starting ${name}!!!`); serverconsole.locerrmessage("Stack:"); serverconsole.locerrmessage(generateErrorStack(err)); - setTimeout(function () { + setTimeout(() => { process.exit(err.errno !== undefined ? err.errno : 1); }, 10); } diff --git a/src/middleware/checkForbiddenPaths.js b/src/middleware/checkForbiddenPaths.js index 8a140d8..18bcb29 100644 --- a/src/middleware/checkForbiddenPaths.js +++ b/src/middleware/checkForbiddenPaths.js @@ -16,7 +16,7 @@ if (process.serverConfig.secure) { getInitializePath(process.serverConfig.cert), ); forbiddenPaths.certificates.push(getInitializePath(process.serverConfig.key)); - Object.keys(process.serverConfig.sni).forEach(function (sniHostname) { + Object.keys(process.serverConfig.sni).forEach((sniHostname) => { forbiddenPaths.certificates.push( getInitializePath(process.serverConfig.sni[sniHostname].cert), ); diff --git a/src/middleware/nonStandardCodesAndHttpAuthentication.js b/src/middleware/nonStandardCodesAndHttpAuthentication.js index fe6f666..2efe961 100644 --- a/src/middleware/nonStandardCodesAndHttpAuthentication.js +++ b/src/middleware/nonStandardCodesAndHttpAuthentication.js @@ -40,11 +40,11 @@ process.serverConfig.nonStandardCodes.forEach((nonStandardCodeRaw) => { }); if (!cluster.isPrimary) { - passwordHashCacheIntervalId = setInterval(function () { - pbkdf2Cache = pbkdf2Cache.filter(function (entry) { + passwordHashCacheIntervalId = setInterval(() => { + pbkdf2Cache = pbkdf2Cache.filter((entry) => { return entry.addDate > new Date() - 3600000; }); - scryptCache = scryptCache.filter(function (entry) { + scryptCache = scryptCache.filter((entry) => { return entry.addDate > new Date() - 3600000; }); }, 1800000); @@ -170,7 +170,7 @@ module.exports = (req, res, logFacilities, config, next) => { // Function to check if passwords match const checkIfPasswordMatches = (list, password, callback, _i) => { if (!_i) _i = 0; - const cb = function (hash) { + const cb = (hash) => { if (hash == list[_i].pass) { callback(true); } else if (_i >= list.length - 1) { @@ -191,7 +191,7 @@ module.exports = (req, res, logFacilities, config, next) => { ); return; } else { - cacheEntry = scryptCache.find(function (entry) { + cacheEntry = scryptCache.find((entry) => { return ( entry.password == hashedPassword && entry.salt == list[_i].salt ); @@ -203,7 +203,7 @@ module.exports = (req, res, logFacilities, config, next) => { password, list[_i].salt, 64, - function (err, derivedKey) { + (err, derivedKey) => { if (err) { res.error(500, err); } else { @@ -230,7 +230,7 @@ module.exports = (req, res, logFacilities, config, next) => { ); return; } else { - cacheEntry = pbkdf2Cache.find(function (entry) { + cacheEntry = pbkdf2Cache.find((entry) => { return ( entry.password == hashedPassword && entry.salt == list[_i].salt ); @@ -244,7 +244,7 @@ module.exports = (req, res, logFacilities, config, next) => { 36250, 64, "sha512", - function (err, derivedKey) { + (err, derivedKey) => { if (err) { res.error(500, err); } else { @@ -304,7 +304,7 @@ module.exports = (req, res, logFacilities, config, next) => { let pbkdf2Count = 0; let scryptCount = 0; if (!authcode.userList || authcode.userList.indexOf(username) > -1) { - usernameMatch = config.users.filter(function (entry) { + usernameMatch = config.users.filter((entry) => { if (entry.scrypt) { scryptCount++; } else if (entry.pbkdf2) { @@ -331,7 +331,7 @@ module.exports = (req, res, logFacilities, config, next) => { } usernameMatch.push(fakeCredentials); } - checkIfPasswordMatches(usernameMatch, password, function (authorized) { + checkIfPasswordMatches(usernameMatch, password, (authorized) => { try { if (!authorized) { if (bruteProtection) { diff --git a/src/middleware/redirectTrailingSlashes.js b/src/middleware/redirectTrailingSlashes.js index 171771b..6835d69 100644 --- a/src/middleware/redirectTrailingSlashes.js +++ b/src/middleware/redirectTrailingSlashes.js @@ -11,7 +11,7 @@ module.exports = (req, res, logFacilities, config, next) => { ) { fs.stat( "." + decodeURIComponent(req.parsedURL.pathname), - function (err, stats) { + (err, stats) => { if (err || !stats.isDirectory()) { try { next(); diff --git a/src/middleware/responseHeaders.js b/src/middleware/responseHeaders.js index e341e21..591551f 100644 --- a/src/middleware/responseHeaders.js +++ b/src/middleware/responseHeaders.js @@ -1,7 +1,7 @@ module.exports = (req, res, logFacilities, config, next) => { if (!req.isProxy) { var hkh = config.getCustomHeaders(); - Object.keys(hkh).forEach(function (hkS) { + Object.keys(hkh).forEach((hkS) => { try { res.setHeader(hkS, hkh[hkS]); } catch (err) { diff --git a/src/middleware/rewriteURL.js b/src/middleware/rewriteURL.js index 82bc97c..7827d4c 100644 --- a/src/middleware/rewriteURL.js +++ b/src/middleware/rewriteURL.js @@ -61,7 +61,7 @@ module.exports = (req, res, logFacilities, config, next) => { ) { rewrittenURL = tempRewrittenURL; try { - mapEntry.replacements.forEach(function (replacement) { + mapEntry.replacements.forEach((replacement) => { rewrittenURL = rewrittenURL.replace( createRegex(replacement.regex), replacement.replacement, @@ -80,7 +80,7 @@ module.exports = (req, res, logFacilities, config, next) => { }; // Rewrite URLs - rewriteURL(req.url, config.rewriteMap, function (err, rewrittenURL) { + rewriteURL(req.url, config.rewriteMap, (err, rewrittenURL) => { if (err) { res.error(500, err); return; diff --git a/src/middleware/staticFileServingAndDirectoryListings.js b/src/middleware/staticFileServingAndDirectoryListings.js index 697b373..946ccb9 100644 --- a/src/middleware/staticFileServingAndDirectoryListings.js +++ b/src/middleware/staticFileServingAndDirectoryListings.js @@ -57,7 +57,7 @@ module.exports = (req, res, logFacilities, config, next) => { config.enableDirectoryListing === undefined; if (!config.enableDirectoryListingVHost) return main; let vhostP = null; - config.enableDirectoryListingVHost.every(function (vhost) { + config.enableDirectoryListingVHost.every((vhost) => { if ( matchHostname(vhost.host, hostname) && ipMatch(vhost.ip, localAddress) diff --git a/src/middleware/webRootPostfixes.js b/src/middleware/webRootPostfixes.js index 92cfcc6..6317237 100644 --- a/src/middleware/webRootPostfixes.js +++ b/src/middleware/webRootPostfixes.js @@ -35,7 +35,7 @@ module.exports = (req, res, logFacilities, config, next) => { : req.url; let urlWithPostfix = preparedReqUrl3; let postfixPrefix = ""; - config.wwwrootPostfixPrefixesVHost.every(function (currentPostfixPrefix) { + config.wwwrootPostfixPrefixesVHost.every((currentPostfixPrefix) => { if (preparedReqUrl3.indexOf(currentPostfixPrefix) == 0) { if (currentPostfixPrefix.match(/\/+$/)) postfixPrefix = currentPostfixPrefix.replace(/\/+$/, ""); @@ -53,7 +53,7 @@ module.exports = (req, res, logFacilities, config, next) => { return true; } }); - config.wwwrootPostfixesVHost.every(function (postfixEntry) { + config.wwwrootPostfixesVHost.every((postfixEntry) => { if ( matchHostname(postfixEntry.host) && ipMatch( diff --git a/src/utils/deleteFolderRecursive.js b/src/utils/deleteFolderRecursive.js index 790ab71..f1d707e 100644 --- a/src/utils/deleteFolderRecursive.js +++ b/src/utils/deleteFolderRecursive.js @@ -2,7 +2,7 @@ const fs = require("fs"); function deleteFolderRecursive(path) { if (fs.existsSync(path)) { - fs.readdirSync(path).forEach(function (file) { + fs.readdirSync(path).forEach((file) => { const curPath = path + "/" + file; if (fs.statSync(curPath).isDirectory()) { // recurse diff --git a/src/utils/forbiddenPaths.js b/src/utils/forbiddenPaths.js index be76508..b91a4f7 100644 --- a/src/utils/forbiddenPaths.js +++ b/src/utils/forbiddenPaths.js @@ -34,7 +34,7 @@ function isForbiddenPath(decodedHref, match) { ); } if (typeof forbiddenPath === "object") { - return forbiddenPath.some(function (forbiddenPathSingle) { + return forbiddenPath.some((forbiddenPathSingle) => { return ( decodedHref === forbiddenPathSingle || (os.platform() === "win32" && @@ -61,7 +61,7 @@ function isIndexOfForbiddenPath(decodedHref, match) { ); } if (typeof forbiddenPath === "object") { - return forbiddenPath.some(function (forbiddenPathSingle) { + return forbiddenPath.some((forbiddenPathSingle) => { return ( decodedHref === forbiddenPathSingle || decodedHref.indexOf(forbiddenPathSingle + "/") === 0 || diff --git a/src/utils/generateErrorStack.js b/src/utils/generateErrorStack.js index d1f23ff..8451a11 100644 --- a/src/utils/generateErrorStack.js +++ b/src/utils/generateErrorStack.js @@ -5,7 +5,7 @@ function generateErrorStack(errorObject) { // If the error stack starts with the error name, return the original stack (it is V8-style then). if ( - errorStack.some(function (errorStackLine) { + errorStack.some((errorStackLine) => { return errorStackLine.indexOf(errorObject.name) == 0; }) ) { @@ -20,7 +20,7 @@ function generateErrorStack(errorObject) { ]; // Process each line of the original error stack. - errorStack.forEach(function (errorStackLine) { + errorStack.forEach((errorStackLine) => { if (errorStackLine != "") { // Split the line into function and location parts (if available). var errorFrame = errorStackLine.split("@"); diff --git a/src/utils/legacyModWrapper.js b/src/utils/legacyModWrapper.js index 0bb5e7c..a1cdbe0 100644 --- a/src/utils/legacyModWrapper.js +++ b/src/utils/legacyModWrapper.js @@ -49,7 +49,7 @@ module.exports = (legacyMod) => { const form = formidable(formidableOptions); // Parse the request and process the fields and files - form.parse(req, function (err, fields, files) { + form.parse(req, (err, fields, files) => { // If there was an error, call the server error function with status code determined by error if (err) { if (err.httpCode) res.error(err.httpCode); diff --git a/src/utils/sendStatistics.js b/src/utils/sendStatistics.js index 5ac60f4..65202c6 100644 --- a/src/utils/sendStatistics.js +++ b/src/utils/sendStatistics.js @@ -6,13 +6,13 @@ let crypto = { __disabled__: null, }; let https = { - createServer: function () { + createServer: () => { throw new Error("Crypto support is not present"); }, - connect: function () { + connect: () => { throw new Error("Crypto support is not present"); }, - get: function () { + get: () => { throw new Error("Crypto support is not present"); }, }; diff --git a/src/utils/serverconsole.js b/src/utils/serverconsole.js index ab4b7d7..56fdc94 100644 --- a/src/utils/serverconsole.js +++ b/src/utils/serverconsole.js @@ -43,7 +43,7 @@ function LOG(s) { autoClose: false, }, ); - logFile.on("error", function (err) { + logFile.on("error", (err) => { if ( !s.match( /^SERVER WARNING MESSAGE(?: \[Request Id: [0-9a-f]{6}\])?: There was a problem while saving logs! Logs will not be kept in log file\. Reason: /, @@ -238,16 +238,16 @@ var serverconsole = { // Wrap around process.exit, so that log contents can be flushed. process.unsafeExit = process.exit; -process.exit = function (code) { +process.exit = (code) => { if (logFile && logFile.writable && !logFile.pending) { try { - logFile.close(function () { + logFile.close(() => { logFile = undefined; logSync = true; process.unsafeExit(code); }); if (process.isBun) { - setInterval(function () { + setInterval(() => { if (!logFile.writable) { logFile = undefined; logSync = true; @@ -255,7 +255,7 @@ process.exit = function (code) { } }, 50); // Interval } - setTimeout(function () { + setTimeout(() => { logFile = undefined; logSync = true; process.unsafeExit(code); diff --git a/src/utils/urlMojibakeFixer.js b/src/utils/urlMojibakeFixer.js index 92824f5..f7e6c47 100644 --- a/src/utils/urlMojibakeFixer.js +++ b/src/utils/urlMojibakeFixer.js @@ -3,7 +3,7 @@ function fixNodeMojibakeURL(string) { var encoded = ""; //Encode URLs - Buffer.from(string, "latin1").forEach(function (value) { + Buffer.from(string, "latin1").forEach((value) => { if (value > 127) { encoded += "%" + (value < 16 ? "0" : "") + value.toString(16).toUpperCase(); @@ -13,7 +13,7 @@ function fixNodeMojibakeURL(string) { }); //Upper case the URL encodings - return encoded.replace(/%[0-9a-f-A-F]{2}/g, function (match) { + return encoded.replace(/%[0-9a-f-A-F]{2}/g, (match) => { return match.toUpperCase(); }); } diff --git a/src/utils/urlParserLegacy.js b/src/utils/urlParserLegacy.js index aee5690..deebdcc 100644 --- a/src/utils/urlParserLegacy.js +++ b/src/utils/urlParserLegacy.js @@ -61,7 +61,7 @@ function parseURL(uri, prepend) { const parsedQuery = parsedURI[7] .substring(1) .match(/([^&=]*)(?:=([^&]*))?/g); - parsedQuery.forEach(function (qp) { + parsedQuery.forEach((qp) => { if (qp.length > 0) { let parsedQP = qp.match(/([^&=]*)(?:=([^&]*))?/); if (parsedQP) {