processes() added user (windows)
This commit is contained in:
+7
-2
@@ -934,7 +934,11 @@ function processes(callback) {
|
||||
try {
|
||||
util
|
||||
.powerShell(
|
||||
'Get-CimInstance Win32_Process | select-Object ProcessId,ParentProcessId,ExecutionState,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage, @{n="CreationDate";e={$_.CreationDate.ToString("yyyy-MM-dd HH:mm:ss")}} | ConvertTo-Json -compress'
|
||||
`Get-CimInstance Win32_Process | select-Object ProcessId,ParentProcessId,ExecutionState,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage,
|
||||
@{n="CreationDate";e={$_.CreationDate.ToString("yyyy-MM-dd HH:mm:ss")}},
|
||||
@{n="User";e={$OwnerInfo = Invoke-CimMethod -InputObject $_ -MethodName GetOwner
|
||||
if($OwnerInfo.ReturnValue -eq 0) {"$($OwnerInfo.Domain)\\$($OwnerInfo.User)"} else {""}
|
||||
}} | ConvertTo-Json -compress`
|
||||
)
|
||||
.then((stdout, error) => {
|
||||
if (!error) {
|
||||
@@ -959,6 +963,7 @@ function processes(callback) {
|
||||
const utime = element.UserModeTime;
|
||||
const stime = element.KernelModeTime;
|
||||
const memw = element.WorkingSetSize;
|
||||
const user = element.User;
|
||||
allcpuu = allcpuu + utime;
|
||||
allcpus = allcpus + stime;
|
||||
result.all++;
|
||||
@@ -995,7 +1000,7 @@ function processes(callback) {
|
||||
started: element.CreationDate,
|
||||
state: statusValue ? _winStatusValues[statusValue] : _winStatusValues[0],
|
||||
tty: '',
|
||||
user: '',
|
||||
user,
|
||||
command: commandLine || name,
|
||||
path: commandPath,
|
||||
params: ''
|
||||
|
||||
+40
-36
@@ -16,7 +16,7 @@
|
||||
const exec = require('child_process').exec;
|
||||
const util = require('./util');
|
||||
|
||||
let _platform = process.platform;
|
||||
const _platform = process.platform;
|
||||
|
||||
const _linux = _platform === 'linux' || _platform === 'android';
|
||||
const _darwin = _platform === 'darwin';
|
||||
@@ -27,20 +27,20 @@ const _netbsd = _platform === 'netbsd';
|
||||
const _sunos = _platform === 'sunos';
|
||||
|
||||
function parseUsersLinux(lines, phase) {
|
||||
let result = [];
|
||||
let result_who = [];
|
||||
let result_w = {};
|
||||
const result = [];
|
||||
const result_who = [];
|
||||
const result_w = {};
|
||||
let w_first = true;
|
||||
let w_header = [];
|
||||
let w_pos = [];
|
||||
const w_pos = [];
|
||||
let who_line = {};
|
||||
|
||||
let is_whopart = true;
|
||||
lines.forEach(function (line) {
|
||||
lines.forEach((line) => {
|
||||
if (line === '---') {
|
||||
is_whopart = false;
|
||||
} else {
|
||||
let l = line.replace(/ +/g, ' ').split(' ');
|
||||
const l = line.replace(/ +/g, ' ').split(' ');
|
||||
|
||||
// who part
|
||||
if (is_whopart) {
|
||||
@@ -55,11 +55,13 @@ function parseUsersLinux(lines, phase) {
|
||||
// w part
|
||||
if (w_first) {
|
||||
// header
|
||||
w_header = l;
|
||||
w_header.forEach(function (item) {
|
||||
w_pos.push(line.indexOf(item));
|
||||
});
|
||||
w_first = false;
|
||||
if (line[0] !== ' ') {
|
||||
w_header = l;
|
||||
w_header.forEach((item) => {
|
||||
w_pos.push(line.indexOf(item));
|
||||
});
|
||||
w_first = false;
|
||||
}
|
||||
} else {
|
||||
// split by w_pos
|
||||
result_w.user = line.substring(w_pos[0], w_pos[1] - 1).trim();
|
||||
@@ -71,10 +73,14 @@ function parseUsersLinux(lines, phase) {
|
||||
.trim();
|
||||
result_w.command = line.substring(w_pos[7], 1000).trim();
|
||||
// find corresponding 'who' line
|
||||
who_line = result_who.filter(function (obj) {
|
||||
return obj.user.substring(0, 8).trim() === result_w.user && obj.tty === result_w.tty;
|
||||
});
|
||||
if (who_line.length === 1) {
|
||||
if (result_who.length || phase === 1) {
|
||||
who_line = result_who.filter((obj) => {
|
||||
return obj.user.substring(0, 8).trim() === result_w.user && obj.tty === result_w.tty;
|
||||
});
|
||||
} else {
|
||||
who_line = [{ user: result_w.user, tty: result_w.tty, date: '', time: '', ip: '' }];
|
||||
}
|
||||
if (who_line.length === 1 && who_line[0].user !== '') {
|
||||
result.push({
|
||||
user: who_line[0].user,
|
||||
tty: who_line[0].tty,
|
||||
@@ -96,17 +102,17 @@ function parseUsersLinux(lines, phase) {
|
||||
}
|
||||
|
||||
function parseUsersDarwin(lines) {
|
||||
let result = [];
|
||||
let result_who = [];
|
||||
let result_w = {};
|
||||
const result = [];
|
||||
const result_who = [];
|
||||
const result_w = {};
|
||||
let who_line = {};
|
||||
|
||||
let is_whopart = true;
|
||||
lines.forEach(function (line) {
|
||||
lines.forEach((line) => {
|
||||
if (line === '---') {
|
||||
is_whopart = false;
|
||||
} else {
|
||||
let l = line.replace(/ +/g, ' ').split(' ');
|
||||
const l = line.replace(/ +/g, ' ').split(' ');
|
||||
|
||||
// who part
|
||||
if (is_whopart) {
|
||||
@@ -132,9 +138,7 @@ function parseUsersDarwin(lines) {
|
||||
result_w.ip = l[2] !== '-' ? l[2] : '';
|
||||
result_w.command = l.slice(5, 1000).join(' ');
|
||||
// find corresponding 'who' line
|
||||
who_line = result_who.filter(function (obj) {
|
||||
return obj.user.substring(0, 10) === result_w.user.substring(0, 10) && (obj.tty.substring(3, 1000) === result_w.tty || obj.tty === result_w.tty);
|
||||
});
|
||||
who_line = result_who.filter((obj) => obj.user.substring(0, 10) === result_w.user.substring(0, 10) && (obj.tty.substring(3, 1000) === result_w.tty || obj.tty === result_w.tty));
|
||||
if (who_line.length === 1) {
|
||||
result.push({
|
||||
user: who_line[0].user,
|
||||
@@ -158,13 +162,13 @@ function users(callback) {
|
||||
|
||||
// linux
|
||||
if (_linux) {
|
||||
exec('export LC_ALL=C; who --ips; echo "---"; w; unset LC_ALL | tail -n +2', function (error, stdout) {
|
||||
exec('export LC_ALL=C; who --ips; echo "---"; w; unset LC_ALL | tail -n +2', (error, stdout) => {
|
||||
if (!error) {
|
||||
// lines / split
|
||||
let lines = stdout.toString().split('\n');
|
||||
result = parseUsersLinux(lines, 1);
|
||||
if (result.length === 0) {
|
||||
exec('who; echo "---"; w | tail -n +2', function (error, stdout) {
|
||||
exec('who; echo "---"; w | tail -n +2', (error, stdout) => {
|
||||
if (!error) {
|
||||
// lines / split
|
||||
lines = stdout.toString().split('\n');
|
||||
@@ -190,10 +194,10 @@ function users(callback) {
|
||||
});
|
||||
}
|
||||
if (_freebsd || _openbsd || _netbsd) {
|
||||
exec('who; echo "---"; w -ih', function (error, stdout) {
|
||||
exec('who; echo "---"; w -ih', (error, stdout) => {
|
||||
if (!error) {
|
||||
// lines / split
|
||||
let lines = stdout.toString().split('\n');
|
||||
const lines = stdout.toString().split('\n');
|
||||
result = parseUsersDarwin(lines);
|
||||
}
|
||||
if (callback) {
|
||||
@@ -203,10 +207,10 @@ function users(callback) {
|
||||
});
|
||||
}
|
||||
if (_sunos) {
|
||||
exec('who; echo "---"; w -h', function (error, stdout) {
|
||||
exec('who; echo "---"; w -h', (error, stdout) => {
|
||||
if (!error) {
|
||||
// lines / split
|
||||
let lines = stdout.toString().split('\n');
|
||||
const lines = stdout.toString().split('\n');
|
||||
result = parseUsersDarwin(lines);
|
||||
}
|
||||
if (callback) {
|
||||
@@ -217,10 +221,10 @@ function users(callback) {
|
||||
}
|
||||
|
||||
if (_darwin) {
|
||||
exec('export LC_ALL=C; who; echo "---"; w -ih; unset LC_ALL', function (error, stdout) {
|
||||
exec('export LC_ALL=C; who; echo "---"; w -ih; unset LC_ALL', (error, stdout) => {
|
||||
if (!error) {
|
||||
// lines / split
|
||||
let lines = stdout.toString().split('\n');
|
||||
const lines = stdout.toString().split('\n');
|
||||
result = parseUsersDarwin(lines);
|
||||
}
|
||||
if (callback) {
|
||||
@@ -239,10 +243,10 @@ function users(callback) {
|
||||
util.powerShell(cmd).then((data) => {
|
||||
if (data) {
|
||||
data = data.split('#-#-#-#');
|
||||
let sessions = parseWinSessions((data[0] || '').split(/\n\s*\n/));
|
||||
let loggedons = parseWinLoggedOn((data[1] || '').split(/\n\s*\n/));
|
||||
let queryUser = parseWinUsersQuery((data[3] || '').split('\r\n'));
|
||||
let users = parseWinUsers((data[2] || '').split(/\n\s*\n/), queryUser);
|
||||
const sessions = parseWinSessions((data[0] || '').split(/\n\s*\n/));
|
||||
const loggedons = parseWinLoggedOn((data[1] || '').split(/\n\s*\n/));
|
||||
const queryUser = parseWinUsersQuery((data[3] || '').split('\r\n'));
|
||||
const users = parseWinUsers((data[2] || '').split(/\n\s*\n/), queryUser);
|
||||
for (let id in loggedons) {
|
||||
if ({}.hasOwnProperty.call(loggedons, id)) {
|
||||
loggedons[id].dateTime = {}.hasOwnProperty.call(sessions, id) ? sessions[id] : '';
|
||||
|
||||
Reference in New Issue
Block a user