diff --git a/common.js b/common.js index 37017ca6..d902cd1b 100644 --- a/common.js +++ b/common.js @@ -30,6 +30,7 @@ module.exports.MakeToArray = function (v) { if (!v || v == null || typeof v == " module.exports.SplitArray = function (v) { return v.split(","); }; module.exports.Clone = function (v) { return JSON.parse(JSON.stringify(v)); }; module.exports.IsFilenameValid = (function () { var x1 = /^[^\\/:\*\?"<>\|]+$/, x2 = /^\./, x3 = /^(nul|prn|con|lpt[0-9]|com[0-9])(\.|$)/i; return function isFilenameValid(fname) { return module.exports.validateString(fname, 1, 4096) && x1.test(fname) && !x2.test(fname) && !x3.test(fname) && (fname[0] != '.'); }; })(); +module.exports.makeFilename = function (v) { return v.split('\\').join('').split('/').join('').split(':').join('').split('*').join('').split('?').join('').split('"').join('').split('<').join('').split('>').join('').split('|').join('').split(' ').join('').split('\'').join(''); } // Move an element from one position in an array to a new position module.exports.ArrayElementMove = function(arr, from, to) { arr.splice(to, 0, arr.splice(from, 1)[0]); }; diff --git a/meshrelay.js b/meshrelay.js index 5bfccf62..9d5676cd 100644 --- a/meshrelay.js +++ b/meshrelay.js @@ -169,30 +169,41 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie var sessionUser = obj.user; if (sessionUser == null) { sessionUser = obj.peer.user; } if ((sessionUser != null) && (domain.sessionrecording == true || ((typeof domain.sessionrecording == 'object') && ((domain.sessionrecording.protocols == null) || (domain.sessionrecording.protocols.indexOf(parseInt(req.query.p)) >= 0))))) { - var now = new Date(Date.now()); - var recFilename = 'relaysession' + ((domain.id == '') ? '' : '-') + domain.id + '-' + now.getUTCFullYear() + '-' + parent.common.zeroPad(now.getUTCMonth(), 2) + '-' + parent.common.zeroPad(now.getUTCDate(), 2) + '-' + parent.common.zeroPad(now.getUTCHours(), 2) + '-' + parent.common.zeroPad(now.getUTCMinutes(), 2) + '-' + parent.common.zeroPad(now.getUTCSeconds(), 2) + '-' + obj.id + '.mcrec' - var recFullFilename = null; - if (domain.sessionrecording.filepath) { - try { parent.parent.fs.mkdirSync(domain.sessionrecording.filepath); } catch (e) { } - recFullFilename = parent.parent.path.join(domain.sessionrecording.filepath, recFilename); - } else { - try { parent.parent.fs.mkdirSync(parent.parent.recordpath); } catch (e) { } - recFullFilename = parent.parent.path.join(parent.parent.recordpath, recFilename); - } - parent.parent.fs.open(recFullFilename, 'w', function (err, fd) { - if (err != null) { - // Unable to record - try { ws.send('c'); } catch (ex) { } // Send connect to both peers - try { relayinfo.peer1.ws.send('c'); } catch (ex) { } + // Get the computer name + parent.db.Get(req.query.nodeid, function (err, nodes) { + var xusername = '', xdevicename = '', xdevicename2 = null; + if ((nodes != null) && (nodes.length == 1)) { xdevicename2 = nodes[0].name; xdevicename = '-' + parent.common.makeFilename(nodes[0].name); } + + // Get the username and make it acceptable as a filename + if (sessionUser._id) { xusername = '-' + parent.common.makeFilename(sessionUser._id.split('/')[2]); } + + var now = new Date(Date.now()); + var recFilename = 'relaysession' + ((domain.id == '') ? '' : '-') + domain.id + '-' + now.getUTCFullYear() + '-' + parent.common.zeroPad(now.getUTCMonth(), 2) + '-' + parent.common.zeroPad(now.getUTCDate(), 2) + '-' + parent.common.zeroPad(now.getUTCHours(), 2) + '-' + parent.common.zeroPad(now.getUTCMinutes(), 2) + '-' + parent.common.zeroPad(now.getUTCSeconds(), 2) + xusername + xdevicename + '-' + obj.id + '.mcrec' + var recFullFilename = null; + if (domain.sessionrecording.filepath) { + try { parent.parent.fs.mkdirSync(domain.sessionrecording.filepath); } catch (e) { } + recFullFilename = parent.parent.path.join(domain.sessionrecording.filepath, recFilename); } else { - // Write the recording file header - var firstBlock = JSON.stringify({ magic: 'MeshCentralRelaySession', ver: 1, userid: sessionUser._id, username: sessionUser.name, sessionid: obj.id, ipaddr1: cleanRemoteAddr(req.ip), ipaddr2: cleanRemoteAddr(obj.peer.req.ip), time: new Date().toLocaleString(), protocol: req.query.p, nodeid: req.query.nodeid }); - recordingEntry(fd, 1, ((req.query.browser) ? 2 : 0), firstBlock, function () { - relayinfo.peer1.ws.logfile = ws.logfile = { fd: fd, lock: false }; - try { ws.send('cr'); } catch (ex) { } // Send connect to both peers, 'cr' indicates the session is being recorded. - try { relayinfo.peer1.ws.send('cr'); } catch (ex) { } - }); + try { parent.parent.fs.mkdirSync(parent.parent.recordpath); } catch (e) { } + recFullFilename = parent.parent.path.join(parent.parent.recordpath, recFilename); } + parent.parent.fs.open(recFullFilename, 'w', function (err, fd) { + if (err != null) { + // Unable to record + try { ws.send('c'); } catch (ex) { } // Send connect to both peers + try { relayinfo.peer1.ws.send('c'); } catch (ex) { } + } else { + // Write the recording file header + var metadata = { magic: 'MeshCentralRelaySession', ver: 1, userid: sessionUser._id, username: sessionUser.name, sessionid: obj.id, ipaddr1: cleanRemoteAddr(req.ip), ipaddr2: cleanRemoteAddr(obj.peer.req.ip), time: new Date().toLocaleString(), protocol: req.query.p, nodeid: req.query.nodeid }; + if (xdevicename2 != null) { metadata.devicename = xdevicename2; } + var firstBlock = JSON.stringify(metadata); + recordingEntry(fd, 1, ((req.query.browser) ? 2 : 0), firstBlock, function () { + relayinfo.peer1.ws.logfile = ws.logfile = { fd: fd, lock: false }; + try { ws.send('cr'); } catch (ex) { } // Send connect to both peers, 'cr' indicates the session is being recorded. + try { relayinfo.peer1.ws.send('cr'); } catch (ex) { } + }); + } + }); }); } else { // Send session start diff --git a/package.json b/package.json index d139828a..1cb7e780 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.4.1-g", + "version": "0.4.1-h", "keywords": [ "Remote Management", "Intel AMT", diff --git a/public/player.htm b/public/player.htm index 9a99cb2a..5e263237 100644 --- a/public/player.htm +++ b/public/player.htm @@ -171,6 +171,7 @@ x += addInfo('UserID', recFileMetadata.userid); x += addInfo('SessionID', recFileMetadata.sessionid); if (recFileMetadata.ipaddr1 && recFileMetadata.ipaddr2) { x += addInfo('Addresses', recFileMetadata.ipaddr1 + ' to ' + recFileMetadata.ipaddr2); } + if (recFileMetadata.devicename) { x += addInfo('DeviceName', recFileMetadata.devicename); } x += addInfo('NodeID', recFileMetadata.nodeid); if (recFileMetadata.protocol) { var p = recFileMetadata.protocol; diff --git a/views/default-min.handlebars b/views/default-min.handlebars index 97c1f1d5..6bf1c971 100644 --- a/views/default-min.handlebars +++ b/views/default-min.handlebars @@ -1 +1 @@ -
{{{logoutControl}}}
My Devices | My Account | My Events | My Files | My Users | My Server |
{{{logoutControl}}}
My Devices | My Account | My Events | My Files | My Users | My Server |