Added agent debug console in agent and assistant.

Ylian Saint-Hilaire committed Dec 15, 2020 at 19:44 UTC 642de7996b31c88836a9d7bcbb5ff558e2eb49b8
2 files changed +14 -2
agents/MeshCentralAssistant.exe
Binary files a/agents/MeshCentralAssistant.exe and b/agents/MeshCentralAssistant.exe differ
agents/meshcore.js
+14 -2
@@ -45,6 +45,7 @@ function createMeshCore(agent) {
45 var obj = {};
46 var agentFileHttpRequests = {}; // Currently active agent HTTPS GET requests from the server.
47 var agentFileHttpPendingRequests = []; // Pending HTTPS GET requests from the server.
48 + var debugConsole = (_MSH().debugConsole == 1);
49
50 if (process.platform == 'win32' && require('user-sessions').isRoot()) {
51 // Check the Agent Uninstall MetaData for correctness, as the installer may have written an incorrect value
@@ -229,6 +230,12 @@ function createMeshCore(agent) {
230 case 'meshToolInfo':
231 try { mesh.SendCommand({ action: 'meshToolInfo', name: data.name, hash: data.hash, cookie: data.cookie?true:false, pipe: true }); } catch (e) { }
232 break;
233 + case 'console':
234 + if (debugConsole) {
235 + var args = splitArgs(data.value);
236 + processConsoleCommand(args[0].toLowerCase(), parseArgs(args), 0, 'pipe');
237 + }
238 + break;
239 }
240 }
241 catch (e) { removeRegisteredApp(this); this.end(); return; }
@@ -2680,7 +2687,7 @@ function createMeshCore(agent) {
2687 var response = null;
2688 switch (cmd) {
2689 case 'help': { // Displays available commands
2683 - var fin = '', f = '', availcommands = 'timerinfo,coreinfo,coredump,service,fdsnapshot,fdcount,startupoptions,alert,agentsize,versions,help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,nwslist,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';
2690 + var fin = '', f = '', availcommands = 'msh,timerinfo,coreinfo,coredump,service,fdsnapshot,fdcount,startupoptions,alert,agentsize,versions,help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,nwslist,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';
2691 if (process.platform == 'win32') { availcommands += ',safemode,wpfhwacceleration,uac'; }
2692 if (amt != null) { availcommands += ',amt,amtconfig,amtevents'; }
2693 if (process.platform != 'freebsd') { availcommands += ',vm';}
@@ -2696,6 +2703,9 @@ function createMeshCore(agent) {
2703 response = "Available commands: \r\n" + fin + ".";
2704 break;
2705 }
2706 + case 'msh':
2707 + response = JSON.stringify(_MSH(), null, 2);
2708 + break;
2709 case 'timerinfo':
2710 response = require('ChainViewer').getTimerInfo();
2711 break;
@@ -3309,6 +3319,7 @@ function createMeshCore(agent) {
3319 var oldNodeId = db.Get('OldNodeId');
3320 if (oldNodeId != null) { response += '\r\nOldNodeID: ' + oldNodeId + '.'; }
3321 if (process.platform == 'linux' || process.platform == 'freebsd') { response += '\r\nX11 support: ' + require('monitor-info').kvm_x11_support + '.'; }
3322 + //response += '\r\Debug Console: ' + debugConsole + '.';
3323 break;
3324 }
3325 case 'osinfo': { // Return the operating system information
@@ -3743,7 +3754,8 @@ function createMeshCore(agent) {
3754 // Send a mesh agent console command
3755 function sendConsoleText(text, sessionid) {
3756 if (typeof text == 'object') { text = JSON.stringify(text); }
3746 - require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: text, sessionid: sessionid });
3757 + if (debugConsole && ((sessionid == null) || (sessionid == 'pipe'))) { broadcastToRegisteredApps({ cmd: 'console', value: text }); }
3758 + if (sessionid != 'pipe') { require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: text, sessionid: sessionid }); }
3759 }
3760
3761 // Called before the process exits