Log the client ip on pad access with logger 'access'

also, don't log every message with log level info!
This commit is contained in:
Marcel Klehr 2013-02-10 16:03:49 +01:00
parent 6191b01633
commit ee89696c4d
2 changed files with 12 additions and 2 deletions

View File

@ -32,6 +32,7 @@ var securityManager = require("../db/SecurityManager");
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins.js"); var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins.js");
var log4js = require('log4js'); var log4js = require('log4js');
var messageLogger = log4js.getLogger("message"); var messageLogger = log4js.getLogger("message");
var accessLogger = log4js.getLogger("access");
var _ = require('underscore'); 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");
@ -121,6 +122,10 @@ exports.handleDisconnect = function(client)
}); });
} }
client.get('remoteAddress', function(er, ip) {
accessLogger.info('[LEAVE] Author "'+session.author+'" on client '+client.id+' with IP "'+ip+'" left pad "'+session.padId+'"')
})
//Delete the sessioninfos entrys of this session //Delete the sessioninfos entrys of this session
delete sessioninfos[client.id]; delete sessioninfos[client.id];
} }
@ -910,6 +915,10 @@ function handleClientReady(client, message)
sessioninfos[client.id].readOnlyPadId = padIds.readOnlyPadId; sessioninfos[client.id].readOnlyPadId = padIds.readOnlyPadId;
sessioninfos[client.id].readonly = padIds.readonly; sessioninfos[client.id].readonly = padIds.readonly;
client.get('remoteAddress', function(er, ip) {
accessLogger.info('[ENTER] Client '+client.id+' with IP "'+ip+'" entered pad "'+padIds.padId+'"')
})
//If this is a reconnect, we don't have to send the client the ClientVars again //If this is a reconnect, we don't have to send the client the ClientVars again
if(message.reconnect == true) if(message.reconnect == true)
{ {

View File

@ -55,13 +55,14 @@ exports.setSocketIO = function(_socket)
socket.sockets.on('connection', function(client) socket.sockets.on('connection', function(client)
{ {
client.set('remoteAddress', client.handshake.address.address);
var clientAuthorized = false; var clientAuthorized = false;
//wrap the original send function to log the messages //wrap the original send function to log the messages
client._send = client.send; client._send = client.send;
client.send = function(message) client.send = function(message)
{ {
messageLogger.info("to " + client.id + ": " + stringifyWithoutPassword(message)); messageLogger.debug("to " + client.id + ": " + stringifyWithoutPassword(message));
client._send(message); client._send(message);
} }
@ -79,7 +80,7 @@ exports.setSocketIO = function(_socket)
//check if component is registered in the components array //check if component is registered in the components array
if(components[message.component]) if(components[message.component])
{ {
messageLogger.info("from " + client.id + ": " + stringifyWithoutPassword(message)); messageLogger.debug("from " + client.id + ": " + stringifyWithoutPassword(message));
components[message.component].handleMessage(client, message); components[message.component].handleMessage(client, message);
} }
} }