diff --git a/agents/meshcmd.js b/agents/meshcmd.js index c5f34c21..67c8b90a 100644 --- a/agents/meshcmd.js +++ b/agents/meshcmd.js @@ -343,7 +343,7 @@ function run(argv) { if (mestate.ProvisioningState.stateStr == 'PRE') { str += ', pre-provisioning state'; } else if (mestate.ProvisioningState.stateStr == 'IN') { str += ', in-provisioning state'; } else if (mestate.ProvisioningState.stateStr == 'POST') { if (mestate.ProvisioningMode.modeStr == 'ENTERPRISE') { str += ', activated in ' + ["none", "client control mode", "admin control mode", "remote assistance mode"][mestate.controlmode.controlMode]; } else { str += ', activated in ' + mestate.ProvisioningMode.modeStr; } } - if (mestate.ehbc.EHBC == true) { str += ', EHBC enabled'; } + if ((mestate.ehbc) && (mestate.ehbc.EHBC == true)) { str += ', EHBC enabled'; } str += '.'; if (mestate.net0 != null) { str += '\r\nWired ' + ((mestate.net0.enabled == 1) ? 'Enabled' : 'Disabled') + ((mestate.net0.dhcpEnabled == 1) ? ', DHCP' : ', Static') + ', ' + mestate.net0.mac + (mestate.net0.address == '0.0.0.0' ? '' : (', ' + mestate.net0.address)); } if (mestate.net1 != null) { str += '\r\nWireless ' + ((mestate.net1.enabled == 1) ? 'Enabled' : 'Disabled') + ((mestate.net1.dhcpEnabled == 1) ? ', DHCP' : ', Static') + ', ' + mestate.net1.mac + (mestate.net1.address == '0.0.0.0' ? '' : (', ' + mestate.net1.address)); } diff --git a/agents/meshcore.js b/agents/meshcore.js index 7e92117c..8dfd04a5 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -852,7 +852,7 @@ function createMeshCore(agent) { var response = null; switch (cmd) { case 'help': { // Displays available commands - response = 'aaaAvailable commands: help, info, args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast.'; + response = 'Available commands: help, info, args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast.'; break; } case 'toast': { diff --git a/agents/modules_meshcmd/processManager.js b/agents/modules_meshcmd/process-manager.js similarity index 64% rename from agents/modules_meshcmd/processManager.js rename to agents/modules_meshcmd/process-manager.js index cc040841..d387b2be 100644 --- a/agents/modules_meshcmd/processManager.js +++ b/agents/modules_meshcmd/process-manager.js @@ -1,13 +1,25 @@ +/* +Copyright 2018 Intel Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // JavaScript source code var GM = require('_GenericMarshal'); - - -function processManager() -{ +function processManager() { this._ObjectID = 'processManager'; - switch(process.platform) - { + switch (process.platform) { case 'win32': this._kernel32 = GM.CreateNativeProxy('kernel32.dll'); this._kernel32.CreateMethod('GetLastError'); @@ -20,24 +32,19 @@ function processManager() break; default: throw (process.platform + ' not supported'); - break; } - this.getProcesses = function getProcesses(callback) - { - switch(process.platform) - { + this.getProcesses = function getProcesses(callback) { + switch (process.platform) { default: throw ('Enumerating processes on ' + process.platform + ' not supported'); - break; case 'win32': var retVal = []; var h = this._kernel32.CreateToolhelp32Snapshot(2, 0); var info = GM.CreateVariable(304); info.toBuffer().writeUInt32LE(304, 0); var nextProcess = this._kernel32.Process32First(h, info); - while (nextProcess.Val) - { - retVal.push({ pid: info.Deref(8, 4).toBuffer().readUInt32LE(0), command: info.Deref(GM.PointerSize == 4 ? 36 : 44, 260).String }); + while (nextProcess.Val) { + retVal.push({ pid: info.Deref(8, 4).toBuffer().readUInt32LE(0), cmd: info.Deref(GM.PointerSize == 4 ? 36 : 44, 260).String }); nextProcess = this._kernel32.Process32Next(h, info); } if (callback) { callback.apply(this, [retVal]); } @@ -51,32 +58,21 @@ function processManager() p.callback = callback; p.args = []; for (var i = 1; i < arguments.length; ++i) { p.args.push(arguments[i]); } - p.on('exit', function onGetProcesses() - { - delete this.Parent._psp[this.pid]; - var retVal = []; - var lines = this.ps.split('\x0D\x0A'); - var key = {}; - var keyi = 0; - for (var i in lines) - { + p.on('exit', function onGetProcesses() { + delete this.Parent._psp[this.pid]; + var retVal = [], lines = this.ps.split('\x0D\x0A'), key = {}, keyi = 0; + for (var i in lines) { var tokens = lines[i].split(' '); var tokenList = []; - for(var x in tokens) - { + for (var x in tokens) { if (i == 0 && tokens[x]) { key[tokens[x]] = keyi++; } - if (i > 0 && tokens[x]) { tokenList.push(tokens[x]);} + if (i > 0 && tokens[x]) { tokenList.push(tokens[x]); } } - if(i>0) - { - if (tokenList[key.PID]) - { - retVal.push({ pid: tokenList[key.PID], user: tokenList[key.USER], command: tokenList[key.COMMAND] }); - } + if ((i > 0) && (tokenList[key.PID])) { + retVal.push({ pid: tokenList[key.PID], user: tokenList[key.USER], cmd: tokenList[key.COMMAND] }); } } - if (this.callback) - { + if (this.callback) { this.args.unshift(retVal); this.callback.apply(this.parent, this.args); } @@ -85,25 +81,18 @@ function processManager() break; } }; - this.getProcessInfo = function getProcessInfo(pid) - { - switch(process.platform) - { + this.getProcessInfo = function getProcessInfo(pid) { + switch (process.platform) { default: throw ('getProcessInfo() not supported for ' + process.platform); - break; case 'linux': - var status = require('fs').readFileSync('/proc/' + pid + '/status'); - var info = {}; - var lines = status.toString().split('\n'); - for(var i in lines) - { + var status = require('fs').readFileSync('/proc/' + pid + '/status'), info = {}, lines = status.toString().split('\n'); + for (var i in lines) { var tokens = lines[i].split(':'); if (tokens.length > 1) { tokens[1] = tokens[1].trim(); } info[tokens[0]] = tokens[1]; } return (info); - break; } }; } diff --git a/agents/modules_meshcmd/UserSessions.js b/agents/modules_meshcmd/user-sessions.js similarity index 63% rename from agents/modules_meshcmd/UserSessions.js rename to agents/modules_meshcmd/user-sessions.js index 7da2bb25..d8fe2d96 100644 --- a/agents/modules_meshcmd/UserSessions.js +++ b/agents/modules_meshcmd/user-sessions.js @@ -1,4 +1,18 @@ +/* +Copyright 2018 Intel Corporation +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ function UserSessions() { @@ -87,6 +101,8 @@ function UserSessions() } this._wts.WTSFreeMemory(pinfo.Deref()); + + Object.defineProperty(retVal, 'connected', { value: showActiveOnly(retVal) }); return (retVal); }; } @@ -94,9 +110,58 @@ function UserSessions() { this.Current = function Current() { - return ({}); + var retVal = {}; + var emitterUtils = require('events').inherits(retVal); + emitterUtils.createEvent('logon'); + + retVal._child = require('child_process').execFile('/usr/bin/last', ['last', '-f', '/var/run/utmp']); + retVal._child.Parent = retVal; + retVal._child._txt = ''; + retVal._child.on('exit', function (code) + { + var lines = this._txt.split('\n'); + var sessions = []; + for(var i in lines) + { + if (lines[i]) + { + console.log(getTokens(lines[i])); + var user = lines[i].substring(0, lines[i].indexOf(' ')); + sessions.push(user); + } + } + sessions.pop(); + console.log(sessions); + }); + retVal._child.stdout.Parent = retVal._child; + retVal._child.stdout.on('data', function (chunk) { this.Parent._txt += chunk.toString(); }); + + return (retVal); } } } +function showActiveOnly(source) +{ + var retVal = []; + for (var i in source) + { + if (source[i].State == 'Active' || source[i].State == 'Connected') + { + retVal.push(source[i]); + } + } + return (retVal); +} +function getTokens(str) +{ + var columns = []; + var i; + + columns.push(str.substring(0, (i=str.indexOf(' ')))); + while (str[++i] == ' '); + columns.push(str.substring(i, str.substring(i).indexOf(' ') + i)); + + return (columns); +} module.exports = new UserSessions(); \ No newline at end of file diff --git a/package.json b/package.json index 2cc47e58..df53fd60 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.1.6-s", + "version": "0.1.6-v", "keywords": [ "Remote Management", "Intel AMT", diff --git a/views/default.handlebars b/views/default.handlebars index 7aac4296..fa127951 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -385,6 +385,7 @@
  +    
@@ -2849,7 +2850,7 @@ // Show action button, only show if we have permissions 4, 8, 64 if ((meshrights & 76) != 0) { x += ''; } x += ''; - if ((connectivity & 1) && (meshrights & 8) && (node.agent.id < 5)) { x += ''; } + //if ((connectivity & 1) && (meshrights & 8) && (node.agent.id < 5)) { x += ''; } QH('p10html', x); // Show node last 7 days timeline @@ -3306,7 +3307,7 @@ QV('d7meshkvm', (mesh.mtype == 2) && ((deskState == false) || (desktop.contype == 1))); // Enable buttons - var online = ((currentNode.conn & 1) != 0); // If Agent (1) connected, enable Terminal + var online = ((currentNode.conn & 1) != 0); // If Agent (1) connected, enable remote desktop QE('connectbutton1', online); var hwonline = ((currentNode.conn & 6) != 0); // If CIRA (2) or AMT (4) connected, enable hardware terminal QE('connectbutton1h', hwonline); @@ -3314,6 +3315,8 @@ QV('deskFocusBtn', (desktop != null) && (desktop.contype == 2) && (deskState != 0) && (desktopsettings.showfocus)); QE('DeskCAD', deskState == 3); QE('DeskToolsButton', online); + QV('DeskToastButton', (currentNode.agent) && (currentNode.agent.id < 5)); + QE('DeskToastButton', online); if (online == false) QV('DeskTools', false); }