mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-27 07:35:53 -05:00
open files/folders on desktop with files and console with openfile (#5986)
Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
parent
5d1c8ca68b
commit
65d1346e06
@ -3308,6 +3308,13 @@ function onTunnelData(data)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'open': {
|
||||
// Open the local file/folder on the users desktop
|
||||
if (cmd.path) {
|
||||
MeshServerLogEx(20, [cmd.path], "Opening: " + cmd.path, cmd);
|
||||
openFileOnDesktop(cmd.path);
|
||||
}
|
||||
}
|
||||
case 'markcoredump': {
|
||||
// If we are asking for the coredump file, set the right path.
|
||||
var coreDumpPath = null;
|
||||
@ -3768,6 +3775,64 @@ function consoleHttpResponse(response) {
|
||||
response.close = function () { sendConsoleText('httprequest.response.close', this.sessionid); consoleHttpRequest = null; }
|
||||
}
|
||||
|
||||
// Open a local file on current user's desktop
|
||||
function openFileOnDesktop(file) {
|
||||
var child = null;
|
||||
try {
|
||||
switch (process.platform) {
|
||||
case 'win32':
|
||||
var uid = require('user-sessions').consoleUid();
|
||||
var user = require('user-sessions').getUsername(uid);
|
||||
var domain = require('user-sessions').getDomain(uid);
|
||||
var task = { name: 'MeshChatTask', user: user, domain: domain, execPath: (require('fs').statSync(file).isDirectory() ? process.env['windir'] + '\\explorer.exe' : file) };
|
||||
if (require('fs').statSync(file).isDirectory()) task.arguments = [file];
|
||||
try {
|
||||
require('win-tasks').addTask(task);
|
||||
require('win-tasks').getTask({ name: 'MeshChatTask' }).run();
|
||||
require('win-tasks').deleteTask('MeshChatTask');
|
||||
return (true);
|
||||
}
|
||||
catch (ex) {
|
||||
var taskoptions = { env: { _target: (require('fs').statSync(file).isDirectory() ? process.env['windir'] + '\\explorer.exe' : file), _user: '"' + domain + '\\' + user + '"' }, _args: "" };
|
||||
if (require('fs').statSync(file).isDirectory()) taskoptions.env._args = file;
|
||||
for (var c1e in process.env) {
|
||||
taskoptions.env[c1e] = process.env[c1e];
|
||||
}
|
||||
var child = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], taskoptions);
|
||||
child.stderr.on('data', function (c) { });
|
||||
child.stdout.on('data', function (c) { });
|
||||
child.stdin.write('SCHTASKS /CREATE /F /TN MeshChatTask /SC ONCE /ST 00:00 ');
|
||||
if (user) { child.stdin.write('/RU $env:_user '); }
|
||||
child.stdin.write('/TR "$env:_target $env:_args"\r\n');
|
||||
child.stdin.write('$ts = New-Object -ComObject Schedule.service\r\n');
|
||||
child.stdin.write('$ts.connect()\r\n');
|
||||
child.stdin.write('$tsfolder = $ts.getfolder("\\")\r\n');
|
||||
child.stdin.write('$task = $tsfolder.GetTask("MeshChatTask")\r\n');
|
||||
child.stdin.write('$taskdef = $task.Definition\r\n');
|
||||
child.stdin.write('$taskdef.Settings.StopIfGoingOnBatteries = $false\r\n');
|
||||
child.stdin.write('$taskdef.Settings.DisallowStartIfOnBatteries = $false\r\n');
|
||||
child.stdin.write('$taskdef.Actions.Item(1).Path = $env:_target\r\n');
|
||||
child.stdin.write('$taskdef.Actions.Item(1).Arguments = $env:_args\r\n');
|
||||
child.stdin.write('$tsfolder.RegisterTaskDefinition($task.Name, $taskdef, 4, $null, $null, $null)\r\n');
|
||||
child.stdin.write('SCHTASKS /RUN /TN MeshChatTask\r\n');
|
||||
child.stdin.write('SCHTASKS /DELETE /F /TN MeshChatTask\r\nexit\r\n');
|
||||
child.waitExit();
|
||||
}
|
||||
break;
|
||||
case 'linux':
|
||||
child = require('child_process').execFile('/usr/bin/xdg-open', ['xdg-open', file], { uid: require('user-sessions').consoleUid() });
|
||||
break;
|
||||
case 'darwin':
|
||||
child = require('child_process').execFile('/usr/bin/open', ['open', file]);
|
||||
break;
|
||||
default:
|
||||
// Unknown platform, ignore this command.
|
||||
break;
|
||||
}
|
||||
} catch (ex) { }
|
||||
return child;
|
||||
}
|
||||
|
||||
// Open a web browser to a specified URL on current user's desktop
|
||||
function openUserDesktopUrl(url) {
|
||||
if ((url.toLowerCase().startsWith('http://') == false) && (url.toLowerCase().startsWith('https://') == false)) { return null; }
|
||||
@ -3833,7 +3898,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
|
||||
var response = null;
|
||||
switch (cmd) {
|
||||
case 'help': { // Displays available commands
|
||||
var fin = '', f = '', availcommands = 'domain,translations,agentupdate,errorlog,msh,timerinfo,coreinfo,coreinfoupdate,coredump,service,fdsnapshot,fdcount,startupoptions,alert,agentsize,versions,help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,wslist,plugin,wsconnect,wssend,wsclose,notify,ls,ps,kill,netinfo,location,power,wakeonlan,setdebug,smbios,rawsmbios,toast,lock,users,openurl,getscript,getclip,setclip,log,av,cpuinfo,sysinfo,apf,scanwifi,wallpaper,agentmsg,task,uninstallagent,display';
|
||||
var fin = '', f = '', availcommands = 'domain,translations,agentupdate,errorlog,msh,timerinfo,coreinfo,coreinfoupdate,coredump,service,fdsnapshot,fdcount,startupoptions,alert,agentsize,versions,help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,wslist,plugin,wsconnect,wssend,wsclose,notify,ls,ps,kill,netinfo,location,power,wakeonlan,setdebug,smbios,rawsmbios,toast,lock,users,openurl,getscript,getclip,setclip,log,av,cpuinfo,sysinfo,apf,scanwifi,wallpaper,agentmsg,task,uninstallagent,display,openfile';
|
||||
if (require('os').dns != null) { availcommands += ',dnsinfo'; }
|
||||
try { require('linux-dhcp'); availcommands += ',dhcp'; } catch (ex) { }
|
||||
if (process.platform == 'win32') {
|
||||
@ -4678,6 +4743,11 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
|
||||
else { if (openUserDesktopUrl(args['_'][0]) == null) { response = 'Failed.'; } else { response = 'Success.'; } }
|
||||
break;
|
||||
}
|
||||
case 'openfile': {
|
||||
if (args['_'].length != 1) { response = 'Proper usage: openfile (filepath)'; } // Display usage
|
||||
else { if (openFileOnDesktop(args['_'][0]) == null) { response = 'Failed.'; } else { response = 'Success.'; } }
|
||||
break;
|
||||
}
|
||||
case 'users': {
|
||||
if (meshCoreObj.users == null) { response = 'Active users are unknown.'; } else { response = 'Active Users: ' + meshCoreObj.users.join(', ') + '.'; }
|
||||
require('user-sessions').enumerateUsers().then(function (u) { for (var i in u) { sendConsoleText(u[i]); } });
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -884,6 +884,7 @@
|
||||
<input type=button style="margin-right:2px" disabled="disabled" id=p13RefreshButton value="Refresh" onclick="p13folderup(9999)" />
|
||||
<input type=button style="margin-right:2px" disabled="disabled" id=p13FindButton value="Find" onclick="p13findfile()" />
|
||||
<input type=button style="margin-right:2px" disabled="disabled" id=p13GoToFolderButton value="GoTo" onclick="p13gotofolder()" />
|
||||
<input type=button style="margin-right:2px" disabled="disabled" id=p13OpenButton value="Open" onclick="p13openfilefolder()" />
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@ -11165,6 +11166,21 @@
|
||||
p13setActions();
|
||||
}
|
||||
|
||||
function p13openfilefolder() {
|
||||
setDialogMode(2, "Open File/Folder", 3, p13openfilefolderEx, "Are you sure you want to open this file/folder on the remote devices desktop ?");
|
||||
}
|
||||
function p13openfilefolderEx() {
|
||||
var openfilefolder = "", checkboxes = document.getElementsByName('fd');
|
||||
for (var i = 0; i < checkboxes.length; i++) {
|
||||
console.log(checkboxes[i]);
|
||||
if (checkboxes[i].checked) {
|
||||
openfilefolder = (isWindowsNode(currentNode) ? '' : '/') + p13filetreelocation.join(isWindowsNode(currentNode) ? '\\' : '/') + (isWindowsNode(currentNode) ? '\\' : '/') + p13filetree.dir[checkboxes[i].value].n;
|
||||
}
|
||||
}
|
||||
if (openfilefolder == "") return;
|
||||
files.sendText({ action: 'open', reqid: 1, path: openfilefolder, dir: (p13getFileSelDirCount() == 1) ? true : false });
|
||||
}
|
||||
|
||||
function p13gotofolder() {
|
||||
setDialogMode(2, "Go To Folder", 3, p13gotofolderEx, '<input type=text id=p13folderinput style=width:100% placeholder="'+(isWindowsNode(currentNode) ? 'C:\\' : '/var/www')+'" />');
|
||||
focusTextBox('p13folderinput');
|
||||
@ -11261,6 +11277,7 @@
|
||||
QE('p13PasteButton', false);
|
||||
QE('p13GoToFolderButton', false);
|
||||
QE('p13DownloadButton', false);
|
||||
QE('p13OpenButton', false);
|
||||
} else {
|
||||
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)
|
||||
var winAgent = ((currentNode.agent.id > 0) && (currentNode.agent.id < 5)) || (currentNode.agent.id == 14)|| (currentNode.agent.id == 34);
|
||||
@ -11279,6 +11296,7 @@
|
||||
QE('p13UnzipButton', advancedFeatures && (cc == 1) && (sfc == 1) && ((p13filetreelocation.length > 0) || (winAgent == false)) && p13getFileSelAllowedExt('.zip'));
|
||||
QE('p13PasteButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false)) && ((p13clipboard != null) && (p13clipboard.length > 0)));
|
||||
QE('p13GoToFolderButton', true);
|
||||
QE('p13OpenButton', (cc == 1));
|
||||
QE('p13DownloadButton', advancedFeatures && (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false)));
|
||||
}
|
||||
var filesState = ((files != null) && (files.state != 0));
|
||||
|
Loading…
Reference in New Issue
Block a user