bugfix users() - parsing values on windows
This commit is contained in:
parent
b999e32cf5
commit
2bfc2707f1
@ -98,6 +98,7 @@ Other changes
|
|||||||
|
|
||||||
| Version | Date | Comment |
|
| Version | Date | Comment |
|
||||||
| -------------- | -------------- | -------- |
|
| -------------- | -------------- | -------- |
|
||||||
|
| 3.30.5 | 2017-10-05 | bugfix `users()` - parsing values on windows |
|
||||||
| 3.30.4 | 2017-10-03 | bugfix `cpuTemperature()` - parsing values on windows |
|
| 3.30.4 | 2017-10-03 | bugfix `cpuTemperature()` - parsing values on windows |
|
||||||
| 3.30.3 | 2017-10-03 | bugfix `cpuTemperature()` - max value on windows |
|
| 3.30.3 | 2017-10-03 | bugfix `cpuTemperature()` - max value on windows |
|
||||||
| 3.30.2 | 2017-09-26 | bugfix `networkInterfaces()` - optimized ip6 address selection |
|
| 3.30.2 | 2017-09-26 | bugfix `networkInterfaces()` - optimized ip6 address selection |
|
||||||
|
|||||||
30
README.md
30
README.md
@ -205,20 +205,22 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (
|
|||||||
| | currentcapacity | X | X | X | current capacity of battery |
|
| | currentcapacity | X | X | X | current capacity of battery |
|
||||||
| | percent | X | X | X | charging level in percent |
|
| | percent | X | X | X | charging level in percent |
|
||||||
| si.graphics(cb) | {...} | X | X | X | arrays of graphics controllers and displays |
|
| si.graphics(cb) | {...} | X | X | X | arrays of graphics controllers and displays |
|
||||||
| | controllers[0].model | X | X | X | graphics controller model |
|
| | controllers[]| X | X | X | graphics controllers array |
|
||||||
| | controllers[0].vendor | X | X | X | e.g. ATI |
|
| | ...[0].model | X | X | X | graphics controller model |
|
||||||
| | controllers[0].bus | X | X | X| on which bus (e.g. PCIe) |
|
| | ...[0].vendor | X | X | X | e.g. ATI |
|
||||||
| | controllers[0].vram | X | X | X | VRAM size (in MB) |
|
| | ...[0].bus | X | X | X| on which bus (e.g. PCIe) |
|
||||||
| | controllers[0].vramDynamic | X | X | X | true if dynamicly allocated ram |
|
| | ...[0].vram | X | X | X | VRAM size (in MB) |
|
||||||
| | displays[0].model | X | X | X | Monitor/Display Model |
|
| | ...[0].vramDynamic | X | X | X | true if dynamicly allocated ram |
|
||||||
| | displays[0].main | X | X | | true if main monitor |
|
| | displays[] | X | X | X | Monitor/Display Array |
|
||||||
| | displays[0].builtin | X | X | | true if built in monitor |
|
| | ...[0].model | X | X | X | Monitor/Display Model |
|
||||||
| | displays[0].connection | X | X | | e.g. DisplayPort or HDMI |
|
| | ...[0].main | X | X | | true if main monitor |
|
||||||
| | displays[0].resolutionx | X | X | X | pixel horizontal |
|
| | ...[0].builtin | X | X | | true if built in monitor |
|
||||||
| | displays[0].resolutiony | X | X | X | pixel vertical |
|
| | ...[0].connection | X | X | | e.g. DisplayPort or HDMI |
|
||||||
| | displays[0].pixeldepth | X | X | X | color depth in bits |
|
| | ...[0].resolutionx | X | X | X | pixel horizontal |
|
||||||
| | displays[0].sizex | X | X | | size in mm horizontal |
|
| | ...[0].resolutiony | X | X | X | pixel vertical |
|
||||||
| | displays[0].sizey | X | X | | size in mm vertical |
|
| | ...[0].pixeldepth | X | X | X | color depth in bits |
|
||||||
|
| | ...[0].sizex | X | X | | size in mm horizontal |
|
||||||
|
| | ...[0].sizey | X | X | | size in mm vertical |
|
||||||
|
|
||||||
#### 4. Operating System
|
#### 4. Operating System
|
||||||
|
|
||||||
|
|||||||
98
lib/users.js
98
lib/users.js
@ -26,7 +26,7 @@ const NOT_SUPPORTED = 'not supported';
|
|||||||
// --------------------------
|
// --------------------------
|
||||||
// array of users online = sessions
|
// array of users online = sessions
|
||||||
|
|
||||||
function parseUsers1(lines) {
|
function parseUsersLinux(lines) {
|
||||||
let result = [];
|
let result = [];
|
||||||
let result_who = [];
|
let result_who = [];
|
||||||
let result_w = {};
|
let result_w = {};
|
||||||
@ -88,7 +88,7 @@ function parseUsers1(lines) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseUsers2(lines) {
|
function parseUsersDarwin(lines) {
|
||||||
let result = [];
|
let result = [];
|
||||||
let result_who = [];
|
let result_who = [];
|
||||||
let result_w = {};
|
let result_w = {};
|
||||||
@ -136,6 +136,79 @@ function parseUsers2(lines) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseUsersWin(lines) {
|
||||||
|
|
||||||
|
function parseDateTime(dt) {
|
||||||
|
const result = {
|
||||||
|
date: '',
|
||||||
|
time: ''
|
||||||
|
}
|
||||||
|
const parts = dt.split(' ');
|
||||||
|
if (parts[0]) {
|
||||||
|
if (parts[0].indexOf('/') >= 0) {
|
||||||
|
// Dateformat: mm/dd/yyyy
|
||||||
|
const dtparts = parts[0].split('/');
|
||||||
|
if (dtparts.length === 3) {
|
||||||
|
result.date = dtparts[2] + '-' + ('0' + dtparts[0]).substr(-2) + '-' + ('0' + dtparts[1]).substr(-2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (parts[0].indexOf('.') >= 0) {
|
||||||
|
// Dateformat: dd.mm.yyyy
|
||||||
|
const dtparts = parts[0].split('.');
|
||||||
|
if (dtparts.length === 3) {
|
||||||
|
result.date = dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (parts[0].indexOf('-') >= 0) {
|
||||||
|
// Dateformat: yyyy-mm-dd
|
||||||
|
const dtparts = parts[0].split('-');
|
||||||
|
if (dtparts.length === 3) {
|
||||||
|
result.date = dtparts[0] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[2]).substr(-2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (parts[1]) {
|
||||||
|
result.time = parts[1];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = [];
|
||||||
|
const header = lines[0];
|
||||||
|
const headerDelimiter = [];
|
||||||
|
if (header) {
|
||||||
|
const start = (header[0] === ' ') ? 1 : 0;
|
||||||
|
headerDelimiter.push(start-1);
|
||||||
|
let nextSpace = 0
|
||||||
|
for (let i = start+1; i < header.length; i++) {
|
||||||
|
if (header[i] === ' ' && header[i-1] === ' ') {
|
||||||
|
nextSpace = i;
|
||||||
|
} else {
|
||||||
|
if (nextSpace) {
|
||||||
|
headerDelimiter.push(nextSpace);
|
||||||
|
nextSpace = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let i = 1; i < lines.length; i++) {
|
||||||
|
if (lines[i].trim()) {
|
||||||
|
const user = lines[i].substring(headerDelimiter[0]+1, headerDelimiter[1]).trim() || '';
|
||||||
|
const tty = lines[i].substring(headerDelimiter[1]+1, headerDelimiter[2] - 2).trim() || '';
|
||||||
|
const dateTime = parseDateTime(lines[i].substring(headerDelimiter[5]+1, 2000).trim()) || '';
|
||||||
|
result.push({
|
||||||
|
user: user,
|
||||||
|
tty: tty,
|
||||||
|
date: dateTime.date,
|
||||||
|
time: dateTime.time,
|
||||||
|
ip: '',
|
||||||
|
command: ''
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
function users(callback) {
|
function users(callback) {
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -148,13 +221,13 @@ function users(callback) {
|
|||||||
if (!error) {
|
if (!error) {
|
||||||
// lines / split
|
// lines / split
|
||||||
let lines = stdout.toString().split('\n');
|
let lines = stdout.toString().split('\n');
|
||||||
result = parseUsers1(lines);
|
result = parseUsersLinux(lines);
|
||||||
if (result.length === 0) {
|
if (result.length === 0) {
|
||||||
exec("who; echo '---'; w | tail -n +2", function (error, stdout) {
|
exec("who; echo '---'; w | tail -n +2", function (error, stdout) {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
// lines / split
|
// lines / split
|
||||||
lines = stdout.toString().split('\n');
|
lines = stdout.toString().split('\n');
|
||||||
result = parseUsers1(lines);
|
result = parseUsersLinux(lines);
|
||||||
}
|
}
|
||||||
if (callback) { callback(result) }
|
if (callback) { callback(result) }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
@ -175,7 +248,7 @@ function users(callback) {
|
|||||||
if (!error) {
|
if (!error) {
|
||||||
// lines / split
|
// lines / split
|
||||||
let lines = stdout.toString().split('\n');
|
let lines = stdout.toString().split('\n');
|
||||||
result = parseUsers2(lines);
|
result = parseUsersDarwin(lines);
|
||||||
}
|
}
|
||||||
if (callback) { callback(result) }
|
if (callback) { callback(result) }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
@ -186,20 +259,7 @@ function users(callback) {
|
|||||||
if (stdout) {
|
if (stdout) {
|
||||||
// lines / split
|
// lines / split
|
||||||
let lines = stdout.toString().split('\r\n');
|
let lines = stdout.toString().split('\r\n');
|
||||||
lines.shift();
|
result = parseUsersWin(lines);
|
||||||
lines.forEach(function (line) {
|
|
||||||
let l = line.replace(/ +/g, " ").split(' ');
|
|
||||||
if (l.length >= 7) {
|
|
||||||
result.push({
|
|
||||||
user: l[0].replace(/>/g, " "),
|
|
||||||
tty: l[1],
|
|
||||||
date: l[5].substr(6,4) + '-' + l[5].substr(3,2) + '-' + l[5].substr(0,2),
|
|
||||||
time: l[4],
|
|
||||||
ip: '',
|
|
||||||
command: ''
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if (callback) { callback(result) }
|
if (callback) { callback(result) }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user