|
|
@ -7,13 +7,16 @@ var url = require('url');
|
|
|
|
var cookieParser = require('cookie-parser')(nconf.get('secret'));
|
|
|
|
var cookieParser = require('cookie-parser')(nconf.get('secret'));
|
|
|
|
|
|
|
|
|
|
|
|
var db = require('../database');
|
|
|
|
var db = require('../database');
|
|
|
|
|
|
|
|
var user = require('../user');
|
|
|
|
var logger = require('../logger');
|
|
|
|
var logger = require('../logger');
|
|
|
|
var ratelimit = require('../middleware/ratelimit');
|
|
|
|
var ratelimit = require('../middleware/ratelimit');
|
|
|
|
|
|
|
|
|
|
|
|
(function (Sockets) {
|
|
|
|
|
|
|
|
var Namespaces = {};
|
|
|
|
var Namespaces = {};
|
|
|
|
var io;
|
|
|
|
var io;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var Sockets = module.exports;
|
|
|
|
|
|
|
|
|
|
|
|
Sockets.init = function (server) {
|
|
|
|
Sockets.init = function (server) {
|
|
|
|
requireModules();
|
|
|
|
requireModules();
|
|
|
|
|
|
|
|
|
|
|
@ -104,6 +107,9 @@ var ratelimit = require('../middleware/ratelimit');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
checkMaintenance(socket, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
function (next) {
|
|
|
|
function (next) {
|
|
|
|
validateSession(socket, next);
|
|
|
|
validateSession(socket, next);
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -132,6 +138,18 @@ var ratelimit = require('../middleware/ratelimit');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function checkMaintenance(socket, callback) {
|
|
|
|
|
|
|
|
var meta = require('../meta');
|
|
|
|
|
|
|
|
if (parseInt(meta.config.maintenanceMode, 10) !== 1) {
|
|
|
|
|
|
|
|
return setImmediate(callback);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
user.isAdministrator(socket.uid, function (err, isAdmin) {
|
|
|
|
|
|
|
|
if (err || isAdmin) {
|
|
|
|
|
|
|
|
return callback(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function validateSession(socket, callback) {
|
|
|
|
function validateSession(socket, callback) {
|
|
|
|
var req = socket.request;
|
|
|
|
var req = socket.request;
|
|
|
|
if (!req.signedCookies || !req.signedCookies[nconf.get('sessionKey')]) {
|
|
|
|
if (!req.signedCookies || !req.signedCookies[nconf.get('sessionKey')]) {
|
|
|
@ -226,4 +244,4 @@ var ratelimit = require('../middleware/ratelimit');
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}(exports));
|
|
|
|
|
|
|
|