users parsing fix (windows)

This commit is contained in:
Sebastian Hildebrandt 2019-05-08 13:18:31 +02:00
parent 0017a7db5f
commit 9329bc7190
4 changed files with 22 additions and 16 deletions

View File

@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page.
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 4.1.7 | 2019-05-08 | `users()` parsing fix (windows) |
| 4.1.6 | 2019-04-24 | `memory()` swap used fix (linux) |
| 4.1.5 | 2019-04-19 | refactored `wmic` calls to work also on Windows XP |
| 4.1.4 | 2019-03-26 | `networkInterfaces()` speed bug (windows) |

View File

@ -80,6 +80,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">4.1.7</th>
<td>2019-05-08</td>
<td><span class="code">users()</span> parsing fix (windows)</td>
</tr>
<tr>
<th scope="row">4.1.6</th>
<td>2019-04-24</td>

View File

@ -150,7 +150,7 @@ function parseUsersWin(lines) {
headerDelimiter.push(start - 1);
let nextSpace = 0;
for (let i = start + 1; i < header.length; i++) {
if (header[i] === ' ' && header[i - 1] === ' ') {
if (header[i] === ' ' && ((header[i - 1] === ' ') || (header[i - 1] === '.'))) {
nextSpace = i;
} else {
if (nextSpace) {
@ -159,20 +159,20 @@ function parseUsersWin(lines) {
}
}
}
}
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 = util.parseDateTime(lines[i].substring(headerDelimiter[5] + 1, 2000).trim()) || '';
result.push({
user: user,
tty: tty,
date: dateTime.date,
time: dateTime.time,
ip: '',
command: ''
});
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 = util.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;

View File

@ -111,7 +111,7 @@ function decodeEscapeSequence(str, base) {
function parseTime(t) {
t = t.toUpperCase();
const parts = t.split(':');
let isPM = (parts[1] && parts[1].indexOf('PM') > -1);
let isPM = (parts[1] && (parts[1].toLowerCase().indexOf('pm') > -1) || (parts[1].toLowerCase().indexOf('p.m.') > -1));
let hour = parseInt(parts[0], 10);
const min = parseInt(parts[1], 10);
hour = isPM && hour < 12 ? hour + 12 : hour;