Clean up the code
This commit is contained in:
parent
1851adc375
commit
92242b757d
1 changed files with 412 additions and 412 deletions
26
index.js
26
index.js
|
@ -19,12 +19,12 @@ var exttointerpreteruser = {};
|
||||||
var scriptExts = [];
|
var scriptExts = [];
|
||||||
try {
|
try {
|
||||||
exttointerpreteruser = JSON.parse(fs.readFileSync(__dirname + "/../../../redbrick-interpreters.json"));
|
exttointerpreteruser = JSON.parse(fs.readFileSync(__dirname + "/../../../redbrick-interpreters.json"));
|
||||||
} catch(ex) {
|
} catch (ex) {
|
||||||
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
scriptExts = JSON.parse(fs.readFileSync(__dirname + "/../../../redbrick-scriptexts.json"));
|
scriptExts = JSON.parse(fs.readFileSync(__dirname + "/../../../redbrick-scriptexts.json"));
|
||||||
} catch(ex) {
|
} catch (ex) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
||||||
".rb": ["ruby"],
|
".rb": ["ruby"],
|
||||||
".php": ["php-cgi"]
|
".php": ["php-cgi"]
|
||||||
};
|
};
|
||||||
if(os.platform() == "win32") {
|
if (os.platform() == "win32") {
|
||||||
exttointerpreter[".exe"] = [];
|
exttointerpreter[".exe"] = [];
|
||||||
exttointerpreter[".bat"] = ["cmd", "/c"];
|
exttointerpreter[".bat"] = ["cmd", "/c"];
|
||||||
exttointerpreter[".vbs"] = ["cscript"];
|
exttointerpreter[".vbs"] = ["cscript"];
|
||||||
|
@ -216,12 +216,12 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
||||||
}
|
}
|
||||||
for (var i = 0; i < bheaders.length; i++) {
|
for (var i = 0; i < bheaders.length; i++) {
|
||||||
var headerp = bheaders[i].match(/^([^:]*)(?:: (.*))?/);
|
var headerp = bheaders[i].match(/^([^:]*)(?:: (.*))?/);
|
||||||
if(!headerp) headerp = [];
|
if (!headerp) headerp = [];
|
||||||
var headern = headerp[1];
|
var headern = headerp[1];
|
||||||
var headerv = headerp[2];
|
var headerv = headerp[2];
|
||||||
if (headern.toLowerCase() == "status") {
|
if (headern.toLowerCase() == "status") {
|
||||||
var httpMatch = headerv.match(/^([0-9]{3})(?: (.*))?$/);
|
var httpMatch = headerv.match(/^([0-9]{3})(?: (.*))?$/);
|
||||||
if(httpMatch) {
|
if (httpMatch) {
|
||||||
code = parseInt(httpMatch[1]);
|
code = parseInt(httpMatch[1]);
|
||||||
if (httpMatch[2]) msg = httpMatch[2];
|
if (httpMatch[2]) msg = httpMatch[2];
|
||||||
else msg = http.STATUS_CODES[code];
|
else msg = http.STATUS_CODES[code];
|
||||||
|
@ -304,7 +304,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
||||||
nEnv["SERVER_ADDR"] = pubip.replace(/^::ffff:/i, "");
|
nEnv["SERVER_ADDR"] = pubip.replace(/^::ffff:/i, "");
|
||||||
if (nEnv["SERVER_ADDR"].indexOf(":") != -1) nEnv["SERVER_ADDR"] = "[" + nEnv["SERVER_ADDR"] + "]";
|
if (nEnv["SERVER_ADDR"].indexOf(":") != -1) nEnv["SERVER_ADDR"] = "[" + nEnv["SERVER_ADDR"] + "]";
|
||||||
}
|
}
|
||||||
if(configJSON.serverAdministratorEmail && configJSON.serverAdministratorEmail != "[no contact information]") {
|
if (configJSON.serverAdministratorEmail && configJSON.serverAdministratorEmail != "[no contact information]") {
|
||||||
nEnv["SERVER_ADMIN"] = configJSON.serverAdministratorEmail;
|
nEnv["SERVER_ADMIN"] = configJSON.serverAdministratorEmail;
|
||||||
}
|
}
|
||||||
nEnv["SERVER_NAME"] = req.headers.host;
|
nEnv["SERVER_NAME"] = req.headers.host;
|
||||||
|
@ -315,9 +315,9 @@ 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, "");
|
||||||
if(req.socket.realRemoteAddress && req.socket.realRemotePort) {
|
if (req.socket.realRemoteAddress && req.socket.realRemotePort) {
|
||||||
nEnv["REMOTE_PORT"] = req.socket.realRemotePort;
|
nEnv["REMOTE_PORT"] = req.socket.realRemotePort;
|
||||||
} else if(!(req.socket.realRemoteAddress && !req.socket.realRemotePort)) {
|
} else if (!(req.socket.realRemoteAddress && !req.socket.realRemotePort)) {
|
||||||
nEnv["REMOTE_PORT"] = req.socket.remotePort;
|
nEnv["REMOTE_PORT"] = req.socket.remotePort;
|
||||||
}
|
}
|
||||||
nEnv["SCRIPT_NAME"] = a;
|
nEnv["SCRIPT_NAME"] = a;
|
||||||
|
@ -366,7 +366,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
||||||
fs.stat("." + href, function (err, stats) {
|
fs.stat("." + href, function (err, stats) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
if (!stats.isFile()) {
|
if (!stats.isFile()) {
|
||||||
if(isCgiBin || scriptExts.indexOf(".php") != -1) {
|
if (isCgiBin || scriptExts.indexOf(".php") != -1) {
|
||||||
fs.stat("." + href + "/index.php", function (e2, s2) {
|
fs.stat("." + href + "/index.php", function (e2, s2) {
|
||||||
if (!e2 && s2.isFile()) {
|
if (!e2 && s2.isFile()) {
|
||||||
try {
|
try {
|
||||||
|
@ -416,7 +416,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
||||||
callServerError(500, "RedBrick/" + version, ex);
|
callServerError(500, "RedBrick/" + version, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(isCgiBin || scriptExts.indexOf(".cgi") != -1) {
|
} else if (isCgiBin || scriptExts.indexOf(".cgi") != -1) {
|
||||||
fs.stat("." + href + "/index.cgi", function (e3, s3) {
|
fs.stat("." + href + "/index.cgi", function (e3, s3) {
|
||||||
if (!e3 && s3.isFile()) {
|
if (!e3 && s3.isFile()) {
|
||||||
try {
|
try {
|
||||||
|
@ -474,7 +474,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
||||||
elseCallback();
|
elseCallback();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if(scriptExts.indexOf(".cgi") != -1) {
|
} else if (scriptExts.indexOf(".cgi") != -1) {
|
||||||
fs.stat("." + href + "/index.cgi", function (e3, s3) {
|
fs.stat("." + href + "/index.cgi", function (e3, s3) {
|
||||||
if (!e3 && s3.isFile()) {
|
if (!e3 && s3.isFile()) {
|
||||||
try {
|
try {
|
||||||
|
@ -532,7 +532,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
||||||
elseCallback();
|
elseCallback();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(isCgiBin || isScriptExt) {
|
if (isCgiBin || isScriptExt) {
|
||||||
try {
|
try {
|
||||||
executeCGIWithEnv(
|
executeCGIWithEnv(
|
||||||
href,
|
href,
|
||||||
|
@ -612,7 +612,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
||||||
elseCallback();
|
elseCallback();
|
||||||
} else {
|
} else {
|
||||||
var newext = path.extname(pathp.fpth);
|
var newext = path.extname(pathp.fpth);
|
||||||
if(isCgiBin || scriptExts.indexOf(newext) != -1) {
|
if (isCgiBin || scriptExts.indexOf(newext) != -1) {
|
||||||
try {
|
try {
|
||||||
executeCGIWithEnv(
|
executeCGIWithEnv(
|
||||||
pathp.fpth.substr(1),
|
pathp.fpth.substr(1),
|
||||||
|
|
Loading…
Reference in a new issue