Improved device files tab, added cut/paste support
Ylian Saint-Hilaire committed
Apr 2, 2018 at 15:34 UTC
63a165aac0ec00d380dc66e54e7a948938b5247c
3 files changed
+47
-29
agents/meshcore.js
+16
@@ -700,6 +700,22 @@ function createMeshCore(agent) {
700
if (this.httprequest.uploadFile) { this.write(new Buffer(JSON.stringify({ action: 'uploadstart', reqid: this.httprequest.uploadFileid }))); }
701
break;
702
}
703
+ case 'copy': {
704
+ // Copy a bunch of files from scpath to dspath
705
+ for (var i in cmd.names) {
706
+ var sc = obj.path.join(cmd.scpath, cmd.names[i]), ds = obj.path.join(cmd.dspath, cmd.names[i]);
707
+ if (sc != ds) { try { fs.copyFileSync(sc, ds); } catch (e) { } }
708
+ }
709
+ break;
710
+ }
711
+ case 'move': {
712
+ // Move a bunch of files from scpath to dspath
713
+ for (var i in cmd.names) {
714
+ var sc = obj.path.join(cmd.scpath, cmd.names[i]), ds = obj.path.join(cmd.dspath, cmd.names[i]);
715
+ if (sc != ds) { try { fs.copyFileSync(sc, ds); fs.unlinkSync(sc); } catch (e) { } }
716
+ }
717
+ break;
718
+ }
719
}
720
}
721
//sendConsoleText("Got tunnel #" + this.httprequest.index + " data: " + data, this.httprequest.sessionid);
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.1.5-s",
3
+ "version": "0.1.5-t",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",
views/default.handlebars
+30
-28
@@ -288,7 +288,7 @@
288
<span id="p5files"></span>
289
</div>
290
<table id="p5toolbarBottom" style=width:100% cellpadding=0 cellspacing=0>
291
- <tr><td class=style6 style="text-align:left"> <span id="bottomstatus"></span></td></tr>
291
+ <tr><td class=style6 style="text-align:left"> <span id="p5bottomstatus"></span></td></tr>
292
</table>
293
</div>
294
<div id=p10 style=display:none>
@@ -453,6 +453,9 @@
453
<input type=button id=p13DeleteFileButton disabled="disabled" value="Delete" onclick="p13deletefile()" onkeypress="return false" onkeydown="return false" />
454
<input type=button id=p13NewFolderButton disabled="disabled" value="New Folder" onclick="p13createfolder()" onkeypress="return false" onkeydown="return false" />
455
<input type=button id=p13UploadButton disabled="disabled" value="Upload" onclick="p13uploadFile()" onkeypress="return false" onkeydown="return false" />
456
+ <input type=button id=p13CutButton disabled="disabled" value="Cut" onclick="p13copyFile(1)" onkeypress="return false" onkeydown="return false" />
457
+ <input type=button id=p13CopyButton disabled="disabled" value="Copy" onclick="p13copyFile(0)" onkeypress="return false" onkeydown="return false" />
458
+ <input type=button id=p13PasteButton disabled="disabled" value="Paste" onclick="p13pasteFile()" onkeypress="return false" onkeydown="return false" />
459
<input type=button id=p13RefreshButton disabled="disabled" value="Refresh" onclick="p13folderup(9999)" onkeypress="return false" onkeydown="return false" />
460
</div>
461
</td>
@@ -479,7 +482,7 @@
482
<span id="p13files"></span>
483
</div>
484
<table id="p13toolbarBottom" style=width:100% cellpadding=0 cellspacing=0>
482
- <tr><td class=style6 style="text-align:left"> <span id="bottomstatus"></span></td></tr>
485
+ <tr><td class=style6 style="text-align:left;padding:3px"> <span id="p13bottomstatus"></span></td></tr>
486
</table>
487
</div>
488
<div id=p14 style=display:none>
@@ -1996,11 +1999,7 @@
1999
if (action == 3) gotoDevice(nodeid, 11); // Terminal
2000
if (action == 4) gotoDevice(nodeid, 13); // Files
2001
if (action == 5) gotoDevice(nodeid, 15); // Console
1999
- //if (action == 6) {
2000
- //var nodes = "";
2001
- //$(":checkbox").each(function () { if ($(this).is(':checked')) { nodes += ($(this).val() + ";"); } });
2002
- //window.location = "multidesktop.aspx?node=" + nodes + "&auto=1";
2003
- //}
2002
+ if (action == 6) { Q('viewselect').value = 3; Q('viewselect').onchange(); Q('autoConnectDesktopCheckbox').checked = true; Q('autoConnectDesktopCheckbox').onclick(); } // Multi-Desktop
2003
}
2004
2005
function cmmeshaction(action) {
@@ -3570,6 +3569,10 @@
3569
delete files;
3570
files = null;
3571
}
3572
+ p13clipboard = p13clipboardFolder = null;
3573
+ p13clipboardCut = 0;
3574
+ p13updateClipview();
3575
+ p13oldlinkpath = null;
3576
}
3577
3578
var p13filetree = null;
@@ -3609,15 +3612,11 @@
3612
return checkedNames;
3613
}
3614
3615
+ //var p13oldlinkpath = null;
3616
function p13updateFiles(checkedNames) {
3617
var html1 = '', html2 = '', displayPath = '<a style=cursor:pointer onclick=p13folderup(0)>Root</a>', fullPath = 'Root';
3618
3615
- // Save all existing checked boxes
3616
- var checkedBoxes = [], checkboxes = document.getElementsByName('fd');
3617
- for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { checkedBoxes.push(checkboxes[i].value) }; } // Save all existing checked boxes
3618
-
3619
// Work on parsing the file path
3620
- var oldlinkpath = p13filetreelocation.join('/');
3620
var x = p13filetree.path.split('\\');
3621
p13filetreelocation = [];
3622
for (var i in x) { if (x[i] != '') { p13filetreelocation.push(x[i]); } } // Remove empty spaces
@@ -3646,11 +3645,11 @@
3645
var h = '';
3646
if (f.t < 3) {
3647
var right = '', title = '';
3649
- h = "<div class=filelist file=999><input style=float:left name=fd class=fcb type=checkbox onchange=p13setActions() value='" + f.nx + "'> <span style=float:right title=\"" + title + "\">" + right + "</span><span><div class=fileIcon" + f.t + "></div><a style=cursor:pointer onclick=p13folderset(\"" + encodeURIComponent(f.nx) + "\")>" + shortname + "</a></span></div>";
3648
+ h = "<div class=filelist file=999><input file=999 style=float:left name=fd class=fcb type=checkbox onchange=p13setActions() value='" + f.nx + "'> <span style=float:right title=\"" + title + "\">" + right + "</span><span><div class=fileIcon" + f.t + "></div><a style=cursor:pointer onclick=p13folderset(\"" + encodeURIComponent(f.nx) + "\")>" + shortname + "</a></span></div>";
3649
} else {
3650
var link = shortname;
3651
if (f.s > 0) { link = "<a target=\"_blank\" style=cursor:pointer onclick=\"p13downloadfile('" + encodeURIComponent(newlinkpath + '/' + name) + "','" + encodeURIComponent(name) + "'," + f.s + ")\">" + shortname + "</a>"; }
3653
- h = "<div class=filelist file=3><input style=float:left name=fd class=fcb type=checkbox onchange=p13setActions() value='" + f.nx + "'> <span class=fsize>" + fdatestr + "</span><span style=float:right>" + fsize + "</span><span><div class=fileIcon" + f.t + "></div>" + link + "</span></div>";
3652
+ h = "<div class=filelist file=3><input file=3 style=float:left name=fd class=fcb type=checkbox onchange=p13setActions() value='" + f.nx + "'> <span class=fsize>" + fdatestr + "</span><span style=float:right>" + fsize + "</span><span><div class=fileIcon" + f.t + "></div>" + link + "</span></div>";
3653
}
3654
3655
if (f.t < 3) { html1 += h; } else { html2 += h; }
@@ -3662,17 +3661,7 @@
3661
QE('p13FolderUp', p13filetreelocation.length != 0);
3662
3663
// Re-check all boxes if needed using names
3665
- if (checkedNames != null) {
3666
- checkedBoxes = [];
3667
- checkboxes = document.getElementsByName('fd');
3668
- for (var i in filetreexx) { if (checkedNames.indexOf(filetreexx[i].n) >= 0) { checkedBoxes.push(filetreexx[i].nx); } }
3669
- }
3670
-
3671
- // Re-check all boxes if needed using ID's
3672
- if (oldlinkpath == newlinkpath) {
3673
- checkboxes = document.getElementsByName('fd');
3674
- for (var i = 0; i < checkboxes.length; i++) { checkboxes[i].checked = (checkedBoxes.indexOf(checkboxes[i].value) >= 0); }
3675
- }
3664
+ if (checkedNames != null) { var checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if (checkedNames.indexOf(p13filetree.dir[checkboxes[i].value].n) >= 0) { checkboxes[i].checked = true; } } }
3665
3666
// Update the actions buttons
3667
p13setActions();
@@ -3714,8 +3703,11 @@
3703
QE('p13SelectAllButton', false);
3704
Q('p13SelectAllButton').value = 'Select All';
3705
QE('p13RefreshButton', false);
3706
+ QE('p13CutButton', false);
3707
+ QE('p13CopyButton', false);
3708
+ QE('p13PasteButton', false);
3709
} else {
3718
- var cc = p13getFileSelCount(), tc = p13getFileCount();
3710
+ var cc = p13getFileSelCount(), tc = p13getFileCount(), sfc = p13getFileSelCount(false); // In order: number of entires selected, number of total entries, number of selected entires that are files (not folders)
3711
var winAgent = ((currentNode.agent.id > 0) && (currentNode.agent.id < 5));
3712
QE('p13DeleteFileButton', (cc > 0) && ((p13filetreelocation.length > 0) || (winAgent == false)));
3713
QE('p13NewFolderButton', ((p13filetreelocation.length > 0) || (winAgent == false)));
@@ -3724,10 +3716,13 @@
3716
QE('p13SelectAllButton', tc > 0);
3717
Q('p13SelectAllButton').value = (cc > 0 ? 'Select None' : 'Select All');
3718
QE('p13RefreshButton', true);
3719
+ QE('p13CutButton', (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false)));
3720
+ QE('p13CopyButton', (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false)));
3721
+ QE('p13PasteButton', ((p13filetreelocation.length > 0) || (winAgent == false)) && ((p13clipboard != null) && (p13clipboard.length > 0)));
3722
}
3723
}
3724
3730
- function p13getFileSelCount() { var cc = 0; var checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) cc++; } return cc; }
3725
+ function p13getFileSelCount(includeDirs) { var cc = 0; var checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && ((includeDirs != false) || (checkboxes[i].attributes.file.value == "3"))) cc++; } return cc; }
3726
function p13getFileCount() { var cc = 0; var checkboxes = document.getElementsByName('fd'); return checkboxes.length; }
3727
function p13selectallfile() { var nv = (p13getFileSelCount() == 0), checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { checkboxes[i].checked = nv; } p13setActions(); }
3728
function p13createfolder() { setDialogMode(2, "New Folder", 3, p13createfolderEx, '<input type=text id=p13renameinput maxlength=64 onkeyup=p13fileNameCheck(event) style=width:100% />'); focusTextBox('p13renameinput'); p13fileNameCheck(); }
@@ -3736,10 +3731,17 @@
3731
function p13deletefileEx() { var delfiles = [], checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { delfiles.push(p13filetree.dir[checkboxes[i].value].n); } } files.send(JSON.stringify({ action: 'rm', reqid: 1, path: p13filetreelocation.join('/'), delfiles: delfiles })); p13folderup(999); }
3732
function p13renamefile() { var renamefile, checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { renamefile = p13filetree.dir[checkboxes[i].value].n; } } setDialogMode(2, "Rename", 3, p13renamefileEx, '<input type=text id=p13renameinput maxlength=64 onkeyup=p13fileNameCheck(event) style=width:100% value="' + renamefile + '" />', { action: 'rename', path: p13filetreelocation.join('/'), oldname: renamefile}); focusTextBox('p13renameinput'); p13fileNameCheck(); }
3733
function p13renamefileEx(b, t) { t.newname = Q('p13renameinput').value; files.send(JSON.stringify(t)); p13folderup(999); }
3739
- function p13fileNameCheck(e) { var x = isFilenameValid(Q('p13renameinput').value); QE('idx_dlgOkButton', x); if ((x == true) && (e.keyCode == 13)) { dialogclose(1); } }
3734
+ function p13fileNameCheck(e) { var x = isFilenameValid(Q('p13renameinput').value); QE('idx_dlgOkButton', x); if ((x == true) && (e != null) && (e.keyCode == 13)) { dialogclose(1); } }
3735
function p13uploadFile() { setDialogMode(2, "Upload File", 3, p13uploadFileEx, '<input type=file name=files id=p13uploadinput style=width:100% multiple=multiple onchange="updateUploadDialogOk(\'p13uploadinput\')" />'); updateUploadDialogOk('p13uploadinput'); }
3736
function p13uploadFileEx() { p13doUploadFiles(Q('p13uploadinput').files); }
3737
3738
+ var p13clipboard = null, p13clipboardFolder = null, p13clipboardCut = 0;
3739
+ function p13copyFile(cut) { var checkboxes = document.getElementsByName('fd'); p13clipboard = []; p13clipboardCut = cut, p13clipboardFolder = p13targetpath; for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && (checkboxes[i].attributes.file.value == "3")) { p13clipboard.push(p13filetree.dir[checkboxes[i].value].n); } } p13updateClipview(); }
3740
+ function p13pasteFile() { var x = ''; if ((p13clipboard != null) && (p13clipboard.length > 0)) { x = 'Confim ' + (p13clipboardCut == 0?'copy':'move') + ' of ' + p13clipboard.length + ' entrie' + ((p13clipboard.length > 1)?'s':'') + ' to this location?' } setDialogMode(2, "Paste", 3, p13pasteFileEx, x); }
3741
+ function p13pasteFileEx() { files.send(JSON.stringify({ action: (p13clipboardCut == 0?'copy':'move'), reqid: 1, scpath: p13clipboardFolder, dspath: p13targetpath, names: p13clipboard })); p13folderup(999); if (p13clipboardCut == 1) { p13clipboard = null, p13clipboardFolder = null, p13clipboardCut = 0; p13updateClipview(); } }
3742
+ function p13updateClipview() { var x = ''; if ((p13clipboard != null) && (p13clipboard.length > 0)) { x = 'Holding ' + p13clipboard.length + ' entrie' + ((p13clipboard.length > 1)?'s':'') + ' for ' + (p13clipboardCut == 0?'copy':'move') + ', <a onclick=p13clearClip() style=cursor:pointer>Clear</a>.' } QH('p13bottomstatus', x); p13setActions(); }
3743
+ function p13clearClip() { p13clipboard = null; p13clipboardFolder = null; p13clipboardCut = 0; p13updateClipview(); }
3744
+
3745
function p13fileDragDrop(e) {
3746
haltEvent(e);
3747
QV('p13bigfail', false);