forked from svrjs/svrjs
Added new config.json property - useWebRootServerSideScript
This commit is contained in:
parent
1578a82069
commit
08692a2ff5
3 changed files with 19 additions and 8 deletions
|
@ -3,7 +3,7 @@
|
||||||
"port": 80,
|
"port": 80,
|
||||||
"pubport": 80,
|
"pubport": 80,
|
||||||
"page404": "404.html",
|
"page404": "404.html",
|
||||||
"timestamp": 1693637517717,
|
"timestamp": 1693652201916,
|
||||||
"blacklist": [],
|
"blacklist": [],
|
||||||
"nonStandardCodes": [],
|
"nonStandardCodes": [],
|
||||||
"enableCompression": true,
|
"enableCompression": true,
|
||||||
|
@ -99,5 +99,5 @@
|
||||||
"enableETag": true,
|
"enableETag": true,
|
||||||
"disableUnusedWorkerTermination": false,
|
"disableUnusedWorkerTermination": false,
|
||||||
"rewriteDirtyURLs": true,
|
"rewriteDirtyURLs": true,
|
||||||
"errorPages": []
|
"errorPages": [],
|
||||||
}
|
}
|
||||||
|
|
21
svr.js
21
svr.js
|
@ -1053,6 +1053,7 @@ var nonStandardCodesRaw = [];
|
||||||
var disableUnusedWorkerTermination = false;
|
var disableUnusedWorkerTermination = false;
|
||||||
var rewriteDirtyURLs = false;
|
var rewriteDirtyURLs = false;
|
||||||
var errorPages = [];
|
var errorPages = [];
|
||||||
|
var useWebRootServerSideScript = true;
|
||||||
|
|
||||||
//Get properties from config.json
|
//Get properties from config.json
|
||||||
if (configJSON.blacklist != undefined) rawBlackList = configJSON.blacklist;
|
if (configJSON.blacklist != undefined) rawBlackList = configJSON.blacklist;
|
||||||
|
@ -1080,6 +1081,7 @@ if (configJSON.disableToHTTPSRedirect != undefined) disableToHTTPSRedirect = con
|
||||||
if (configJSON.disableUnusedWorkerTermination != undefined) disableUnusedWorkerTermination = configJSON.disableUnusedWorkerTermination;
|
if (configJSON.disableUnusedWorkerTermination != undefined) disableUnusedWorkerTermination = configJSON.disableUnusedWorkerTermination;
|
||||||
if (configJSON.rewriteDirtyURLs != undefined) rewriteDirtyURLs = configJSON.rewriteDirtyURLs;
|
if (configJSON.rewriteDirtyURLs != undefined) rewriteDirtyURLs = configJSON.rewriteDirtyURLs;
|
||||||
if (configJSON.errorPages != undefined) errorPages = configJSON.errorPages;
|
if (configJSON.errorPages != undefined) errorPages = configJSON.errorPages;
|
||||||
|
if (configJSON.useWebRootServerSideScript != undefined) useWebRootServerSideScript = configJSON.useWebRootServerSideScript;
|
||||||
if (configJSON.wwwroot != undefined) {
|
if (configJSON.wwwroot != undefined) {
|
||||||
var wwwroot = configJSON.wwwroot;
|
var wwwroot = configJSON.wwwroot;
|
||||||
if (cluster.isPrimary || cluster.isPrimary === undefined) process.chdir(wwwroot);
|
if (cluster.isPrimary || cluster.isPrimary === undefined) process.chdir(wwwroot);
|
||||||
|
@ -1466,14 +1468,18 @@ if (!disableMods) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Determine path of server-side script file
|
||||||
|
var SSJSPath = "./serverSideScript.js";
|
||||||
|
if (!useWebRootServerSideScript) SSJSPath = __dirname + "/serverSideScript.js";
|
||||||
|
|
||||||
// Check if a custom server side script file exists
|
// Check if a custom server side script file exists
|
||||||
if (fs.existsSync("./serverSideScript.js") && fs.statSync("./serverSideScript.js").isFile()) {
|
if (fs.existsSync(SSJSPath) && fs.statSync(SSJSPath).isFile()) {
|
||||||
try {
|
try {
|
||||||
// Prepend necessary modules and variables to the custom server side script
|
// Prepend necessary modules and variables to the custom server side script
|
||||||
var 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 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) {\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.substr(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 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 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) {\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.substr(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 modfoot = "\r\nif(!disableEndElseCallbackExecute) {\r\ntry{\r\nelseCallback();\r\n} catch(err) {\r\n}\r\n}\r\n}\r\n}\r\nmodule.exports = Mod;";
|
var 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
|
// Write the modified server side script to the temp folder
|
||||||
fs.writeFileSync(__dirname + "/temp/" + tempServerSideScriptName, modhead + fs.readFileSync("./serverSideScript.js") + modfoot);
|
fs.writeFileSync(__dirname + "/temp/" + tempServerSideScriptName, modhead + fs.readFileSync(SSJSPath) + modfoot);
|
||||||
|
|
||||||
// Initialize variables for server side script loading
|
// Initialize variables for server side script loading
|
||||||
var aMod = undefined;
|
var aMod = undefined;
|
||||||
|
@ -1712,7 +1718,11 @@ if (secure) {
|
||||||
}
|
}
|
||||||
forbiddenPaths.svrjs = getInitializePath("./" + ((__dirname[__dirname.length - 1] != "/") ? __filename.replace(__dirname + "/", "") : __filename.replace(__dirname, "")));
|
forbiddenPaths.svrjs = getInitializePath("./" + ((__dirname[__dirname.length - 1] != "/") ? __filename.replace(__dirname + "/", "") : __filename.replace(__dirname, "")));
|
||||||
forbiddenPaths.serverSideScripts = [];
|
forbiddenPaths.serverSideScripts = [];
|
||||||
forbiddenPaths.serverSideScripts.push("/serverSideScript.js");
|
if (useWebRootServerSideScript) {
|
||||||
|
forbiddenPaths.serverSideScripts.push("/serverSideScript.js");
|
||||||
|
} else {
|
||||||
|
forbiddenPaths.serverSideScripts.push(getInitializePath("./serverSideScript.js"));
|
||||||
|
}
|
||||||
forbiddenPaths.serverSideScripts.push(getInitializePath("./temp/serverSideScript.js"));
|
forbiddenPaths.serverSideScripts.push(getInitializePath("./temp/serverSideScript.js"));
|
||||||
forbiddenPaths.serverSideScriptDirectories = [];
|
forbiddenPaths.serverSideScriptDirectories = [];
|
||||||
forbiddenPaths.serverSideScriptDirectories.push(getInitializePath("./temp/modloader"));
|
forbiddenPaths.serverSideScriptDirectories.push(getInitializePath("./temp/modloader"));
|
||||||
|
@ -3482,7 +3492,7 @@ if (!cluster.isPrimary) {
|
||||||
medCallback(false);
|
medCallback(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(list[_i].scode != errorCode || !matchHostname(list[_i].host)) {
|
if(list[_i].scode != errorCode || !matchHostname(list[_i].host)) {
|
||||||
getErrorFileName(list, callback, _i+1);
|
getErrorFileName(list, callback, _i+1);
|
||||||
return;
|
return;
|
||||||
|
@ -5801,7 +5811,8 @@ function saveConfig() {
|
||||||
if (configJSONobj.disableUnusedWorkerTermination === undefined) configJSONobj.disableUnusedWorkerTermination = false;
|
if (configJSONobj.disableUnusedWorkerTermination === undefined) configJSONobj.disableUnusedWorkerTermination = false;
|
||||||
if (configJSONobj.rewriteDirtyURLs === undefined) configJSONobj.rewriteDirtyURLs = false;
|
if (configJSONobj.rewriteDirtyURLs === undefined) configJSONobj.rewriteDirtyURLs = false;
|
||||||
if (configJSONobj.errorPages === undefined) configJSONobj.errorPages = [];
|
if (configJSONobj.errorPages === undefined) configJSONobj.errorPages = [];
|
||||||
|
if (configJSONobj.useWebRootServerSideScript === undefined) configJSONobj.useWebRootServerSideScript = true;
|
||||||
|
|
||||||
var configString = JSON.stringify(configJSONobj, null, 2);
|
var configString = JSON.stringify(configJSONobj, null, 2);
|
||||||
fs.writeFileSync(__dirname + "/config.json", configString);
|
fs.writeFileSync(__dirname + "/config.json", configString);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
35
|
36
|
Reference in a new issue