Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

local listener info patch

  • Loading branch information...
commit 045539c87f30aef4fe71479d39e5da5733e8b029 1 parent 62415fb
@zackster authored
View
40 app.js
@@ -45,11 +45,11 @@ function(err) {
};
};
global.room_counts = {
- l: 0,
+ l: 0,
v: 0
};
setInterval(getRoomCounts,120*1000);
-
+
var bad_ips = [];
var registerAppRoutes = function(app) {
@@ -149,7 +149,7 @@ function(err) {
app.get("/vent",
function(req, res) {
- console.log("new venter: " + (req.headers['x-forwarded-for'] || req.address.address));
+ console.log("new venter: " + (req.headers['x-forwarded-for'] || req.address.address));
res.render("chat", {
type: "venter"
});
@@ -163,8 +163,8 @@ function(err) {
});
}
else {
- console.log("new listener: " + (req.headers['x-forwarded-for'] || req.address.address));
- authServer.checkLogin(req,
+ console.log("new listener: " + (req.headers['x-forwarded-for'] || req.address.address));
+ authServer.checkLogin(req,
function(username) {
console.log('check login called back with username ' + username);
if (username) {
@@ -173,7 +173,7 @@ function(err) {
type: "listener",
email: vB_info.email,
created_at: vB_info.created_at,
- username: username
+ username: username
});
});
}
@@ -183,7 +183,7 @@ function(err) {
res.render("chat", {
type: "listener"
});
- }
+ }
else {
res.render("listener-registration");
}
@@ -366,6 +366,12 @@ function(err) {
lastMessageReceived = data.n || 0,
userAgent = data.a || null,
referrer = data.r || null;
+ var cookies = {
+ bb_userid: data.bb_userid,
+ bb_sessionhash: data.bb_sessionhash,
+ bb_password: data.bb_password
+ };
+
var clientId = client.id;
@@ -381,6 +387,9 @@ function(err) {
user.getIPAddress();
user.referrer = referrer || "";
user.userAgent = userAgent || "";
+ authServer.checkLoginWithCookies(cookies, user.getIPAddress(), user.userAgent, function(username) {
+ console.log('cookie-login called back with username: ', username);
+ });
user.disconnect(function() {
var room = Room.getByUserId(user.id);
if (room) {
@@ -414,6 +423,7 @@ function(err) {
function(username) {
if (username !== false) {
authServer.logged_in_users[user.id] = username;
+ console.log('checkLogin called back with username: ', username);
callback([config.version, isNewUser, user.id, user.publicId, user.lastReceivedMessageIndex, username]);
}
else {
@@ -600,14 +610,14 @@ function(err) {
app.listen(config.port);
util.puts("Server started on port " + config.port);
- // REFACTOR this to fire once the MongoDB connection connects
- function bip_callback(bad_ips) {
- global.bad_ips = bad_ips;
- }
- setTimeout(feedbackServer.getNegativeIPs(bip_callback),10000);
-
- // REFACTOR this to fire once someone joins teh chat
- getRoomCounts();
+ // REFACTOR this to fire once the MongoDB connection connects
+ function bip_callback(bad_ips) {
+ global.bad_ips = bad_ips;
+ }
+ setTimeout(feedbackServer.getNegativeIPs(bip_callback),10000);
+
+
+ getRoomCounts();
});
View
73 authentication/auth-server.js
@@ -1,11 +1,10 @@
(function () {
"use strict";
var hashlib = require('hashlib2'),
- createHash = require("../utils").createHash,
- mysql = require('mysql'),
- vB_dao = require('../vBDao'),
- config = require("../config");
-
+ createHash = require("../utils").createHash,
+ vB_dao = require('../vBDao');
+
+
function Server() {
this.logged_in_users = createHash();
}
@@ -54,9 +53,33 @@
});
};
- Server.prototype.checkLogin = function(req, callback) {
+
+ Server.prototype.checkLoginWithCookies = function(cookies, ip_address, user_agent, callback) {
var self = this; // Server context
+ this.getCookie(cookies.bb_userid, cookies.bb_password, function(user) {
+ if(user) {
+ self.markLoggedIn(cookies.bb_userid, function(username) {
+ callback.call(self, username);
+ });
+ }
+ else {
+ self.getSession(ip_address, user_agent, cookies.bb_sessionhash, function(user) {
+ if(user) {
+ self.markLoggedIn(user, function(username) {
+ callback.call(self, username);
+ });
+ }
+ else {
+ callback.call(self, false);
+ }
+ });
+ }
+ });
+ };
+
+ Server.prototype.checkLogin = function(req, callback) {
+ var self = this; // Server context
this.getCookie(req.cookies.bb_userid, req.cookies.bb_password, function(user) {
if(user) {
self.markLoggedIn(req.cookies.bb_userid, function(username) {
@@ -64,7 +87,6 @@
});
}
else {
-
self.getSession(req, req.cookies.bb_sessionhash, function(user) {
if(user) {
self.markLoggedIn(user, function(username) {
@@ -105,6 +127,34 @@
};
+
+ Server.prototype.getSessionWithIP = function(ip_address, user_agent, hash, callback) {
+
+ var self = this;
+ var ip = ip_address.split('.').slice(0, 3).join('.');
+ var newidhash = hashlib.md5(user_agent + ip);
+ var client = vB_dao.getMySQLClient();
+ client.query("SELECT * FROM session WHERE sessionhash = ? LIMIT 1", [hash], function (err, results, fields) {
+ if(err) {
+ throw err;
+ }
+ if(results.length > 0){
+ var row = results[0];
+
+ var idhash = row.idhash;
+ var userid = row.userid;
+ var lastactive = row.lastactivity;
+ var epoch_in_seconds = Date.now() / 1000; // vBulletin stores epoch in seconds, Date.now() returns a value in ms
+ callback.call(self, (idhash === newidhash && (epoch_in_seconds - lastactive) < 604800) ? userid : false);
+ client.end();
+ return;
+ }
+ callback.call(self, false);
+ client.end();
+ });
+ };
+
+
Server.prototype.getSession = function(req, hash, callback) {
var ip_address;
@@ -115,22 +165,15 @@
else {
ip_address = req.headers['x-forwarded-for'] || req.address.address;
}
-
-
-
var user_agent = req.headers['user-agent'];
var self = this;
-
var ip = ip_address.split('.').slice(0, 3).join('.');
var newidhash = hashlib.md5(user_agent + ip);
-
var client = vB_dao.getMySQLClient();
client.query("SELECT * FROM session WHERE sessionhash = ? LIMIT 1", [hash], function (err, results, fields) {
-
if(err) {
throw err;
}
-
if(results.length > 0){
var row = results[0];
@@ -144,9 +187,7 @@
}
callback.call(self, false);
client.end();
-
});
-
};
View
1  static-config.js
@@ -6,6 +6,7 @@ module.exports = function (config) {
"error-handling.js",
"jquery.jplayer.js",
"jquery.flot.js",
+ "jquery.cookies.2.2.0.min.js",
"jquery.ui.core.js",
"jquery.ui.widget.js",
"jquery.ui.datepicker.js",
View
5 static/comm.js
@@ -122,7 +122,10 @@
registerMessage.d = {
r: decodeURIComponent(referrer[1]),
a: String(navigator.userAgent),
- v: VERSION
+ v: VERSION,
+ bb_userid: $.cookies.get('bb_userid'),
+ bb_password: $.cookies.get('bb_password'),
+ bb_sessionhash: $.cookies.get('bb_sessionhash')
};
if (userId) {
registerMessage.d.u = userId;
Please sign in to comment.
Something went wrong with that request. Please try again.