@@ -37,7 +37,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-
Packages used by SVR.JS 3.4.20 and utilities
+
Packages used by SVR.JS 3.4.21 and utilities
License: MIT
diff --git a/mods/easteregg.tar.gz b/mods/easteregg.tar.gz
new file mode 100644
index 0000000..83c2ef0
Binary files /dev/null and b/mods/easteregg.tar.gz differ
diff --git a/serverSideScript.js b/serverSideScript.js
index 747a3c8..99b7b6d 100644
--- a/serverSideScript.js
+++ b/serverSideScript.js
@@ -62,13 +62,19 @@ if(href == "/hello.svr") {
callServerError(403,"SVR.JS-exampleproxy"); //Server error
serverconsole.errmessage("Client fails to recieve content."); //Log into SVR.JS
} else if(href.indexOf("/proxy.svr/") == 0) {
+ var hn = href.split("/")[2]; //Hostname
+ if(hn != "this" && !(req.socket.realRemoteAddress ? req.socket.realRemoteAddress : req.socket.remoteAddress).match(/^(?:localhost$|::1$|f[c-d][0-9a-f]{2}:|(?:::ffff:)?(?:(?:127|10)\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|192\.168\.[0-9]{1,3}\.[0-9]{1,3}|172\.(?:1[6-9]|2[0-9]|3[0-1])\.[0-9]{1,3}\.[0-9]{1,3})$)/i) ) {
+ //Prevent open proxy
+ callServerError(403,"SVR.JS-exampleproxy"); //Server error
+ serverconsole.errmessage("Client fails to recieve content."); //Log into SVR.JS
+ }
var hdrs = req.headers;
- hdrs["Host"] = (href.split("/")[2] == "this" ? req.headers.host : href.split("/")[2]);
+ hdrs["Host"] = (hn == "this" ? req.headers.host : hn);
hdrs["Origin"] = (req.headers.host == undefined ? "" : req.headers.host);
var options = {
- hostname: (href.split("/")[2] == "this" ? req.headers.host.split(":")[0] : href.split("/")[2].split(":")[0]),
- port: (href.split("/")[2] == "this" ? req.headers.host.split(":")[1] : (href.split("/")[2].split(":")[1] == undefined ? 80 : href.split("/")[2].split(":")[1])),
- path: req.url.replace("/proxy.svr/" + href.split("/")[2],""),
+ hostname: (hn == "this" ? req.headers.host.split(":")[0] : hn.split(":")[0]),
+ port: (hn == "this" ? req.headers.host.split(":")[1] : (hn.split(":")[1] == undefined ? 80 : hn.split(":")[1])),
+ path: req.url.replace("/proxy.svr/" + hn,""),
method: req.method,
headers: filterHeaders(hdrs)
};
diff --git a/svr.js b/svr.js
index 1fbbc0e..b008628 100644
--- a/svr.js
+++ b/svr.js
@@ -71,7 +71,7 @@ function deleteFolderRecursive(path) {
}
var os = require("os");
-var version = "3.4.20";
+var version = "3.4.21";
var singlethreaded = false;
if (process.versions) process.versions.svrjs = version; //Inject SVR.JS into process.versions
@@ -137,8 +137,10 @@ if (!singlethreaded) {
}
// Cluster & IPC shim for Bun
- if (process.isBun && cluster.isMaster === undefined) {
+
+ cluster.bunShim = function () {
cluster.isMaster = !process.env.NODE_UNIQUE_ID;
+ cluster.isPrimary = cluster.isMaster;
cluster.isWorker = !cluster.isMaster;
if (cluster.isWorker) {
@@ -171,7 +173,8 @@ if (!singlethreaded) {
socket.on("end", function () {
process.emit("message", receivedData);
});
- }).listen(os.platform() === "win32" ? path.join("\\\\?\\pipe", __dirname, "temp/.W" + process.pid + ".ipc") : (__dirname + "/temp/.W" + process.pid + ".ipc"));
+ });
+ fakeIPCServer.listen(os.platform() === "win32" ? path.join("\\\\?\\pipe", __dirname, "temp/.W" + process.pid + ".ipc") : (__dirname + "/temp/.W" + process.pid + ".ipc"));
process.send = function (message) {
// Create a fake IPC connection to send messages
@@ -179,6 +182,12 @@ if (!singlethreaded) {
fakeIPCConnection.end(message);
});
};
+
+ process.removeFakeIPC = function() {
+ // Close IPC server
+ process.send = function() {};
+ fakeIPCServer.close();
+ }
}
}
@@ -209,18 +218,32 @@ if (!singlethreaded) {
sendImplemented = false;
}
+ oldLog = console.log;
+ console.log = function(a,b,c,d,e,f) {
+ if(a == "ChildProcess.prototype.send() - Sorry! Not implemented yet") {
+ throw new Error("NOT IMPLEMENTED");
+ } else {
+ oldLog(a,b,c,d,e,f);
+ }
+ }
+
try {
- eval("'use strict';(" + String(worker.send).replace(/console\.log *\( *(["'])ChildProcess\.prototype\.send\(\) - Sorry! Not implemented yet\1 *\) *;?/, "throw new Error(\"NOT IMPLEMENTED\"); //") + ")(undefined)");
- } catch (ex) {
- if (ex.message === "NOT IMPLEMENTED") {
+ worker.send(undefined);
+ } catch (err) {
+ if (err.message === "NOT IMPLEMENTED") {
sendImplemented = false;
}
}
+ console.log = oldLog;
+
return sendImplemented;
}
if (!checkSendImplementation(newWorker)) {
+ var net = require("net");
+ var os = require("os");
+
// Create a fake IPC server for worker process to receive messages
var fakeWorkerIPCServer = net.createServer(function (socket) {
var receivedData = "";
@@ -232,7 +255,8 @@ if (!singlethreaded) {
socket.on("end", function () {
newWorker.emit("message", receivedData);
});
- }).listen(os.platform() === "win32" ? path.join("\\\\?\\pipe", __dirname, "temp/.P" + newWorker.process.pid + ".ipc") : (__dirname + "/temp/.P" + newWorker.process.pid + ".ipc"));
+ });
+ fakeWorkerIPCServer.listen(os.platform() === "win32" ? path.join("\\\\?\\pipe", __dirname, "temp/.P" + newWorker.process.pid + ".ipc") : (__dirname + "/temp/.P" + newWorker.process.pid + ".ipc"));
// Cleanup when worker process exits
newWorker.on("exit", function () {
@@ -248,12 +272,9 @@ if (!singlethreaded) {
var fakeWorkerIPCConnection = net.createConnection(os.platform() === "win32" ? path.join("\\\\?\\pipe", __dirname, "temp/.W" + newWorker.process.pid + ".ipc") : (__dirname + "/temp/.W" + newWorker.process.pid + ".ipc"), function () {
fakeWorkerIPCConnection.end(message);
});
- } catch (ex) {
- if (tries > 25) throw ex;
-
- setTimeout(function () {
- newWorker.send(message, undefined, undefined, tries + 1);
- }, 10);
+ } catch (err) {
+ if (tries > 50) throw err;
+ newWorker.send(message, fakeParam2, fakeParam3, fakeParam4, tries + 1);
}
};
}
@@ -263,6 +284,13 @@ if (!singlethreaded) {
return newWorker;
};
}
+
+ if (process.isBun && (cluster.isMaster === undefined || (cluster.isMaster && process.env.NODE_UNIQUE_ID))) {
+ cluster.bunShim();
+ }
+
+ // Shim cluster.isPrimary field
+ if (cluster.isPrimary === undefined && cluster.isMaster !== undefined) cluster.isPrimary = cluster.isMaster;
}
var bruteForceDb = {};
@@ -275,9 +303,20 @@ function SVRJSFork() {
//Log
if (SVRJSInitialized) serverconsole.locmessage("Starting next thread, because previous one hung up/crashed...");
//Fork new worker
- var newWorker = cluster.fork();
+ var newWorker = {};
+ try {
+ newWorker = cluster.fork();
+ } catch (err) {
+ if(err.name == "NotImplementedError") {
+ // If cluster.fork throws a NotImplementedError, shim cluster module
+ cluster.bunShim();
+ newWorker = cluster.fork();
+ } else {
+ throw err;
+ }
+ }
newWorker.on("error", function (err) {
- serverconsole.locwarnmessage("There was a problem when handling SVR.JS worker! (from master process side) Reason: " + err.message);
+ if(!reallyExiting) serverconsole.locwarnmessage("There was a problem when handling SVR.JS worker! (from master process side) Reason: " + err.message);
});
newWorker.on("exit", function () {
if (!exiting && Object.keys(cluster.workers).length == 0) {
@@ -905,9 +944,9 @@ if (configJSON.disableNonEncryptedServer != undefined) disableNonEncryptedServer
if (configJSON.disableToHTTPSRedirect != undefined) disableToHTTPSRedirect = configJSON.disableToHTTPSRedirect;
if (configJSON.wwwroot != undefined) {
var wwwroot = configJSON.wwwroot;
- if (cluster.isMaster || cluster.isMaster === undefined) process.chdir(wwwroot);
+ if (cluster.isPrimary || cluster.isPrimary === undefined) process.chdir(wwwroot);
} else {
- if (cluster.isMaster || cluster.isMaster === undefined) process.chdir(__dirname);
+ if (cluster.isPrimary || cluster.isPrimary === undefined) process.chdir(__dirname);
}
//Compability for older mods
@@ -950,7 +989,6 @@ try {
if (vnum === undefined) vnum = 0;
if (process.isBun) vnum = 59;
// NOTE: One of regexes used here is reported as vulnerable according to Devina ReDOS checker, but it's actually just FALSE POSITIVE.
-
function sanitizeURL(resource) {
if (resource == "*") return "*";
if (resource == "") return "";
@@ -961,7 +999,12 @@ function sanitizeURL(resource) {
// Decode URL-encoded characters while preserving certain characters
resource = resource.replace(/%([0-9a-f]{2})/gi, function (match, hex) {
var decodedChar = String.fromCharCode(parseInt(hex, 16));
- return /(?![;?:@&=+$,#%])[!-~]/.test(decodedChar) ? decodedChar : "%" + hex;
+ return /(?!["<>^`{|}?#%])[!-~]/.test(decodedChar) ? decodedChar : "%" + hex;
+ });
+ // Encode certain characters
+ resource = resource.replace(/[<>^`{|}]]/g, function (character) {
+ var charCode = character.charCodeAt(0);
+ return "%" + (charcode < 16 ? "0" : "") + charCode.toString(16).toUpperCase();
});
var sanitizedResource = resource;
// Ensure the resource starts with a slash
@@ -978,6 +1021,20 @@ function sanitizeURL(resource) {
else return sanitizedResource;
}
+function fixNodeMojibakeURL(string) {
+ var encoded = "";
+ Buffer.from(string, "latin1").forEach(function (value) {
+ if(value > 127) {
+ encoded += "%" + (value < 16 ? "0" : "") + value.toString(16).toUpperCase();
+ } else {
+ encoded += String.fromCodePoint(value);
+ }
+ });
+ return encoded.replace(/%[0-9a-f-A-F]{2}/g, function (match) {
+ return match.toUpperCase();
+ });
+}
+
var key = "";
var cert = "";
@@ -1016,10 +1073,10 @@ function LOG(s) {
try {
if (configJSON.enableLogging || configJSON.enableLogging == undefined) {
if (logSync) {
- fs.appendFileSync(__dirname + "/log/" + (cluster.isMaster ? "master" : (cluster.isMaster === undefined ? "singlethread" : "worker")) + "-" + timestamp + ".log", "[" + new Date().toISOString() + "] " + s + "\r\n");
+ fs.appendFileSync(__dirname + "/log/" + (cluster.isPrimary ? "master" : (cluster.isPrimary === undefined ? "singlethread" : "worker")) + "-" + timestamp + ".log", "[" + new Date().toISOString() + "] " + s + "\r\n");
} else {
if (!logFile) {
- logFile = fs.createWriteStream(__dirname + "/log/" + (cluster.isMaster ? "master" : (cluster.isMaster === undefined ? "singlethread" : "worker")) + "-" + timestamp + ".log", {
+ logFile = fs.createWriteStream(__dirname + "/log/" + (cluster.isPrimary ? "master" : (cluster.isPrimary === undefined ? "singlethread" : "worker")) + "-" + timestamp + ".log", {
flags: "a",
autoClose: false
});
@@ -1160,11 +1217,11 @@ process.exit = function (code) {
if (!disableMods) {
var modloaderFolderName = "modloader";
- if (cluster.isMaster === false) {
+ if (cluster.isPrimary === false) {
modloaderFolderName = ".modloader_w" + Math.floor(Math.random() * 65536);
}
var tempServerSideScriptName = "serverSideScript.js";
- if (!process.isBun && cluster.isMaster === false) {
+ if (!process.isBun && cluster.isPrimary === false) {
tempServerSideScriptName = ".serverSideScript_w" + Math.floor(Math.random() * 65536) + ".js";
}
for (var i = 0; i < modFiles.length; i++) {
@@ -1234,7 +1291,7 @@ if (!disableMods) {
}
}
} catch (ex) {
- if (cluster.isMaster || cluster.isMaster === undefined) {
+ if (cluster.isPrimary || cluster.isPrimary === undefined) {
serverconsole.locwarnmessage("There was a problem while loading a \"" + modFiles[i] + "\" mod.");
serverconsole.locwarnmessage("Stack:");
serverconsole.locwarnmessage(generateErrorStack(ex));
@@ -1263,7 +1320,7 @@ if (!disableMods) {
}
mods.push(amod);
} catch (ex) {
- if (cluster.isMaster || cluster.isMaster === undefined) {
+ if (cluster.isPrimary || cluster.isPrimary === undefined) {
serverconsole.locwarnmessage("There was a problem while loading server side JavaScript.");
serverconsole.locwarnmessage("Stack:");
serverconsole.locwarnmessage(generateErrorStack(ex));
@@ -1480,7 +1537,7 @@ forbiddenPaths.serverSideScriptDirectories.push(getInitializePath("./mods"));
forbiddenPaths.log = getInitializePath("./log");
//Create server
-if (!cluster.isMaster) {
+if (!cluster.isPrimary) {
var reqcounter = 0;
var server = {};
var server2 = {};
@@ -1613,7 +1670,7 @@ if (!cluster.isMaster) {
server2.on("error", function (err) {
if (err.code == "EADDRINUSE" || err.code == "EADDRNOTAVAIL" || err.code == "EACCES") {
attmtsRedir--;
- if (cluster.isMaster === undefined) {
+ if (cluster.isPrimary === undefined) {
if (err.code == "EADDRINUSE") {
serverconsole.locerrmessage("Address in use by another process.");
} else if (err.code == "EADDRNOTAVAIL") {
@@ -1629,14 +1686,14 @@ if (!cluster.isMaster) {
server2.close();
setTimeout(start, 900);
} else {
- if (cluster.isMaster !== undefined) process.send("\x12" + err.code);
+ if (cluster.isPrimary !== undefined) process.send("\x12" + err.code);
process.exit(errors[err.code]);
}
} else {
serverconsole.locerrmessage("There was a problem starting SVR.JS!!!");
serverconsole.locerrmessage("Stack:");
serverconsole.locerrmessage(generateErrorStack(err));
- if (cluster.isMaster !== undefined) process.send("\x12CRASH");
+ if (cluster.isPrimary !== undefined) process.send("\x12CRASH");
process.exit(err.code ? errors[err.code] : 1);
}
});
@@ -1867,11 +1924,9 @@ if (!cluster.isMaster) {
res.end();
return;
}
- try {
- req.url = encodeURI(Buffer.from(req.url, "latin1").toString("utf8")).replace(/%25/gi, "%");
- } catch (ex) {
- //URL not converted...
- }
+
+ req.url = fixNodeMojibakeURL(req.url);
+
res.writeHeadNative = res.writeHead;
res.writeHead = function (a, b, c) {
if (parseInt(a) >= 400 && parseInt(a) <= 599) {
@@ -1920,7 +1975,7 @@ if (!cluster.isMaster) {
400: "The request you made is invalid.",
417: "Expectation in Expect property couldn't be satisfied.",
500: "The server had an unexpected error. Below, the error stack is shown: {stack}
Please contact with developer/administrator at {contact}.",
- 501: "The request requires use of a function, which isn't implemented (yet) by the server."
+ 501: "The request requires use of a function, which isn't currently implemented by the server."
};
//Server error calling method
@@ -2588,7 +2643,7 @@ if (!cluster.isMaster) {
var modFunction = ffinals;
for (var i = proxyMods.length - 1; i >= 0; i--) {
- modFunction = proxyMods[i].callback(req, socket, head, configJSON, serverconsole, modFunction);
+ modFunction = proxyMods[i].proxyCallback(req, socket, head, configJSON, serverconsole, modFunction);
}
modFunction();
}
@@ -2760,11 +2815,7 @@ if (!cluster.isMaster) {
return;
}
- try {
- request.url = encodeURI(Buffer.from(request.url, "latin1").toString("utf8")).replace(/%25/gi, "%");
- } catch (ex) {
- //Request URL not modified...
- }
+ request.url = fixNodeMojibakeURL(request.url);
var headWritten = false;
response.writeHeadNative = response.writeHead;
@@ -2955,9 +3006,9 @@ if (!cluster.isMaster) {
431: "The request you sent contains headers, that are too large.",
451: "The requested file isn't accessible for legal reasons.",
500: "The server had an unexpected error. Below, the error stack is shown:
{stack}
Please contact with developer/administrator at {contact}.",
- 501: "The request requires use of a function, which isn't implemented (yet) by the server.",
+ 501: "The request requires use of a function, which isn't currently implemented by the server.",
502: "The server had an error, while it was acting as a gateway.
Please contact with developer/administrator at {contact}.",
- 503: "Service provided by the server isn't available (yet).
Please contact with developer/administrator at {contact}.",
+ 503: "The service provided by the server is currently unavailable, possibly due to maintenance downtime or capacity problems. Please try again later.
Please contact with developer/administrator at {contact}.",
504: "The server couldn't get response in time, while it was acting as a gateway.
Please contact with developer/administrator at {contact}.",
505: "The server doesn't support HTTP version used in the request.",
506: "Variant header is configured to be engaged in content negotiation.
Please contact with developer/administrator at {contact}.",
@@ -3288,21 +3339,10 @@ if (!cluster.isMaster) {
return;
}
- if (href == "/invoke500.svr" || (os.platform() == "win32" && href.toLowerCase() == "/invoke500.svr")) {
- if (version.indexOf("Nightly-") === 0 && uobject.query.crash !== undefined) throw new Error("Intentionally crashed");
+ if (version.indexOf("Nightly-") === 0 && (href == "/invoke500.svr" || (os.platform() == "win32" && href.toLowerCase() == "/invoke500.svr"))) {
+ if (uobject.query.crash !== undefined) throw new Error("Intentionally crashed");
try {
- if (uobject.query.aprilfools === undefined) throw new Error("This page is intended to return 500 code.");
- var hdhds = getCustomHeaders();
- hdhds["Content-Type"] = "text/html; charset=utf-8";
- if (uobject.query.activate === undefined) {
- res.writeHead(599, "You may be a victim of software counterfeiting.", hdhds);
- res.end("
To use all DorianTech SVR.JS features, such as all directory traversal protections; use server-side JS; and recieve product support, your copy of DorianTech SVR.JS must be validated as genuine.
This copy of SVR.JS is not genuine.");
- serverconsole.resmessage("You may be a victim of software counterfeiting.");
- } else {
- res.writeHead(200, "OK", hdhds);
- res.end("\n\n\n\nSVR.JS Genuine Advantage\n\n\n
Activate SVR.JS
\nYou will then be able to use all of SVR.JS features through SVR.JS Genuine Advantage!\n\n
Wait...
\n\n\n\nThis copy of SVR.JS is not genuine.");
- }
- return;
+ throw new Error("This page is intended to return 500 code.");
} catch (ex) {
callServerError(500, undefined, generateErrorStack(ex));
return;
@@ -3318,35 +3358,15 @@ if (!cluster.isMaster) {
res.writeHead(200, "OK", hdhds);
res.end((head == "" ? "SVR.JS status" + (request.headers.host == undefined ? "" : " for " + String(req.headers.host).replace(/&/g, "&").replace(//g, ">")) + "" : head.replace(//i, "SVR.JS status" + (request.headers.host == undefined ? "" : " for " + String(req.headers.host).replace(/&/g, "&").replace(//g, ">")) + "")) + "
And Satan created Mammon. His work won people from all over the school. When people abandoned them through the Piracy Window, so Satan went back in time and created the Server to continue to wreak havoc all over the school.
\n
from The Summary of Book of ZSOiE
\n \n \n");
- return;
- }
- var randomValue = Math.random();
- if (randomValue > 0.85714) {
- res.end("\n\n\n\n \n The Book of ZSOiE, 7:28\n \n \n \n \n \n \n
The Server continues to cultivate it's Dafa. The Author found the Robot and asked him for help. Then the Robot started to help the Author to improve his Server. And the Author tries to create yet another server without using the main node...
\n
from The Book of ZSOiE, 7:28
\n \n \n");
- } else if (randomValue > 0.71429) {
- res.end("\n\n\n\n \n The Book of ZSOiE, 7:16\n \n \n \n \n \n \n
The Server is still going. But the Author commanded to the Server: \"thou shalt you split to two branches.\". And the Server did split it's Dafa. One of two branches stopped serving on old and rusty node. Other one is still serving on that, but it will later vanish... \"Mammon will get confused\" - said the Author.
\n
from The Book of ZSOiE, 7:16
\n \n \n");
- } else if (randomValue > 0.57143) {
- res.end("\n\n\n\n \n The Book of ZSOiE, 7:2\n \n \n \n \n \n \n
The old Server forces died. The all-powerful new Server rosen from ashes of old Server like phoenix followed the ways of Durability-Ease-Reliability and cultivated his Dafa. Then, the Author and Whyvn appeared on best former Mammon's disciples paper.
\n
from The Book of ZSOiE, 7:2
\n \n \n");
- } else if (randomValue > 0.42857) {
- res.end("\n\n\n\n \n The Book of ZSOiE, 6:24\n \n \n \n \n \n \n
Mammon had enough karmic retribution. The Author tried it's Server on main node's substitute. Then, the Author saw, that Server's Dafa is good, and that main node, it's substitute, and older Mammon are good. Meanwhile the Author, Whyvn, and Snovbyn rejoiced even more from their success over older Mammon.
\n
from The Book of ZSOiE, 6:24
\n \n \n");
- } else if (randomValue > 0.32143) {
- res.end("\n\n\n\n \n The Book of ZSOiE, 6:6\n \n \n \n \n \n \n
And the Server is about to come. The Author along with Whyvn and Snovbyn passing the Mammon's test rejoiced their success over older Mammon.
\n
from The Book of ZSOiE, 6:6
\n \n \n");
- } else if (randomValue > 0.14286) {
- res.end("\n\n\n\n \n The Book of ZSOiE, 5:25\n \n \n \n \n \n \n
The twins of Mammon quarrelled. The Author with it's Server and it's main node plunged the Mammon's servers into darkness. Meanwhile Whyvn and Snovbyn helped him to break Mammon's servers.
\n
from The Book of ZSOiE, 5:25
\n \n \n");
- } else {
- res.end("\n\n\n\n \n The Book of ZSOiE, 3:16\n \n \n \n \n \n \n
Mammon slept. Meanwhile, the Author, Whyvn and Snovbyn being in very skill-requiring challenge casted tcpdump and mongodb on him.
\n
from The Book of ZSOiE, 3:16
\n \n \n");
- }
- return;
} else if (version.indexOf("Nightly-") === 0 && (href == "/crash.svr" || (os.platform() == "win32" && href.toLowerCase() == "/crash.svr"))) {
throw new Error("Intentionally crashed");
}
+ /////////////////////////////////////////////
+ ////THERE IS NO MORE "THE BOOK OF ZSOIE"!////
+ //// But it's in easteregg.tar.gz mod... ////
+ /////////////////////////////////////////////
+
var pth = decodeURIComponent(href).replace(/\/+/g, "/").substr(1);
fs.stat("./" + pth, function (err, stats) {
if (err) {
@@ -4131,7 +4151,7 @@ if (!cluster.isMaster) {
server.on("error", function (err) {
if (err.code == "EADDRINUSE" || err.code == "EADDRNOTAVAIL" || err.code == "EACCES") {
attmts--;
- if (cluster.isMaster === undefined) {
+ if (cluster.isPrimary === undefined) {
if (err.code == "EADDRINUSE") {
serverconsole.locerrmessage("Address in use by another process.");
} else if (err.code == "EADDRNOTAVAIL") {
@@ -4147,14 +4167,14 @@ if (!cluster.isMaster) {
server2.close();
setTimeout(start, 900);
} else {
- if (cluster.isMaster !== undefined) process.send("\x12" + err.code);
+ if (cluster.isPrimary !== undefined) process.send("\x12" + err.code);
process.exit(errors[err.code]);
}
} else {
serverconsole.locerrmessage("There was a problem starting SVR.JS!!!");
serverconsole.locerrmessage("Stack:");
serverconsole.locerrmessage(generateErrorStack(err));
- if (cluster.isMaster !== undefined) process.send("\x12CRASH");
+ if (cluster.isPrimary !== undefined) process.send("\x12CRASH");
process.exit(err.code ? errors[err.code] : 1);
}
});
@@ -4246,7 +4266,7 @@ var messageTransmitted = false;
function listeningMessage() {
if (messageTransmitted) return;
messageTransmitted = true;
- if (!cluster.isMaster && cluster.isMaster !== undefined) {
+ if (!cluster.isPrimary && cluster.isPrimary !== undefined) {
process.send("\x12LISTEN");
return;
}
@@ -4274,7 +4294,7 @@ var closedMaster = false;
function start(init) {
init = Boolean(init);
- if (cluster.isMaster || cluster.isMaster === undefined) {
+ if (cluster.isPrimary || cluster.isPrimary === undefined) {
if (init) {
for (i = 0; i < logo.length; i++) console.log(logo[i]); //Print logo
console.log();
@@ -4283,7 +4303,7 @@ function start(init) {
if (vnum <= 57 && JSON.stringify(rewriteMap) != "[]") serverconsole.locwarnmessage("Some URL rewriting regexes will not work in Node.JS 8.x and earlier.");
if (http2.__disabled__ !== undefined) serverconsole.locwarnmessage("HTTP/2 isn't supported by your Node.JS version!");
if (process.isBun) serverconsole.locwarnmessage("Bun support is experimental.");
- if (cluster.isMaster === undefined) serverconsole.locwarnmessage("You're running SVR.JS on single thread. Reliability may suffer.");
+ if (cluster.isPrimary === undefined) serverconsole.locwarnmessage("You're running SVR.JS on single thread. Reliability may suffer.");
if (crypto.__disabled__ !== undefined) serverconsole.locwarnmessage("Your Node.JS version doesn't have crypto support!");
if (!process.isBun && process.version == "v8.5.0") serverconsole.locwarnmessage("Your Node.JS version is vulnerable to path validation vulnerability (CVE-2017-14849).");
if (process.getuid && process.getuid() == 0) serverconsole.locwarnmessage("You're running SVR.JS as root. It's recommended to run SVR.JS as an non-root user.");
@@ -4312,7 +4332,7 @@ function start(init) {
}
- if (!cluster.isMaster) {
+ if (!cluster.isPrimary) {
if (secure) {
server.listen(sport);
if (!disableNonEncryptedServer) server2.listen(port);
@@ -4329,13 +4349,13 @@ function start(init) {
if (secure && !disableNonEncryptedServer) {
server2.close();
}
- if (cluster.isMaster === undefined) serverconsole.climessage("Server closed.");
+ if (cluster.isPrimary === undefined) serverconsole.climessage("Server closed.");
else {
process.send("Server closed.");
process.send("\x12CLOSE");
}
} catch (ex) {
- if (cluster.isMaster === undefined) serverconsole.climessage("Cannot close server! Reason: " + ex.message);
+ if (cluster.isPrimary === undefined) serverconsole.climessage("Cannot close server! Reason: " + ex.message);
else process.send("Cannot close server! Reason: " + ex.message);
}
},
@@ -4347,29 +4367,29 @@ function start(init) {
} else {
server.listen(port); // ReOpen Server
}
- if (cluster.isMaster === undefined) serverconsole.climessage("Server opened.");
+ if (cluster.isPrimary === undefined) serverconsole.climessage("Server opened.");
else {
process.send("Server opened.");
process.send("\x12OPEN");
}
} catch (ex) {
- if (cluster.isMaster === undefined) serverconsole.climessage("Cannot open server! Reason: " + ex.message);
+ if (cluster.isPrimary === undefined) serverconsole.climessage("Cannot open server! Reason: " + ex.message);
else process.send("Cannot open server! Reason: " + ex.message);
}
},
help: function () {
- if (cluster.isMaster === undefined) serverconsole.climessage("Server commands:\n" + Object.keys(commands).join(" "));
+ if (cluster.isPrimary === undefined) serverconsole.climessage("Server commands:\n" + Object.keys(commands).join(" "));
else process.send("Server commands:\n" + Object.keys(commands).join(" "));
},
mods: function () {
- if (cluster.isMaster === undefined) serverconsole.climessage("Mods:");
+ if (cluster.isPrimary === undefined) serverconsole.climessage("Mods:");
else process.send("Mods:");
for (var i = 0; i < modInfos.length; i++) {
- if (cluster.isMaster === undefined) serverconsole.climessage((i + 1).toString() + ". " + modInfos[i].name + " " + modInfos[i].version);
+ if (cluster.isPrimary === undefined) serverconsole.climessage((i + 1).toString() + ". " + modInfos[i].name + " " + modInfos[i].version);
else process.send((i + 1).toString() + ". " + modInfos[i].name + " " + modInfos[i].version);
}
if (modInfos.length == 0) {
- if (cluster.isMaster === undefined) serverconsole.climessage("No mods installed.");
+ if (cluster.isPrimary === undefined) serverconsole.climessage("No mods installed.");
else process.send("No mods installed.");
}
},
@@ -4385,8 +4405,8 @@ function start(init) {
},
block: function (ip) {
if (ip == undefined || JSON.stringify(ip) == "[]") {
- if (cluster.isMaster === undefined) serverconsole.climessage("Cannot block non-existent IP.");
- else if (!cluster.isMaster) process.send("Cannot block non-existent IP.");
+ if (cluster.isPrimary === undefined) serverconsole.climessage("Cannot block non-existent IP.");
+ else if (!cluster.isPrimary) process.send("Cannot block non-existent IP.");
} else {
for (var i = 0; i < ip.length; i++) {
if (ip[i].indexOf(":") == -1) {
@@ -4396,14 +4416,14 @@ function start(init) {
blacklist.add(ip[i]);
}
}
- if (cluster.isMaster === undefined) serverconsole.climessage("IPs successfully blocked.");
- else if (!cluster.isMaster) process.send("IPs successfully blocked.");
+ if (cluster.isPrimary === undefined) serverconsole.climessage("IPs successfully blocked.");
+ else if (!cluster.isPrimary) process.send("IPs successfully blocked.");
}
},
unblock: function (ip) {
if (ip == undefined || JSON.stringify(ip) == "[]") {
- if (cluster.isMaster === undefined) serverconsole.climessage("Cannot unblock non-existent IP.");
- else if (!cluster.isMaster) process.send("Cannot unblock non-existent IP.");
+ if (cluster.isPrimary === undefined) serverconsole.climessage("Cannot unblock non-existent IP.");
+ else if (!cluster.isPrimary) process.send("Cannot unblock non-existent IP.");
} else {
for (var i = 0; i < ip.length; i++) {
if (ip[i].indexOf(":") == -1) {
@@ -4411,19 +4431,19 @@ function start(init) {
}
blacklist.remove(ip[i]);
}
- if (cluster.isMaster === undefined) serverconsole.climessage("IPs successfully unblocked.");
- else if (!cluster.isMaster) process.send("IPs successfully unblocked.");
+ if (cluster.isPrimary === undefined) serverconsole.climessage("IPs successfully unblocked.");
+ else if (!cluster.isPrimary) process.send("IPs successfully unblocked.");
}
},
restart: function () {
- if (cluster.isMaster === undefined) serverconsole.climessage("This command is not supported on single-threaded SVR.JS.");
+ if (cluster.isPrimary === undefined) serverconsole.climessage("This command is not supported on single-threaded SVR.JS.");
else process.send("This command need to be run in SVR.JS master.");
}
};
if (init) {
- if (cluster.isMaster === undefined) {
+ if (cluster.isPrimary === undefined) {
setInterval(function () {
try {
saveConfig();
@@ -4432,7 +4452,7 @@ function start(init) {
throw new Error(ex);
}
}, 300000);
- } else if (cluster.isMaster) {
+ } else if (cluster.isPrimary) {
setInterval(function () {
var allClusters = Object.keys(cluster.workers);
for (var i = 0; i < allClusters.length; i++) {
@@ -4452,7 +4472,7 @@ function start(init) {
}
}, 300000);
}
- if (!cluster.isMaster && cluster.isMaster !== undefined) {
+ if (!cluster.isPrimary && cluster.isPrimary !== undefined) {
process.on("message", function (line) {
try {
if (line == "") {
@@ -4495,7 +4515,7 @@ function start(init) {
var argss = line.split(" ");
var command = argss.shift();
if (line != "") {
- if (cluster.isMaster !== undefined) {
+ if (cluster.isPrimary !== undefined) {
var allClusters = Object.keys(cluster.workers);
if (command == "block") commands.block(argss);
if (command == "unblock") commands.unblock(argss);
@@ -4577,9 +4597,9 @@ function start(init) {
});
}
- if (cluster.isMaster || cluster.isMaster === undefined) {
+ if (cluster.isPrimary || cluster.isPrimary === undefined) {
//Cluster forking code
- if (cluster.isMaster !== undefined && init) {
+ if (cluster.isPrimary !== undefined && init) {
var cpus = os.cpus().length;
if (cpus > 16) cpus = 16;
try {
@@ -4758,7 +4778,7 @@ function saveConfig() {
}
//Process event listeners
-if (cluster.isMaster || cluster.isMaster === undefined) {
+if (cluster.isPrimary || cluster.isPrimary === undefined) {
process.on("uncaughtException", function (ex) {
//CRASH HANDLER
serverconsole.locerrmessage("SVR.JS master process just crashed!!!");
@@ -4805,7 +4825,7 @@ if (cluster.isMaster || cluster.isMaster === undefined) {
}
});
process.on("SIGINT", function () {
- if (cluster.isMaster !== undefined) {
+ if (cluster.isPrimary !== undefined) {
exiting = true;
var allClusters = Object.keys(cluster.workers);
for (var i = 0; i < allClusters.length; i++) {
diff --git a/svrpasswd.js b/svrpasswd.js
index 0942229..4ad2956 100644
--- a/svrpasswd.js
+++ b/svrpasswd.js
@@ -277,24 +277,30 @@ function password(callback) {
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
- prompt: 'Password: ',
- terminal: false
+ prompt: 'Password: '
});
rl.prompt();
- rl.once('line', (line) => {
- //rl.close();
+ process.stdout.writeold = process.stdout.write;
+ process.stdout.write = function (s) {
+ process.stdout.writeold(s.replace(/[^\r\n]/g, ""));
+ };
+ rl.once('line', function (line) {
+ process.stdout.write = process.stdout.writeold;
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: 'Confirm password: ',
- terminal: false
});
rl.prompt();
- rl.on('line', (line2) => {
+ process.stdout.writeold = process.stdout.write;
+ process.stdout.write = function (s) {
+ process.stdout.writeold(s.replace(/[^\r\n]/g, ""));
+ };
+ rl.on('line', function (line2) {
+ process.stdout.write = process.stdout.writeold;
rl.close();
if (line != line2) callback(false);
else callback(line);
-
});
});
}
diff --git a/tests.html b/tests.html
index b122751..7ab9e84 100644
--- a/tests.html
+++ b/tests.html
@@ -1,7 +1,7 @@
- SVR.JS 3.4.20 Tests
+ SVR.JS 3.4.21 Tests
-