@depup/systeminformation 5.31.4-depup.0 → 5.33.1-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/network.js CHANGED
@@ -16,6 +16,9 @@
16
16
  const os = require('os');
17
17
  const exec = require('child_process').exec;
18
18
  const execSync = require('child_process').execSync;
19
+ const execFileSync = require('child_process').execFileSync;
20
+ const readFileSync = require('fs').readFileSync;
21
+
19
22
  const fs = require('fs');
20
23
  const util = require('./util');
21
24
 
@@ -416,15 +419,7 @@ function getWindowsIEEE8021x(connectionType, iface, ifaces) {
416
419
  try {
417
420
  const SSID = getWindowsWirelessIfaceSSID(iface);
418
421
  if (SSID !== 'Unknown') {
419
- let ifaceSanitized = '';
420
- const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(SSID);
421
- const l = util.mathMin(s.length, 32);
422
-
423
- for (let i = 0; i <= l; i++) {
424
- if (s[i] !== undefined) {
425
- ifaceSanitized = ifaceSanitized + s[i];
426
- }
427
- }
422
+ const ifaceSanitized = util.sanitizeString(SSID);
428
423
  const profiles = execSync(`netsh wlan show profiles "${ifaceSanitized}"`, util.execOptsWin).split('\r\n');
429
424
  i8021xState = (profiles.find((l) => l.indexOf('802.1X') >= 0) || '').trim();
430
425
  i8021xProtocol = (profiles.find((l) => l.indexOf('EAP') >= 0) || '').trim();
@@ -536,24 +531,30 @@ function getDarwinNics() {
536
531
  }
537
532
 
538
533
  function getLinuxIfaceConnectionName(interfaceName) {
539
- const cmd = `nmcli device status 2>/dev/null | grep ${interfaceName}`;
540
-
541
534
  try {
542
- const result = execSync(cmd, util.execOptsLinux).toString();
535
+ const output = execFileSync('nmcli', ['device', 'status'], { ...util.execOptsLinux, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
536
+ const result = util.grep(output, interfaceName);
537
+
543
538
  const resultFormat = result.replace(/\s+/g, ' ').trim();
544
539
  const connectionNameLines = resultFormat.split(' ').slice(3);
545
540
  const connectionName = connectionNameLines.join(' ');
546
- return connectionName !== '--' ? connectionName : '';
541
+ const connectionNameSanitized = util.sanitizeString(connectionName, false);
542
+
543
+ return connectionNameSanitized !== '--' ? connectionNameSanitized : '';
547
544
  } catch {
548
545
  return '';
549
546
  }
550
547
  }
551
548
 
552
- function checkLinuxDCHPInterfaces(file) {
549
+ function checkLinuxDCHPInterfaces(file, depth) {
553
550
  let result = [];
551
+ depth = depth || 0;
552
+ if (depth > 10) {
553
+ return result;
554
+ }
554
555
  try {
555
- const cmd = `cat ${file} 2> /dev/null | grep 'iface\\|source'`;
556
- const lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
556
+ const content = readFileSync(file, { encoding: 'utf8' });
557
+ const lines = content.split('\n').filter((l) => /iface|source/.test(l));
557
558
 
558
559
  lines.forEach((line) => {
559
560
  const parts = line.replace(/\s+/g, ' ').trim().split(' ');
@@ -564,7 +565,7 @@ function checkLinuxDCHPInterfaces(file) {
564
565
  }
565
566
  if (line.toLowerCase().includes('source')) {
566
567
  const file = line.split(' ')[1];
567
- result = result.concat(checkLinuxDCHPInterfaces(file));
568
+ result = result.concat(checkLinuxDCHPInterfaces(file, depth + 1));
568
569
  }
569
570
  });
570
571
  } catch {
@@ -617,9 +618,9 @@ function parseLinuxDHCPNics(sections) {
617
618
  function getLinuxIfaceDHCPstatus(iface, connectionName, DHCPNics) {
618
619
  let result = false;
619
620
  if (connectionName) {
620
- const cmd = `nmcli connection show "${connectionName}" 2>/dev/null | grep ipv4.method;`;
621
621
  try {
622
- const lines = execSync(cmd, util.execOptsLinux).toString();
622
+ const output = execFileSync('nmcli', ['connection', 'show', connectionName], { ...util.execOptsLinux, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
623
+ const lines = util.grep(output, 'ipv4.method');
623
624
  const resultFormat = lines.replace(/\s+/g, ' ').trim();
624
625
 
625
626
  const dhcStatus = resultFormat.split(' ').slice(1).toString();
@@ -643,9 +644,10 @@ function getLinuxIfaceDHCPstatus(iface, connectionName, DHCPNics) {
643
644
 
644
645
  function getDarwinIfaceDHCPstatus(iface) {
645
646
  let result = false;
646
- const cmd = `ipconfig getpacket "${iface}" 2>/dev/null | grep lease_time;`;
647
+
647
648
  try {
648
- const lines = execSync(cmd).toString().split('\n');
649
+ const output = execFileSync('ipconfig', ['getpacket', iface], { ...util.execOptsLinux, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
650
+ const lines = util.grep(output, 'lease_time');
649
651
  if (lines.length && lines[0].startsWith('lease_time')) {
650
652
  result = true;
651
653
  }
@@ -657,9 +659,9 @@ function getDarwinIfaceDHCPstatus(iface) {
657
659
 
658
660
  function getLinuxIfaceDNSsuffix(connectionName) {
659
661
  if (connectionName) {
660
- const cmd = `nmcli connection show "${connectionName}" 2>/dev/null | grep ipv4.dns-search;`;
661
662
  try {
662
- const result = execSync(cmd, util.execOptsLinux).toString();
663
+ const output = execFileSync('nmcli', ['connection', 'show', connectionName], { ...util.execOptsLinux, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
664
+ const result = util.grep(output, 'ipv4.dns-search');
663
665
  const resultFormat = result.replace(/\s+/g, ' ').trim();
664
666
  const dnsSuffix = resultFormat.split(' ').slice(1).toString();
665
667
  return dnsSuffix === '--' ? 'Not defined' : dnsSuffix;
@@ -673,9 +675,9 @@ function getLinuxIfaceDNSsuffix(connectionName) {
673
675
 
674
676
  function getLinuxIfaceIEEE8021xAuth(connectionName) {
675
677
  if (connectionName) {
676
- const cmd = `nmcli connection show "${connectionName}" 2>/dev/null | grep 802-1x.eap;`;
677
678
  try {
678
- const result = execSync(cmd, util.execOptsLinux).toString();
679
+ const output = execFileSync('nmcli', ['connection', 'show', connectionName], { ...util.execOptsLinux, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
680
+ const result = util.grep(output, '802-1x.eap');
679
681
  const resultFormat = result.replace(/\s+/g, ' ').trim();
680
682
  const authenticationProtocol = resultFormat.split(' ').slice(1).toString();
681
683
 
@@ -825,14 +827,7 @@ function networkInterfaces(callback, rescan, defaultString) {
825
827
  nic.ip6subnet = ip6linksubnet;
826
828
  }
827
829
 
828
- let ifaceSanitized = '';
829
- const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(nic.iface);
830
- const l = util.mathMin(s.length, 2000);
831
- for (let i = 0; i <= l; i++) {
832
- if (s[i] !== undefined) {
833
- ifaceSanitized = ifaceSanitized + s[i];
834
- }
835
- }
830
+ const ifaceSanitized = util.sanitizeString(nic.iface);
836
831
 
837
832
  result.push({
838
833
  iface: nic.iface,
@@ -948,14 +943,7 @@ function networkInterfaces(callback, rescan, defaultString) {
948
943
  ip6subnet = ip6linksubnet;
949
944
  }
950
945
  const iface = dev.split(':')[0].trim();
951
- let ifaceSanitized = '';
952
- const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(iface);
953
- const l = util.mathMin(s.length, 2000);
954
- for (let i = 0; i <= l; i++) {
955
- if (s[i] !== undefined) {
956
- ifaceSanitized = ifaceSanitized + s[i];
957
- }
958
- }
946
+ const ifaceSanitized = util.sanitizeString(iface);
959
947
  const cmd = `echo -n "addr_assign_type: "; cat /sys/class/net/${ifaceSanitized}/addr_assign_type 2>/dev/null; echo;
960
948
  echo -n "address: "; cat /sys/class/net/${ifaceSanitized}/address 2>/dev/null; echo;
961
949
  echo -n "addr_len: "; cat /sys/class/net/${ifaceSanitized}/addr_len 2>/dev/null; echo;
@@ -1087,14 +1075,7 @@ function networkInterfaces(callback, rescan, defaultString) {
1087
1075
  nics8021xInfo = getWindowsWiredProfilesInformation();
1088
1076
  dnsSuffixes = getWindowsDNSsuffixes();
1089
1077
  for (let dev in ifaces) {
1090
- let ifaceSanitized = '';
1091
- const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(dev);
1092
- const l = util.mathMin(s.length, 2000);
1093
- for (let i = 0; i <= l; i++) {
1094
- if (s[i] !== undefined) {
1095
- ifaceSanitized = ifaceSanitized + s[i];
1096
- }
1097
- }
1078
+ const ifaceSanitized = util.sanitizeString(dev);
1098
1079
 
1099
1080
  let iface = dev;
1100
1081
  let ip4 = '';
@@ -1340,17 +1321,18 @@ function networkStatsSingle(iface) {
1340
1321
  if (sections[i].trim() !== '') {
1341
1322
  const lines = sections[i].trim().split('\r\n');
1342
1323
  perfData.push({
1343
- name: util
1344
- .getValue(lines, 'Name', ':')
1324
+ name: util.getValue(lines, 'Name', ':').toLowerCase(),
1325
+ desc: util
1326
+ .getValue(lines, 'InterfaceDescription', ':')
1345
1327
  .replace(/[()[\] ]+/g, '')
1346
1328
  .replace(/#|\//g, '_')
1347
1329
  .toLowerCase(),
1348
- rx_bytes: parseInt(util.getValue(lines, 'BytesReceivedPersec', ':'), 10),
1349
- rx_errors: parseInt(util.getValue(lines, 'PacketsReceivedErrors', ':'), 10),
1350
- rx_dropped: parseInt(util.getValue(lines, 'PacketsReceivedDiscarded', ':'), 10),
1351
- tx_bytes: parseInt(util.getValue(lines, 'BytesSentPersec', ':'), 10),
1352
- tx_errors: parseInt(util.getValue(lines, 'PacketsOutboundErrors', ':'), 10),
1353
- tx_dropped: parseInt(util.getValue(lines, 'PacketsOutboundDiscarded', ':'), 10)
1330
+ rx_bytes: parseInt(util.getValue(lines, 'ReceivedBytes', ':'), 10),
1331
+ rx_errors: parseInt(util.getValue(lines, 'ReceivedPacketErrors', ':'), 10),
1332
+ rx_dropped: parseInt(util.getValue(lines, 'ReceivedDiscardedPackets', ':'), 10),
1333
+ tx_bytes: parseInt(util.getValue(lines, 'SentBytes', ':'), 10),
1334
+ tx_errors: parseInt(util.getValue(lines, 'OutboundPacketErrors', ':'), 10),
1335
+ tx_dropped: parseInt(util.getValue(lines, 'OutboundDiscardedPackets', ':'), 10)
1354
1336
  });
1355
1337
  }
1356
1338
  }
@@ -1360,14 +1342,7 @@ function networkStatsSingle(iface) {
1360
1342
 
1361
1343
  return new Promise((resolve) => {
1362
1344
  process.nextTick(() => {
1363
- let ifaceSanitized = '';
1364
- const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(iface);
1365
- const l = util.mathMin(s.length, 2000);
1366
- for (let i = 0; i <= l; i++) {
1367
- if (s[i] !== undefined) {
1368
- ifaceSanitized = ifaceSanitized + s[i];
1369
- }
1370
- }
1345
+ const ifaceSanitized = util.sanitizeString(iface, true);
1371
1346
 
1372
1347
  let result = {
1373
1348
  iface: ifaceSanitized,
@@ -1456,7 +1431,7 @@ function networkStatsSingle(iface) {
1456
1431
  rx_errors = rx_errors + parseInt(line[5]);
1457
1432
  }
1458
1433
  tx_bytes = tx_bytes + parseInt(line[10]);
1459
- if (line[12].trim() !== '-') {
1434
+ if (line[12] && line[12].trim() !== '-') {
1460
1435
  tx_dropped = tx_dropped + parseInt(line[12]);
1461
1436
  }
1462
1437
  if (line[9].trim() !== '-') {
@@ -1476,7 +1451,7 @@ function networkStatsSingle(iface) {
1476
1451
  result.operstate = (stdout.toString().split(':')[1] || '').trim();
1477
1452
  result.operstate = (result.operstate || '').toLowerCase();
1478
1453
  result.operstate = result.operstate === 'active' ? 'up' : result.operstate === 'inactive' ? 'down' : 'unknown';
1479
- cmd = 'netstat -bdI ' + ifaceSanitized; // lgtm [js/shell-command-constructed-from-input]
1454
+ cmd = 'netstat -bdnI ' + ifaceSanitized; // lgtm [js/shell-command-constructed-from-input]
1480
1455
  exec(cmd, (error, stdout) => {
1481
1456
  if (!error) {
1482
1457
  lines = stdout.toString().split('\n');
@@ -1506,7 +1481,7 @@ function networkStatsSingle(iface) {
1506
1481
  // Performance Data
1507
1482
  util
1508
1483
  .powerShell(
1509
- 'Get-CimInstance Win32_PerfRawData_Tcpip_NetworkInterface | select Name,BytesReceivedPersec,PacketsReceivedErrors,PacketsReceivedDiscarded,BytesSentPersec,PacketsOutboundErrors,PacketsOutboundDiscarded | fl'
1484
+ 'Get-NetAdapterStatistics | select Name,InterfaceDescription,ReceivedBytes,ReceivedPacketErrors,ReceivedDiscardedPackets,SentBytes,OutboundPacketErrors,OutboundDiscardedPackets | fl'
1510
1485
  )
1511
1486
  .then((stdout, error) => {
1512
1487
  if (!error) {
@@ -1534,10 +1509,11 @@ function networkStatsSingle(iface) {
1534
1509
  .replace(/[()[\] ]+/g, '')
1535
1510
  .replace('#', '_')
1536
1511
  .toLowerCase()) &&
1537
- det.ifaceName
1538
- .replace(/[()[\] ]+/g, '')
1539
- .replace(/#|\//g, '_')
1540
- .toLowerCase() === detail.name
1512
+ (det.iface.toLowerCase() === detail.name ||
1513
+ det.ifaceName
1514
+ .replace(/[()[\] ]+/g, '')
1515
+ .replace(/#|\//g, '_')
1516
+ .toLowerCase() === detail.desc)
1541
1517
  ) {
1542
1518
  ifaceName = det.iface;
1543
1519
  rx_bytes = detail.rx_bytes;
@@ -1755,10 +1731,10 @@ function networkConnections(callback) {
1755
1731
  const hasState = states.indexOf(line[5]) >= 0;
1756
1732
  const connstate = hasState ? line[5] : 'UNKNOWN';
1757
1733
  let pidField = '';
1758
- if (line[line.length - 9].indexOf(':') >= 0) {
1734
+ if (line[line.length - 9] && line[line.length - 9].indexOf(':') >= 0) {
1759
1735
  pidField = line[line.length - 9].split(':')[1];
1760
1736
  } else {
1761
- pidField = line[pidPos + (hasState ? 0 : -1)];
1737
+ pidField = line[pidPos + (hasState ? 0 : -1)] || '';
1762
1738
 
1763
1739
  if (pidField.indexOf(':') >= 0) {
1764
1740
  pidField = pidField.split(':')[1];
@@ -1784,6 +1760,11 @@ function networkConnections(callback) {
1784
1760
  }
1785
1761
  resolve(result);
1786
1762
  });
1763
+ } else {
1764
+ if (callback) {
1765
+ callback(result);
1766
+ }
1767
+ resolve(result);
1787
1768
  }
1788
1769
  });
1789
1770
  }
@@ -1874,6 +1855,11 @@ function networkConnections(callback) {
1874
1855
  callback(result);
1875
1856
  }
1876
1857
  resolve(result);
1858
+ } else {
1859
+ if (callback) {
1860
+ callback(result);
1861
+ }
1862
+ resolve(result);
1877
1863
  }
1878
1864
  });
1879
1865
  } catch {
package/lib/osinfo.js CHANGED
@@ -18,6 +18,7 @@ const fs = require('fs');
18
18
  const util = require('./util');
19
19
  const exec = require('child_process').exec;
20
20
  const execSync = require('child_process').execSync;
21
+ const execFile = require('child_process').execFile;
21
22
 
22
23
  const _platform = process.platform;
23
24
 
@@ -189,7 +190,7 @@ function getWindowsRelease(build) {
189
190
  // FQDN
190
191
 
191
192
  function getFQDN() {
192
- let fqdn = os.hostname;
193
+ let fqdn = os.hostname();
193
194
  if (_linux || _darwin) {
194
195
  try {
195
196
  const stdout = execSync('hostname -f 2>/dev/null', util.execOptsLinux);
@@ -291,7 +292,7 @@ function osInfo(callback) {
291
292
  const distro = util.getValue(lines, 'kern.ostype');
292
293
  const logofile = getLogoFile(distro);
293
294
  const release = util.getValue(lines, 'kern.osrelease').split('-')[0];
294
- const serial = util.getValue(lines, 'kern.uuid');
295
+ const serial = util.getValue(lines, 'kern.hostuuid');
295
296
  const bootmethod = util.getValue(lines, 'machdep.bootmethod');
296
297
  const uefiConf = stdout.toString().indexOf('<type>efi</type>') >= 0;
297
298
  const uefi = bootmethod ? bootmethod.toLowerCase().indexOf('uefi') >= 0 : uefiConf ? uefiConf : null;
@@ -546,6 +547,13 @@ function versions(apps, callback) {
546
547
  const appsObj = checkVersionParam(apps);
547
548
  let totalFunctions = appsObj.counter;
548
549
 
550
+ if (totalFunctions <= 0) {
551
+ if (callback) {
552
+ callback(appsObj.versions);
553
+ }
554
+ return resolve(appsObj.versions);
555
+ }
556
+
549
557
  let functionProcessed = (() => {
550
558
  return () => {
551
559
  if (--totalFunctions === 0) {
@@ -820,15 +828,22 @@ function versions(apps, callback) {
820
828
  if (!error) {
821
829
  const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
822
830
  appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
831
+ if (appsObj.versions.postgresql.includes('(') && postgresql.length >= 2 && !postgresql[postgresql.length - 2].includes('(')) {
832
+ appsObj.versions.postgresql = postgresql[postgresql.length - 2];
833
+ }
834
+ functionProcessed();
823
835
  } else {
824
836
  exec('pg_config --version', (error, stdout) => {
825
837
  if (!error) {
826
838
  const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
827
839
  appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
840
+ if (appsObj.versions.postgresql.includes('(') && postgresql.length >= 2 && !postgresql[postgresql.length - 2].includes('(')) {
841
+ appsObj.versions.postgresql = postgresql[postgresql.length - 2];
842
+ }
828
843
  }
844
+ functionProcessed();
829
845
  });
830
846
  }
831
- functionProcessed();
832
847
  });
833
848
  }
834
849
  }
@@ -1144,7 +1159,6 @@ function shell(callback) {
1144
1159
  process.nextTick(() => {
1145
1160
  if (_windows) {
1146
1161
  try {
1147
- const result = 'CMD';
1148
1162
  util.powerShell(`Get-CimInstance -className win32_process | where-object {$_.ProcessId -eq ${process.ppid} } | select Name`).then((stdout) => {
1149
1163
  let result = 'CMD';
1150
1164
  if (stdout) {
@@ -1159,9 +1173,9 @@ function shell(callback) {
1159
1173
  });
1160
1174
  } catch {
1161
1175
  if (callback) {
1162
- callback(result);
1176
+ callback('CMD');
1163
1177
  }
1164
- resolve(result);
1178
+ resolve('CMD');
1165
1179
  }
1166
1180
  } else {
1167
1181
  let result = '';
@@ -1251,9 +1265,13 @@ echo -n "hardware: "; cat /sys/class/dmi/id/product_uuid 2> /dev/null; echo;`;
1251
1265
  result.os = util.getValue(lines, 'os').toLowerCase();
1252
1266
  result.hardware = util.getValue(lines, 'hardware').toLowerCase();
1253
1267
  if (!result.hardware) {
1254
- const lines = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
1255
- const serial = util.getValue(lines, 'serial');
1256
- result.hardware = serial || '';
1268
+ try {
1269
+ const lines = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
1270
+ const serial = util.getValue(lines, 'serial');
1271
+ result.hardware = serial || '';
1272
+ } catch {
1273
+ result.hardware = '';
1274
+ }
1257
1275
  }
1258
1276
  if (callback) {
1259
1277
  callback(result);
package/lib/printer.js CHANGED
@@ -121,7 +121,7 @@ function printer(callback) {
121
121
  // printers.conf
122
122
  if (!error) {
123
123
  const parts = stdout.toString().split('<Printer ');
124
- const printerHeader = parseLinuxCupsHeader(parts[0]);
124
+ const printerHeader = parseLinuxCupsHeader(parts[0].split('\n'));
125
125
  for (let i = 1; i < parts.length; i++) {
126
126
  const printers = parseLinuxCupsPrinter(parts[i].split('\n'));
127
127
  if (printers.name) {
@@ -141,11 +141,11 @@ function printer(callback) {
141
141
  const printers = parseLinuxLpstatPrinter(parts[i].split('\n'), i);
142
142
  result.push(printers);
143
143
  }
144
+ if (callback) {
145
+ callback(result);
146
+ }
147
+ resolve(result);
144
148
  });
145
- if (callback) {
146
- callback(result);
147
- }
148
- resolve(result);
149
149
  } else {
150
150
  if (callback) {
151
151
  callback(result);
package/lib/processes.js CHANGED
@@ -207,7 +207,7 @@ function services(srv, callback) {
207
207
  if (callback) {
208
208
  callback(result);
209
209
  }
210
- resolve(result);
210
+ return resolve(result);
211
211
  }
212
212
  let args = _darwin ? ['-caxo', 'pcpu,pmem,pid,command'] : ['-axo', 'pcpu,pmem,pid,command'];
213
213
  if (srvString !== '' && srvs.length > 0) {
@@ -307,7 +307,7 @@ function services(srv, callback) {
307
307
  // store old values
308
308
  _services_cpu.all = all;
309
309
  _services_cpu.list = Object.assign({}, list_new);
310
- _services_cpu.ms = Date.now() - _services_cpu.ms;
310
+ _services_cpu.ms = Date.now();
311
311
  _services_cpu.result = Object.assign({}, result);
312
312
  if (callback) {
313
313
  callback(result);
@@ -365,8 +365,7 @@ function services(srv, callback) {
365
365
  }
366
366
  resolve(result);
367
367
  }
368
- }
369
- if (_windows) {
368
+ } else if (_windows) {
370
369
  try {
371
370
  let wincommand = 'Get-CimInstance Win32_Service';
372
371
  if (srvs[0] !== '*') {
@@ -442,6 +441,11 @@ function services(srv, callback) {
442
441
  }
443
442
  resolve(result);
444
443
  }
444
+ } else {
445
+ if (callback) {
446
+ callback(result);
447
+ }
448
+ resolve(result);
445
449
  }
446
450
  } else {
447
451
  if (callback) {
@@ -568,6 +572,9 @@ function processes(callback) {
568
572
  }
569
573
 
570
574
  function parseLine(line) {
575
+ if (parsedhead.length < 13) {
576
+ return null;
577
+ }
571
578
  let offset = 0;
572
579
  let offset2 = 0;
573
580
 
@@ -709,7 +716,10 @@ function processes(callback) {
709
716
  lines.shift();
710
717
  lines.forEach((line) => {
711
718
  if (line.trim() !== '') {
712
- result.push(parseLine(line));
719
+ const parsed = parseLine(line);
720
+ if (parsed) {
721
+ result.push(parsed);
722
+ }
713
723
  }
714
724
  });
715
725
  }
@@ -737,7 +747,15 @@ function processes(callback) {
737
747
  started = formatDateTime(new Date(Date.now() - (elapsed_parts[0] * 60 + elapsed_parts[1] * 1) * 60 * 1000));
738
748
  } else if (etime.indexOf(':') >= 0) {
739
749
  const elapsed_parts = etime.split(':');
740
- started = formatDateTime(new Date(Date.now() - (elapsed_parts.length > 1 ? (elapsed_parts[0] * 60 + elapsed_parts[1]) * 1000 : elapsed_parts[0] * 1000)));
750
+ let seconds = 0;
751
+ if (elapsed_parts.length === 3) {
752
+ seconds = elapsed_parts[0] * 3600 + elapsed_parts[1] * 60 + elapsed_parts[2] * 1;
753
+ } else if (elapsed_parts.length === 2) {
754
+ seconds = elapsed_parts[0] * 60 + elapsed_parts[1] * 1;
755
+ } else {
756
+ seconds = elapsed_parts[0] * 1;
757
+ }
758
+ started = formatDateTime(new Date(Date.now() - seconds * 1000));
741
759
  }
742
760
  return started;
743
761
  }
@@ -877,7 +895,7 @@ function processes(callback) {
877
895
  // store old values
878
896
  _processes_cpu.all = all;
879
897
  _processes_cpu.list = Object.assign({}, list_new);
880
- _processes_cpu.ms = Date.now() - _processes_cpu.ms;
898
+ _processes_cpu.ms = Date.now();
881
899
  _processes_cpu.result = Object.assign({}, result);
882
900
  if (callback) {
883
901
  callback(result);
@@ -948,6 +966,9 @@ function processes(callback) {
948
966
  try {
949
967
  stdout = stdout.trim().replace(/^\uFEFF/, '');
950
968
  processArray = JSON.parse(stdout);
969
+ if (!Array.isArray(processArray)) {
970
+ processArray = [processArray];
971
+ }
951
972
  } catch {}
952
973
  processArray.forEach((element) => {
953
974
  const pid = element.ProcessId;
@@ -989,7 +1010,7 @@ function processes(callback) {
989
1010
  cpuu: 0,
990
1011
  cpus: 0,
991
1012
  mem: (memw / os.totalmem()) * 100,
992
- priority: element.Priority | null,
1013
+ priority: element.Priority || null,
993
1014
  memVsz: element.PageFileUsage || null,
994
1015
  memRss: Math.floor((element.WorkingSetSize || 0) / 1024),
995
1016
  nice: 0,
@@ -1030,7 +1051,7 @@ function processes(callback) {
1030
1051
  _processes_cpu.all_utime = allcpuu;
1031
1052
  _processes_cpu.all_stime = allcpus;
1032
1053
  _processes_cpu.list = Object.assign({}, list_new);
1033
- _processes_cpu.ms = Date.now() - _processes_cpu.ms;
1054
+ _processes_cpu.ms = Date.now();
1034
1055
  _processes_cpu.result = Object.assign({}, result);
1035
1056
  }
1036
1057
  if (callback) {
@@ -1139,6 +1160,9 @@ function processLoad(proc, callback) {
1139
1160
  try {
1140
1161
  stdout = stdout.trim().replace(/^\uFEFF/, '');
1141
1162
  processArray = JSON.parse(stdout);
1163
+ if (!Array.isArray(processArray)) {
1164
+ processArray = [processArray];
1165
+ }
1142
1166
  } catch {}
1143
1167
 
1144
1168
  // go through all processes
@@ -1233,7 +1257,7 @@ function processLoad(proc, callback) {
1233
1257
  _process_cpu.all_utime = allcpuu;
1234
1258
  _process_cpu.all_stime = allcpus;
1235
1259
  _process_cpu.list = Object.assign({}, list_new);
1236
- _process_cpu.ms = Date.now() - _process_cpu.ms;
1260
+ _process_cpu.ms = Date.now();
1237
1261
  _process_cpu.result = JSON.parse(JSON.stringify(result));
1238
1262
  if (callback) {
1239
1263
  callback(result);
@@ -1247,9 +1271,7 @@ function processLoad(proc, callback) {
1247
1271
  }
1248
1272
  resolve(result);
1249
1273
  }
1250
- }
1251
-
1252
- if (_darwin || _linux || _freebsd || _openbsd || _netbsd) {
1274
+ } else if (_darwin || _linux || _freebsd || _openbsd || _netbsd) {
1253
1275
  const params = ['-axo', 'pid,ppid,pcpu,pmem,comm'];
1254
1276
  util.execSafe('ps', params).then((stdout) => {
1255
1277
  if (stdout) {
@@ -1270,7 +1292,9 @@ function processLoad(proc, callback) {
1270
1292
  });
1271
1293
  return found;
1272
1294
  });
1273
- lines.shift();
1295
+ if (processesString === '*') {
1296
+ lines.shift();
1297
+ }
1274
1298
  lines.forEach((line) => {
1275
1299
  const data = line.trim().replace(/ +/g, ' ').split(' ');
1276
1300
  if (data.length > 4) {
@@ -1396,7 +1420,7 @@ function processLoad(proc, callback) {
1396
1420
 
1397
1421
  _process_cpu.all = all;
1398
1422
  _process_cpu.list = Object.assign({}, list_new);
1399
- _process_cpu.ms = Date.now() - _process_cpu.ms;
1423
+ _process_cpu.ms = Date.now();
1400
1424
  _process_cpu.result = Object.assign({}, result);
1401
1425
  if (callback) {
1402
1426
  callback(result);
@@ -1416,7 +1440,17 @@ function processLoad(proc, callback) {
1416
1440
  resolve(result);
1417
1441
  }
1418
1442
  });
1443
+ } else {
1444
+ if (callback) {
1445
+ callback(result);
1446
+ }
1447
+ resolve(result);
1448
+ }
1449
+ } else {
1450
+ if (callback) {
1451
+ callback(result);
1419
1452
  }
1453
+ resolve(result);
1420
1454
  }
1421
1455
  });
1422
1456
  });
package/lib/system.js CHANGED
@@ -16,7 +16,6 @@
16
16
  const fs = require('fs');
17
17
  const os = require('os');
18
18
  const util = require('./util');
19
- const { uuid } = require('./osinfo');
20
19
  const exec = require('child_process').exec;
21
20
  const execSync = require('child_process').execSync;
22
21
  const execPromise = util.promisify(require('child_process').exec);
@@ -123,7 +122,7 @@ function system(callback) {
123
122
  }
124
123
  if (!result.virtual) {
125
124
  try {
126
- const disksById = execSync('ls -1 /dev/disk/by-id/ 2>/dev/null; pciconf -lv 2>/dev/null', util.execOptsLinux).toString();
125
+ const disksById = execSync('ls -1 /dev/disk/by-id/ 2>/dev/null; pciconf -lv 2>/dev/null || true', util.execOptsLinux).toString();
127
126
  if (disksById.indexOf('_QEMU_') >= 0 || disksById.indexOf('QEMU ') >= 0) {
128
127
  result.virtual = true;
129
128
  result.virtualHost = 'QEMU';
@@ -781,7 +780,7 @@ function chassis(callback) {
781
780
  let lines = stdout.toString().split('\n');
782
781
  result.manufacturer = cleanDefaults(util.getValue(lines, 'chassis_vendor'));
783
782
  const ctype = parseInt(util.getValue(lines, 'chassis_type').replace(/\D/g, ''));
784
- result.type = cleanDefaults(ctype && !isNaN(ctype) && ctype < chassisTypes.length ? chassisTypes[ctype - 1] : '');
783
+ result.type = cleanDefaults(ctype && !isNaN(ctype) && ctype <= chassisTypes.length ? chassisTypes[ctype - 1] : '');
785
784
  result.version = cleanDefaults(util.getValue(lines, 'chassis_version'));
786
785
  result.serial = cleanDefaults(util.getValue(lines, 'chassis_serial'));
787
786
  result.assetTag = cleanDefaults(util.getValue(lines, 'chassis_asset_tag'));
@@ -827,7 +826,7 @@ function chassis(callback) {
827
826
  result.manufacturer = cleanDefaults(util.getValue(lines, 'manufacturer', ':'));
828
827
  result.model = cleanDefaults(util.getValue(lines, 'model', ':'));
829
828
  const ctype = parseInt(util.getValue(lines, 'ChassisTypes', ':').replace(/\D/g, ''));
830
- result.type = ctype && !isNaN(ctype) && ctype < chassisTypes.length ? chassisTypes[ctype - 1] : '';
829
+ result.type = ctype && !isNaN(ctype) && ctype <= chassisTypes.length ? chassisTypes[ctype - 1] : '';
831
830
  result.version = cleanDefaults(util.getValue(lines, 'version', ':'));
832
831
  result.serial = cleanDefaults(util.getValue(lines, 'serialnumber', ':'));
833
832
  result.assetTag = cleanDefaults(util.getValue(lines, 'partnumber', ':'));
package/lib/usb.js CHANGED
@@ -275,10 +275,6 @@ function usb(callback) {
275
275
  result.push(usb);
276
276
  }
277
277
  }
278
- if (callback) {
279
- callback(result);
280
- }
281
- resolve(result);
282
278
  }
283
279
  if (callback) {
284
280
  callback(result);