Fix handling of REMOTE_PORT

This commit is contained in:
Dorian Niemiec 2023-09-03 11:31:18 +02:00
parent a80d91de48
commit 696be56402

View file

@ -310,7 +310,11 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
nEnv["GATEWAY_INTERFACE"] = "CGI/1.1"; nEnv["GATEWAY_INTERFACE"] = "CGI/1.1";
nEnv["REQUEST_URI"] = (!origHref || origHref == href) ? req.url : (origHref + (uobject.search ? ("?" + uobject.search) : "")); nEnv["REQUEST_URI"] = (!origHref || origHref == href) ? req.url : (origHref + (uobject.search ? ("?" + 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, ""); 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, "");
nEnv["REMOTE_PORT"] = (req.socket.realRemotePort ? req.socket.realRemotePort : req.socket.remotePort); if(req.socket.realRemoteAddress && req.socket.realRemotePort) {
nEnv["REMOTE_PORT"] = req.socket.realRemotePort;
} else if(!(req.socket.realRemoteAddress && !req.socket.realRemotePort)) {
nEnv["REMOTE_PORT"] = req.socket.remotePort;
}
nEnv["SCRIPT_NAME"] = a; nEnv["SCRIPT_NAME"] = a;
nEnv["SCRIPT_FILENAME"] = (process.cwd() + (require("os").platform == "win32" ? a.replace(/\//g, "\\") : a)).replace((require("os").platform == "win32" ? /\\\\/g : /\/\//g), (require("os").platform == "win32" ? "\\" : "/")); nEnv["SCRIPT_FILENAME"] = (process.cwd() + (require("os").platform == "win32" ? a.replace(/\//g, "\\") : a)).replace((require("os").platform == "win32" ? /\\\\/g : /\/\//g), (require("os").platform == "win32" ? "\\" : "/"));
if (req.socket.encrypted) nEnv["HTTPS"] = "ON"; if (req.socket.encrypted) nEnv["HTTPS"] = "ON";