Fixed desktop tools
Ylian Saint-Hilaire committed
Sep 11, 2018 at 14:28 UTC
fa5ce67e6758f3c3db823041bcc2d394b27b7606
5 files changed
+52
-58
MeshCentralServer.njsproj
-2
@@ -31,8 +31,6 @@
31
<Compile Include="agents\modules_meshcmd\amt-xml.js" />
32
<Compile Include="agents\modules_meshcmd\amt.js" />
33
<Compile Include="agents\modules_meshcmd\process-manager.js" />
34
- <Compile Include="agents\modules_meshcmd\serviceHost.js" />
35
- <Compile Include="agents\modules_meshcmd\serviceManager.js" />
34
<Compile Include="agents\modules_meshcmd\smbios.js" />
35
<Compile Include="agents\modules_meshcmd\user-sessions.js" />
36
<Compile Include="agents\modules_meshcore\amt-lme.js" />
agents/modules_meshcmd/process-manager.js
+19
-8
@@ -14,11 +14,13 @@ See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16
17
-// JavaScript source code
17
var GM = require('_GenericMarshal');
18
19
+// Used on Windows and Linux to get information about running processes
20
function processManager() {
21
- this._ObjectID = 'processManager';
21
+ this._ObjectID = 'process-manager'; // Used for debugging, allows you to get the object type at runtime.
22
+
23
+ // Setup the platform specific calls.
24
switch (process.platform) {
25
case 'win32':
26
this._kernel32 = GM.CreateNativeProxy('kernel32.dll');
@@ -32,12 +34,16 @@ function processManager() {
34
break;
35
default:
36
throw (process.platform + ' not supported');
37
+ break;
38
}
39
+
40
+ // Return a object of: pid -> process information.
41
this.getProcesses = function getProcesses(callback) {
42
switch (process.platform) {
38
- default:
43
+ default: // This is not a supported platform.
44
throw ('Enumerating processes on ' + process.platform + ' not supported');
40
- case 'win32':
45
+ break;
46
+ case 'win32': // Windows processes
47
var retVal = {};
48
var h = this._kernel32.CreateToolhelp32Snapshot(2, 0);
49
var info = GM.CreateVariable(304);
@@ -49,7 +55,7 @@ function processManager() {
55
}
56
if (callback) { callback.apply(this, [retVal]); }
57
break;
52
- case 'linux':
58
+ case 'linux': // Linux processes
59
if (!this._psp) { this._psp = {}; }
60
var p = this._childProcess.execFile("/bin/ps", ["ps", "-uxa"], { type: this._childProcess.SpawnTypes.TERM });
61
this._psp[p.pid] = p;
@@ -68,8 +74,8 @@ function processManager() {
74
if (i == 0 && tokens[x]) { key[tokens[x]] = keyi++; }
75
if (i > 0 && tokens[x]) { tokenList.push(tokens[x]); }
76
}
71
- if ((i > 0) && (tokenList[key.PID])) {
72
- retVal[tokenList[key.PID]] = { user: tokenList[key.USER], cmd: tokenList[key.COMMAND] };
77
+ if (i > 0) {
78
+ if (tokenList[key.PID]) { retVal[tokenList[key.PID]] = { user: tokenList[key.USER], cmd: tokenList[key.COMMAND] }; }
79
}
80
}
81
if (this.callback) {
@@ -81,18 +87,23 @@ function processManager() {
87
break;
88
}
89
};
90
+
91
+ // Get information about a specific process on Linux
92
this.getProcessInfo = function getProcessInfo(pid) {
93
switch (process.platform) {
94
default:
95
throw ('getProcessInfo() not supported for ' + process.platform);
96
+ break;
97
case 'linux':
89
- var status = require('fs').readFileSync('/proc/' + pid + '/status'), info = {}, lines = status.toString().split('\n');
98
+ var status = require('fs').readFileSync('/proc/' + pid + '/status');
99
+ var info = {}, lines = status.toString().split('\n');
100
for (var i in lines) {
101
var tokens = lines[i].split(':');
102
if (tokens.length > 1) { tokens[1] = tokens[1].trim(); }
103
info[tokens[0]] = tokens[1];
104
}
105
return (info);
106
+ break;
107
}
108
};
109
}
agents/modules_meshcore/process-manager.js
+31
-45
@@ -14,14 +14,14 @@ See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16
17
-
17
var GM = require('_GenericMarshal');
18
20
-function processManager()
21
-{
22
- this._ObjectID = 'process-manager';
23
- switch(process.platform)
24
- {
19
+// Used on Windows and Linux to get information about running processes
20
+function processManager() {
21
+ this._ObjectID = 'process-manager'; // Used for debugging, allows you to get the object type at runtime.
22
+
23
+ // Setup the platform specific calls.
24
+ switch (process.platform) {
25
case 'win32':
26
this._kernel32 = GM.CreateNativeProxy('kernel32.dll');
27
this._kernel32.CreateMethod('GetLastError');
@@ -36,27 +36,26 @@ function processManager()
36
throw (process.platform + ' not supported');
37
break;
38
}
39
- this.getProcesses = function getProcesses(callback)
40
- {
41
- switch(process.platform)
42
- {
43
- default:
39
+
40
+ // Return a object of: pid -> process information.
41
+ this.getProcesses = function getProcesses(callback) {
42
+ switch (process.platform) {
43
+ default: // This is not a supported platform.
44
throw ('Enumerating processes on ' + process.platform + ' not supported');
45
break;
46
- case 'win32':
47
- var retVal = [];
46
+ case 'win32': // Windows processes
47
+ var retVal = {};
48
var h = this._kernel32.CreateToolhelp32Snapshot(2, 0);
49
var info = GM.CreateVariable(304);
50
info.toBuffer().writeUInt32LE(304, 0);
51
var nextProcess = this._kernel32.Process32First(h, info);
52
- while (nextProcess.Val)
53
- {
54
- retVal.push({ pid: info.Deref(8, 4).toBuffer().readUInt32LE(0), command: info.Deref(GM.PointerSize == 4 ? 36 : 44, 260).String });
52
+ while (nextProcess.Val) {
53
+ retVal[info.Deref(8, 4).toBuffer().readUInt32LE(0)] = { cmd: info.Deref(GM.PointerSize == 4 ? 36 : 44, 260).String };
54
nextProcess = this._kernel32.Process32Next(h, info);
55
}
56
if (callback) { callback.apply(this, [retVal]); }
57
break;
59
- case 'linux':
58
+ case 'linux': // Linux processes
59
if (!this._psp) { this._psp = {}; }
60
var p = this._childProcess.execFile("/bin/ps", ["ps", "-uxa"], { type: this._childProcess.SpawnTypes.TERM });
61
this._psp[p.pid] = p;
@@ -65,32 +64,21 @@ function processManager()
64
p.callback = callback;
65
p.args = [];
66
for (var i = 1; i < arguments.length; ++i) { p.args.push(arguments[i]); }
68
- p.on('exit', function onGetProcesses()
69
- {
70
- delete this.Parent._psp[this.pid];
71
- var retVal = [];
72
- var lines = this.ps.split('\x0D\x0A');
73
- var key = {};
74
- var keyi = 0;
75
- for (var i in lines)
76
- {
67
+ p.on('exit', function onGetProcesses() {
68
+ delete this.Parent._psp[this.pid];
69
+ var retVal = {}, lines = this.ps.split('\x0D\x0A'), key = {}, keyi = 0;
70
+ for (var i in lines) {
71
var tokens = lines[i].split(' ');
72
var tokenList = [];
79
- for(var x in tokens)
80
- {
73
+ for (var x in tokens) {
74
if (i == 0 && tokens[x]) { key[tokens[x]] = keyi++; }
82
- if (i > 0 && tokens[x]) { tokenList.push(tokens[x]);}
75
+ if (i > 0 && tokens[x]) { tokenList.push(tokens[x]); }
76
}
84
- if(i>0)
85
- {
86
- if (tokenList[key.PID])
87
- {
88
- retVal.push({ pid: tokenList[key.PID], user: tokenList[key.USER], command: tokenList[key.COMMAND] });
89
- }
77
+ if (i > 0) {
78
+ if (tokenList[key.PID]) { retVal[tokenList[key.PID]] = { user: tokenList[key.USER], cmd: tokenList[key.COMMAND] }; }
79
}
80
}
92
- if (this.callback)
93
- {
81
+ if (this.callback) {
82
this.args.unshift(retVal);
83
this.callback.apply(this.parent, this.args);
84
}
@@ -99,19 +87,17 @@ function processManager()
87
break;
88
}
89
};
102
- this.getProcessInfo = function getProcessInfo(pid)
103
- {
104
- switch(process.platform)
105
- {
90
+
91
+ // Get information about a specific process on Linux
92
+ this.getProcessInfo = function getProcessInfo(pid) {
93
+ switch (process.platform) {
94
default:
95
throw ('getProcessInfo() not supported for ' + process.platform);
96
break;
97
case 'linux':
98
var status = require('fs').readFileSync('/proc/' + pid + '/status');
111
- var info = {};
112
- var lines = status.toString().split('\n');
113
- for(var i in lines)
114
- {
99
+ var info = {}, lines = status.toString().split('\n');
100
+ for (var i in lines) {
101
var tokens = lines[i].split(':');
102
if (tokens.length > 1) { tokens[1] = tokens[1].trim(); }
103
info[tokens[0]] = tokens[1];
views/default.handlebars
+1
-2
@@ -1522,7 +1522,7 @@
1522
QV('NoMeshesPanel', meshcount == 0);
1523
QV('devListToolbarView', (meshcount != 0) && (nodes.length > 0));
1524
QV('devListToolbarSort', (meshcount != 0) && (nodes.length > 0) && (view < 4));
1525
- if ((meshcount == 0) || (nodes.length == 0)) { view = 1; }
1525
+ if ((meshcount == 0) || (nodes.length == 0)) { view = 1; sort = 0; }
1526
if (view == 4) {
1527
setTimeout( function() { if (xxmap.map != null) { xxmap.map.updateSize(); } }, 200);
1528
// TODO
@@ -3711,7 +3711,6 @@
3711
if (Q('DeskTools').nodeid != message.nodeid) return;
3712
var p = [], processes = null;
3713
try { processes = JSON.parse(message.value); } catch (e) { }
3714
- console.log(processes);
3714
if (processes != null) {
3715
for (var pid in processes) { p.push( { p:parseInt(pid), c:processes[pid].cmd, d:processes[pid].cmd.toLowerCase(), u: processes[pid].user } ); }
3716
if (deskTools.sort == 0) { p.sort(sortProcessPid); } else if (deskTools.sort == 1) { p.sort(sortProcessName); }
webserver.js
+1
-1
@@ -653,7 +653,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
653
obj.users[req.session.userid] = { type: 'user', _id: req.session.userid, name: '~', email: '~', domain: domain.id, siteadmin: 0xFFFFFFFF };
654
obj.db.SetUser(obj.users[req.session.userid]);
655
}
656
- } else if (obj.args.user && (!req.session || !req.session.userid) && obj.users['user/' + domain.id + '/' + obj.args.user.toLowerCase()]) {
656
+ } else if (obj.args.user && obj.users['user/' + domain.id + '/' + obj.args.user.toLowerCase()]) {
657
// If a default user is active, setup the session here.
658
if (req.session && req.session.loginmode) { delete req.session.loginmode; }
659
req.session.userid = 'user/' + domain.id + '/' + obj.args.user.toLowerCase();