Add audit log entries on API calls

Closes #627
This commit is contained in:
Nick O'Leary
2015-05-14 14:22:28 +01:00
parent 911288e695
commit 7de0216976
8 changed files with 97 additions and 15 deletions

View File

@@ -48,6 +48,7 @@ function start() {
wsServer = new ws.Server({server:server,path:path});
wsServer.on('connection',function(ws) {
log.audit({event: "comms.open"});
var pendingAuth = (settings.adminAuth != null);
if (!pendingAuth) {
activeConnections.push(ws);
@@ -55,6 +56,7 @@ function start() {
pendingConnections.push(ws);
}
ws.on('close',function() {
log.audit({event: "comms.close",user:ws.user});
removeActiveConnection(ws);
removePendingConnection(ws);
});
@@ -88,19 +90,25 @@ function start() {
if (client) {
Users.get(client.user).then(function(user) {
if (user) {
ws.user = user;
log.audit({event: "comms.auth",user:ws.user});
completeConnection(client.scope,true);
} else {
log.audit({event: "comms.auth.fail"});
completeConnection(null,false);
}
});
} else {
log.audit({event: "comms.auth.fail"});
completeConnection(null,false);
}
});
} else {
if (anonymousUser) {
log.audit({event: "comms.auth",user:anonymousUser});
completeConnection(anonymousUser.permissions,false);
} else {
log.audit({event: "comms.auth.fail"});
completeConnection(null,false);
}
//TODO: duplicated code - pull non-auth message handling out