Fix a few minor express issues

This commit is contained in:
calzoneman 2013-11-24 18:13:58 -06:00
parent 7f3561bd27
commit 01464ed394
2 changed files with 16 additions and 20 deletions

View File

@ -31,7 +31,6 @@ var defaults = {
"ip-connection-limit" : 10, "ip-connection-limit" : 10,
"guest-login-delay" : 60, "guest-login-delay" : 60,
"channel-save-interval" : 5, "channel-save-interval" : 5,
"trust-x-forward" : false,
"enable-mail" : false, "enable-mail" : false,
"mail-transport" : "SMTP", "mail-transport" : "SMTP",
"mail-config" : { "mail-config" : {

View File

@ -73,7 +73,9 @@ var Server = function (cfg) {
self.httplog = new Logger.Logger(path.join(__dirname, self.httplog = new Logger.Logger(path.join(__dirname,
"../httpaccess.log")); "../httpaccess.log"));
self.express = express(); self.express = express();
self.express.use(express.bodyParser()); self.express.use(express.urlencoded());
self.express.use(express.json());
self.express.use(express.cookieParser());
// channel route // channel route
self.express.get("/r/:channel(*)", function (req, res, next) { self.express.get("/r/:channel(*)", function (req, res, next) {
@ -178,24 +180,22 @@ var Server = function (cfg) {
}; };
Server.prototype.getHTTPIP = function (req) { Server.prototype.getHTTPIP = function (req) {
var raw = req.connection.remoteAddress; var ip = req.ip;
var forward = req.header("x-forwarded-for"); if (ip === "127.0.0.1" || ip === "::1") {
if((this.cfg["trust-x-forward"] || raw === "127.0.0.1") && forward) { var fwd = req.header("x-forwarded-for");
var ip = forward.split(",")[0]; if (fwd && typeof fwd === "string") {
Logger.syslog.log("REVPROXY " + raw + " => " + ip); return fwd;
return ip; }
} }
return raw; return ip;
}; };
Server.prototype.getSocketIP = function (socket) { Server.prototype.getSocketIP = function (socket) {
var raw = socket.handshake.address.address; var raw = socket.handshake.address.address;
if(this.cfg["trust-x-forward"] || raw === "127.0.0.1") { if (raw === "127.0.0.1" || raw === "::1") {
if(typeof socket.handshake.headers["x-forwarded-for"] == "string") { var fwd = socket.handshake.headers["x-forwarded-for"];
var ip = socket.handshake.headers["x-forwarded-for"] if (fwd && typeof fwd === "string") {
.split(",")[0]; return fwd;
Logger.syslog.log("REVPROXY " + raw + " => " + ip);
return ip;
} }
} }
return raw; return raw;
@ -247,16 +247,13 @@ Server.prototype.logHTTP = function (req, status) {
if (status === undefined) if (status === undefined)
status = 200; status = 200;
var ip = req.connection.remoteAddress; var ip = this.getHTTPIP(req);
var ip2 = req.header("x-forwarded-for") ||
req.header("cf-connecting-ip");
var ipstr = !ip2 ? ip : ip + " (X-Forwarded-For " + ip2 + ")";
var url = req.url; var url = req.url;
// Remove query // Remove query
if(url.indexOf("?") != -1) if(url.indexOf("?") != -1)
url = url.substring(0, url.lastIndexOf("?")); url = url.substring(0, url.lastIndexOf("?"));
this.httplog.log([ this.httplog.log([
ipstr, ip,
req.method, req.method,
url, url,
status, status,