systeminformation 6.0.0-beta.6 → 6.0.0-beta.7

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.
@@ -18,7 +18,7 @@ const networkStatsSingle = async (iface) => {
18
18
  let rx_errors = 0;
19
19
  let tx_dropped = 0;
20
20
  let tx_errors = 0;
21
- const { stdout } = await (0, exec_1.execSave)(`netstat -ibndI ${iface}`);
21
+ const stdout = await (0, exec_1.execSecure)('netstat', ['-ibndI', iface]);
22
22
  if (stdout) {
23
23
  const lines = stdout.split('\n');
24
24
  for (let i = 1; i < lines.length; i++) {
@@ -4,7 +4,6 @@ exports.mergeControllerNvidia = exports.nvidiaDevices = exports.nvidiaSmi = expo
4
4
  const promises_1 = require("fs/promises");
5
5
  const const_1 = require("./const");
6
6
  const exec_1 = require("./exec");
7
- const security_1 = require("./security");
8
7
  let _nvidiaSmiPath = null;
9
8
  const getNvidiaSmi = async () => {
10
9
  if (_nvidiaSmiPath !== null) {
@@ -49,11 +48,9 @@ const nvidiaSmi = async () => {
49
48
  const nvidiaSmiExe = await (0, exports.getNvidiaSmi)();
50
49
  if (nvidiaSmiExe) {
51
50
  const nvidiaSmiOpts = '--query-gpu=driver_version,pci.sub_device_id,name,pci.bus_id,fan.speed,memory.total,memory.used,memory.free,utilization.gpu,utilization.memory,temperature.gpu,temperature.memory,power.draw,power.limit,clocks.gr,clocks.mem --format=csv,noheader,nounits';
52
- const cmd = `${nvidiaSmiExe} ${nvidiaSmiOpts}`;
53
51
  try {
54
- const sanitized = (0, security_1.sanitizeShellString)(cmd) + (const_1.LINUX ? ' 2>/dev/null' : '') + (const_1.WINDOWS ? ' 2> nul' : '');
55
- const { stdout } = await (0, exec_1.exec)(sanitized, const_1.execOptsWin);
56
- return stdout;
52
+ const { stdout } = await (0, exec_1.execFile)(nvidiaSmiExe, nvidiaSmiOpts.split(' '), const_1.execOptsWin);
53
+ return String(stdout);
57
54
  }
58
55
  catch { }
59
56
  }
@@ -12,6 +12,13 @@ const diskLayout = async () => {
12
12
  let stdout = '';
13
13
  let cmd = '';
14
14
  let cmdFullSmart = '';
15
+ const addSmartCmds = (bsdName) => {
16
+ if (typeof bsdName !== 'string' || !/^disk\d+(s\d+)*$/.test(bsdName)) {
17
+ return;
18
+ }
19
+ cmd += `printf "\n${bsdName}|"; diskutil info /dev/${bsdName} | grep SMART;`;
20
+ cmdFullSmart += `${cmdFullSmart ? 'printf ",";' : ''}smartctl -a -j ${bsdName};`;
21
+ };
15
22
  try {
16
23
  ({ stdout } = await (0, exec_1.exec)(`system_profiler SPSerialATADataType SPNVMeDataType SPUSBDataType SPStorageDataType -xml`, { maxBuffer: const_1.MAX_BUFFER_SIZE }));
17
24
  const data = (0, darwin_1.plistParser)(stdout, false);
@@ -44,8 +51,7 @@ const diskLayout = async () => {
44
51
  temperature: null,
45
52
  bsdName: disk.bsd_name
46
53
  });
47
- cmd += 'printf "\n' + disk.bsd_name + '|"; diskutil info /dev/' + disk.bsd_name + ' | grep SMART;';
48
- cmdFullSmart += `${cmdFullSmart ? 'printf ",";' : ''}smartctl -a -j ${disk.bsd_name};`;
54
+ addSmartCmds(disk.bsd_name);
49
55
  });
50
56
  }
51
57
  });
@@ -74,8 +80,7 @@ const diskLayout = async () => {
74
80
  temperature: null,
75
81
  bsdName: disk.bsd_name
76
82
  });
77
- cmd += 'printf "\n' + disk.bsd_name + '|"; diskutil info /dev/' + disk.bsd_name + ' | grep SMART;';
78
- cmdFullSmart += `${cmdFullSmart ? 'printf ",";' : ''}smartctl -a -j ${disk.bsd_name};`;
83
+ addSmartCmds(disk.bsd_name);
79
84
  });
80
85
  }
81
86
  });
@@ -106,8 +111,7 @@ const diskLayout = async () => {
106
111
  temperature: null,
107
112
  bsdName: media.bsd_name
108
113
  });
109
- cmd += 'printf "\n' + media.bsd_name + '|"; diskutil info /dev/' + media.bsd_name + ' | grep SMART;';
110
- cmdFullSmart += `${cmdFullSmart ? 'printf ",";' : ''}smartctl -a -j ${disk.bsd_name};`;
114
+ addSmartCmds(media.bsd_name);
111
115
  }
112
116
  else if (disk?._items.length) {
113
117
  disk._items.forEach((subdisk) => {
@@ -19,11 +19,11 @@ const networkStatsSingle = async (iface) => {
19
19
  let rx_errors = 0;
20
20
  let tx_dropped = 0;
21
21
  let tx_errors = 0;
22
- let stdout = '';
23
- ({ stdout } = await (0, exec_1.execSave)(`ifconfig ${iface} | grep "status"`));
24
- operstate = (stdout.split(':')[1] || '').trim().toLowerCase();
22
+ let stdout = await (0, exec_1.execSecure)('ifconfig', [iface]);
23
+ const statusLine = stdout.split('\n').find((l) => l.includes('status')) || '';
24
+ operstate = (statusLine.split(':')[1] || '').trim().toLowerCase();
25
25
  operstate = operstate === 'active' ? 'up' : operstate === 'inactive' ? 'down' : 'unknown';
26
- ({ stdout } = await (0, exec_1.execSave)(`netstat -bdnI ${iface}`));
26
+ stdout = await (0, exec_1.execSecure)('netstat', ['-bdnI', iface]);
27
27
  if (stdout) {
28
28
  const lines = stdout.toString().split('\n');
29
29
  if (lines.length > 1 && lines[1].trim() !== '') {
@@ -267,7 +267,7 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
267
267
  ip6subnet = ip6linksubnet;
268
268
  }
269
269
  const ifaceDevName = dev.split(':')[0].trim();
270
- const ifaceSanitized = (0, security_1.sanitizeString)(ifaceDevName);
270
+ const ifaceSanitized = (0, security_1.sanitizeString)(ifaceDevName, true);
271
271
  const cmd = `echo -n "addr_assign_type: "; cat /sys/class/net/${ifaceSanitized}/addr_assign_type 2>/dev/null; echo;
272
272
  echo -n "address: "; cat /sys/class/net/${ifaceSanitized}/address 2>/dev/null; echo;
273
273
  echo -n "addr_len: "; cat /sys/class/net/${ifaceSanitized}/addr_len 2>/dev/null; echo;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.networkStats = void 0;
4
4
  const files_1 = require("../common/files");
5
- const exec_1 = require("../common/exec");
6
5
  const common_1 = require("../common");
7
6
  const security_1 = require("../common/security");
8
7
  const defaults_1 = require("../common/defaults");
@@ -13,40 +12,13 @@ const networkStatsSingle = async (iface) => {
13
12
  await (0, common_1.nextTick)();
14
13
  const defaults = { ...defaults_1.initNetworkSpeed, iface };
15
14
  if (!_network[iface] || (_network[iface] && !_network[iface].ms) || (_network[iface] && _network[iface].ms && Date.now() - _network[iface].ms >= 500)) {
16
- if (await (0, files_1.fileExists)('/sys/class/net/' + iface)) {
17
- const cmd = 'cat /sys/class/net/' +
18
- iface +
19
- '/operstate; ' +
20
- 'cat /sys/class/net/' +
21
- iface +
22
- '/statistics/rx_bytes; ' +
23
- 'cat /sys/class/net/' +
24
- iface +
25
- '/statistics/tx_bytes; ' +
26
- 'cat /sys/class/net/' +
27
- iface +
28
- '/statistics/rx_dropped; ' +
29
- 'cat /sys/class/net/' +
30
- iface +
31
- '/statistics/rx_errors; ' +
32
- 'cat /sys/class/net/' +
33
- iface +
34
- '/statistics/tx_dropped; ' +
35
- 'cat /sys/class/net/' +
36
- iface +
37
- '/statistics/tx_errors; ';
38
- const { stdout } = await (0, exec_1.execSave)(cmd);
39
- if (stdout) {
40
- const lines = stdout.split('\n');
41
- const operstate = lines[0].trim();
42
- const rx_bytes = (0, common_1.toInt)(lines[1]);
43
- const tx_bytes = (0, common_1.toInt)(lines[2]);
44
- const rx_dropped = (0, common_1.toInt)(lines[3]);
45
- const rx_errors = (0, common_1.toInt)(lines[4]);
46
- const tx_dropped = (0, common_1.toInt)(lines[5]);
47
- const tx_errors = (0, common_1.toInt)(lines[6]);
48
- return (0, network_1.calcNetworkSpeed)(iface, rx_bytes, tx_bytes, rx_dropped, rx_errors, tx_dropped, tx_errors, operstate, _network);
49
- }
15
+ const dir = '/sys/class/net/' + iface;
16
+ if (/^[\w.:@-]+$/.test(iface) && (await (0, files_1.fileExists)(dir))) {
17
+ const [operstate, rx_bytes, tx_bytes, rx_dropped, rx_errors, tx_dropped, tx_errors] = await Promise.all([
18
+ (0, files_1.readSysfs)(dir + '/operstate'),
19
+ ...['rx_bytes', 'tx_bytes', 'rx_dropped', 'rx_errors', 'tx_dropped', 'tx_errors'].map(async (f) => (0, common_1.toInt)(await (0, files_1.readSysfs)(dir + '/statistics/' + f)))
20
+ ]);
21
+ return (0, network_1.calcNetworkSpeed)(iface, rx_bytes, tx_bytes, rx_dropped, rx_errors, tx_dropped, tx_errors, operstate, _network);
50
22
  }
51
23
  return defaults;
52
24
  }
package/dist/versions.js CHANGED
@@ -414,90 +414,45 @@ const versions = async (apps) => {
414
414
  });
415
415
  }
416
416
  if (Object.keys(appsObj.versions).includes('postgresql')) {
417
- if (const_1.LINUX) {
418
- (0, exec_1.exec)('locate bin/postgres')
419
- .then((res) => {
420
- const postgresqlBin = res.stdout.split('\n').sort();
421
- if (postgresqlBin.length) {
422
- (0, exec_1.exec)(postgresqlBin[postgresqlBin.length - 1] + ' -V')
423
- .then((res) => {
424
- if (res.stdout) {
425
- const postgresql = res.stdout.split('\n')[0].split(' ') || [];
426
- appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
417
+ if (const_1.WINDOWS) {
418
+ windows_1.ps.exec('Get-CimInstance Win32_Service | select caption | fl')
419
+ .then((stdout) => {
420
+ const serviceSections = (stdout ? stdout.toString() : '').split(/\n\s*\n/);
421
+ serviceSections.forEach((item) => {
422
+ const lines = item.trim().split('\r\n');
423
+ const srvCaption = (0, common_1.getValue)(lines, 'caption', ':', true).toLowerCase();
424
+ if (srvCaption.indexOf('postgresql') > -1) {
425
+ const parts = srvCaption.split(' server ');
426
+ if (parts.length > 1) {
427
+ appsObj.versions.postgresql = parts[1];
427
428
  }
428
- functionProcessed();
429
- })
430
- .catch(() => {
431
- functionProcessed();
432
- });
433
- }
434
- else {
435
- functionProcessed();
436
- }
429
+ }
430
+ });
431
+ functionProcessed();
437
432
  })
438
433
  .catch(() => {
439
- (0, exec_1.exec)('psql -V')
440
- .then((res) => {
441
- const postgresql = res.stdout.split('\n')[0].split(' ') || [];
442
- appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
443
- appsObj.versions.postgresql = appsObj.versions.postgresql.split('-')[0];
444
- functionProcessed();
445
- })
446
- .catch(() => {
447
- functionProcessed();
448
- });
434
+ functionProcessed();
449
435
  });
450
436
  }
451
437
  else {
452
- if (const_1.WINDOWS) {
453
- windows_1.ps.exec('Get-CimInstance Win32_Service | select caption | fl')
454
- .then((stdout) => {
455
- const serviceSections = (stdout ? stdout.toString() : '').split(/\n\s*\n/);
456
- serviceSections.forEach((item) => {
457
- const lines = item.trim().split('\r\n');
458
- const srvCaption = (0, common_1.getValue)(lines, 'caption', ':', true).toLowerCase();
459
- if (srvCaption.indexOf('postgresql') > -1) {
460
- const parts = srvCaption.split(' server ');
461
- if (parts.length > 1) {
462
- appsObj.versions.postgresql = parts[1];
463
- }
464
- }
465
- });
466
- functionProcessed();
467
- })
468
- .catch(() => {
469
- functionProcessed();
470
- });
471
- }
472
- else {
473
- (0, exec_1.exec)('postgres -V')
474
- .then((res) => {
475
- if (res.stdout) {
476
- const postgresql = res.stdout.split('\n')[0].split(' ') || [];
477
- appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
478
- if (appsObj.versions.postgresql.includes('(') && postgresql.length >= 2 && !postgresql[postgresql.length - 2].includes('(')) {
479
- appsObj.versions.postgresql = postgresql[postgresql.length - 2];
480
- }
438
+ const parsePostgres = (stdout) => {
439
+ const postgresql = stdout.split('\n')[0].split(' ') || [];
440
+ let version = postgresql.length ? postgresql[postgresql.length - 1] : '';
441
+ if (version.includes('(') && postgresql.length >= 2 && !postgresql[postgresql.length - 2].includes('(')) {
442
+ version = postgresql[postgresql.length - 2];
443
+ }
444
+ return version.split('-')[0];
445
+ };
446
+ (async () => {
447
+ for (const cmd of ['postgres -V', 'pg_config --version', 'psql -V']) {
448
+ const { stdout } = await (0, exec_1.execSave)(cmd);
449
+ if (stdout) {
450
+ appsObj.versions.postgresql = parsePostgres(stdout);
451
+ break;
481
452
  }
482
- functionProcessed();
483
- })
484
- .catch(() => {
485
- (0, exec_1.exec)('pg_config --version 2> /dev/null')
486
- .then((res) => {
487
- if (res.stdout) {
488
- const postgresql = res.stdout.toString().split('\n')[0].split(' ') || [];
489
- appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
490
- if (appsObj.versions.postgresql.includes('(') && postgresql.length >= 2 && !postgresql[postgresql.length - 2].includes('(')) {
491
- appsObj.versions.postgresql = postgresql[postgresql.length - 2];
492
- }
493
- }
494
- })
495
- .catch(() => { })
496
- .finally(() => {
497
- functionProcessed();
498
- });
499
- });
500
- }
453
+ }
454
+ functionProcessed();
455
+ })();
501
456
  }
502
457
  }
503
458
  if (Object.keys(appsObj.versions).includes('perl')) {
@@ -99,6 +99,9 @@ const diskLayout = async () => {
99
99
  const smartDev = JSON.parse(stdout.trim());
100
100
  if (smartDev?.devices && smartDev.devices.length > 0) {
101
101
  for (const dev of smartDev.devices) {
102
+ if (!/^[\w/.,:\\-]+$/.test(String(dev.name || ''))) {
103
+ continue;
104
+ }
102
105
  try {
103
106
  const { stdout: smartOut } = await (0, exec_1.execSave)(`smartctl -j -a ${dev.name}`, const_1.execOptsWin);
104
107
  const smartData = JSON.parse(smartOut);
@@ -149,8 +149,8 @@ const getWindowsWiredProfilesInformation = async () => {
149
149
  };
150
150
  const getWindowsWirelessIfaceSSID = async (interfaceName) => {
151
151
  try {
152
- const { stdout } = await (0, exec_1.exec)(`netsh wlan show interface name="${interfaceName}" | findstr "SSID"`, const_1.execOptsWin);
153
- const SSID = stdout.split('\r\n')[0];
152
+ const { stdout } = await (0, exec_1.execFile)('netsh', ['wlan', 'show', 'interface', `name=${(0, security_1.sanitizeString)(interfaceName)}`], const_1.execOptsWin);
153
+ const SSID = String(stdout).split('\r\n').find((l) => l.includes('SSID')) || '';
154
154
  const parseSSID = (SSID.split(':').pop() || '').trim();
155
155
  return parseSSID;
156
156
  }
@@ -197,11 +197,10 @@ const getWindowsIEEE8021x = async (connectionType, iface, interfaces) => {
197
197
  let i8021xState = '';
198
198
  let i8021xProtocol = '';
199
199
  try {
200
- const SSID = await getWindowsWirelessIfaceSSID((0, security_1.sanitizeString)(iface));
200
+ const SSID = await getWindowsWirelessIfaceSSID(iface);
201
201
  if (SSID !== 'Unknown') {
202
- const ifaceSanitized = (0, security_1.sanitizeString)(SSID);
203
- const { stdout } = await (0, exec_1.exec)(`netsh wlan show profiles "${ifaceSanitized}"`, const_1.execOptsWin);
204
- const profiles = stdout.split('\r\n');
202
+ const { stdout } = await (0, exec_1.execFile)('netsh', ['wlan', 'show', 'profiles', (0, security_1.sanitizeString)(SSID)], const_1.execOptsWin);
203
+ const profiles = String(stdout).split('\r\n');
205
204
  i8021xState = (profiles.find((l) => l.indexOf('802.1X') >= 0) || '').trim();
206
205
  i8021xProtocol = (profiles.find((l) => l.indexOf('EAP') >= 0) || '').trim();
207
206
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "6.0.0-beta.6",
3
+ "version": "6.0.0-beta.7",
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)",