Added SSH file operation log.

Ylian Saint-Hilaire committed May 24, 2021 at 19:47 UTC f3c180a2c22eee4c2b6264bb5023a6994f406370
1 file changed +28 -4
apprelays.js
+28 -4
@@ -165,7 +165,6 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) {
165
166 // Construct a SSH Relay object, called upon connection
167 module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) {
168 - console.log('CreateSshRelay');
168 const Net = require('net');
169 const WebSocket = require('ws');
170
@@ -795,7 +794,12 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user
794 if (obj.sftp == null) return;
795 var requestedPath = msg.path;
796 if (requestedPath.startsWith('/') == false) { requestedPath = '/' + requestedPath; }
798 - obj.sftp.mkdir(requestedPath, function (err) { console.log(err); });
797 + obj.sftp.mkdir(requestedPath, function (err) { });
798 +
799 + // Event the file delete
800 + var targets = ['*', 'server-users'];
801 + if (user.groups) { for (var i in user.groups) { targets.push('server-users:' + i); } }
802 + parent.parent.DispatchEvent(targets, obj, { etype: 'node', action: 'agentlog', nodeid: obj.nodeid, userid: user._id, username: user.name, msgid: 44, msgArgs: [requestedPath], msg: 'Create folder: \"' + requestedPath + '\"', domain: domain.id });
803 break;
804 }
805 case 'rm': {
@@ -806,7 +810,13 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user
810 const ul = obj.path.join(requestedPath, msg.delfiles[i]).split('\\').join('/');
811 obj.sftp.unlink(ul, function (err) { });
812 if (msg.rec === true) { obj.sftp.rmdir(ul + '/', function (err) { }); }
813 +
814 + // Event the file delete
815 + var targets = ['*', 'server-users'];
816 + if (user.groups) { for (var i in user.groups) { targets.push('server-users:' + i); } }
817 + parent.parent.DispatchEvent(targets, obj, { etype: 'node', action: 'agentlog', nodeid: obj.nodeid, userid: user._id, username: user.name, msgid: 45, msgArgs: [ul], msg: 'Delete: \"' + ul + '\"', domain: domain.id });
818 }
819 +
820 break;
821 }
822 case 'rename': {
@@ -816,6 +826,11 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user
826 const oldpath = obj.path.join(requestedPath, msg.oldname).split('\\').join('/');
827 const newpath = obj.path.join(requestedPath, msg.newname).split('\\').join('/');
828 obj.sftp.rename(oldpath, newpath, function (err) { });
829 +
830 + // Event the file rename
831 + var targets = ['*', 'server-users'];
832 + if (user.groups) { for (var i in user.groups) { targets.push('server-users:' + i); } }
833 + parent.parent.DispatchEvent(targets, obj, { etype: 'node', action: 'agentlog', nodeid: obj.nodeid, userid: user._id, username: user.name, msgid: 48, msgArgs: [oldpath, msg.newname], msg: 'Rename: \"' + oldpath + '\" to \"' + msg.newname + '\"', domain: domain.id });
834 break;
835 }
836 case 'upload': {
@@ -832,6 +847,11 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user
847 } else {
848 obj.uploadHandle = handle;
849 try { obj.ws.send(Buffer.from(JSON.stringify({ action: 'uploadstart', reqid: obj.uploadReqid }))) } catch (ex) { }
850 +
851 + // Event the file upload
852 + var targets = ['*', 'server-users'];
853 + if (user.groups) { for (var i in user.groups) { targets.push('server-users:' + i); } }
854 + parent.parent.DispatchEvent(targets, obj, { etype: 'node', action: 'agentlog', nodeid: obj.nodeid, userid: user._id, username: user.name, msgid: 105, msgArgs: [obj.uploadFullpath, obj.uploadSize], msg: 'Upload: ' + obj.uploadFullpath + ', Size: ' + obj.uploadSize, domain: domain.id });
855 }
856 });
857 break;
@@ -878,8 +898,12 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user
898 try { obj.ws.send(Buffer.from(JSON.stringify({ action: 'download', sub: 'cancel', id: obj.downloadId }))) } catch (ex) { }
899 } else {
900 obj.downloadHandle = handle;
881 - // MeshServerLogEx((cmd.ask == 'coredump') ? 104 : 49, [cmd.path], 'Download: \"' + cmd.path + '\"', this.httprequest);
901 try { obj.ws.send(JSON.stringify({ action: 'download', sub: 'start', id: obj.downloadId })) } catch (ex) { }
902 +
903 + // Event the file download
904 + var targets = ['*', 'server-users'];
905 + if (user.groups) { for (var i in user.groups) { targets.push('server-users:' + i); } }
906 + parent.parent.DispatchEvent(targets, obj, { etype: 'node', action: 'agentlog', nodeid: obj.nodeid, userid: user._id, username: user.name, msgid: 49, msgArgs: [obj.downloadFullpath], msg: 'Download: ' + obj.downloadFullpath, domain: domain.id });
907 }
908 });
909 break;
@@ -927,7 +951,7 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user
951 }
952 }
953 }
930 - } catch (ex) { console.log(ex); obj.close(); }
954 + } catch (ex) { obj.close(); }
955 });
956
957 function uploadNextBlock() {