Update to RedBrick 2.5.0
This commit is contained in:
parent
63a87ea149
commit
0294279efb
2 changed files with 474 additions and 426 deletions
178
index.js
178
index.js
|
@ -15,6 +15,19 @@ try {
|
|||
}
|
||||
var configJSONS = JSON.parse(fs.readFileSync(__dirname + "/../../../config.json")); // Read configuration JSON
|
||||
|
||||
var exttointerpreteruser = {};
|
||||
var scriptExts = [];
|
||||
try {
|
||||
exttointerpreteruser = JSON.parse(fs.readFileSync(__dirname + "/../../../redbrick-interpreters.json"));
|
||||
} catch (ex) {
|
||||
|
||||
}
|
||||
try {
|
||||
scriptExts = JSON.parse(fs.readFileSync(__dirname + "/../../../redbrick-scriptexts.json"));
|
||||
} catch (ex) {
|
||||
|
||||
}
|
||||
|
||||
function Mod() {}
|
||||
|
||||
Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, ext, uobject, search, defaultpage, users, page404, head, foot, fd, elseCallback, configJSON, callServerError, getCustomHeaders, origHref, redirect, parsePostData) {
|
||||
|
@ -62,16 +75,9 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
|||
if (os.platform() == "win32") {
|
||||
exttointerpreter[".exe"] = [];
|
||||
exttointerpreter[".bat"] = ["cmd", "/c"];
|
||||
exttointerpreter[".cmd"] = ["cmd", "/c"];
|
||||
exttointerpreter[".vbs"] = ["cscript"];
|
||||
}
|
||||
var exttointerpreteruser = {};
|
||||
fs.readFile(__dirname + "/../../../redbrick-interpreters.json", function (err, data) {
|
||||
if (!err) {
|
||||
try {
|
||||
exttointerpreteruser = JSON.parse(data.toString());
|
||||
} catch (ex) {}
|
||||
}
|
||||
|
||||
fs.stat(fname, function (err, stats) {
|
||||
if (err) {
|
||||
if (!callServerError) {
|
||||
|
@ -270,7 +276,6 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
|||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function executeCGIWithEnv(a, b, req, res, pubip, port, software, dh) {
|
||||
|
@ -330,10 +335,38 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
|||
executeCGI("." + a, req, res, dh, nEnv);
|
||||
}
|
||||
|
||||
if (href.match(new RegExp("/cgi-bin(?:$|[?#/])", os.platform() == "win32" ? "i" : ""))) {
|
||||
var isCgiBin = href.match(new RegExp("/cgi-bin(?:$|[?#/])", os.platform() == "win32" ? "i" : ""));
|
||||
var isScriptExt = scriptExts.indexOf("." + ext) != -1;
|
||||
|
||||
if ((href == "/redbrick-interpreters.json" || href == "/redbrick-scriptexts.json" || (os.platform() == "win32" && (href.toLowerCase() == "/redbrick-interpreters.json" || href.toLowerCase() == "/redbrick-scriptexts.json"))) && path.normalize(__dirname + "/../../..") == process.cwd()) {
|
||||
if (!callServerError) {
|
||||
res.writeHead(403, "Forbidden", {
|
||||
"Content-Type": "text/html",
|
||||
"Server": "RedBrick/" + version
|
||||
});
|
||||
res.write(
|
||||
"<html><head><title>403 Forbidden</title></head><body><h1>403 Forbidden</h1><p>You don't have access to specific page.</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(JSON.stringify(exttointerpreteruser, null, 2));
|
||||
} else {
|
||||
callServerError(403, "RedBrick/" + version);
|
||||
}
|
||||
} else {
|
||||
fs.stat("." + href, function (err, stats) {
|
||||
if (!err) {
|
||||
if (!stats.isFile()) {
|
||||
if (isCgiBin || scriptExts.indexOf(".php") != -1) {
|
||||
fs.stat("." + href + "/index.php", function (e2, s2) {
|
||||
if (!e2 && s2.isFile()) {
|
||||
try {
|
||||
|
@ -383,7 +416,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
|||
callServerError(500, "RedBrick/" + version, ex);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (isCgiBin || scriptExts.indexOf(".cgi") != -1) {
|
||||
fs.stat("." + href + "/index.cgi", function (e3, s3) {
|
||||
if (!e3 && s3.isFile()) {
|
||||
try {
|
||||
|
@ -437,9 +470,69 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
|||
elseCallback();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
elseCallback();
|
||||
}
|
||||
});
|
||||
} else if (scriptExts.indexOf(".cgi") != -1) {
|
||||
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(
|
||||
"<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, " ") +
|
||||
"</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 {
|
||||
elseCallback();
|
||||
}
|
||||
} else {
|
||||
if (isCgiBin || isScriptExt) {
|
||||
try {
|
||||
executeCGIWithEnv(
|
||||
href,
|
||||
|
@ -487,12 +580,15 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
|||
callServerError(500, "RedBrick/" + version, ex);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
elseCallback();
|
||||
}
|
||||
}
|
||||
} else if (err && err.code == "ENOTDIR") {
|
||||
function checkPath(pth, cb, a) {
|
||||
// Function to check the path of the file and execute CGI script
|
||||
var cpth = pth.split("/");
|
||||
if (cpth.length < 3) {
|
||||
if (cpth.length < (isCgiBin ? 3 : 2)) {
|
||||
cb(false);
|
||||
return;
|
||||
}
|
||||
|
@ -505,34 +601,18 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
|||
fpth: pth,
|
||||
rpth: (a !== undefined ? "/" + a : "")
|
||||
})
|
||||
} else {
|
||||
fs.stat(pth + "/index.php", function (e2, s2) {
|
||||
if (!e2 && s2.isFile()) {
|
||||
cb({
|
||||
fpth: (pth + "/index.php").replace(/\/+/g, "/"),
|
||||
rpth: (a !== undefined ? "/" + a : "")
|
||||
})
|
||||
} else {
|
||||
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("/"));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
checkPath("." + href, function (pathp) {
|
||||
if (!pathp) {
|
||||
elseCallback();
|
||||
} else {
|
||||
var newext = path.extname(pathp.fpth);
|
||||
if (isCgiBin || scriptExts.indexOf(newext) != -1) {
|
||||
try {
|
||||
executeCGIWithEnv(
|
||||
pathp.fpth.substr(1),
|
||||
|
@ -580,47 +660,15 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
|||
callServerError(500, "RedBrick/" + version, ex);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
elseCallback();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (err && err.code == "ENOENT") {
|
||||
elseCallback(); //Invoke default error handler
|
||||
} else {
|
||||
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>" +
|
||||
err.stack.replace(/\r\n/g, "<br/>").replace(/\n/g, "<br/>").replace(/\r/g, "<br/>").replace(/ /g, " ") +
|
||||
"</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, err);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if ((href == "/redbrick-interpreters.json" || (os.platform() == "win32" && href.toLowerCase() == "/redbrick-interpreters.json")) && path.normalize(__dirname + "/../../..") == process.cwd()) {
|
||||
if (!callServerError) {
|
||||
res.writeHead(200, "OK", {
|
||||
"Content-Type": "application/json",
|
||||
"Server": "RedBrick/" + version
|
||||
});
|
||||
res.end(JSON.stringify(exttointerpreteruser, null, 2));
|
||||
} else {
|
||||
callServerError(200, "RedBrick/" + version, exttointerpreteruser);
|
||||
}
|
||||
} else {
|
||||
elseCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
2
mod.info
2
mod.info
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"name": "DorianTech RedBrick CGI engine for SVR.JS",
|
||||
"version": "2.4.3"
|
||||
"version": "2.5.0"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue