forked from svrjs/svrjs
Replace some strings with template strings
This commit is contained in:
parent
d92fc14991
commit
488bee1a95
16 changed files with 316 additions and 519 deletions
|
@ -64,7 +64,7 @@ function clientErrorHandler(err, socket) {
|
|||
headername.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})`);
|
||||
head += headername + ": " + headerValueS;
|
||||
});
|
||||
} else {
|
||||
|
@ -72,7 +72,7 @@ function clientErrorHandler(err, socket) {
|
|||
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})`);
|
||||
head += headername + ": " + headers[headername];
|
||||
}
|
||||
head += "\r\n";
|
||||
|
@ -264,9 +264,7 @@ function clientErrorHandler(err, socket) {
|
|||
// Disable custom error page for HTTP SSL error
|
||||
res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders);
|
||||
res.write(
|
||||
'<!DOCTYPE html><html><head><title>{errorMessage}</title><meta name="viewport" content="width=device-width, initial-scale=1.0" /><style>' +
|
||||
defaultPageCSS +
|
||||
"</style></head><body><h1>{errorMessage}</h1><p>{errorDesc}</p><p><i>{server}</i></p></body></html>"
|
||||
`<!DOCTYPE html><html><head><title>{errorMessage}</title><meta name="viewport" content="width=device-width, initial-scale=1.0" /><style>${defaultPageCSS}${"</style></head><body><h1>{errorMessage}</h1><p>{errorDesc}</p><p><i>{server}</i></p></body></html>"
|
||||
.replace(
|
||||
/{errorMessage}/g,
|
||||
errorCode.toString() +
|
||||
|
@ -274,7 +272,7 @@ function clientErrorHandler(err, socket) {
|
|||
http.STATUS_CODES[errorCode]
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">"),
|
||||
.replace(/>/g, ">")
|
||||
)
|
||||
.replace(/{errorDesc}/g, serverHTTPErrorDescs[errorCode])
|
||||
.replace(
|
||||
|
@ -286,7 +284,7 @@ function clientErrorHandler(err, socket) {
|
|||
.replace(/\r\n/g, "<br/>")
|
||||
.replace(/\n/g, "<br/>")
|
||||
.replace(/\r/g, "<br/>")
|
||||
.replace(/ {2}/g, " "),
|
||||
.replace(/ {2}/g, " ")
|
||||
)
|
||||
.replace(
|
||||
/{server}/g,
|
||||
|
@ -298,7 +296,7 @@ function clientErrorHandler(err, socket) {
|
|||
)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">"),
|
||||
.replace(/>/g, ">")
|
||||
)
|
||||
.replace(
|
||||
/{contact}/g,
|
||||
|
@ -307,8 +305,8 @@ function clientErrorHandler(err, socket) {
|
|||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/\./g, "[dot]")
|
||||
.replace(/@/g, "[at]"),
|
||||
),
|
||||
.replace(/@/g, "[at]")
|
||||
)}`,
|
||||
);
|
||||
res.end();
|
||||
} else {
|
||||
|
@ -380,13 +378,9 @@ function clientErrorHandler(err, socket) {
|
|||
res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders);
|
||||
res.write(
|
||||
(
|
||||
'<!DOCTYPE html><html><head><title>{errorMessage}</title><meta name="viewport" content="width=device-width, initial-scale=1.0" /><style>' +
|
||||
defaultPageCSS +
|
||||
"</style></head><body><h1>{errorMessage}</h1><p>{errorDesc}</p>" +
|
||||
(additionalError == 404
|
||||
`<!DOCTYPE html><html><head><title>{errorMessage}</title><meta name="viewport" content="width=device-width, initial-scale=1.0" /><style>${defaultPageCSS}</style></head><body><h1>{errorMessage}</h1><p>{errorDesc}</p>${additionalError == 404
|
||||
? ""
|
||||
: "<p>Additionally, a {additionalError} error occurred while loading an error page.</p>") +
|
||||
"<p><i>{server}</i></p></body></html>"
|
||||
: "<p>Additionally, a {additionalError} error occurred while loading an error page.</p>"}<p><i>{server}</i></p></body></html>`
|
||||
)
|
||||
.replace(
|
||||
/{errorMessage}/g,
|
||||
|
@ -444,20 +438,16 @@ function clientErrorHandler(err, socket) {
|
|||
process.reqcounter++;
|
||||
process.malformedcounter++;
|
||||
logFacilities.locmessage(
|
||||
"Somebody connected to " +
|
||||
(config.secure && fromMain
|
||||
`Somebody connected to ${config.secure && fromMain
|
||||
? (typeof config.sport == "number" ? "port " : "socket ") + config.sport
|
||||
: (typeof config.port == "number" ? "port " : "socket ") +
|
||||
config.port) +
|
||||
"...",
|
||||
config.port}...`,
|
||||
);
|
||||
logFacilities.reqmessage(
|
||||
"Client " +
|
||||
(!reqip || reqip == ""
|
||||
`Client ${!reqip || reqip == ""
|
||||
? "[unknown client]"
|
||||
: reqip +
|
||||
(reqport && reqport !== 0 && reqport != "" ? ":" + reqport : "")) +
|
||||
" sent invalid request.",
|
||||
(reqport && reqport !== 0 && reqport != "" ? ":" + reqport : "")} sent invalid request.`,
|
||||
);
|
||||
try {
|
||||
head = fs.existsSync("./.head")
|
||||
|
@ -486,7 +476,7 @@ function clientErrorHandler(err, socket) {
|
|||
return;
|
||||
} else {
|
||||
logFacilities.errmessage(
|
||||
"An SSL error occured: " + (err.code ? err.code : err.message),
|
||||
`An SSL error occured: ${err.code ? err.code : err.message}`,
|
||||
);
|
||||
callServerError(400);
|
||||
return;
|
||||
|
@ -494,7 +484,7 @@ function clientErrorHandler(err, socket) {
|
|||
}
|
||||
|
||||
if (err.code && err.code.indexOf("ERR_HTTP2_") == 0) {
|
||||
logFacilities.errmessage("An HTTP/2 error occured: " + err.code);
|
||||
logFacilities.errmessage(`An HTTP/2 error occured: ${err.code}`);
|
||||
callServerError(400);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -33,22 +33,16 @@ function noproxyHandler(req, socket, head) {
|
|||
var reqport = socket.remotePort;
|
||||
process.reqcounter++;
|
||||
logFacilities.locmessage(
|
||||
"Somebody connected to " +
|
||||
(config.secure
|
||||
`Somebody connected to ${config.secure
|
||||
? (typeof config.sport == "number" ? "port " : "socket ") + config.sport
|
||||
: (typeof config.port == "number" ? "port " : "socket ") +
|
||||
config.port) +
|
||||
"...",
|
||||
config.port}...`,
|
||||
);
|
||||
logFacilities.reqmessage(
|
||||
"Client " +
|
||||
(!reqip || reqip == ""
|
||||
`Client ${!reqip || reqip == ""
|
||||
? "[unknown client]"
|
||||
: reqip +
|
||||
(reqport && reqport !== 0 && reqport != "" ? ":" + reqport : "")) +
|
||||
" wants to proxy " +
|
||||
req.url +
|
||||
" through this server",
|
||||
(reqport && reqport !== 0 && reqport != "" ? ":" + reqport : "")} wants to proxy ${req.url} through this server`,
|
||||
);
|
||||
if (req.headers["user-agent"] != undefined)
|
||||
logFacilities.reqmessage("Client uses " + req.headers["user-agent"]);
|
||||
|
|
|
@ -39,22 +39,16 @@ function proxyHandler(req, socket, head) {
|
|||
var reqport = socket.remotePort;
|
||||
process.reqcounter++;
|
||||
logFacilities.locmessage(
|
||||
"Somebody connected to " +
|
||||
(config.secure
|
||||
`Somebody connected to ${config.secure
|
||||
? (typeof config.sport == "number" ? "port " : "socket ") + config.sport
|
||||
: (typeof config.port == "number" ? "port " : "socket ") +
|
||||
config.port) +
|
||||
"...",
|
||||
config.port}...`,
|
||||
);
|
||||
logFacilities.reqmessage(
|
||||
"Client " +
|
||||
(!reqip || reqip == ""
|
||||
`Client ${!reqip || reqip == ""
|
||||
? "[unknown client]"
|
||||
: reqip +
|
||||
(reqport && reqport !== 0 && reqport != "" ? ":" + reqport : "")) +
|
||||
" wants to proxy " +
|
||||
req.url +
|
||||
" through this server",
|
||||
(reqport && reqport !== 0 && reqport != "" ? ":" + reqport : "")} wants to proxy ${req.url} through this server`,
|
||||
);
|
||||
if (req.headers["user-agent"] != undefined)
|
||||
logFacilities.reqmessage("Client uses " + req.headers["user-agent"]);
|
||||
|
@ -81,7 +75,7 @@ function proxyHandler(req, socket, head) {
|
|||
}
|
||||
} else {
|
||||
logFacilities.errmessage(
|
||||
name + " doesn't support proxy without proxy mod.",
|
||||
`${name} doesn't support proxy without proxy mod.`,
|
||||
);
|
||||
if (!socket.destroyed) socket.end("HTTP/1.1 501 Not Implemented\n\n");
|
||||
}
|
||||
|
|
|
@ -204,12 +204,10 @@ function requestHandler(req, res) {
|
|||
req.isProxy = false;
|
||||
if (req.url[0] != "/" && req.url != "*") req.isProxy = true;
|
||||
logFacilities.locmessage(
|
||||
"Somebody connected to " +
|
||||
(config.secure && fromMain
|
||||
`Somebody connected to ${config.secure && fromMain
|
||||
? (typeof config.sport == "number" ? "port " : "socket ") + config.sport
|
||||
: (typeof config.port == "number" ? "port " : "socket ") +
|
||||
config.port) +
|
||||
"...",
|
||||
config.port}...`,
|
||||
);
|
||||
|
||||
if (req.socket == null) {
|
||||
|
@ -269,13 +267,10 @@ function requestHandler(req, res) {
|
|||
}
|
||||
|
||||
logFacilities.reqmessage(
|
||||
"Client " +
|
||||
(!reqip || reqip == ""
|
||||
`Client ${!reqip || reqip == ""
|
||||
? "[unknown client]"
|
||||
: reqip +
|
||||
(reqport && reqport !== 0 && reqport != "" ? ":" + reqport : "")) +
|
||||
" wants " +
|
||||
(req.method == "GET"
|
||||
(reqport && reqport !== 0 && reqport != "" ? ":" + reqport : "")} wants ${req.method == "GET"
|
||||
? "content in "
|
||||
: req.method == "POST"
|
||||
? "to post content in "
|
||||
|
@ -285,9 +280,7 @@ function requestHandler(req, res) {
|
|||
? "to delete content in "
|
||||
: req.method == "PATCH"
|
||||
? "to patch content in "
|
||||
: "to access content using " + req.method + " method in ") +
|
||||
(req.headers.host == undefined || req.isProxy ? "" : req.headers.host) +
|
||||
req.url,
|
||||
: "to access content using " + req.method + " method in "}${req.headers.host == undefined || req.isProxy ? "" : req.headers.host}${req.url}`,
|
||||
);
|
||||
if (req.headers["user-agent"] != undefined)
|
||||
logFacilities.reqmessage("Client uses " + req.headers["user-agent"]);
|
||||
|
@ -536,13 +529,9 @@ function requestHandler(req, res) {
|
|||
res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders);
|
||||
res.write(
|
||||
(
|
||||
'<!DOCTYPE html><html><head><title>{errorMessage}</title><meta name="viewport" content="width=device-width, initial-scale=1.0" /><style>' +
|
||||
defaultPageCSS +
|
||||
"</style></head><body><h1>{errorMessage}</h1><p>{errorDesc}</p>" +
|
||||
(additionalError == 404
|
||||
`<!DOCTYPE html><html><head><title>{errorMessage}</title><meta name="viewport" content="width=device-width, initial-scale=1.0" /><style>${defaultPageCSS}</style></head><body><h1>{errorMessage}</h1><p>{errorDesc}</p>${additionalError == 404
|
||||
? ""
|
||||
: "<p>Additionally, a {additionalError} error occurred while loading an error page.</p>") +
|
||||
"<p><i>{server}</i></p></body></html>"
|
||||
: "<p>Additionally, a {additionalError} error occurred while loading an error page.</p>"}<p><i>{server}</i></p></body></html>`
|
||||
)
|
||||
.replace(
|
||||
/{errorMessage}/g,
|
||||
|
|
|
@ -15,7 +15,7 @@ function serverErrorHandler(err, isRedirect, server, start) {
|
|||
: serverErrorDescs["UNKNOWN"],
|
||||
);
|
||||
serverconsole.locmessage(
|
||||
(isRedirect ? attmtsRedir : attmts) + " attempts left.",
|
||||
`${isRedirect ? attmtsRedir : attmts} attempts left.`,
|
||||
);
|
||||
} else {
|
||||
try {
|
||||
|
@ -59,7 +59,7 @@ process.messageEventListeners.push((worker, serverconsole) => {
|
|||
? serverErrorDescs[errCode]
|
||||
: serverErrorDescs["UNKNOWN"],
|
||||
);
|
||||
serverconsole.locmessage(tries + " attempts left.");
|
||||
serverconsole.locmessage(`${tries} attempts left.`);
|
||||
}
|
||||
if (message.length >= 9 && message.indexOf("\x12ERRCRASH") == 0) {
|
||||
const errno = os.constants.errno[message.substring(9)];
|
||||
|
|
204
src/index.js
204
src/index.js
|
@ -658,9 +658,7 @@ if (!disableMods) {
|
|||
else {
|
||||
modInfos.push({
|
||||
name:
|
||||
"Unknown mod (" +
|
||||
modFileRaw +
|
||||
"; module.exports.modInfo not set)",
|
||||
`Unknown mod (${modFileRaw}; module.exports.modInfo not set)`,
|
||||
version: "ERROR",
|
||||
});
|
||||
}
|
||||
|
@ -736,7 +734,7 @@ if (!disableMods) {
|
|||
} catch (err) {
|
||||
// If failed to read info file, add a placeholder entry to modInfos with an error message
|
||||
modInfos.push({
|
||||
name: "Unknown mod (" + modFileRaw + ";" + err.message + ")",
|
||||
name: `Unknown mod (${modFileRaw}; ${err.message})`,
|
||||
version: "ERROR",
|
||||
});
|
||||
}
|
||||
|
@ -775,14 +773,11 @@ if (!disableMods) {
|
|||
try {
|
||||
// Prepend necessary modules and variables to the custom server side script
|
||||
const modhead =
|
||||
"var readline = require('readline');\r\nvar os = require('os');\r\nvar http = require('http');\r\nvar url = require('url');\r\nvar fs = require('fs');\r\nvar path = require('path');\r\n" +
|
||||
(hexstrbase64 === undefined
|
||||
`var readline = require('readline');\r\nvar os = require('os');\r\nvar http = require('http');\r\nvar url = require('url');\r\nvar fs = require('fs');\r\nvar path = require('path');\r\n${hexstrbase64 === undefined
|
||||
? ""
|
||||
: "var hexstrbase64 = require('../hexstrbase64/index.js');\r\n") +
|
||||
(crypto.__disabled__ === undefined
|
||||
: "var hexstrbase64 = require('../hexstrbase64/index.js');\r\n"}${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 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`;
|
||||
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
|
||||
|
@ -877,10 +872,9 @@ function listeningMessage() {
|
|||
if (process.serverConfig.secure && (sListenToLocalhost || sListenToAny)) {
|
||||
if (typeof process.serverConfig.sport === "number") {
|
||||
serverconsole.locmessage(
|
||||
"* https://localhost" +
|
||||
(process.serverConfig.sport == 443
|
||||
`* https://localhost${process.serverConfig.sport == 443
|
||||
? ""
|
||||
: ":" + process.serverConfig.sport),
|
||||
: ":" + process.serverConfig.sport}`,
|
||||
);
|
||||
} else {
|
||||
serverconsole.locmessage("* " + process.serverConfig.sport); // Unix socket or Windows named pipe
|
||||
|
@ -895,10 +889,9 @@ function listeningMessage() {
|
|||
) {
|
||||
if (typeof process.serverConfig.port === "number") {
|
||||
serverconsole.locmessage(
|
||||
"* http://localhost" +
|
||||
(process.serverConfig.port == 80
|
||||
`* http://localhost${process.serverConfig.port == 80
|
||||
? ""
|
||||
: ":" + process.serverConfig.port),
|
||||
: ":" + process.serverConfig.port}`,
|
||||
);
|
||||
} else {
|
||||
serverconsole.locmessage("* " + process.serverConfig.port); // Unix socket or Windows named pipe
|
||||
|
@ -911,11 +904,9 @@ function listeningMessage() {
|
|||
(!sListenToAny || (host != "" && host != "[offline]"))
|
||||
)
|
||||
serverconsole.locmessage(
|
||||
"* https://" +
|
||||
(sAccHost.indexOf(":") > -1 ? "[" + sAccHost + "]" : sAccHost) +
|
||||
(process.serverConfig.sport == 443
|
||||
`* https://${sAccHost.indexOf(":") > -1 ? "[" + sAccHost + "]" : sAccHost}${process.serverConfig.sport == 443
|
||||
? ""
|
||||
: ":" + process.serverConfig.sport),
|
||||
: ":" + process.serverConfig.sport}`,
|
||||
);
|
||||
if (
|
||||
!(
|
||||
|
@ -927,21 +918,17 @@ function listeningMessage() {
|
|||
typeof process.serverConfig.port === "number"
|
||||
)
|
||||
serverconsole.locmessage(
|
||||
"* http://" +
|
||||
(accHost.indexOf(":") > -1 ? "[" + accHost + "]" : accHost) +
|
||||
(process.serverConfig.port == 80
|
||||
`* http://${accHost.indexOf(":") > -1 ? "[" + accHost + "]" : accHost}${process.serverConfig.port == 80
|
||||
? ""
|
||||
: ":" + process.serverConfig.port),
|
||||
: ":" + process.serverConfig.port}`,
|
||||
);
|
||||
ipStatusCallback(() => {
|
||||
if (pubip != "") {
|
||||
if (process.serverConfig.secure && !sListenToLocalhost)
|
||||
serverconsole.locmessage(
|
||||
"* https://" +
|
||||
(pubip.indexOf(":") > -1 ? "[" + pubip + "]" : pubip) +
|
||||
(process.serverConfig.spubport == 443
|
||||
`* https://${pubip.indexOf(":") > -1 ? "[" + pubip + "]" : pubip}${process.serverConfig.spubport == 443
|
||||
? ""
|
||||
: ":" + process.serverConfig.spubport),
|
||||
: ":" + process.serverConfig.spubport}`,
|
||||
);
|
||||
if (
|
||||
!(
|
||||
|
@ -951,21 +938,17 @@ function listeningMessage() {
|
|||
!listenToLocalhost
|
||||
)
|
||||
serverconsole.locmessage(
|
||||
"* http://" +
|
||||
(pubip.indexOf(":") > -1 ? "[" + pubip + "]" : pubip) +
|
||||
(process.serverConfig.pubport == 80
|
||||
`* http://${pubip.indexOf(":") > -1 ? "[" + pubip + "]" : pubip}${process.serverConfig.pubport == 80
|
||||
? ""
|
||||
: ":" + process.serverConfig.pubport),
|
||||
: ":" + process.serverConfig.pubport}`,
|
||||
);
|
||||
}
|
||||
if (domain != "") {
|
||||
if (process.serverConfig.secure && !sListenToLocalhost)
|
||||
serverconsole.locmessage(
|
||||
"* https://" +
|
||||
domain +
|
||||
(process.serverConfig.spubport == 443
|
||||
`* https://${domain}${process.serverConfig.spubport == 443
|
||||
? ""
|
||||
: ":" + process.serverConfig.spubport),
|
||||
: ":" + process.serverConfig.spubport}`,
|
||||
);
|
||||
if (
|
||||
!(
|
||||
|
@ -975,11 +958,9 @@ function listeningMessage() {
|
|||
!listenToLocalhost
|
||||
)
|
||||
serverconsole.locmessage(
|
||||
"* http://" +
|
||||
domain +
|
||||
(process.serverConfig.pubport == 80
|
||||
`* http://${domain}${process.serverConfig.pubport == 80
|
||||
? ""
|
||||
: ":" + process.serverConfig.pubport),
|
||||
: ":" + process.serverConfig.pubport}`,
|
||||
);
|
||||
}
|
||||
serverconsole.locmessage('For CLI help, you can type "help"');
|
||||
|
@ -994,8 +975,7 @@ function listeningMessage() {
|
|||
sendStatistics(modInfos, (err) => {
|
||||
if (err)
|
||||
serverconsole.locwarnmessage(
|
||||
"There was a problem, when sending data to statistics server! Reason: " +
|
||||
err.message,
|
||||
`There was a problem, when sending data to statistics server! Reason: ${err.message}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -1223,7 +1203,7 @@ let commands = {
|
|||
log("Server closed.");
|
||||
if (cluster.isPrimary !== undefined) process.send("\x12CLOSE");
|
||||
} catch (err) {
|
||||
log("Cannot close server! Reason: " + err.message);
|
||||
log(`Cannot close server! Reason: ${err.message}`);
|
||||
}
|
||||
},
|
||||
open: (args, log) => {
|
||||
|
@ -1259,21 +1239,17 @@ let commands = {
|
|||
}
|
||||
log("Server opened.");
|
||||
} catch (err) {
|
||||
log("Cannot open server! Reason: " + err.message);
|
||||
log(`Cannot open server! Reason: ${err.message}`);
|
||||
}
|
||||
},
|
||||
help: (args, log) => {
|
||||
log("Server commands:\n" + Object.keys(commands).join(" "));
|
||||
log(`Server commands:\n${Object.keys(commands).join(" ")}`);
|
||||
},
|
||||
mods: (args, log) => {
|
||||
log("Mods:");
|
||||
for (let i = 0; i < modInfos.length; i++) {
|
||||
log(
|
||||
(i + 1).toString() +
|
||||
". " +
|
||||
modInfos[i].name +
|
||||
" " +
|
||||
modInfos[i].version,
|
||||
`${(i + 1).toString()}. ${modInfos[i].name} ${modInfos[i].version}`,
|
||||
);
|
||||
}
|
||||
if (modInfos.length == 0) {
|
||||
|
@ -1340,8 +1316,8 @@ let commands = {
|
|||
},
|
||||
restart: (args, log) => {
|
||||
if (cluster.isPrimary === undefined)
|
||||
log("This command is not supported on single-threaded " + name + ".");
|
||||
else log("This command need to be run in " + name + " master.");
|
||||
log(`This command is not supported on single-threaded ${name}.`);
|
||||
else log(`This command need to be run in ${name} master.`);
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -1385,8 +1361,7 @@ function SVRJSFork() {
|
|||
) {
|
||||
threadLimitWarned = true;
|
||||
serverconsole.locwarnmessage(
|
||||
name +
|
||||
" limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.",
|
||||
`${name} limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.`,
|
||||
);
|
||||
}
|
||||
if (
|
||||
|
@ -1402,8 +1377,7 @@ function SVRJSFork() {
|
|||
} else {
|
||||
if (SVRJSInitialized)
|
||||
serverconsole.locwarnmessage(
|
||||
name +
|
||||
" limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.",
|
||||
`${name} limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.`,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
|
@ -1419,8 +1393,7 @@ function SVRJSFork() {
|
|||
) {
|
||||
threadLimitWarned = true;
|
||||
serverconsole.locwarnmessage(
|
||||
name +
|
||||
" limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.",
|
||||
`${name} limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.`,
|
||||
);
|
||||
}
|
||||
if (
|
||||
|
@ -1436,8 +1409,7 @@ function SVRJSFork() {
|
|||
} else {
|
||||
if (SVRJSInitialized)
|
||||
serverconsole.locwarnmessage(
|
||||
name +
|
||||
" limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.",
|
||||
`${name} limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
@ -1533,8 +1505,7 @@ function msgListener(message) {
|
|||
serverconsole.locmessage("Configuration saved.");
|
||||
} else if (message.indexOf("\x12SAVEERR") == 0) {
|
||||
serverconsole.locwarnmessage(
|
||||
"There was a problem while saving configuration file. Reason: " +
|
||||
message.substring(8),
|
||||
`There was a problem while saving configuration file. Reason: ${message.substring(8)}`,
|
||||
);
|
||||
} else if (message[0] == "\x12") {
|
||||
// Discard unrecognized control messages
|
||||
|
@ -1656,9 +1627,7 @@ function start(init) {
|
|||
for (let i = 0; i < logo.length; i++) console.log(logo[i]); // Print logo
|
||||
console.log();
|
||||
console.log(
|
||||
"Welcome to \x1b[1m" +
|
||||
name +
|
||||
" - a web server running on Node.JS\x1b[0m",
|
||||
`Welcome to \x1b[1m${name} - a web server running on Node.JS\x1b[0m`,
|
||||
);
|
||||
|
||||
// Print warnings
|
||||
|
@ -1672,13 +1641,7 @@ function start(init) {
|
|||
);
|
||||
if (process.isBun) {
|
||||
serverconsole.locwarnmessage(
|
||||
"Bun support is experimental. Some features of " +
|
||||
name +
|
||||
", " +
|
||||
name +
|
||||
" mods and " +
|
||||
name +
|
||||
" server-side JavaScript may not work as expected.",
|
||||
`Bun support is experimental. Some features of ${name}, ${name} mods and ${name} server-side JavaScript may not work as expected.`,
|
||||
);
|
||||
if (
|
||||
process.isBun &&
|
||||
|
@ -1698,9 +1661,7 @@ function start(init) {
|
|||
}
|
||||
if (cluster.isPrimary === undefined)
|
||||
serverconsole.locwarnmessage(
|
||||
"You're running " +
|
||||
name +
|
||||
" on single thread. Reliability may suffer, as the server is stopped after crash.",
|
||||
`You're running ${name} on single thread. Reliability may suffer, as the server is stopped after crash.`,
|
||||
);
|
||||
if (crypto.__disabled__ !== undefined)
|
||||
serverconsole.locwarnmessage(
|
||||
|
@ -1730,13 +1691,7 @@ function start(init) {
|
|||
);
|
||||
if (process.getuid && process.getuid() == 0)
|
||||
serverconsole.locwarnmessage(
|
||||
"You're running " +
|
||||
name +
|
||||
" as root. It's recommended to run " +
|
||||
name +
|
||||
" as an non-root user. Running " +
|
||||
name +
|
||||
" as root may increase the risks of OS command execution vulnerabilities.",
|
||||
`You're running ${name} as root. It's recommended to run ${name} as an non-root user. Running ${name} as root may increase the risks of OS command execution vulnerabilities.`,
|
||||
);
|
||||
if (
|
||||
!process.isBun &&
|
||||
|
@ -1765,15 +1720,11 @@ function start(init) {
|
|||
);
|
||||
if (process.serverConfig.disableMods)
|
||||
serverconsole.locwarnmessage(
|
||||
"" +
|
||||
name +
|
||||
" is running without mods and server-side JavaScript enabled. Web applications may not work as expected",
|
||||
`${name} is running without mods and server-side JavaScript enabled. Web applications may not work as expected`,
|
||||
);
|
||||
if (process.serverConfig.optOutOfStatisticsServer)
|
||||
serverconsole.locmessage(
|
||||
"" +
|
||||
name +
|
||||
" is configured to opt out of sending data to the statistics server.",
|
||||
`${name} is configured to opt out of sending data to the statistics server.`,
|
||||
);
|
||||
console.log();
|
||||
|
||||
|
@ -1781,9 +1732,7 @@ function start(init) {
|
|||
if (process.isPrimary || process.isPrimary === undefined) {
|
||||
modLoadingErrors.forEach(function (modLoadingError) {
|
||||
serverconsole.locwarnmessage(
|
||||
'There was a problem while loading a "' +
|
||||
String(modLoadingError.modName).replace(/[\r\n]/g, "") +
|
||||
'" mod.',
|
||||
`There was a problem while loading a "${String(modLoadingError.modName).replace(/[\r\n]/g, "")}" mod.`,
|
||||
);
|
||||
serverconsole.locwarnmessage("Stack:");
|
||||
serverconsole.locwarnmessage(
|
||||
|
@ -1808,28 +1757,21 @@ function start(init) {
|
|||
const CPUs = os.cpus();
|
||||
if (CPUs.length > 0)
|
||||
serverconsole.locmessage(
|
||||
"CPU: " + (CPUs.length > 1 ? CPUs.length + "x " : "") + CPUs[0].model,
|
||||
`CPU: ${CPUs.length > 1 ? CPUs.length + "x " : ""}${CPUs[0].model}`,
|
||||
);
|
||||
|
||||
// Throw errors
|
||||
if (vnum < 64)
|
||||
throw new Error(
|
||||
"" +
|
||||
name +
|
||||
" requires Node.JS 10.0.0 and newer, but your Node.JS version isn't supported by " +
|
||||
name +
|
||||
".",
|
||||
`${name} requires Node.JS 10.0.0 and newer, but your Node.JS version isn't supported by ${name}.`,
|
||||
);
|
||||
if (configJSONRErr)
|
||||
throw new Error(
|
||||
"Can't read " +
|
||||
name +
|
||||
" configuration file: " +
|
||||
configJSONRErr.message,
|
||||
`Can't read ${name} configuration file: ${configJSONRErr.message}`,
|
||||
);
|
||||
if (configJSONPErr)
|
||||
throw new Error(
|
||||
"" + name + " configuration parse error: " + configJSONPErr.message,
|
||||
`${name} configuration parse error: ${configJSONPErr.message}`,
|
||||
);
|
||||
if (
|
||||
process.serverConfig.enableHTTP2 &&
|
||||
|
@ -1837,15 +1779,11 @@ function start(init) {
|
|||
typeof process.serverConfig.port != "number"
|
||||
)
|
||||
throw new Error(
|
||||
"HTTP/2 without HTTPS, along with Unix sockets/Windows named pipes aren't supported by " +
|
||||
name +
|
||||
".",
|
||||
`HTTP/2 without HTTPS, along with Unix sockets/Windows named pipes aren't supported by ${name}.`,
|
||||
);
|
||||
if (process.serverConfig.enableHTTP2 && http2.__disabled__ !== undefined)
|
||||
throw new Error(
|
||||
"HTTP/2 isn't supported by your Node.JS version! You may not be able to use HTTP/2 with " +
|
||||
name +
|
||||
"",
|
||||
`HTTP/2 isn't supported by your Node.JS version! You may not be able to use HTTP/2 with ${name}`,
|
||||
);
|
||||
if (listenAddress) {
|
||||
if (listenAddress.match(/^[0-9]+$/))
|
||||
|
@ -1857,20 +1795,19 @@ function start(init) {
|
|||
/^(?:2(?:2[4-9]|3[0-9])\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$|ff[0-9a-f][0-9a-f]:[0-9a-f:])/i,
|
||||
)
|
||||
)
|
||||
throw new Error("" + name + " can't listen on multicast address.");
|
||||
throw new Error(`${name} can't listen on multicast address.`);
|
||||
if (brdIPs.indexOf(listenAddress) > -1)
|
||||
throw new Error("" + name + " can't listen on broadcast address.");
|
||||
throw new Error(`${name} can't listen on broadcast address.`);
|
||||
if (netIPs.indexOf(listenAddress) > -1)
|
||||
throw new Error("" + name + " can't listen on subnet address.");
|
||||
throw new Error(`${name} can't listen on subnet address.`);
|
||||
}
|
||||
if (certificateError)
|
||||
throw new Error(
|
||||
"There was a problem with SSL certificate/private key: " +
|
||||
certificateError.message,
|
||||
`There was a problem with SSL certificate/private key: ${certificateError.message}`,
|
||||
);
|
||||
if (wwwrootError)
|
||||
throw new Error(
|
||||
"There was a problem with your web root: " + wwwrootError.message,
|
||||
`There was a problem with your web root: ${wwwrootError.message}`,
|
||||
);
|
||||
if (sniReDos)
|
||||
throw new Error(
|
||||
|
@ -1886,29 +1823,23 @@ function start(init) {
|
|||
)
|
||||
)
|
||||
serverconsole.locmessage(
|
||||
"Starting HTTP server at " +
|
||||
(typeof process.serverConfig.port == "number"
|
||||
`Starting HTTP server at ${typeof process.serverConfig.port == "number"
|
||||
? listenAddress
|
||||
? (listenAddress.indexOf(":") > -1
|
||||
? "[" + listenAddress + "]"
|
||||
: listenAddress) + ":"
|
||||
: "port "
|
||||
: "") +
|
||||
process.serverConfig.port.toString() +
|
||||
"...",
|
||||
: ""}${process.serverConfig.port.toString()}...`,
|
||||
);
|
||||
if (process.serverConfig.secure)
|
||||
serverconsole.locmessage(
|
||||
"Starting HTTPS server at " +
|
||||
(typeof process.serverConfig.sport == "number"
|
||||
`Starting HTTPS server at ${typeof process.serverConfig.sport == "number"
|
||||
? sListenAddress
|
||||
? (sListenAddress.indexOf(":") > -1
|
||||
? "[" + sListenAddress + "]"
|
||||
: sListenAddress) + ":"
|
||||
: "port "
|
||||
: "") +
|
||||
process.serverConfig.sport.toString() +
|
||||
"...",
|
||||
: ""}${process.serverConfig.sport.toString()}...`,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2013,8 +1944,7 @@ function start(init) {
|
|||
addListenersToWorker(cluster.workers[goodWorkers[wN]]);
|
||||
}
|
||||
serverconsole.locwarnmessage(
|
||||
"There was a problem while saving configuration file. Reason: " +
|
||||
err.message,
|
||||
`There was a problem while saving configuration file. Reason: ${err.message}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -2062,13 +1992,13 @@ function start(init) {
|
|||
commands[command](argss, (msg) => process.send(msg));
|
||||
process.send("\x12END");
|
||||
} else {
|
||||
process.send('Unrecognized command "' + line.split(" ")[0] + '".');
|
||||
process.send(`Unrecognized command "${line.split(" ")[0]}".`);
|
||||
process.send("\x12END");
|
||||
}
|
||||
} catch (err) {
|
||||
if (line != "") {
|
||||
process.send(
|
||||
"Can't execute command \"" + line.split(" ")[0] + '".',
|
||||
`Can't execute command \"${line.split(" ")[0]}".`,
|
||||
);
|
||||
process.send("\x12END");
|
||||
}
|
||||
|
@ -2106,7 +2036,7 @@ function start(init) {
|
|||
}
|
||||
if (stopError)
|
||||
serverconsole.climessage(
|
||||
"Some " + name + " workers might not be stopped.",
|
||||
`Some ${name} workers might not be stopped.`,
|
||||
);
|
||||
SVRJSInitialized = false;
|
||||
closedMaster = true;
|
||||
|
@ -2115,7 +2045,7 @@ function start(init) {
|
|||
forkWorkers(workersToFork, function () {
|
||||
SVRJSInitialized = true;
|
||||
exiting = false;
|
||||
serverconsole.climessage("" + name + " workers restarted.");
|
||||
serverconsole.climessage(`${name} workers restarted.`);
|
||||
});
|
||||
|
||||
return;
|
||||
|
@ -2136,7 +2066,7 @@ function start(init) {
|
|||
addListenersToWorker(cluster.workers[clusterID]);
|
||||
}
|
||||
serverconsole.climessage(
|
||||
"Can't run command \"" + command + '".',
|
||||
`Can't run command "${command}".`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -2380,8 +2310,7 @@ function start(init) {
|
|||
addListenersToWorker(cluster.workers[goodWorkers[wN]]);
|
||||
}
|
||||
serverconsole.locwarnmessage(
|
||||
"There was a problem while terminating unused worker process. Reason: " +
|
||||
err.message,
|
||||
`There was a problem while terminating unused worker process. Reason: ${err.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -2399,7 +2328,7 @@ function start(init) {
|
|||
if (cluster.isPrimary || cluster.isPrimary === undefined) {
|
||||
// Crash handler
|
||||
function crashHandlerMaster(err) {
|
||||
serverconsole.locerrmessage(name + " main process just crashed!!!");
|
||||
serverconsole.locerrmessage(`${name} main process just crashed!!!`);
|
||||
serverconsole.locerrmessage("Stack:");
|
||||
serverconsole.locerrmessage(
|
||||
err.stack ? generateErrorStack(err) : String(err),
|
||||
|
@ -2417,8 +2346,7 @@ if (cluster.isPrimary || cluster.isPrimary === undefined) {
|
|||
}
|
||||
} catch (err) {
|
||||
serverconsole.locwarnmessage(
|
||||
"There was a problem while saving configuration file. Reason: " +
|
||||
err.message,
|
||||
`There was a problem while saving configuration file. Reason: ${err.message}`,
|
||||
);
|
||||
}
|
||||
try {
|
||||
|
@ -2474,7 +2402,7 @@ if (cluster.isPrimary || cluster.isPrimary === undefined) {
|
|||
} else {
|
||||
// Crash handler
|
||||
function crashHandler(err) {
|
||||
serverconsole.locerrmessage(name + " worker just crashed!!!");
|
||||
serverconsole.locerrmessage(`${name} worker just crashed!!!`);
|
||||
serverconsole.locerrmessage("Stack:");
|
||||
serverconsole.locerrmessage(
|
||||
err.stack ? generateErrorStack(err) : String(err),
|
||||
|
@ -2499,7 +2427,7 @@ if (cluster.isPrimary || cluster.isPrimary === undefined) {
|
|||
try {
|
||||
start(true);
|
||||
} catch (err) {
|
||||
serverconsole.locerrmessage("There was a problem starting " + name + "!!!");
|
||||
serverconsole.locerrmessage(`There was a problem starting ${name}!!!`);
|
||||
serverconsole.locerrmessage("Stack:");
|
||||
serverconsole.locerrmessage(generateErrorStack(err));
|
||||
setTimeout(function () {
|
||||
|
|
|
@ -90,7 +90,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
!config.exposeServerVersion
|
||||
) {
|
||||
res.error(403);
|
||||
logFacilities.errmessage("Access to " + name + " script is denied.");
|
||||
logFacilities.errmessage(`Access to ${name} script is denied.`);
|
||||
return;
|
||||
} else if (
|
||||
(isForbiddenPath(decodedHrefWithoutDuplicateSlashes, "svrjs") ||
|
||||
|
|
|
@ -9,29 +9,21 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
eheaders["Content-Type"] = "text/html; charset=utf-8";
|
||||
res.writeHead(501, http.STATUS_CODES[501], eheaders);
|
||||
res.write(
|
||||
'<!DOCTYPE html><html><head><title>Proxy not implemented</title><meta name="viewport" content="width=device-width, initial-scale=1.0" /><style>' +
|
||||
defaultPageCSS +
|
||||
"</style></head><body><h1>Proxy not implemented</h1><p>" +
|
||||
name
|
||||
`<!DOCTYPE html><html><head><title>Proxy not implemented</title><meta name="viewport" content="width=device-width, initial-scale=1.0" /><style>${defaultPageCSS}</style></head><body><h1>Proxy not implemented</h1><p>${name
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">") +
|
||||
" doesn't support proxy without proxy mod. If you're administator of this server, then install this mod in order to use " +
|
||||
name
|
||||
.replace(/>/g, ">")} doesn't support proxy without proxy mod. If you're administator of this server, then install this mod in order to use ${name
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">") +
|
||||
" as a proxy.</p><p><i>" +
|
||||
config
|
||||
.replace(/>/g, ">")} as a proxy.</p><p><i>${config
|
||||
.generateServerString()
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">") +
|
||||
"</i></p></body></html>",
|
||||
.replace(/>/g, ">")}</i></p></body></html>`,
|
||||
);
|
||||
res.end();
|
||||
logFacilities.errmessage(
|
||||
name + " doesn't support proxy without proxy mod.",
|
||||
`${name} doesn't support proxy without proxy mod.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
} else if (nonscode.scode == 410) {
|
||||
logFacilities.errmessage("Content is gone.");
|
||||
} else if (nonscode.scode == 418) {
|
||||
logFacilities.errmessage(name + " is always a teapot ;)");
|
||||
logFacilities.errmessage(`${name} is always a teapot ;)`);
|
||||
} else {
|
||||
logFacilities.errmessage("Client fails receiving content.");
|
||||
}
|
||||
|
@ -186,8 +186,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
res.error(
|
||||
500,
|
||||
new Error(
|
||||
name +
|
||||
" doesn't support scrypt-hashed passwords on Node.JS versions without scrypt hash support.",
|
||||
`${name} doesn't support scrypt-hashed passwords on Node.JS versions without scrypt hash support.`,
|
||||
),
|
||||
);
|
||||
return;
|
||||
|
@ -226,8 +225,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
res.error(
|
||||
500,
|
||||
new Error(
|
||||
name +
|
||||
" doesn't support PBKDF2-hashed passwords on Node.JS versions without crypto support.",
|
||||
`${name} doesn't support PBKDF2-hashed passwords on Node.JS versions without crypto support.`,
|
||||
),
|
||||
);
|
||||
return;
|
||||
|
@ -272,11 +270,9 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
try {
|
||||
const ha = config.getCustomHeaders();
|
||||
ha["WWW-Authenticate"] =
|
||||
'Basic realm="' +
|
||||
(authcode.realm
|
||||
`Basic realm="${authcode.realm
|
||||
? authcode.realm.replace(/(\\|")/g, "\\$1")
|
||||
: name + " HTTP Basic Authorization") +
|
||||
'", charset="UTF-8"';
|
||||
: name + " HTTP Basic Authorization"}", charset="UTF-8"`;
|
||||
const credentials = req.headers["authorization"];
|
||||
if (!credentials) {
|
||||
res.error(401, ha);
|
||||
|
@ -353,9 +349,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
}
|
||||
res.error(401, ha);
|
||||
logFacilities.errmessage(
|
||||
'User "' +
|
||||
String(username).replace(/[\r\n]/g, "") +
|
||||
'" failed to log in.',
|
||||
`User "${String(username).replace(/[\r\n]/g, "")}" failed to log in.`,
|
||||
);
|
||||
} else {
|
||||
if (bruteProtection) {
|
||||
|
@ -369,9 +363,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
}
|
||||
}
|
||||
logFacilities.reqmessage(
|
||||
'Client is logged in as "' +
|
||||
String(username).replace(/[\r\n]/g, "") +
|
||||
'".',
|
||||
`Client is logged in as "${String(username).replace(/[\r\n]/g, "")}".`,
|
||||
);
|
||||
req.authUser = username;
|
||||
next();
|
||||
|
|
|
@ -67,11 +67,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
hostname = hostname.join(":");
|
||||
if (hostname == config.domain && hostname.indexOf("www.") != 0) {
|
||||
res.redirect(
|
||||
(req.socket.encrypted ? "https" : "http") +
|
||||
"://www." +
|
||||
hostname +
|
||||
(hostport ? ":" + hostport : "") +
|
||||
req.url.replace(/\/+/g, "/"),
|
||||
`${req.socket.encrypted ? "https" : "http"}://www.${hostname}${hostport ? ":" + hostport : ""}${req.url.replace(/\/+/g, "/")}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -87,20 +87,17 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
}
|
||||
if (rewrittenURL != req.url) {
|
||||
logFacilities.resmessage(
|
||||
"URL rewritten: " + req.url + " => " + rewrittenURL,
|
||||
`URL rewritten: ${req.url} => ${rewrittenURL}`,
|
||||
);
|
||||
req.url = rewrittenURL;
|
||||
try {
|
||||
req.parsedURL = new URL(
|
||||
req.url,
|
||||
"http" +
|
||||
(req.socket.encrypted ? "s" : "") +
|
||||
"://" +
|
||||
(req.headers.host
|
||||
`http${req.socket.encrypted ? "s" : ""}://${req.headers.host
|
||||
? req.headers.host
|
||||
: config.domain
|
||||
? config.domain
|
||||
: "unknown.invalid"),
|
||||
: "unknown.invalid"}`,
|
||||
);
|
||||
} catch (err) {
|
||||
res.error(400, err);
|
||||
|
@ -134,14 +131,11 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
try {
|
||||
req.parsedURL = new URL(
|
||||
req.url,
|
||||
"http" +
|
||||
(req.socket.encrypted ? "s" : "") +
|
||||
"://" +
|
||||
(req.headers.host
|
||||
`http${req.socket.encrypted ? "s" : ""}://${req.headers.host
|
||||
? req.headers.host
|
||||
: config.domain
|
||||
? config.domain
|
||||
: "unknown.invalid"),
|
||||
: "unknown.invalid"}`,
|
||||
);
|
||||
} catch (err) {
|
||||
res.error(400, err);
|
||||
|
|
|
@ -581,7 +581,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
|
||||
// Generate HTML head and footer based on configuration and custom content
|
||||
let htmlHead =
|
||||
(!config.enableDirectoryListingWithDefaultHead || res.head == ""
|
||||
`${(!config.enableDirectoryListingWithDefaultHead || res.head == ""
|
||||
? !headerHasHTMLTag
|
||||
? "<!DOCTYPE html><html><head><title>Directory: " +
|
||||
decodeURIComponent(origHref)
|
||||
|
@ -598,7 +598,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">") +
|
||||
"</title>",
|
||||
"</title>"
|
||||
)
|
||||
: res.head.replace(
|
||||
/<head>/i,
|
||||
|
@ -607,40 +607,31 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">") +
|
||||
"</title>",
|
||||
"</title>"
|
||||
)) +
|
||||
(!headerHasHTMLTag ? customDirListingHeader : "") +
|
||||
"<h1>Directory: " +
|
||||
decodeURIComponent(origHref)
|
||||
(!headerHasHTMLTag ? customDirListingHeader : "")}<h1>Directory: ${decodeURIComponent(origHref)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">") +
|
||||
'</h1><table id="directoryListing"> <tr> <th></th> <th>Filename</th> <th>Size</th> <th>Date</th> </tr>' +
|
||||
(checkPathLevel(decodeURIComponent(origHref)) < 1
|
||||
.replace(/>/g, ">")}</h1><table id="directoryListing"> <tr> <th></th> <th>Filename</th> <th>Size</th> <th>Date</th> </tr>${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(/\/[^\/]*\/?$/, "/") +
|
||||
'">Return</a></td><td></td><td></td></tr>');
|
||||
'">Return</a></td><td></td><td></td></tr>'}`;
|
||||
|
||||
let htmlFoot =
|
||||
"</table><p><i>" +
|
||||
config
|
||||
`</table><p><i>${config
|
||||
.generateServerString()
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">") +
|
||||
(req.headers.host == undefined
|
||||
.replace(/>/g, ">")}${req.headers.host == undefined
|
||||
? ""
|
||||
: " on " +
|
||||
String(req.headers.host)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")) +
|
||||
"</i></p>" +
|
||||
customDirListingFooter +
|
||||
(!config.enableDirectoryListingWithDefaultHead || res.foot == ""
|
||||
.replace(/>/g, ">")}</i></p>${customDirListingFooter}${!config.enableDirectoryListingWithDefaultHead || res.foot == ""
|
||||
? "</body></html>"
|
||||
: res.foot);
|
||||
: res.foot}`;
|
||||
|
||||
if (
|
||||
fs.existsSync(
|
||||
|
@ -745,41 +736,26 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
const emime = eext ? mime.contentType(eext) : false;
|
||||
if (filelist[i].errored) {
|
||||
directoryListingRows.push(
|
||||
'<tr><td style="width: 24px;"><img src="/.dirimages/bad.png" alt="[BAD]" width="24px" height="24px" /></td><td style="word-wrap: break-word; word-break: break-word; overflow-wrap: break-word;"><a href="' +
|
||||
(href + "/" + encodeURI(ename)).replace(
|
||||
`<tr><td style="width: 24px;"><img src="/.dirimages/bad.png" alt="[BAD]" width="24px" height="24px" /></td><td style="word-wrap: break-word; word-break: break-word; overflow-wrap: break-word;"><a href="${(href + "/" + encodeURI(ename)).replace(
|
||||
/\/+/g,
|
||||
"/",
|
||||
) +
|
||||
'">' +
|
||||
ename
|
||||
"/"
|
||||
)}">${ename
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">") +
|
||||
"</a></td><td>-</td><td>" +
|
||||
(estats ? estats.mtime.toDateString() : "-") +
|
||||
"</td></tr>\r\n",
|
||||
.replace(/>/g, ">")}</a></td><td>-</td><td>${estats ? estats.mtime.toDateString() : "-"}</td></tr>\r\n`,
|
||||
);
|
||||
} else {
|
||||
let entry =
|
||||
'<tr><td style="width: 24px;"><img src="[img]" alt="[alt]" width="24px" height="24px" /></td><td style="word-wrap: break-word; word-break: break-word; overflow-wrap: break-word;"><a href="' +
|
||||
(
|
||||
`<tr><td style="width: 24px;"><img src="[img]" alt="[alt]" width="24px" height="24px" /></td><td style="word-wrap: break-word; word-break: break-word; overflow-wrap: break-word;"><a href="${(
|
||||
origHref +
|
||||
"/" +
|
||||
encodeURIComponent(ename)
|
||||
).replace(/\/+/g, "/") +
|
||||
(estats.isDirectory() ? "/" : "") +
|
||||
'">' +
|
||||
ename
|
||||
).replace(/\/+/g, "/")}${estats.isDirectory() ? "/" : ""}">${ename
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">") +
|
||||
"</a></td><td>" +
|
||||
(estats.isDirectory()
|
||||
.replace(/>/g, ">")}</a></td><td>${estats.isDirectory()
|
||||
? "-"
|
||||
: sizify(estats.size.toString())) +
|
||||
"</td><td>" +
|
||||
estats.mtime.toDateString() +
|
||||
"</td></tr>\r\n";
|
||||
: sizify(estats.size.toString())}</td><td>${estats.mtime.toDateString()}</td></tr>\r\n`;
|
||||
|
||||
// Determine the file type and set the appropriate image and alt text
|
||||
if (estats.isDirectory()) {
|
||||
|
@ -788,20 +764,14 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
.replace("[alt]", "[DIR]");
|
||||
} else if (!estats.isFile()) {
|
||||
entry =
|
||||
'<tr><td style="width: 24px;"><img src="[img]" alt="[alt]" width="24px" height="24px" /></td><td style="word-wrap: break-word; word-break: break-word; overflow-wrap: break-word;"><a href="' +
|
||||
(
|
||||
`<tr><td style="width: 24px;"><img src="[img]" alt="[alt]" width="24px" height="24px" /></td><td style="word-wrap: break-word; word-break: break-word; overflow-wrap: break-word;"><a href="${(
|
||||
origHref +
|
||||
"/" +
|
||||
encodeURIComponent(ename)
|
||||
).replace(/\/+/g, "/") +
|
||||
'">' +
|
||||
ename
|
||||
).replace(/\/+/g, "/")}">${ename
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">") +
|
||||
"</a></td><td>-</td><td>" +
|
||||
estats.mtime.toDateString() +
|
||||
"</td></tr>\r\n";
|
||||
.replace(/>/g, ">")}</a></td><td>-</td><td>${estats.mtime.toDateString()}</td></tr>\r\n`;
|
||||
|
||||
// Determine the special file types (block device, character device, etc.)
|
||||
if (estats.isBlockDevice()) {
|
||||
|
@ -943,8 +913,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
} else {
|
||||
res.error(501);
|
||||
logFacilities.errmessage(
|
||||
name +
|
||||
" doesn't support block devices, character devices, FIFOs nor sockets.",
|
||||
`${name} doesn't support block devices, character devices, FIFOs nor sockets.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -32,57 +32,39 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
|
||||
//Those entries are just dates and numbers converted/formatted to strings, so no escaping is needed.
|
||||
statusBody +=
|
||||
"Current time: " +
|
||||
new Date().toString() +
|
||||
"<br/>Thread start time: " +
|
||||
new Date(new Date() - process.uptime() * 1000).toString() +
|
||||
"<br/>Thread uptime: " +
|
||||
formatRelativeTime(Math.floor(process.uptime())) +
|
||||
"<br/>";
|
||||
statusBody += "OS uptime: " + formatRelativeTime(os.uptime()) + "<br/>";
|
||||
statusBody += "Total request count: " + process.reqcounter + "<br/>";
|
||||
`Current time: ${new Date().toString()}<br/>Thread start time: ${new Date(new Date() - process.uptime() * 1000).toString()}<br/>Thread uptime: ${formatRelativeTime(Math.floor(process.uptime()))}<br/>`;
|
||||
statusBody += `OS uptime: ${formatRelativeTime(os.uptime())}<br/>`;
|
||||
statusBody += `Total request count: ${process.reqcounter}<br/>`;
|
||||
statusBody +=
|
||||
"Average request rate: " +
|
||||
Math.round((process.reqcounter / process.uptime()) * 100) / 100 +
|
||||
" requests/s<br/>";
|
||||
statusBody += "Client errors (4xx): " + process.err4xxcounter + "<br/>";
|
||||
statusBody += "Server errors (5xx): " + process.err5xxcounter + "<br/>";
|
||||
`Average request rate: ${Math.round((process.reqcounter / process.uptime()) * 100) / 100} requests/s<br/>`;
|
||||
statusBody += `Client errors (4xx): ${process.err4xxcounter}<br/>`;
|
||||
statusBody += `Server errors (5xx): ${process.err5xxcounter}<br/>`;
|
||||
statusBody +=
|
||||
"Average error rate: " +
|
||||
Math.round(
|
||||
`Average error rate: ${Math.round(
|
||||
((process.err4xxcounter + process.err5xxcounter) / process.reqcounter) *
|
||||
10000,
|
||||
10000
|
||||
) /
|
||||
100 +
|
||||
"%<br/>";
|
||||
statusBody += "Malformed HTTP requests: " + process.malformedcounter;
|
||||
100}%<br/>`;
|
||||
statusBody += `Malformed HTTP requests: ${process.malformedcounter}`;
|
||||
if (process.memoryUsage)
|
||||
statusBody +=
|
||||
"<br/>Memory usage of thread: " +
|
||||
sizify(process.memoryUsage().rss, true) +
|
||||
"B";
|
||||
`<br/>Memory usage of thread: ${sizify(process.memoryUsage().rss, true)}B`;
|
||||
if (process.cpuUsage)
|
||||
statusBody +=
|
||||
"<br/>Total CPU usage by thread: u" +
|
||||
process.cpuUsage().user / 1000 +
|
||||
"ms s" +
|
||||
process.cpuUsage().system / 1000 +
|
||||
"ms - " +
|
||||
Math.round(
|
||||
`<br/>Total CPU usage by thread: u${process.cpuUsage().user / 1000}ms s${process.cpuUsage().system / 1000}ms - ${Math.round(
|
||||
((process.cpuUsage().user + process.cpuUsage().system) /
|
||||
1000000 /
|
||||
process.uptime()) *
|
||||
1000,
|
||||
1000
|
||||
) /
|
||||
1000 +
|
||||
"%";
|
||||
statusBody += "<br/>Thread PID: " + process.pid + "<br/>";
|
||||
1000}%`;
|
||||
statusBody += `<br/>Thread PID: ${process.pid}<br/>`;
|
||||
|
||||
res.writeHead(200, http.STATUS_CODES[200], {
|
||||
"Content-Type": "text/html; charset=utf-8",
|
||||
});
|
||||
res.end(
|
||||
(res.head == ""
|
||||
`${res.head == ""
|
||||
? "<!DOCTYPE html><html><head><title>" +
|
||||
name
|
||||
.replace(/&/g, "&")
|
||||
|
@ -114,24 +96,17 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")) +
|
||||
"</title>",
|
||||
)) +
|
||||
"<h1>" +
|
||||
name
|
||||
"</title>"
|
||||
)}<h1>${name
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">") +
|
||||
" status" +
|
||||
(req.headers.host == undefined
|
||||
.replace(/>/g, ">")} status${req.headers.host == undefined
|
||||
? ""
|
||||
: " for " +
|
||||
String(req.headers.host)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")) +
|
||||
"</h1>" +
|
||||
statusBody +
|
||||
(res.foot == "" ? "</body></html>" : res.foot),
|
||||
.replace(/>/g, ">")}</h1>${statusBody}${res.foot == "" ? "</body></html>" : res.foot}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -14,21 +14,18 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
let sanitizedURL =
|
||||
sanitizedHref + req.parsedURL.search + req.parsedURL.hash;
|
||||
logFacilities.resmessage(
|
||||
"URL sanitized: " + req.url + " => " + sanitizedURL,
|
||||
`URL sanitized: ${req.url} => ${sanitizedURL}`,
|
||||
);
|
||||
if (config.rewriteDirtyURLs) {
|
||||
req.url = sanitizedURL;
|
||||
try {
|
||||
req.parsedURL = new URL(
|
||||
req.url,
|
||||
"http" +
|
||||
(req.socket.encrypted ? "s" : "") +
|
||||
"://" +
|
||||
(req.headers.host
|
||||
`http${req.socket.encrypted ? "s" : ""}://${req.headers.host
|
||||
? req.headers.host
|
||||
: config.domain
|
||||
? config.domain
|
||||
: "unknown.invalid"),
|
||||
: "unknown.invalid"}`,
|
||||
);
|
||||
} catch (err) {
|
||||
res.error(400, err);
|
||||
|
@ -40,7 +37,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
}
|
||||
} else if (req.url != preparedReqUrl && !req.isProxy) {
|
||||
logFacilities.resmessage(
|
||||
"URL sanitized: " + req.url + " => " + preparedReqUrl,
|
||||
`URL sanitized: ${req.url} => ${preparedReqUrl}`,
|
||||
);
|
||||
if (config.rewriteDirtyURLs) {
|
||||
req.url = preparedReqUrl;
|
||||
|
|
|
@ -80,14 +80,11 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
try {
|
||||
req.parsedURL = new URL(
|
||||
req.url,
|
||||
"http" +
|
||||
(req.socket.encrypted ? "s" : "") +
|
||||
"://" +
|
||||
(req.headers.host
|
||||
`http${req.socket.encrypted ? "s" : ""}://${req.headers.host
|
||||
? req.headers.host
|
||||
: config.domain
|
||||
? config.domain
|
||||
: "unknown.invalid"),
|
||||
: "unknown.invalid"}`,
|
||||
);
|
||||
} catch (err) {
|
||||
res.error(400, err);
|
||||
|
@ -115,20 +112,17 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
let rewrittenAgainURL =
|
||||
sHref + req.parsedURL.search + req.parsedURL.hash;
|
||||
logFacilities.resmessage(
|
||||
"URL sanitized: " + req.url + " => " + rewrittenAgainURL,
|
||||
`URL sanitized: ${req.url} => ${rewrittenAgainURL}`,
|
||||
);
|
||||
req.url = rewrittenAgainURL;
|
||||
try {
|
||||
req.parsedURL = new URL(
|
||||
req.url,
|
||||
"http" +
|
||||
(req.socket.encrypted ? "s" : "") +
|
||||
"://" +
|
||||
(req.headers.host
|
||||
`http${req.socket.encrypted ? "s" : ""}://${req.headers.host
|
||||
? req.headers.host
|
||||
: config.domain
|
||||
? config.domain
|
||||
: "unknown.invalid"),
|
||||
: "unknown.invalid"}`,
|
||||
);
|
||||
} catch (err) {
|
||||
res.error(400, err);
|
||||
|
|
|
@ -4,16 +4,9 @@ const getOS = require("./getOS.js");
|
|||
|
||||
function generateServerString(exposeServerVersion) {
|
||||
return exposeServerVersion
|
||||
? name.replace(/ /g, "-") +
|
||||
"/" +
|
||||
version +
|
||||
" (" +
|
||||
getOS() +
|
||||
"; " +
|
||||
(process.isBun
|
||||
? `${name.replace(/ /g, "-")}/${version} (${getOS()}; ${process.isBun
|
||||
? "Bun/v" + process.versions.bun + "; like Node.JS/" + process.version
|
||||
: "Node.JS/" + process.version) +
|
||||
")"
|
||||
: "Node.JS/" + process.version})`
|
||||
: name.replace(/ /g, "-");
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue