systeminformation 5.33.15 → 5.33.16

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/processes.js CHANGED
@@ -21,7 +21,7 @@ const execSync = require('child_process').execSync;
21
21
 
22
22
  const util = require('./util');
23
23
 
24
- let _platform = process.platform;
24
+ const _platform = process.platform;
25
25
 
26
26
  const _linux = _platform === 'linux' || _platform === 'android';
27
27
  const _darwin = _platform === 'darwin';
@@ -71,7 +71,7 @@ const _winStatusValues = {
71
71
 
72
72
  function parseTimeUnix(time) {
73
73
  let result = time;
74
- let parts = time.replace(/ +/g, ' ').split(' ');
74
+ const parts = time.replace(/ +/g, ' ').split(' ');
75
75
  if (parts.length === 5) {
76
76
  result = parts[4] + '-' + ('0' + ('JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'.indexOf(parts[1].toUpperCase()) / 3 + 1)).slice(-2) + '-' + ('0' + parts[2]).slice(-2) + ' ' + parts[3];
77
77
  }
@@ -155,8 +155,8 @@ function services(srv, callback) {
155
155
  srvString = '------';
156
156
  }
157
157
  let srvs = srvString.split('|');
158
- let result = [];
159
- let dataSrv = [];
158
+ const result = [];
159
+ const dataSrv = [];
160
160
 
161
161
  if (_linux || _freebsd || _openbsd || _netbsd || _darwin) {
162
162
  if ((_linux || _freebsd || _openbsd || _netbsd) && srvString === '*') {
@@ -213,23 +213,20 @@ function services(srv, callback) {
213
213
  if (srvString !== '' && srvs.length > 0) {
214
214
  util.execSafe('ps', args).then((stdout) => {
215
215
  if (stdout) {
216
- let lines = stdout.replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
217
- srvs.forEach(function (srv) {
216
+ const lines = stdout.replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
217
+ srvs.forEach((srv) => {
218
218
  let ps;
219
219
  if (_darwin) {
220
- ps = lines.filter(function (e) {
221
- return e.toLowerCase().indexOf(srv) !== -1;
222
- });
220
+ ps = lines.filter((e) => e.toLowerCase().indexOf(srv) !== -1);
223
221
  } else {
224
- ps = lines.filter(function (e) {
225
- return (
222
+ ps = lines.filter(
223
+ (e) =>
226
224
  e.toLowerCase().indexOf(' ' + srv.toLowerCase() + ':') !== -1 ||
227
225
  e.toLowerCase().indexOf('(' + srv.toLowerCase() + ' ') !== -1 ||
228
226
  e.toLowerCase().indexOf('(' + srv.toLowerCase() + ')') !== -1 ||
229
227
  e.toLowerCase().indexOf(' ' + srv.toLowerCase().replace(/[0-9.]/g, '') + ':') !== -1 ||
230
228
  e.toLowerCase().indexOf('/' + srv.toLowerCase()) !== -1
231
- );
232
- });
229
+ );
233
230
  }
234
231
  const pids = [];
235
232
  for (const p of ps) {
@@ -243,20 +240,8 @@ function services(srv, callback) {
243
240
  running: ps.length > 0,
244
241
  startmode: '',
245
242
  pids: pids,
246
- cpu: parseFloat(
247
- ps
248
- .reduce(function (pv, cv) {
249
- return pv + parseFloat(cv.trim().split(' ')[0]);
250
- }, 0)
251
- .toFixed(2)
252
- ),
253
- mem: parseFloat(
254
- ps
255
- .reduce(function (pv, cv) {
256
- return pv + parseFloat(cv.trim().split(' ')[1]);
257
- }, 0)
258
- .toFixed(2)
259
- )
243
+ cpu: parseFloat(ps.reduce((pv, cv) => pv + parseFloat(cv.trim().split(' ')[0]), 0).toFixed(2)),
244
+ mem: parseFloat(ps.reduce((pv, cv) => pv + parseFloat(cv.trim().split(' ')[1]), 0).toFixed(2))
260
245
  });
261
246
  });
262
247
  if (_linux) {
@@ -267,30 +252,30 @@ function services(srv, callback) {
267
252
  item.cpu = 0;
268
253
  });
269
254
  let cmd = 'cat /proc/stat | grep "cpu "';
270
- for (let i in result) {
271
- for (let j in result[i].pids) {
255
+ for (const i in result) {
256
+ for (const j in result[i].pids) {
272
257
  cmd += ';cat /proc/' + result[i].pids[j] + '/stat';
273
258
  }
274
259
  }
275
260
  // freeze the baseline before the async call - a concurrent call overwrites _services_cpu
276
261
  // and would leave this one dividing by a few jiffies (#1007)
277
262
  const cpuBaseline = Object.assign({}, _services_cpu);
278
- exec(cmd, { maxBuffer: 1024 * 102400 }, function (error, stdout) {
279
- let curr_processes = stdout.toString().split('\n');
263
+ exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
264
+ const curr_processes = stdout.toString().split('\n');
280
265
 
281
266
  // first line (all - /proc/stat)
282
- let all = parseProcStat(curr_processes.shift());
267
+ const all = parseProcStat(curr_processes.shift());
283
268
 
284
269
  // process
285
- let list_new = {};
270
+ const list_new = {};
286
271
  let resultProcess = {};
287
272
  curr_processes.forEach((element) => {
288
273
  resultProcess = calcProcStatLinux(element, all, cpuBaseline);
289
274
 
290
275
  if (resultProcess.pid) {
291
276
  let listPos = -1;
292
- for (let i in result) {
293
- for (let j in result[i].pids) {
277
+ for (const i in result) {
278
+ for (const j in result[i].pids) {
294
279
  if (parseInt(result[i].pids[j]) === parseInt(resultProcess.pid)) {
295
280
  listPos = i;
296
281
  }
@@ -330,11 +315,9 @@ function services(srv, callback) {
330
315
  args = ['-o', 'comm'];
331
316
  util.execSafe('ps', args).then((stdout) => {
332
317
  if (stdout) {
333
- let lines = stdout.replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
334
- srvs.forEach(function (srv) {
335
- let ps = lines.filter(function (e) {
336
- return e.indexOf(srv) !== -1;
337
- });
318
+ const lines = stdout.replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
319
+ srvs.forEach((srv) => {
320
+ const ps = lines.filter((e) => e.indexOf(srv) !== -1);
338
321
  result.push({
339
322
  name: srv,
340
323
  running: ps.length > 0,
@@ -348,7 +331,7 @@ function services(srv, callback) {
348
331
  }
349
332
  resolve(result);
350
333
  } else {
351
- srvs.forEach(function (srv) {
334
+ srvs.forEach((srv) => {
352
335
  result.push({
353
336
  name: srv,
354
337
  running: false,
@@ -377,22 +360,23 @@ function services(srv, callback) {
377
360
  if (srvs[0] !== '*') {
378
361
  wincommand += ' -Filter "';
379
362
  srvs.forEach((srv) => {
380
- wincommand += `Name='${srv}' or `;
363
+ // whitelist: srv is inserted into a PowerShell string
364
+ wincommand += `Name='${srv.replace(/[^a-zA-Z0-9 _.\-@]/g, '')}' or `;
381
365
  });
382
366
  wincommand = `${wincommand.slice(0, -4)}"`;
383
367
  }
384
368
  wincommand += ' | select Name,Caption,Started,StartMode,ProcessId | fl';
385
369
  util.powerShell(wincommand).then((stdout, error) => {
386
370
  if (!error) {
387
- let serviceSections = stdout.split(/\n\s*\n/);
371
+ const serviceSections = stdout.split(/\n\s*\n/);
388
372
  serviceSections.forEach((element) => {
389
373
  if (element.trim() !== '') {
390
- let lines = element.trim().split('\r\n');
391
- let srvName = util.getValue(lines, 'Name', ':', true).toLowerCase();
392
- let srvCaption = util.getValue(lines, 'Caption', ':', true).toLowerCase();
393
- let started = util.getValue(lines, 'Started', ':', true);
394
- let startMode = util.getValue(lines, 'StartMode', ':', true);
395
- let pid = util.getValue(lines, 'ProcessId', ':', true);
374
+ const lines = element.trim().split('\r\n');
375
+ const srvName = util.getValue(lines, 'Name', ':', true).toLowerCase();
376
+ const srvCaption = util.getValue(lines, 'Caption', ':', true).toLowerCase();
377
+ const started = util.getValue(lines, 'Started', ':', true);
378
+ const startMode = util.getValue(lines, 'StartMode', ':', true);
379
+ const pid = util.getValue(lines, 'ProcessId', ':', true);
396
380
  if (srvString === '*' || srvs.indexOf(srvName) >= 0 || srvs.indexOf(srvCaption) >= 0) {
397
381
  result.push({
398
382
  name: srvName,
@@ -483,8 +467,12 @@ function parseProcStat(line) {
483
467
  // drops NaN/Infinity/negative values and scales cpuu + cpus down proportionally
484
468
  // if their sum exceeds 100 (normalized against all cores)
485
469
  function clampCpuPair(cpuu, cpus) {
486
- if (!isFinite(cpuu) || cpuu < 0) { cpuu = 0; }
487
- if (!isFinite(cpus) || cpus < 0) { cpus = 0; }
470
+ if (!isFinite(cpuu) || cpuu < 0) {
471
+ cpuu = 0;
472
+ }
473
+ if (!isFinite(cpus) || cpus < 0) {
474
+ cpus = 0;
475
+ }
488
476
  const total = cpuu + cpus;
489
477
  if (total > 100) {
490
478
  cpuu = (cpuu / total) * 100;
@@ -494,13 +482,13 @@ function clampCpuPair(cpuu, cpus) {
494
482
  }
495
483
 
496
484
  function calcProcStatLinux(line, all, _cpu_old) {
497
- let statparts = line.replace(/ +/g, ' ').split(')');
485
+ const statparts = line.replace(/ +/g, ' ').split(')');
498
486
  if (statparts.length >= 2) {
499
- let parts = statparts[1].split(' ');
487
+ const parts = statparts[1].split(' ');
500
488
  if (parts.length >= 16) {
501
- let pid = parseInt(statparts[0].split(' ')[0]);
502
- let utime = parseInt(parts[12]);
503
- let stime = parseInt(parts[13]);
489
+ const pid = parseInt(statparts[0].split(' ')[0]);
490
+ const utime = parseInt(parts[12]);
491
+ const stime = parseInt(parts[13]);
504
492
 
505
493
  // calc - child times (cutime/cstime) are deliberately left out: reaping a child adds its
506
494
  // whole lifetime in one interval, which is what produced the >100% spikes in #1007.
@@ -580,7 +568,7 @@ function processes(callback) {
580
568
  result = result.substr(0, result.length - 1);
581
569
  }
582
570
  if (result.substr(0, 1) !== '[') {
583
- let parts = result.split('/');
571
+ const parts = result.split('/');
584
572
  if (isNaN(parseInt(parts[parts.length - 1]))) {
585
573
  result = parts[parts.length - 1];
586
574
  } else {
@@ -733,9 +721,9 @@ function processes(callback) {
733
721
  }
734
722
 
735
723
  function parseProcesses(lines) {
736
- let result = [];
724
+ const result = [];
737
725
  if (lines.length > 1) {
738
- let head = lines[0];
726
+ const head = lines[0];
739
727
  parsedhead = util.parseHead(head, 8);
740
728
  lines.shift();
741
729
  lines.forEach((line) => {
@@ -784,7 +772,7 @@ function processes(callback) {
784
772
  return started;
785
773
  }
786
774
 
787
- let result = [];
775
+ const result = [];
788
776
  lines.forEach((line) => {
789
777
  if (line.trim() !== '') {
790
778
  line = line.trim().replace(/ +/g, ' ').replace(/,+/g, '.');
@@ -833,7 +821,7 @@ function processes(callback) {
833
821
 
834
822
  return new Promise((resolve) => {
835
823
  process.nextTick(() => {
836
- let result = {
824
+ const result = {
837
825
  all: 0,
838
826
  running: 0,
839
827
  blocked: 0,
@@ -883,20 +871,20 @@ function processes(callback) {
883
871
  // and would leave this one dividing by a few jiffies (#1007)
884
872
  const cpuBaseline = Object.assign({}, _processes_cpu);
885
873
  exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
886
- let curr_processes = stdout.toString().split('\n');
874
+ const curr_processes = stdout.toString().split('\n');
887
875
 
888
876
  // first line (all - /proc/stat)
889
- let all = parseProcStat(curr_processes.shift());
877
+ const all = parseProcStat(curr_processes.shift());
890
878
 
891
879
  // process
892
- let list_new = {};
880
+ const list_new = {};
893
881
  let resultProcess = {};
894
882
  curr_processes.forEach((element) => {
895
883
  resultProcess = calcProcStatLinux(element, all, cpuBaseline);
896
884
 
897
885
  if (resultProcess.pid) {
898
886
  // store pcpu in outer array
899
- let listPos = result.list
887
+ const listPos = result.list
900
888
  .map((e) => {
901
889
  return e.pid;
902
890
  })
@@ -940,7 +928,7 @@ function processes(callback) {
940
928
  }
941
929
  exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
942
930
  if (!error) {
943
- let lines = stdout.toString().split('\n');
931
+ const lines = stdout.toString().split('\n');
944
932
  lines.shift();
945
933
 
946
934
  result.list = parseProcesses2(lines).slice();
@@ -1058,10 +1046,10 @@ function processes(callback) {
1058
1046
  result.sleeping = result.all - result.running - result.blocked - result.unknown;
1059
1047
  result.list = procs;
1060
1048
  procStats.forEach((element) => {
1061
- let resultProcess = calcProcStatWin(element, allcpuu + allcpus, cpuBaseline);
1049
+ const resultProcess = calcProcStatWin(element, allcpuu + allcpus, cpuBaseline);
1062
1050
 
1063
1051
  // store pcpu in outer array
1064
- let listPos = result.list.map((e) => e.pid).indexOf(resultProcess.pid);
1052
+ const listPos = result.list.map((e) => e.pid).indexOf(resultProcess.pid);
1065
1053
  if (listPos >= 0) {
1066
1054
  result.list[listPos].cpu = resultProcess.cpuu + resultProcess.cpus;
1067
1055
  result.list[listPos].cpuu = resultProcess.cpuu;
@@ -1166,8 +1154,8 @@ function processLoad(proc, callback) {
1166
1154
  if (util.isPrototypePolluted() && processesString !== '*') {
1167
1155
  processesString = '------';
1168
1156
  }
1169
- let processes = processesString.split('|');
1170
- let result = [];
1157
+ const processes = processesString.split('|');
1158
+ const result = [];
1171
1159
 
1172
1160
  const procSanitized = util.isPrototypePolluted() ? '' : util.sanitizeShellString(proc) || '*';
1173
1161
 
@@ -1253,7 +1241,7 @@ function processLoad(proc, callback) {
1253
1241
 
1254
1242
  if (processesString !== '*') {
1255
1243
  // add missing processes
1256
- let processesMissing = processes.filter((name) => procStats.filter((item) => item.name.toLowerCase().indexOf(name) >= 0).length === 0);
1244
+ const processesMissing = processes.filter((name) => procStats.filter((item) => item.name.toLowerCase().indexOf(name) >= 0).length === 0);
1257
1245
  processesMissing.forEach((procName) => {
1258
1246
  result.push({
1259
1247
  proc: procName,
@@ -1267,7 +1255,7 @@ function processLoad(proc, callback) {
1267
1255
 
1268
1256
  // calculate proc stats for each proc
1269
1257
  procStats.forEach((element) => {
1270
- let resultProcess = calcProcStatWin(element, allcpuu + allcpus, cpuBaseline);
1258
+ const resultProcess = calcProcStatWin(element, allcpuu + allcpus, cpuBaseline);
1271
1259
 
1272
1260
  let listPos = -1;
1273
1261
  for (let j = 0; j < result.length; j++) {
@@ -1385,7 +1373,7 @@ function processLoad(proc, callback) {
1385
1373
 
1386
1374
  if (processesString !== '*') {
1387
1375
  // add missing processes
1388
- let processesMissing = processes.filter((name) => {
1376
+ const processesMissing = processes.filter((name) => {
1389
1377
  return (
1390
1378
  procStats.filter((item) => {
1391
1379
  return item.name.toLowerCase().indexOf(name) >= 0;
@@ -1408,8 +1396,8 @@ function processLoad(proc, callback) {
1408
1396
  item.cpu = 0;
1409
1397
  });
1410
1398
  let cmd = 'cat /proc/stat | grep "cpu "';
1411
- for (let i in result) {
1412
- for (let j in result[i].pids) {
1399
+ for (const i in result) {
1400
+ for (const j in result[i].pids) {
1413
1401
  cmd += ';cat /proc/' + result[i].pids[j] + '/stat';
1414
1402
  }
1415
1403
  }
@@ -1417,13 +1405,13 @@ function processLoad(proc, callback) {
1417
1405
  // and would leave this one dividing by a few jiffies (#1007)
1418
1406
  const cpuBaseline = Object.assign({}, _process_cpu);
1419
1407
  exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
1420
- let curr_processes = stdout.toString().split('\n');
1408
+ const curr_processes = stdout.toString().split('\n');
1421
1409
 
1422
1410
  // first line (all - /proc/stat)
1423
- let all = parseProcStat(curr_processes.shift());
1411
+ const all = parseProcStat(curr_processes.shift());
1424
1412
 
1425
1413
  // process
1426
- let list_new = {};
1414
+ const list_new = {};
1427
1415
  let resultProcess = {};
1428
1416
  curr_processes.forEach((element) => {
1429
1417
  resultProcess = calcProcStatLinux(element, all, cpuBaseline);
@@ -1431,7 +1419,7 @@ function processLoad(proc, callback) {
1431
1419
  if (resultProcess.pid) {
1432
1420
  // find result item
1433
1421
  let resultItemId = -1;
1434
- for (let i in result) {
1422
+ for (const i in result) {
1435
1423
  if (result[i].pids.indexOf(resultProcess.pid) >= 0) {
1436
1424
  resultItemId = i;
1437
1425
  }
package/lib/util.js CHANGED
@@ -749,6 +749,9 @@ function sanitizeShellString(str, strict) {
749
749
  s[i] === "'" ||
750
750
  s[i] === '`' ||
751
751
  s[i] === '"' ||
752
+ // unicode quotes (U+2018-U+201E) and dashes (U+2013-U+2015) are treated as ' " - by PowerShell
753
+ (s[i] >= '‘' && s[i] <= '„') ||
754
+ (s[i] >= '–' && s[i] <= '―') ||
752
755
  s[i].length > 1 ||
753
756
  (strict && s[i] === '(') ||
754
757
  (strict && s[i] === ')') ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "5.33.15",
3
+ "version": "5.33.16",
4
4
  "description": "Advanced, lightweight system and OS information library",
5
5
  "license": "MIT",
6
6
  "author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",