systeminformation 5.6.0 → 5.6.4

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/CHANGELOG.md CHANGED
@@ -77,6 +77,10 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.
77
77
 
78
78
  | Version | Date | Comment |
79
79
  | -------------- | -------------- | -------- |
80
+ | 5.6.4 | 2021-03-15 | `sanitizeShellString()` and other security improvements |
81
+ | 5.6.3 | 2021-03-14 | `sanitizeShellString()` improvement |
82
+ | 5.6.2 | 2021-03-10 | `networkInterfaces()` `cpu()` improvement (win) |
83
+ | 5.6.1 | 2021-03-03 | `get()` fixed issue boolean parameters |
80
84
  | 5.6.0 | 2021-03-03 | `cpuTemperature()` added socket and chipset temp (linux) |
81
85
  | 5.5.0 | 2021-02-25 | `dockerVolumes()` added |
82
86
  | 5.4.0 | 2021-02-24 | `dockerImages()` added |
package/README.md CHANGED
@@ -30,7 +30,7 @@
30
30
  [![Sponsoring][sponsor-badge]][sponsor-url]
31
31
  [![MIT license][license-img]][license-url]
32
32
 
33
- This is amazing. Started as a small project just for myself, it now has > 10,000 lines of code, > 400 versions published, > 3 mio downloads per month, > 30 mio downloads overall. Thank you to all who contributed to this project!
33
+ This is amazing. Started as a small project just for myself, it now has > 10,000 lines of code, > 400 versions published, up to 3 mio downloads per month, > 30 mio downloads overall. Thank you to all who contributed to this project!
34
34
 
35
35
  ## New Version 5.0
36
36
 
package/lib/cpu.js CHANGED
@@ -750,88 +750,88 @@ function getCpu() {
750
750
  }
751
751
  if (_windows) {
752
752
  try {
753
- util.wmic('cpu get /value').then((stdout, error) => {
754
- if (!error) {
755
- let lines = stdout.split('\r\n');
756
- let name = util.getValue(lines, 'name', '=') || '';
757
- if (name.indexOf('@') >= 0) {
758
- result.brand = name.split('@')[0].trim();
759
- result.speed = name.split('@')[1] ? parseFloat(name.split('@')[1].trim()) : 0;
760
- _cpu_speed = result.speed;
761
- } else {
762
- result.brand = name.trim();
763
- result.speed = 0;
764
- }
765
- result = cpuBrandManufacturer(result);
766
- result.revision = util.getValue(lines, 'revision', '=');
767
- result.cache.l1d = 0;
768
- result.cache.l1i = 0;
769
- result.cache.l2 = util.getValue(lines, 'l2cachesize', '=');
770
- result.cache.l3 = util.getValue(lines, 'l3cachesize', '=');
771
- if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2, 10) * 1024; }
772
- if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3, 10) * 1024; }
773
- result.vendor = util.getValue(lines, 'manufacturer', '=');
774
- result.speedMax = Math.round(parseFloat(util.getValue(lines, 'maxclockspeed', '=').replace(/,/g, '.')) / 10.0) / 100;
775
- if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
776
- result.speed = getAMDSpeed(result.brand);
777
- }
778
- if (result.speed === 0) {
779
- result.speed = result.speedMax;
780
- }
781
- result.speedMin = result.speed;
753
+ const workload = [];
754
+ workload.push(util.wmic('cpu get /value'));
755
+ workload.push(util.wmic('path Win32_CacheMemory get CacheType,InstalledSize,Purpose'));
756
+
757
+ Promise.all(
758
+ workload
759
+ ).then(data => {
760
+ let lines = data[0].split('\r\n');
761
+ let name = util.getValue(lines, 'name', '=') || '';
762
+ if (name.indexOf('@') >= 0) {
763
+ result.brand = name.split('@')[0].trim();
764
+ result.speed = name.split('@')[1] ? parseFloat(name.split('@')[1].trim()) : 0;
765
+ _cpu_speed = result.speed;
766
+ } else {
767
+ result.brand = name.trim();
768
+ result.speed = 0;
769
+ }
770
+ result = cpuBrandManufacturer(result);
771
+ result.revision = util.getValue(lines, 'revision', '=');
772
+ result.cache.l1d = 0;
773
+ result.cache.l1i = 0;
774
+ result.cache.l2 = util.getValue(lines, 'l2cachesize', '=');
775
+ result.cache.l3 = util.getValue(lines, 'l3cachesize', '=');
776
+ if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2, 10) * 1024; }
777
+ if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3, 10) * 1024; }
778
+ result.vendor = util.getValue(lines, 'manufacturer', '=');
779
+ result.speedMax = Math.round(parseFloat(util.getValue(lines, 'maxclockspeed', '=').replace(/,/g, '.')) / 10.0) / 100;
780
+ if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
781
+ result.speed = getAMDSpeed(result.brand);
782
+ }
783
+ if (result.speed === 0) {
784
+ result.speed = result.speedMax;
785
+ }
786
+ result.speedMin = result.speed;
782
787
 
783
- let description = util.getValue(lines, 'description', '=').split(' ');
784
- for (let i = 0; i < description.length; i++) {
785
- if (description[i].toLowerCase().startsWith('family') && (i + 1) < description.length && description[i + 1]) {
786
- result.family = description[i + 1];
787
- }
788
- if (description[i].toLowerCase().startsWith('model') && (i + 1) < description.length && description[i + 1]) {
789
- result.model = description[i + 1];
790
- }
791
- if (description[i].toLowerCase().startsWith('stepping') && (i + 1) < description.length && description[i + 1]) {
792
- result.stepping = description[i + 1];
793
- }
794
- }
795
- // socket type
796
- const socketId = util.getValue(lines, 'UpgradeMethod', '=');
797
- if (socketTypes[socketId]) {
798
- result.socket = socketTypes[socketId];
799
- }
800
- // # threads / # cores
801
- const countProcessors = util.countLines(lines, 'Caption');
802
- const countThreads = util.getValue(lines, 'NumberOfLogicalProcessors', '=');
803
- const countCores = util.getValue(lines, 'NumberOfCores', '=');
804
- if (countProcessors) {
805
- result.processors = parseInt(countProcessors) || 1;
788
+ let description = util.getValue(lines, 'description', '=').split(' ');
789
+ for (let i = 0; i < description.length; i++) {
790
+ if (description[i].toLowerCase().startsWith('family') && (i + 1) < description.length && description[i + 1]) {
791
+ result.family = description[i + 1];
806
792
  }
807
- if (countCores && countThreads) {
808
- result.cores = parseInt(countThreads) || util.cores();
809
- result.physicalCores = parseInt(countCores) || util.cores();
793
+ if (description[i].toLowerCase().startsWith('model') && (i + 1) < description.length && description[i + 1]) {
794
+ result.model = description[i + 1];
810
795
  }
811
- if (countProcessors > 1) {
812
- result.cores = result.cores * countProcessors;
813
- result.physicalCores = result.physicalCores * countProcessors;
796
+ if (description[i].toLowerCase().startsWith('stepping') && (i + 1) < description.length && description[i + 1]) {
797
+ result.stepping = description[i + 1];
814
798
  }
815
799
  }
816
- util.wmic('path Win32_CacheMemory get CacheType,InstalledSize,Purpose').then((stdout, error) => {
817
- if (!error) {
818
- let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
819
- lines.forEach(function (line) {
820
- if (line !== '') {
821
- line = line.trim().split(/\s\s+/);
822
- // L1 Instructions
823
- if (line[2] === 'L1 Cache' && line[0] === '3') {
824
- result.cache.l1i = parseInt(line[1], 10);
825
- }
826
- // L1 Data
827
- if (line[2] === 'L1 Cache' && line[0] === '4') {
828
- result.cache.l1d = parseInt(line[1], 10);
829
- }
830
- }
831
- });
800
+ // socket type
801
+ const socketId = util.getValue(lines, 'UpgradeMethod', '=');
802
+ if (socketTypes[socketId]) {
803
+ result.socket = socketTypes[socketId];
804
+ }
805
+ // # threads / # cores
806
+ const countProcessors = util.countLines(lines, 'Caption');
807
+ const countThreads = util.getValue(lines, 'NumberOfLogicalProcessors', '=');
808
+ const countCores = util.getValue(lines, 'NumberOfCores', '=');
809
+ if (countProcessors) {
810
+ result.processors = parseInt(countProcessors) || 1;
811
+ }
812
+ if (countCores && countThreads) {
813
+ result.cores = parseInt(countThreads) || util.cores();
814
+ result.physicalCores = parseInt(countCores) || util.cores();
815
+ }
816
+ if (countProcessors > 1) {
817
+ result.cores = result.cores * countProcessors;
818
+ result.physicalCores = result.physicalCores * countProcessors;
819
+ }
820
+ lines = data[1].split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
821
+ lines.forEach(function (line) {
822
+ if (line !== '') {
823
+ line = line.trim().split(/\s\s+/);
824
+ // L1 Instructions
825
+ if (line[2] === 'L1 Cache' && line[0] === '3') {
826
+ result.cache.l1i = parseInt(line[1], 10);
827
+ }
828
+ // L1 Data
829
+ if (line[2] === 'L1 Cache' && line[0] === '4') {
830
+ result.cache.l1d = parseInt(line[1], 10);
831
+ }
832
832
  }
833
- resolve(result);
834
833
  });
834
+ resolve(result);
835
835
  });
836
836
  } catch (e) {
837
837
  resolve(result);
package/lib/docker.js CHANGED
@@ -98,6 +98,9 @@ function dockerImages(all, callback) {
98
98
  callback = all;
99
99
  all = false;
100
100
  }
101
+ if (typeof all === 'string' && all === 'true') {
102
+ all = true;
103
+ }
101
104
  if (typeof all !== 'boolean' && all !== undefined) {
102
105
  all = false;
103
106
  }
@@ -218,6 +221,9 @@ function dockerContainers(all, callback) {
218
221
  callback = all;
219
222
  all = false;
220
223
  }
224
+ if (typeof all === 'string' && all === 'true') {
225
+ all = true;
226
+ }
221
227
  if (typeof all !== 'boolean' && all !== undefined) {
222
228
  all = false;
223
229
  }
@@ -464,7 +470,7 @@ function dockerContainerStats(containerIDs, callback) {
464
470
  if (containerIDsSanitized !== '*') {
465
471
  containerIDsSanitized = '';
466
472
  const s = (util.isPrototypePolluted() ? '' : util.sanitizeShellString(containerIDs, true)).trim();
467
- for (let i = 0; i <= 2000; i++) {
473
+ for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
468
474
  if (!(s[i] === undefined)) {
469
475
  s[i].__proto__.toLowerCase = util.stringToLower;
470
476
  const sl = s[i].toLowerCase();
package/lib/index.js CHANGED
@@ -362,12 +362,17 @@ function get(valueObject, callback) {
362
362
  // result is in an array, go through all elements of array and pick only the right ones
363
363
  const partialArray = [];
364
364
  data[i].forEach(element => {
365
- const partialRes = {};
366
- keys.forEach(k => {
367
- if ({}.hasOwnProperty.call(element, k)) {
368
- partialRes[k] = element[k];
369
- }
370
- });
365
+ let partialRes = {};
366
+ if (keys.length === 1 && (keys[0] === '*' || keys[0] === 'all')) {
367
+ partialRes = element;
368
+ } else {
369
+ keys.forEach(k => {
370
+ if ({}.hasOwnProperty.call(element, k)) {
371
+ partialRes[k] = element[k];
372
+ }
373
+ });
374
+ }
375
+ // if there is a filter, then just take those elements
371
376
  if (filter && filterParts.length === 2) {
372
377
  if ({}.hasOwnProperty.call(partialRes, filterParts[0].trim())) {
373
378
  const val = partialRes[filterParts[0].trim()];
package/lib/internet.js CHANGED
@@ -13,8 +13,7 @@
13
13
  // 12. Internet
14
14
  // ----------------------------------------------------------------------------------
15
15
 
16
- const exec = require('child_process').exec;
17
- const execFile = require('child_process').execFile;
16
+ // const exec = require('child_process').exec;
18
17
  const util = require('./util');
19
18
 
20
19
  let _platform = process.platform;
@@ -46,11 +45,11 @@ function inetChecksite(url, callback) {
46
45
  }
47
46
  let urlSanitized = '';
48
47
  const s = util.sanitizeShellString(url, true);
49
- for (let i = 0; i <= 2000; i++) {
48
+ for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
50
49
  if (!(s[i] === undefined)) {
51
50
  s[i].__proto__.toLowerCase = util.stringToLower;
52
51
  const sl = s[i].toLowerCase();
53
- if (sl && sl[0] && !sl[1]) {
52
+ if (sl && sl[0] && !sl[1] && sl[0].length === 1) {
54
53
  urlSanitized = urlSanitized + sl[0];
55
54
  }
56
55
  }
@@ -65,12 +64,14 @@ function inetChecksite(url, callback) {
65
64
  }
66
65
  let t = Date.now();
67
66
  if (_linux || _freebsd || _openbsd || _netbsd || _darwin || _sunos) {
68
- let args = ' -I --connect-timeout 5 -m 5 ' + urlSanitized + ' 2>/dev/null | head -n 1 | cut -d " " -f2';
67
+ let args = ['-I', '--connect-timeout', '5', '-m', '5'];
68
+ args.push(urlSanitized);
69
69
  let cmd = 'curl';
70
- exec(cmd + args, function (error, stdout) {
71
- let statusCode = parseInt(stdout.toString());
70
+ util.execSave(cmd, args).then((stdout) => {
71
+ const lines = stdout.split('\n');
72
+ let statusCode = lines[0] && lines[0].indexOf(' ') >= 0 ? parseInt(lines[0].split(' ')[1], 10) : 404;
72
73
  result.status = statusCode || 404;
73
- result.ok = !error && (statusCode === 200 || statusCode === 301 || statusCode === 302 || statusCode === 304);
74
+ result.ok = (statusCode === 200 || statusCode === 301 || statusCode === 302 || statusCode === 304);
74
75
  result.ms = (result.ok ? Date.now() - t : null);
75
76
  if (callback) { callback(result); }
76
77
  resolve(result);
@@ -142,7 +143,7 @@ function inetLatency(host, callback) {
142
143
  }
143
144
  let hostSanitized = '';
144
145
  const s = (util.isPrototypePolluted() ? '8.8.8.8' : util.sanitizeShellString(host, true)).trim();
145
- for (let i = 0; i <= 2000; i++) {
146
+ for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
146
147
  if (!(s[i] === undefined)) {
147
148
  s[i].__proto__.toLowerCase = util.stringToLower;
148
149
  const sl = s[i].toLowerCase();
@@ -171,10 +172,10 @@ function inetLatency(host, callback) {
171
172
  params = '-c2 -t3 ' + hostSanitized;
172
173
  filt = 'avg';
173
174
  }
174
- execFile('ping', params.split(' '), function (error, stdout) {
175
+ util.execSave('ping', params.split(' ')).then((stdout) => {
175
176
  let result = null;
176
- if (!error) {
177
- const lines = stdout.toString().split('\n').filter(line => line.indexOf(filt) >= 0).join('\n');
177
+ if (stdout) {
178
+ const lines = stdout.split('\n').filter(line => line.indexOf(filt) >= 0).join('\n');
178
179
 
179
180
  const line = lines.split('=');
180
181
  if (line.length > 1) {
@@ -191,10 +192,10 @@ function inetLatency(host, callback) {
191
192
  if (_sunos) {
192
193
  const params = '-s -a ' + hostSanitized + ' 56 2';
193
194
  const filt = 'avg';
194
- execFile('ping', params.split(' '), { timeout: 3000 }, function (error, stdout) {
195
+ util.execSave('ping', params.split(' '), { timeout: 3000 }).then((stdout) => {
195
196
  let result = null;
196
- if (!error) {
197
- const lines = stdout.toString().split('\n').filter(line => line.indexOf(filt) >= 0).join('\n');
197
+ if (stdout) {
198
+ const lines = stdout.split('\n').filter(line => line.indexOf(filt) >= 0).join('\n');
198
199
  const line = lines.split('=');
199
200
  if (line.length > 1) {
200
201
  const parts = line[1].split('/');
@@ -211,9 +212,9 @@ function inetLatency(host, callback) {
211
212
  let result = null;
212
213
  try {
213
214
  const params = hostSanitized + ' -n 1';
214
- execFile('ping', params.split(' '), util.execOptsWin, function (error, stdout) {
215
- if (!error) {
216
- let lines = stdout.toString().split('\r\n');
215
+ util.execSave('ping', params.split(' '), util.execOptsWin).then((stdout) => {
216
+ if (stdout) {
217
+ let lines = stdout.split('\r\n');
217
218
  lines.shift();
218
219
  lines.forEach(function (line) {
219
220
  if ((line.toLowerCase().match(/ms/g) || []).length === 3) {
package/lib/network.js CHANGED
@@ -221,6 +221,7 @@ function parseLinesWindowsNics(sections, nconfigsections) {
221
221
  let netEnabled = util.getValue(lines, 'NetEnabled', '=');
222
222
  let adapterType = util.getValue(lines, 'AdapterTypeID', '=') === '9' ? 'wireless' : 'wired';
223
223
  let ifacename = util.getValue(lines, 'Name', '=').replace(/\]/g, ')').replace(/\[/g, '(');
224
+ let iface = util.getValue(lines, 'NetConnectionID', '=').replace(/\]/g, ')').replace(/\[/g, '(');
224
225
  if (ifacename.toLowerCase().indexOf('wi-fi') >= 0 || ifacename.toLowerCase().indexOf('wireless') >= 0) {
225
226
  adapterType = 'wireless';
226
227
  }
@@ -230,6 +231,7 @@ function parseLinesWindowsNics(sections, nconfigsections) {
230
231
  mac: util.getValue(lines, 'MACAddress', '=').toLowerCase(),
231
232
  dhcp: util.getValue(linesNicConfig, 'dhcpEnabled', '=').toLowerCase(),
232
233
  name: ifacename,
234
+ iface,
233
235
  netEnabled: netEnabled === 'TRUE',
234
236
  speed: isNaN(speed) ? null : speed,
235
237
  operstate: util.getValue(lines, 'NetConnectionStatus', '=') === '2' ? 'up' : 'down',
@@ -243,7 +245,7 @@ function parseLinesWindowsNics(sections, nconfigsections) {
243
245
  }
244
246
 
245
247
  function getWindowsNics() {
246
- const cmd = util.getWmic() + ' nic get MACAddress, name, NetEnabled, Speed, NetConnectionStatus, AdapterTypeId /value';
248
+ const cmd = util.getWmic() + ' nic get MACAddress, name, NetConnectionId, NetEnabled, Speed, NetConnectionStatus, AdapterTypeId /value';
247
249
  const cmdnicconfig = util.getWmic() + ' nicconfig get dhcpEnabled /value';
248
250
  try {
249
251
  const nsections = execSync(cmd, util.execOptsWin).split(/\n\s*\n/);
@@ -774,6 +776,7 @@ function networkInterfaces(callback, rescan = true) {
774
776
  _dhcpNics = getLinuxDHCPNics();
775
777
  }
776
778
  for (let dev in ifaces) {
779
+ let iface = dev;
777
780
  let ip4 = '';
778
781
  let ip4subnet = '';
779
782
  let ip6 = '';
@@ -873,6 +876,7 @@ function networkInterfaces(callback, rescan = true) {
873
876
  dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, dev);
874
877
  nics.forEach(detail => {
875
878
  if (detail.mac === mac) {
879
+ iface = detail.iface || iface;
876
880
  ifaceName = detail.name;
877
881
  dhcp = detail.dhcp;
878
882
  operstate = detail.operstate;
@@ -895,7 +899,7 @@ function networkInterfaces(callback, rescan = true) {
895
899
  }
896
900
  const virtual = internal ? false : testVirtualNic(dev, ifaceName, mac);
897
901
  result.push({
898
- iface: dev,
902
+ iface,
899
903
  ifaceName,
900
904
  ip4,
901
905
  ip4subnet,
@@ -1057,7 +1061,7 @@ function networkStatsSingle(iface) {
1057
1061
  process.nextTick(() => {
1058
1062
  let ifaceSanitized = '';
1059
1063
  const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(iface);
1060
- for (let i = 0; i <= 2000; i++) {
1064
+ for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
1061
1065
  if (!(s[i] === undefined)) {
1062
1066
  ifaceSanitized = ifaceSanitized + s[i];
1063
1067
  }
package/lib/processes.js CHANGED
@@ -111,7 +111,7 @@ function services(srv, callback) {
111
111
  srvString.__proto__.trim = util.stringTrim;
112
112
 
113
113
  const s = util.sanitizeShellString(srv);
114
- for (let i = 0; i <= 2000; i++) {
114
+ for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
115
115
  if (!(s[i] === undefined)) {
116
116
  srvString = srvString + s[i];
117
117
  }
@@ -164,11 +164,15 @@ function services(srv, callback) {
164
164
  }
165
165
  }
166
166
  }
167
- let comm = (_darwin) ? 'ps -caxo pcpu,pmem,pid,command' : 'ps -axo pcpu,pmem,pid,command';
167
+ if ((_darwin) && srvString === '*') { // service enumeration not yet suported on mac OS
168
+ if (callback) { callback(result); }
169
+ resolve(result);
170
+ }
171
+ let args = (_darwin) ? ['-caxo', 'pcpu,pmem,pid,command'] : ['-axo', 'pcpu,pmem,pid,command'];
168
172
  if (srvString !== '' && srvs.length > 0) {
169
- exec(comm + ' | grep -v grep | grep -iE "' + srvString + '"', { maxBuffer: 1024 * 20000 }, function (error, stdout) { // lgtm [js/shell-command-constructed-from-input]
170
- if (!error) {
171
- let lines = stdout.toString().replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
173
+ util.execSave('ps', args).then((stdout) => {
174
+ if (stdout) {
175
+ let lines = stdout.replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
172
176
  srvs.forEach(function (srv) {
173
177
  let ps;
174
178
  if (_darwin) {
@@ -263,9 +267,10 @@ function services(srv, callback) {
263
267
  resolve(result);
264
268
  }
265
269
  } else {
266
- exec('ps -o comm | grep -v grep | egrep "' + srvString + '"', { maxBuffer: 1024 * 20000 }, function (error, stdout) { // lgtm [js/shell-command-constructed-from-input]
267
- if (!error) {
268
- let lines = stdout.toString().replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
270
+ args = ['-o', 'comm'];
271
+ util.execSave('ps', args).then((stdout) => {
272
+ if (stdout) {
273
+ let lines = stdout.replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
269
274
  srvs.forEach(function (srv) {
270
275
  let ps = lines.filter(function (e) {
271
276
  return e.indexOf(srv) !== -1;
@@ -905,7 +910,7 @@ function processLoad(proc, callback) {
905
910
  processesString.__proto__.trim = util.stringTrim;
906
911
 
907
912
  const s = util.sanitizeShellString(proc);
908
- for (let i = 0; i <= 2000; i++) {
913
+ for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
909
914
  if (!(s[i] === undefined)) {
910
915
  processesString = processesString + s[i];
911
916
  }
package/lib/util.js CHANGED
@@ -58,6 +58,7 @@ const stringToString = new String().toString;
58
58
  const stringSubstr = new String().substr;
59
59
  const stringTrim = new String().trim;
60
60
  const stringStartWith = new String().startsWith;
61
+ const mathMin = Math.min;
61
62
 
62
63
  function isFunction(functionToCheck) {
63
64
  let getType = {};
@@ -389,6 +390,42 @@ function powerShell(cmd) {
389
390
  });
390
391
  }
391
392
 
393
+ function execSave(cmd, args, options) {
394
+ let result = '';
395
+ options = options || {};
396
+
397
+ return new Promise((resolve) => {
398
+ process.nextTick(() => {
399
+ try {
400
+ const child = spawn(cmd, args, options);
401
+
402
+ if (child && !child.pid) {
403
+ child.on('error', function () {
404
+ resolve(result);
405
+ });
406
+ }
407
+ if (child && child.pid) {
408
+ child.stdout.on('data', function (data) {
409
+ result += data.toString();
410
+ });
411
+ child.on('close', function () {
412
+ child.kill();
413
+ resolve(result);
414
+ });
415
+ child.on('error', function () {
416
+ child.kill();
417
+ resolve(result);
418
+ });
419
+ } else {
420
+ resolve(result);
421
+ }
422
+ } catch (e) {
423
+ resolve(result);
424
+ }
425
+ });
426
+ });
427
+ }
428
+
392
429
  function getCodepage() {
393
430
  if (_windows) {
394
431
  if (!codepage) {
@@ -506,7 +543,7 @@ function countLines(lines, startingWith) {
506
543
  function sanitizeShellString(str, strict = false) {
507
544
  const s = str || '';
508
545
  let result = '';
509
- for (let i = 0; i <= 2000; i++) {
546
+ for (let i = 0; i <= mathMin(s.length, 2000); i++) {
510
547
  if (!(s[i] === undefined ||
511
548
  s[i] === '>' ||
512
549
  s[i] === '<' ||
@@ -529,10 +566,11 @@ function sanitizeShellString(str, strict = false) {
529
566
  s[i] === '\'' ||
530
567
  s[i] === '`' ||
531
568
  s[i] === '"' ||
532
- strict && s[i] === '@' ||
533
- strict && s[i] === ' ' ||
534
- strict && s[i] == '{' ||
535
- strict && s[i] == ')')) {
569
+ s[i].length > 1 ||
570
+ (strict && s[i] === '@') ||
571
+ (strict && s[i] === ' ') ||
572
+ (strict && s[i] == '{') ||
573
+ (strict && s[i] == ')'))) {
536
574
  result = result + s[i];
537
575
  }
538
576
  }
@@ -924,6 +962,7 @@ exports.wmic = wmic;
924
962
  exports.darwinXcodeExists = darwinXcodeExists;
925
963
  exports.getVboxmanage = getVboxmanage;
926
964
  exports.powerShell = powerShell;
965
+ exports.execSave = execSave;
927
966
  exports.nanoSeconds = nanoSeconds;
928
967
  exports.countUniqueLines = countUniqueLines;
929
968
  exports.countLines = countLines;
@@ -942,5 +981,6 @@ exports.stringToString = stringToString;
942
981
  exports.stringSubstr = stringSubstr;
943
982
  exports.stringTrim = stringTrim;
944
983
  exports.stringStartWith = stringStartWith;
984
+ exports.mathMin = mathMin;
945
985
  exports.WINDIR = WINDIR;
946
986
  exports.getFilesInPath = getFilesInPath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "5.6.0",
3
+ "version": "5.6.4",
4
4
  "description": "Simple system and OS information library",
5
5
  "license": "MIT",
6
6
  "author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",