From 4c84830027596623846cafd5f28a5439a48223e2 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 1 Aug 2019 15:35:23 -0700 Subject: [PATCH] Fix folder drag & drop and added relay events. --- agents/meshcore.js | 6 +++++- agents/meshcore.min.js | 6 +++++- meshrelay.js | 13 +++++++++++++ package.json | 2 +- public/images/icon-relay.png | Bin 0 -> 340 bytes public/styles/style.css | 8 ++++++++ views/default-min.handlebars | 2 +- views/default.handlebars | 29 ++++++++++++++++++++++------- views/messenger-min.handlebars | 2 +- 9 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 public/images/icon-relay.png diff --git a/agents/meshcore.js b/agents/meshcore.js index 791f7d34..75938549 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1311,7 +1311,11 @@ function createMeshCore(agent) for (var i in cmd.delfiles) { var p = obj.path.join(cmd.path, cmd.delfiles[i]), delcount = 0; try { delcount = deleteFolderRecursive(p, cmd.rec); } catch (e) { } - MeshServerLog((cmd.rec ? 'Delete recursive: \"' : 'Delete: \"') + p + '\", ' + delcount + ' element(s) removed', this.httprequest); + if ((delcount == 1) && !cmd.rec) { + MeshServerLog('Delete: \"' + p + '\"', this.httprequest); + } else { + MeshServerLog((cmd.rec ? 'Delete recursive: \"' : 'Delete: \"') + p + '\", ' + delcount + ' element(s) removed', this.httprequest); + } } break; } diff --git a/agents/meshcore.min.js b/agents/meshcore.min.js index 791f7d34..75938549 100644 --- a/agents/meshcore.min.js +++ b/agents/meshcore.min.js @@ -1311,7 +1311,11 @@ function createMeshCore(agent) for (var i in cmd.delfiles) { var p = obj.path.join(cmd.path, cmd.delfiles[i]), delcount = 0; try { delcount = deleteFolderRecursive(p, cmd.rec); } catch (e) { } - MeshServerLog((cmd.rec ? 'Delete recursive: \"' : 'Delete: \"') + p + '\", ' + delcount + ' element(s) removed', this.httprequest); + if ((delcount == 1) && !cmd.rec) { + MeshServerLog('Delete: \"' + p + '\"', this.httprequest); + } else { + MeshServerLog((cmd.rec ? 'Delete recursive: \"' : 'Delete: \"') + p + '\", ' + delcount + ' element(s) removed', this.httprequest); + } } break; } diff --git a/meshrelay.js b/meshrelay.js index 5c837888..d1144436 100644 --- a/meshrelay.js +++ b/meshrelay.js @@ -157,6 +157,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie relayinfo.peer1.ws.send('c'); relayinfo.peer1.ws._socket.resume(); // Release the traffic relayinfo.peer2.ws._socket.resume(); // Release the traffic + ws.time = relayinfo.peer1.ws.time = Date.now(); relayinfo.peer1.ws.peer = relayinfo.peer2.ws; relayinfo.peer2.ws.peer = relayinfo.peer1.ws; @@ -165,6 +166,12 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie if (relayinfo.timeout) { clearTimeout(relayinfo.timeout); delete relayinfo.timeout; } parent.parent.debug(1, 'Relay connected: ' + obj.id + ' (' + cleanRemoteAddr(ws._socket.remoteAddress) + ' --> ' + cleanRemoteAddr(obj.peer.ws._socket.remoteAddress) + ')'); + + // Log the connection + 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 { // Connected already, drop (TODO: maybe we should re-connect?) ws.close(); @@ -237,6 +244,12 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie try { peer.ws.close(); } catch (e) { } // Soft disconnect 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); + } + // Aggressive peer cleanup delete peer.id; delete peer.ws; diff --git a/package.json b/package.json index b90ea903..7885e0c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.3.8-y", + "version": "0.3.9-a", "keywords": [ "Remote Management", "Intel AMT", diff --git a/public/images/icon-relay.png b/public/images/icon-relay.png new file mode 100644 index 0000000000000000000000000000000000000000..b514f6511df70442ee3820de763cd002694236e8 GIT binary patch literal 340 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucL5ULAh?3y^w370~qEv>0#LT=By}Z;C1rt33 zJW2;=^(r^?1HP%hUT1oNfDYSn3LHol!}Zh_o}CS-eD47wLnt*#D^m%e^0nH(fWVn z>HMy%Z@&sCs*xu367o=e^B8}XMx e*58<8n!oc8 {{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file + {{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file diff --git a/views/default.handlebars b/views/default.handlebars index e7742dee..814ae810 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -5723,7 +5723,13 @@ QV('p13bigfail', false); QV('p13bigok', false); if (e.dataTransfer == null || e.dataTransfer.files.length == 0 || p13filetree == null) return; - p13doUploadFiles(e.dataTransfer.files); + + // Check if these are files we can upload, remove all folders. + var files = []; + for (var i in e.dataTransfer.files) { if ((e.dataTransfer.files[i].type != null) && (e.dataTransfer.files[i].size != null) && (e.dataTransfer.files[i].type != '') && (e.dataTransfer.files[i].size != 0)) { files.push(e.dataTransfer.files[i]); } } + if (files.length == 0) return; + + p13doUploadFiles(files); } var p13dragtimer = null; @@ -5969,6 +5975,7 @@ var icon = 'si3'; if (event.etype == 'user') icon = 'm2'; if (event.etype == 'server') icon = 'si3'; + if (event.etype == 'relay') icon = 'relayIcon16'; var msg = event.msg.split('(R)').join('®'); if (event.username) { @@ -7257,21 +7264,27 @@ QV('bigok', false); //QV('p5fileCatchAllInput', false); + // Check if these are files we can upload, remove all folders. + if (e.dataTransfer == null) return; + var files = []; + for (var i in e.dataTransfer.files) { if ((e.dataTransfer.files[i].type != null) && (e.dataTransfer.files[i].size != null) && (e.dataTransfer.files[i].type != '') && (e.dataTransfer.files[i].size != 0)) { files.push(e.dataTransfer.files[i]); } } + if (files.length == 0) return; + // For Chrome & Firefox var error = 0; p5uploadFile(); // Display the the dialog box - try { Q('p5uploadinput').files = e.dataTransfer.files; } catch (ex) { error = 1; } // Set the files in the dialog box + try { Q('p5uploadinput').files = files; } catch (ex) { error = 1; } // Set the files in the dialog box if (error == 0) { p5uploadFileEx(); } // Press the submit button setDialogMode(0); // Close the dialog box // For IE browser - This will not work with very large files if (error == 1) { - if (e.dataTransfer == null || e.dataTransfer.files.length == 0 || filetreelocation.length == 0) return; - var names = [], sizes = [], types = [], datas = [], readercount = e.dataTransfer.files.length, totalSize = 0; - for (var i = 0; i < e.dataTransfer.files.length; i++) { totalSize += e.dataTransfer.files[i].size; } + if (filetreelocation.length == 0) return; + var names = [], sizes = [], types = [], datas = [], readercount = files.length, totalSize = 0; + for (var i = 0; i < files.length; i++) { totalSize += files[i].size; } if (totalSize > 1300000) { p5uploadFile(); return; } // File is too large, not sure what the real maximum is. - for (var i = 0; i < e.dataTransfer.files.length; i++) { - var reader = new FileReader(), file = e.dataTransfer.files[i]; + for (var i = 0; i < files.length; i++) { + var reader = new FileReader(), file = files[i]; names.push(file.name); sizes.push(file.size); types.push(file.type); @@ -7349,6 +7362,7 @@ var icon = 'si3'; if (event.etype == 'user') icon = 'm2'; if (event.etype == 'server') icon = 'si3'; + if (event.etype == 'relay') icon = 'relayIcon16'; var msg = event.msg.split('(R)').join('®'); if (event.nodeid) { @@ -8054,6 +8068,7 @@ var icon = 'si3'; if (event.etype == 'user') icon = 'm2'; if (event.etype == 'server') icon = 'si3'; + if (event.etype == 'relay') icon = 'relayIcon16'; var msg = event.msg.split('(R)').join('®'); if (event.nodeid) { diff --git a/views/messenger-min.handlebars b/views/messenger-min.handlebars index ded0098a..e2159fe1 100644 --- a/views/messenger-min.handlebars +++ b/views/messenger-min.handlebars @@ -1 +1 @@ - MeshMessenger
MeshMessenger
\ No newline at end of file + MeshMessenger
MeshMessenger
\ No newline at end of file