diff --git a/a.tar.gz b/a.tar.gz new file mode 100644 index 0000000..66f123c Binary files /dev/null and b/a.tar.gz differ diff --git a/index.js b/index.js index 395f0f8..776f625 100644 --- a/index.js +++ b/index.js @@ -355,6 +355,19 @@ if (typeof fastcgiConfO.multiConfig == "object" && fastcgiConfO.multiConfig !== } var disableModExposeSupported = process.versions.svrjs && process.versions.svrjs.match(/^(?:Nightly-|(?:[4-9]|[123][0-9])[0-9]*\.|3\.(?:[1-9][0-9]+\.|9\.(?:[1-9])|4\.(?:(?:[3-9]|[12][0-9])[0-9]+|29)))/i); +var normalizedWebrootSupported = process.versions.svrjs && process.versions.svrjs.match(/^(?:Nightly-|(?:[5-9]|[1234][0-9])[0-9]*\.|4\.(?:(?:[1][0-9]|[2-9])+\.))/i); + +function normalizeWebroot(currentWebroot) { + if (currentWebroot === undefined) { + return process.cwd(); + } else if (!path.isAbsolute(currentWebroot)) { + return ( + process.cwd() + (os.platform() == "win32" ? "\\" : "/") + currentWebroot + ); + } else { + return currentWebroot; + } +} function Mod() {} @@ -364,6 +377,8 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e configJSON = configJSONS; } + var detectedWwwroot = normalizedWebrootSupported ? normalizeWebroot(configJSON.wwwroot) : process.cwd(); + function checkIfThereIsA401Rule() { var actually401 = false; @@ -600,11 +615,11 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e nEnv["SERVER_ADMIN"] = configJSON.serverAdministratorEmail; } nEnv["SERVER_NAME"] = req.headers.host; - nEnv["DOCUMENT_ROOT"] = process.cwd(); + nEnv["DOCUMENT_ROOT"] = detectedWwwroot; nEnv["SCRIPT_NAME"] = cPath; - nEnv["SCRIPT_FILENAME"] = (process.cwd() + (require("os").platform == "win32" ? cPath.replace(/\//g, "\\") : cPath)).replace((require("os").platform == "win32" ? /\\\\/g : /\/\//g), (require("os").platform == "win32" ? "\\" : "/")); + nEnv["SCRIPT_FILENAME"] = (detectedWwwroot + (require("os").platform == "win32" ? cPath.replace(/\//g, "\\") : cPath)).replace((require("os").platform == "win32" ? /\\\\/g : /\/\//g), (require("os").platform == "win32" ? "\\" : "/")); nEnv["PATH_INFO"] = decodeURIComponent(b); - nEnv["PATH_TRANSLATED"] = b ? ((process.cwd() + decodeURIComponent(require("os").platform == "win32" ? b.replace(/\//g, "\\") : b)).replace((require("os").platform == "win32" ? /\\\\/g : /\/\//g), (require("os").platform == "win32" ? "\\" : "/"))) : ""; + nEnv["PATH_TRANSLATED"] = b ? ((detectedWwwroot + decodeURIComponent(require("os").platform == "win32" ? b.replace(/\//g, "\\") : b)).replace((require("os").platform == "win32" ? /\\\\/g : /\/\//g), (require("os").platform == "win32" ? "\\" : "/"))) : ""; nEnv["REQUEST_METHOD"] = req.method; nEnv["REQUEST_URI"] = (!origHref || origHref == href) ? req.url : (origHref + (uobject.search ? ((uobject.search[0] == "?" ? "" : "?") + uobject.search) : "")); nEnv["REMOTE_ADDR"] = (req.socket.realRemoteAddress ? req.socket.realRemoteAddress : ((req.headers["x-forwarded-for"] && configJSON.enableIPSpoofing) ? req.headers["x-forwarded-for"].split(",")[0].replace(/ /g, "") : req.socket.remoteAddress)).replace(/^::ffff:/i, ""); @@ -701,7 +716,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e callServerError(500, "GreenRhombus/" + version, ex); } } - } else if (((href == "/greenrhombus-config.json" || (os.platform() == "win32" && href.toLowerCase() == "/greenrhombus-config.json")) && path.normalize(__dirname + "/../../..") == process.cwd()) || ((href == "/greenrhombus-scriptexts.json" || (os.platform() == "win32" && href.toLowerCase() == "/greenrhombus-scriptexts.json")) && path.normalize(__dirname + "/../../..") == process.cwd())) { + } else if (((href == "/greenrhombus-config.json" || (os.platform() == "win32" && href.toLowerCase() == "/greenrhombus-config.json")) && path.normalize(__dirname + "/../../..") == detectedWwwroot) || ((href == "/greenrhombus-scriptexts.json" || (os.platform() == "win32" && href.toLowerCase() == "/greenrhombus-scriptexts.json")) && path.normalize(__dirname + "/../../..") == detectedWwwroot)) { if (!callServerError) { res.writeHead(200, "OK", { "Content-Type": "application/json", @@ -712,11 +727,11 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e callServerError(200, "GreenRhombus/" + version, exttointerpreteruser); } } else { - fs.stat("." + decodeURIComponent(href), function (err, stats) { + fs.stat(detectedWwwroot + decodeURIComponent(href), function (err, stats) { if (!err) { if (!stats.isFile()) { if (scriptExts.indexOf(".php") != -1) { - fs.stat("." + decodeURIComponent(href) + "/index.php", function (e2, s2) { + fs.stat(detectedWwwroot + decodeURIComponent(href) + "/index.php", function (e2, s2) { if (!e2 && s2.isFile()) { try { executeFastCGIWithEnv( @@ -774,7 +789,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e } }); } else if (scriptExts.indexOf(".cgi") != -1) { - fs.stat("." + decodeURIComponent(href) + "/index.cgi", function (e3, s3) { + fs.stat(detectedWwwroot + decodeURIComponent(href) + "/index.cgi", function (e3, s3) { if (!e3 && s3.isFile()) { try { executeFastCGIWithEnv( @@ -902,7 +917,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e if (!a) b = []; else var b = a.split("/"); var isFile = false; - fs.stat(pth, function (err, stats) { + fs.stat(detectedWwwroot + "/" + pth, function (err, stats) { if (!err && stats.isFile()) { cb({ fpth: pth,