working handling of setting client ip and anonymizing etc

This commit is contained in:
John McLear 2014-11-04 23:25:18 +00:00
parent f418dfa205
commit 9fa77cdea2
4 changed files with 24 additions and 15 deletions

View File

@ -37,6 +37,7 @@ var _ = require('underscore');
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js"); var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js");
var channels = require("channels"); var channels = require("channels");
var stats = require('../stats'); var stats = require('../stats');
var remoteAddress = require("../utils/RemoteAddress").remoteAddress;
/** /**
* A associative array that saves informations about a session * A associative array that saves informations about a session
@ -115,16 +116,18 @@ exports.handleDisconnect = function(client)
//if this connection was already etablished with a handshake, send a disconnect message to the others //if this connection was already etablished with a handshake, send a disconnect message to the others
if(session && session.author) if(session && session.author)
{ {
/*
client.get('remoteAddress', function(er, ip) {
//Anonymize the IP address if IP logging is disabled
if(settings.disableIPlogging) {
ip = 'ANONYMOUS';
}
accessLogger.info('[LEAVE] Pad "'+session.padId+'": Author "'+session.author+'" on client '+client.id+' with IP "'+ip+'" left the pad') console.log(remoteAddress);
})
*/ // Get the IP address from our persistant object
var ip = remoteAddress[client.id];
// Anonymize the IP address if IP logging is disabled
if(settings.disableIPlogging) {
ip = 'ANONYMOUS';
}
accessLogger.info('[LEAVE] Pad "'+session.padId+'": Author "'+session.author+'" on client '+client.id+' with IP "'+ip+'" left the pad')
//get the author color out of the db //get the author color out of the db
authorManager.getAuthorColorId(session.author, function(err, color) authorManager.getAuthorColorId(session.author, function(err, color)

View File

@ -24,6 +24,7 @@ var log4js = require('log4js');
var messageLogger = log4js.getLogger("message"); var messageLogger = log4js.getLogger("message");
var securityManager = require("../db/SecurityManager"); var securityManager = require("../db/SecurityManager");
var readOnlyManager = require("../db/ReadOnlyManager"); var readOnlyManager = require("../db/ReadOnlyManager");
var remoteAddress = require("../utils/RemoteAddress").remoteAddress;
var settings = require('../utils/Settings'); var settings = require('../utils/Settings');
/** /**
@ -57,12 +58,14 @@ exports.setSocketIO = function(_socket) {
socket.sockets.on('connection', function(client) socket.sockets.on('connection', function(client)
{ {
// Broken: See http://stackoverflow.com/questions/4647348/send-message-to-specific-client-with-socket-io-and-node-js // Broken: See http://stackoverflow.com/questions/4647348/send-message-to-specific-client-with-socket-io-and-node-js
// Fixed by having a persistant object, ideally this would actually be in the database layer
// TODO move to database layer
if(settings.trustProxy && client.handshake.headers['x-forwarded-for'] !== undefined){ if(settings.trustProxy && client.handshake.headers['x-forwarded-for'] !== undefined){
// client.set('remoteAddress', client.handshake.headers['x-forwarded-for']); remoteAddress[client.id] = client.handshake.headers['x-forwarded-for'];
} }
else{ else{
// client.set('remoteAddress', client.handshake.address); remoteAddress[client.id] = client.handshake.address;
} }
var clientAuthorized = false; var clientAuthorized = false;

View File

@ -51,9 +51,11 @@ exports.expressCreateServer = function (hook_name, args, cb) {
// This debug logging environment is set in Settings.js // This debug logging environment is set in Settings.js
//minify socket.io javascript //minify socket.io javascript
if(settings.minify) // Due to a shitty decision by the SocketIO team minification is
// io.enable('browser client minification'); // no longer available, details available at:
// http://stackoverflow.com/questions/23981741/minify-socket-io-socket-io-js-with-1-0
// if(settings.minify) io.enable('browser client minification');
//Initalize the Socket.IO Router //Initalize the Socket.IO Router
socketIORouter.setSocketIO(io); socketIORouter.setSocketIO(io);
socketIORouter.addComponent("pad", padMessageHandler); socketIORouter.addComponent("pad", padMessageHandler);

View File

@ -0,0 +1 @@
exports.remoteAddress = {};