From 4011f3608672ba7b12a98277f1f758132200b88b Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Sat, 19 Aug 2023 20:13:50 +0200 Subject: [PATCH] Added index.cgi file and HTTPS environment value support. --- index.js | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index d2c1105..807a564 100644 --- a/index.js +++ b/index.js @@ -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["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" ? "\\" : "/")); + if (req.socket.encrypted) nEnv["HTTPS"] = "ON"; if (req.headers["content-type"]) nEnv["CONTENT_TYPE"] = req.headers["content-type"]; if (req.headers["content-length"]) nEnv["CONTENT_LENGTH"] = req.headers["content-length"]; var nh = JSON.parse(JSON.stringify(req.headers)); @@ -340,8 +341,59 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e } } } else { - - elseCallback(); + fs.stat("." + href + "/index.cgi", function (e3, s3) { + 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( + "500 Internal Server Error

500 Internal Server Error

A server had unexpected exception. Below, the stack trace of the error is shown:

" + + ex.stack.replace(/\r\n/g, "
").replace(/\n/g, "
").replace(/\r/g, "
").replace(/ /g, " ") + + "

Please contact the developer/administrator of the website.

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) + + "

" + ); + res.end(); + } else { + callServerError(500, "RedBrick/" + version, ex); + } + } + } else { + elseCallback(); + } + }); } }); } else { @@ -418,8 +470,17 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e rpth: (a !== undefined ? "/" + a : "") }) } else { - b.unshift(cpth.pop()); - return checkPath(cpth.join("/"), cb, b.join("/")); + fs.stat(pth + "/index.cgi", function (e3, s3) { + 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("/")); + } + }); } }); }