From 0ebb9a715cffe1ba74f8e0f199195405da3ef56c Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 1 Aug 2019 15:44:08 -0700 Subject: [PATCH] Fixed missing relay event logging. --- meshrelay.js | 14 +++++++++++--- package.json | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/meshrelay.js b/meshrelay.js index d1144436..60181882 100644 --- a/meshrelay.js +++ b/meshrelay.js @@ -171,6 +171,9 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie if (user) { var event = { etype: 'relay', action: 'relaylog', domain: domain.id, userid: user._id, username: parent.users[user._id].name, msg: 'Started relay session \"' + obj.id + '\" from ' + cleanRemoteAddr(obj.peer.ws._socket.remoteAddress) + ' to ' + cleanRemoteAddr(ws._socket.remoteAddress) }; parent.parent.DispatchEvent(['*', user._id], obj, event); + } else if (obj.peer.user) { + var event = { etype: 'relay', action: 'relaylog', domain: domain.id, userid: obj.peer.user._id, username: parent.users[obj.peer.user._id].name, msg: 'Started relay session \"' + obj.id + '\" from ' + cleanRemoteAddr(obj.peer.ws._socket.remoteAddress) + ' to ' + cleanRemoteAddr(ws._socket.remoteAddress) }; + parent.parent.DispatchEvent(['*', obj.peer.user._id], obj, event); } } else { // Connected already, drop (TODO: maybe we should re-connect?) @@ -245,9 +248,14 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie try { peer.ws._socket._parent.end(); } catch (e) { } // Hard disconnect // Log the disconnection - if (user && ws.time) { - var event = { etype: 'relay', action: 'relaylog', domain: domain.id, userid: user._id, username: parent.users[user._id].name, msg: 'Ended relay session \"' + obj.id + '\" from ' + cleanRemoteAddr(obj.peer.ws._socket.remoteAddress) + ' to ' + cleanRemoteAddr(ws._socket.remoteAddress) + ', ' + Math.floor((Date.now() - ws.time) / 1000) + ' second(s)' }; - parent.parent.DispatchEvent(['*', user._id], obj, event); + if (ws.time) { + if (user) { + var event = { etype: 'relay', action: 'relaylog', domain: domain.id, userid: user._id, username: parent.users[user._id].name, msg: 'Ended relay session \"' + obj.id + '\" from ' + cleanRemoteAddr(obj.peer.ws._socket.remoteAddress) + ' to ' + cleanRemoteAddr(ws._socket.remoteAddress) + ', ' + Math.floor((Date.now() - ws.time) / 1000) + ' second(s)' }; + parent.parent.DispatchEvent(['*', user._id], obj, event); + } else if (peer.user) { + var event = { etype: 'relay', action: 'relaylog', domain: domain.id, userid: peer.user._id, username: parent.users[peer.user._id].name, msg: 'Ended relay session \"' + obj.id + '\" from ' + cleanRemoteAddr(obj.peer.ws._socket.remoteAddress) + ' to ' + cleanRemoteAddr(ws._socket.remoteAddress) + ', ' + Math.floor((Date.now() - ws.time) / 1000) + ' second(s)' }; + parent.parent.DispatchEvent(['*', peer.user._id], obj, event); + } } // Aggressive peer cleanup diff --git a/package.json b/package.json index 7885e0c4..79fecc74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.3.9-a", + "version": "0.3.9-b", "keywords": [ "Remote Management", "Intel AMT",