Added index.cgi file and HTTPS environment value support.

This commit is contained in:
Dorian Niemiec 2023-08-19 20:18:44 +02:00
parent b584fa637c
commit f5a4148ea9
2 changed files with 66 additions and 5 deletions

View file

@ -274,6 +274,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
nEnv["REMOTE_PORT"] = (req.socket.realRemotePort ? req.socket.realRemotePort : req.socket.remotePort); nEnv["REMOTE_PORT"] = (req.socket.realRemotePort ? req.socket.realRemotePort : 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.headers["content-type"]) nEnv["CONTENT_TYPE"] = req.headers["content-type"]; if (req.headers["content-type"]) nEnv["CONTENT_TYPE"] = req.headers["content-type"];
if (req.headers["content-length"]) nEnv["CONTENT_LENGTH"] = req.headers["content-length"]; if (req.headers["content-length"]) nEnv["CONTENT_LENGTH"] = req.headers["content-length"];
var nh = JSON.parse(JSON.stringify(req.headers)); var nh = JSON.parse(JSON.stringify(req.headers));
@ -340,8 +341,59 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
} }
} }
} else { } else {
fs.stat("." + href + "/index.cgi", function (e3, s3) {
elseCallback(); if (!e3 && s3.isFile()) {
try {
executeCGIWithEnv(
(href + "/index.cgi").replace(/\/+/g, "/"),
"",
req,
res,
req.socket.localAddress,
req.socket.localPort,
getCustomHeaders ?
getCustomHeaders()["Server"] +
" RedBrick/" +
version :
"SVR.JS/" +
configJSON.version +
" (" +
os.platform()[0].toUpperCase() +
os.platform().slice(1) +
"; Node.JS/" +
process.version +
") RedBrick/" +
version,
bheaders
);
} catch (ex) {
if (!callServerError) {
res.writeHead(500, "Internal Server Error", abheaders);
res.write(
"<html><head><title>500 Internal Server Error</title></head><body><h1>500 Internal Server Error</h1><p>A server had unexpected exception. Below, the stack trace of the error is shown:</p><code>" +
ex.stack.replace(/\r\n/g, "<br/>").replace(/\n/g, "<br/>").replace(/\r/g, "<br/>").replace(/ /g, "&nbsp;") +
"</code><p>Please contact the developer/administrator of the website.</p><p style=\"font-style: italic; font-weight: normal;\">SVR.JS " +
configJSON.version +
" (" +
os.platform()[0].toUpperCase() +
os.platform().slice(1) +
"; Node.JS/" +
process.version +
") RedBrick/" +
version +
" " +
(req.headers.host == undefined ? "" : " on " + req.headers.host) +
"</p></body></html>"
);
res.end();
} else {
callServerError(500, "RedBrick/" + version, ex);
}
}
} else {
elseCallback();
}
});
} }
}); });
} else { } else {
@ -418,8 +470,17 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
rpth: (a !== undefined ? "/" + a : "") rpth: (a !== undefined ? "/" + a : "")
}) })
} else { } else {
b.unshift(cpth.pop()); fs.stat(pth + "/index.cgi", function (e3, s3) {
return checkPath(cpth.join("/"), cb, b.join("/")); if (!e3 && s3.isFile()) {
cb({
fpth: (pth + "/index.cgi").replace(/\/+/g, "/"),
rpth: (a !== undefined ? "/" + a : "")
})
} else {
b.unshift(cpth.pop());
return checkPath(cpth.join("/"), cb, b.join("/"));
}
});
} }
}); });
} }

View file

@ -1,4 +1,4 @@
{ {
"name": "DorianTech RedBrick CGI engine for SVR.JS", "name": "DorianTech RedBrick CGI engine for SVR.JS",
"version": "2.3.3" "version": "2.3.4"
} }