systeminformation 6.0.0-beta.7 → 6.0.0-beta.9

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.
Files changed (58) hide show
  1. package/README.md +17 -1
  2. package/dist/common/defaults.d.ts +2 -1
  3. package/dist/common/defaults.js +11 -1
  4. package/dist/common/files.d.ts +8 -0
  5. package/dist/common/files.js +58 -3
  6. package/dist/common/nvidia.js +2 -1
  7. package/dist/common/parse.d.ts +4 -6
  8. package/dist/common/parse.js +24 -69
  9. package/dist/common/security.d.ts +1 -0
  10. package/dist/common/security.js +3 -1
  11. package/dist/common/types.d.ts +12 -2
  12. package/dist/cpu-current-load.js +5 -5
  13. package/dist/cpu-current-speed.js +5 -3
  14. package/dist/darwin/index.d.ts +1 -0
  15. package/dist/darwin/index.js +3 -1
  16. package/dist/darwin/serial-ports.d.ts +2 -0
  17. package/dist/darwin/serial-ports.js +94 -0
  18. package/dist/get-data.d.ts +2 -0
  19. package/dist/get-data.js +3 -1
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.js +3 -1
  22. package/dist/linux/audio.js +11 -2
  23. package/dist/linux/baseboard.js +9 -20
  24. package/dist/linux/bios.js +6 -15
  25. package/dist/linux/camera.js +2 -1
  26. package/dist/linux/chassis.js +4 -10
  27. package/dist/linux/cpu-temperature.js +34 -19
  28. package/dist/linux/cpu.js +3 -1
  29. package/dist/linux/disk-layout.js +2 -5
  30. package/dist/linux/disks-io.js +6 -6
  31. package/dist/linux/fans.js +3 -2
  32. package/dist/linux/fs-size.js +120 -26
  33. package/dist/linux/fs-stats.js +6 -9
  34. package/dist/linux/gpu.js +2 -1
  35. package/dist/linux/index.d.ts +1 -0
  36. package/dist/linux/index.js +3 -1
  37. package/dist/linux/mem-layout.js +2 -2
  38. package/dist/linux/network-interfaces.js +10 -29
  39. package/dist/linux/network-stats.js +1 -1
  40. package/dist/linux/npu.js +2 -1
  41. package/dist/linux/os-info.js +19 -4
  42. package/dist/linux/printer.js +4 -4
  43. package/dist/linux/process-load.js +9 -12
  44. package/dist/linux/processes.js +88 -79
  45. package/dist/linux/serial-ports.d.ts +2 -0
  46. package/dist/linux/serial-ports.js +102 -0
  47. package/dist/linux/services.js +12 -12
  48. package/dist/linux/system.js +1 -7
  49. package/dist/linux/uuid.js +4 -10
  50. package/dist/serial-ports.d.ts +1 -0
  51. package/dist/serial-ports.js +17 -0
  52. package/dist/windows/index.d.ts +1 -0
  53. package/dist/windows/index.js +3 -1
  54. package/dist/windows/process-load.js +5 -4
  55. package/dist/windows/processes.js +10 -6
  56. package/dist/windows/serial-ports.d.ts +3 -0
  57. package/dist/windows/serial-ports.js +73 -0
  58. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.osInfo = exports.observe = exports.npu = exports.npm = exports.networkStats = exports.networkInterfaces = exports.networkInterfaceDefault = exports.networkGatewayDefault = exports.networkConnections = exports.mouse = exports.memLayout = exports.mem = exports.keyboard = exports.inetPublicIp = exports.inetLatency = exports.inetChecksite = exports.gpu = exports.getAllData = exports.getDynamicData = exports.getStaticData = exports.get = exports.fullLoad = exports.fsStats = exports.fsSize = exports.fsOpenFiles = exports.dockerAll = exports.dockerVolumes = exports.dockerContainerProcesses = exports.dockerContainerStats = exports.dockerContainers = exports.dockerImages = exports.dockerInfo = exports.displays = exports.disksIO = exports.diskLayout = exports.currentLoad = exports.fans = exports.cpuTemperature = exports.cpuFlags = exports.cpuCurrentSpeed = exports.cpuCache = exports.cpu = exports.chassis = exports.camera = exports.bluetoothDevices = exports.blockDevices = exports.bios = exports.battery = exports.baseboard = exports.audio = void 0;
4
- exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.time = exports.thunderbolt = exports.system = exports.software = exports.shell = exports.services = exports.processLoad = exports.processes = exports.printer = exports.pci = void 0;
4
+ exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.time = exports.thunderbolt = exports.system = exports.software = exports.shell = exports.services = exports.serialPorts = exports.processLoad = exports.processes = exports.printer = exports.pci = void 0;
5
5
  var audio_1 = require("./audio");
6
6
  Object.defineProperty(exports, "audio", { enumerable: true, get: function () { return audio_1.audio; } });
7
7
  var baseboard_1 = require("./baseboard");
@@ -102,6 +102,8 @@ var processes_1 = require("./processes");
102
102
  Object.defineProperty(exports, "processes", { enumerable: true, get: function () { return processes_1.processes; } });
103
103
  var process_load_1 = require("./process-load");
104
104
  Object.defineProperty(exports, "processLoad", { enumerable: true, get: function () { return process_load_1.processLoad; } });
105
+ var serial_ports_1 = require("./serial-ports");
106
+ Object.defineProperty(exports, "serialPorts", { enumerable: true, get: function () { return serial_ports_1.serialPorts; } });
105
107
  var services_1 = require("./services");
106
108
  Object.defineProperty(exports, "services", { enumerable: true, get: function () { return services_1.services; } });
107
109
  var shell_1 = require("./shell");
@@ -4,8 +4,11 @@ exports.audio = void 0;
4
4
  const node_os_1 = require("node:os");
5
5
  const common_1 = require("../common");
6
6
  const const_1 = require("../common/const");
7
+ const promises_1 = require("node:fs/promises");
7
8
  const exec_1 = require("../common/exec");
9
+ const files_1 = require("../common/files");
8
10
  const mappings_1 = require("../common/mappings");
11
+ const security_1 = require("../common/security");
9
12
  const getAudioPci = async () => {
10
13
  const result = [];
11
14
  try {
@@ -86,8 +89,14 @@ const parseAudioAlsa = (stdout) => {
86
89
  };
87
90
  const getAudioAlsa = async () => {
88
91
  try {
89
- const { stdout } = await (0, exec_1.exec)('cat /proc/asound/cards 2>/dev/null; echo "--pcm--"; ls -d /proc/asound/card*/pcm* 2>/dev/null', const_1.execOptsLinux);
90
- return parseAudioAlsa(stdout.toString());
92
+ const cards = await (0, files_1.readSysfs)('/proc/asound/cards');
93
+ const pcms = [];
94
+ for (const card of (await (0, promises_1.readdir)('/proc/asound')).filter((entry) => /^card\d+$/.test(entry)).sort()) {
95
+ for (const pcm of (await (0, promises_1.readdir)(`/proc/asound/${card}`)).filter((entry) => entry.startsWith('pcm') && (0, security_1.isSafePathSegment)(entry)).sort()) {
96
+ pcms.push(`/proc/asound/${card}/${pcm}`);
97
+ }
98
+ }
99
+ return parseAudioAlsa(`${cards}\n--pcm--\n${pcms.join('\n')}\n`);
91
100
  }
92
101
  catch {
93
102
  return [];
@@ -7,36 +7,25 @@ const common_1 = require("../common");
7
7
  const const_1 = require("../common/const");
8
8
  const defaults_1 = require("../common/defaults");
9
9
  const exec_1 = require("../common/exec");
10
+ const files_1 = require("../common/files");
10
11
  const parse_1 = require("../common/parse");
11
12
  const raspberry_1 = require("../common/raspberry");
12
13
  const baseboard = async () => {
13
14
  await (0, common_1.nextTick)();
14
15
  const defaults = (0, common_1.cloneObj)(defaults_1.initBaseboard);
15
- let cmd = '';
16
- if (process.arch === 'arm') {
17
- cmd = 'cat /proc/cpuinfo | grep Serial';
18
- }
19
- else {
20
- cmd = 'export LC_ALL=C; dmidecode -t 2 2>/dev/null; unset LC_ALL';
21
- }
22
- const workload = [];
23
- workload.push((0, exec_1.exec)(cmd, const_1.execOptsLinux));
24
- workload.push((0, exec_1.exec)('export LC_ALL=C; dmidecode -t memory 2>/dev/null', const_1.execOptsLinux));
25
- const data = await Promise.allSettled(workload).then((results) => results.map((result) => (result.status === 'fulfilled' ? result.value : null)));
26
- let lines = data[0] ? data[0].stdout.split('\n') : [''];
16
+ const boardTask = process.arch === 'arm'
17
+ ? (0, files_1.readFileLines)('/proc/cpuinfo').then((cpuinfo) => cpuinfo.filter((line) => line.indexOf('Serial') >= 0))
18
+ : (0, exec_1.execSave)('export LC_ALL=C; dmidecode -t 2 2>/dev/null; unset LC_ALL', const_1.execOptsLinux).then((res) => res.stdout.split('\n'));
19
+ const memTask = (0, exec_1.execSave)('export LC_ALL=C; dmidecode -t memory 2>/dev/null', const_1.execOptsLinux).then((res) => res.stdout.split('\n'));
20
+ const [boardLines, memLines] = await Promise.all([boardTask, memTask]);
21
+ let lines = boardLines;
27
22
  let manufacturer = (0, common_1.getValue)(lines, 'Manufacturer');
28
23
  let model = (0, common_1.getValue)(lines, 'Product Name');
29
24
  let version = (0, common_1.getValue)(lines, 'Version');
30
25
  let serial = (0, common_1.getValue)(lines, 'Serial Number');
31
26
  let assetTag = (0, common_1.getValue)(lines, 'Asset Tag');
32
- cmd = `echo -n "board_asset_tag: "; cat /sys/devices/virtual/dmi/id/board_asset_tag 2>/dev/null; echo;
33
- echo -n "board_name: "; cat /sys/devices/virtual/dmi/id/board_name 2>/dev/null; echo;
34
- echo -n "board_serial: "; cat /sys/devices/virtual/dmi/id/board_serial 2>/dev/null; echo;
35
- echo -n "board_vendor: "; cat /sys/devices/virtual/dmi/id/board_vendor 2>/dev/null; echo;
36
- echo -n "board_version: "; cat /sys/devices/virtual/dmi/id/board_version 2>/dev/null; echo;`;
37
27
  try {
38
- const { stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux);
39
- lines = stdout.split('\n');
28
+ lines = await (0, files_1.readSysfsMany)(files_1.DMI_PATH, ['board_asset_tag', 'board_name', 'board_serial', 'board_vendor', 'board_version']);
40
29
  manufacturer = !manufacturer ? (0, common_1.getValue)(lines, 'board_vendor') : manufacturer;
41
30
  model = !model ? (0, common_1.getValue)(lines, 'board_name') : model;
42
31
  version = !version ? (0, common_1.getValue)(lines, 'board_version') : version;
@@ -49,7 +38,7 @@ const baseboard = async () => {
49
38
  model = (0, parse_1.cleanDefaults)(model);
50
39
  version = (0, parse_1.cleanDefaults)(version);
51
40
  manufacturer = (0, parse_1.cleanDefaults)(manufacturer);
52
- lines = data[1] ? data[1].stdout.split('\n') : [''];
41
+ lines = memLines;
53
42
  let memMax = (0, common_1.toInt)((0, common_1.getValue)(lines, 'Maximum Capacity')) * 1024 * 1024 * 1024 || null;
54
43
  let memSlots = (0, common_1.toInt)((0, common_1.getValue)(lines, 'Number Of Devices')) || null;
55
44
  let linesRpi = [];
@@ -5,19 +5,14 @@ const common_1 = require("../common");
5
5
  const defaults_1 = require("../common/defaults");
6
6
  const datetime_1 = require("../common/datetime");
7
7
  const exec_1 = require("../common/exec");
8
+ const files_1 = require("../common/files");
8
9
  const const_1 = require("../common/const");
9
10
  const bios = async () => {
10
11
  await (0, common_1.nextTick)();
11
12
  const result = (0, common_1.cloneObj)(defaults_1.initBios);
12
- let cmd = '';
13
- if (process.arch === 'arm') {
14
- cmd = 'cat /proc/cpuinfo | grep Serial';
15
- }
16
- else {
17
- cmd = 'export LC_ALL=C; dmidecode -t bios 2>/dev/null; unset LC_ALL';
18
- }
19
- const { stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux);
20
- let lines = stdout.toString().split('\n');
13
+ let lines = process.arch === 'arm'
14
+ ? (await (0, files_1.readFileLines)('/proc/cpuinfo')).filter((line) => line.indexOf('Serial') >= 0)
15
+ : (await (0, exec_1.execSave)('export LC_ALL=C; dmidecode -t bios 2>/dev/null; unset LC_ALL', const_1.execOptsLinux)).stdout.split('\n');
21
16
  result.vendor = (0, common_1.getValue)(lines, 'Vendor');
22
17
  result.version = (0, common_1.getValue)(lines, 'Version');
23
18
  let datetime = (0, common_1.getValue)(lines, 'Release Date');
@@ -28,7 +23,7 @@ const bios = async () => {
28
23
  if (language) {
29
24
  result.language = language;
30
25
  }
31
- if (lines.length && stdout.toString().indexOf('Characteristics:') >= 0) {
26
+ if (lines.some((line) => line.indexOf('Characteristics:') >= 0)) {
32
27
  const features = [];
33
28
  lines.forEach((line) => {
34
29
  if (line.indexOf(' is supported') >= 0) {
@@ -38,12 +33,8 @@ const bios = async () => {
38
33
  });
39
34
  result.features = features;
40
35
  }
41
- cmd = `echo -n "bios_date: "; cat /sys/devices/virtual/dmi/id/bios_date 2>/dev/null; echo;
42
- echo -n "bios_vendor: "; cat /sys/devices/virtual/dmi/id/bios_vendor 2>/dev/null; echo;
43
- echo -n "bios_version: "; cat /sys/devices/virtual/dmi/id/bios_version 2>/dev/null; echo;`;
44
36
  try {
45
- const { stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux);
46
- lines = stdout.split('\n');
37
+ lines = await (0, files_1.readSysfsMany)(files_1.DMI_PATH, ['bios_date', 'bios_vendor', 'bios_version']);
47
38
  result.vendor = !result.vendor ? (0, common_1.getValue)(lines, 'bios_vendor') : result.vendor;
48
39
  result.version = !result.version ? (0, common_1.getValue)(lines, 'bios_version') : result.version;
49
40
  datetime = (0, common_1.getValue)(lines, 'bios_date');
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.camera = void 0;
4
4
  const promises_1 = require("node:fs/promises");
5
5
  const common_1 = require("../common");
6
+ const security_1 = require("../common/security");
6
7
  const V4L_PATH = '/sys/class/video4linux';
7
8
  const readAttr = async (path) => {
8
9
  try {
@@ -17,7 +18,7 @@ const camera = async () => {
17
18
  const result = [];
18
19
  const seen = new Set();
19
20
  try {
20
- const nodes = (await (0, promises_1.readdir)(V4L_PATH)).filter((node) => node.startsWith('video')).sort();
21
+ const nodes = (await (0, promises_1.readdir)(V4L_PATH)).filter((node) => node.startsWith('video') && (0, security_1.isSafePathSegment)(node)).sort();
21
22
  for (const node of nodes) {
22
23
  const base = `${V4L_PATH}/${node}`;
23
24
  const name = await readAttr(`${base}/name`);
@@ -2,12 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chassis = void 0;
4
4
  const common_1 = require("../common");
5
- const exec_1 = require("../common/exec");
5
+ const files_1 = require("../common/files");
6
6
  const defaults_1 = require("../common/defaults");
7
7
  const mappings_1 = require("../common/mappings");
8
8
  const parse_1 = require("../common/parse");
9
- const parseChassis = (stdout, defaults) => {
10
- const lines = stdout.toString().split('\n');
9
+ const parseChassis = (lines, defaults) => {
11
10
  const manufacturer = (0, parse_1.cleanDefaults)((0, common_1.getValue)(lines, 'chassis_vendor'));
12
11
  const ctype = parseInt((0, common_1.getValue)(lines, 'chassis_type').replace(/\D/g, ''));
13
12
  const chassisType = ctype && !isNaN(ctype) && ctype <= mappings_1.chassisTypes.length ? mappings_1.chassisTypes[ctype - 1] : '';
@@ -26,14 +25,9 @@ const parseChassis = (stdout, defaults) => {
26
25
  const chassis = async () => {
27
26
  await (0, common_1.nextTick)();
28
27
  const defaults = (0, common_1.cloneObj)(defaults_1.initChassis);
29
- const cmd = `echo -n "chassis_asset_tag: "; cat /sys/devices/virtual/dmi/id/chassis_asset_tag 2>/dev/null; echo;
30
- echo -n "chassis_serial: "; cat /sys/devices/virtual/dmi/id/chassis_serial 2>/dev/null; echo;
31
- echo -n "chassis_type: "; cat /sys/devices/virtual/dmi/id/chassis_type 2>/dev/null; echo;
32
- echo -n "chassis_vendor: "; cat /sys/devices/virtual/dmi/id/chassis_vendor 2>/dev/null; echo;
33
- echo -n "chassis_version: "; cat /sys/devices/virtual/dmi/id/chassis_version 2>/dev/null; echo;`;
34
28
  try {
35
- const { stdout } = await (0, exec_1.execSave)(cmd);
36
- return parseChassis(stdout, defaults);
29
+ const lines = await (0, files_1.readSysfsMany)(files_1.DMI_PATH, ['chassis_asset_tag', 'chassis_serial', 'chassis_type', 'chassis_vendor', 'chassis_version']);
30
+ return parseChassis(lines, defaults);
37
31
  }
38
32
  catch { }
39
33
  return defaults;
@@ -7,35 +7,50 @@ const common_1 = require("../common");
7
7
  const defaults_1 = require("../common/defaults");
8
8
  const exec_1 = require("../common/exec");
9
9
  const files_1 = require("../common/files");
10
+ const security_1 = require("../common/security");
11
+ const readHwmonTemps = async () => {
12
+ const entries = [];
13
+ let mons = [];
14
+ try {
15
+ mons = (await (0, promises_1.readdir)('/sys/class/hwmon')).filter(security_1.isSafePathSegment).sort();
16
+ }
17
+ catch { }
18
+ for (const mon of mons) {
19
+ const dir = `/sys/class/hwmon/${mon}`;
20
+ let labels = [];
21
+ try {
22
+ labels = (await (0, promises_1.readdir)(dir)).filter((file) => /^temp\d+_label$/.test(file)).sort();
23
+ }
24
+ catch { }
25
+ for (const label of labels) {
26
+ const [name, value] = await Promise.all([(0, files_1.readSysfs)(`${dir}/${label}`), (0, files_1.readSysfs)(`${dir}/${label.replace(/_label$/, '_input')}`)]);
27
+ entries.push(`${name}___${value}`);
28
+ }
29
+ }
30
+ return entries;
31
+ };
10
32
  const cpuTemperature = async () => {
11
33
  await (0, common_1.nextTick)();
12
34
  const result = (0, common_1.cloneObj)(defaults_1.initCpuTemperature);
13
35
  let cpuThermal = null;
14
36
  try {
15
- const cmd = 'cat /sys/class/thermal/thermal_zone*/type 2>/dev/null; echo "-----"; cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null;';
16
- const { stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux);
17
- const parts = stdout.split('-----\n');
18
- if (parts.length === 2) {
19
- const lines = parts[0].split('\n');
20
- const lines2 = parts[1].split('\n');
21
- for (let i = 0; i < lines.length; i++) {
22
- const line = lines[i].trim();
23
- if (line.startsWith('acpi') && lines2[i]) {
24
- result.socket.push(Math.round(Number.parseInt(lines2[i], 10) / 100) / 10);
25
- }
26
- if (line.startsWith('pch') && lines2[i]) {
27
- result.chipset = Math.round(Number.parseInt(lines2[i], 10) / 100) / 10;
28
- }
29
- if (cpuThermal === null && line.indexOf('cpu') !== -1 && lines2[i]) {
30
- cpuThermal = Math.round(parseInt(lines2[i], 10) / 100) / 10;
31
- }
37
+ const zones = (await (0, promises_1.readdir)('/sys/class/thermal')).filter((zone) => zone.startsWith('thermal_zone') && (0, security_1.isSafePathSegment)(zone)).sort();
38
+ for (const zone of zones) {
39
+ const [line, temp] = await Promise.all([(0, files_1.readSysfs)(`/sys/class/thermal/${zone}/type`), (0, files_1.readSysfs)(`/sys/class/thermal/${zone}/temp`)]);
40
+ if (line.startsWith('acpi') && temp) {
41
+ result.socket.push(Math.round(Number.parseInt(temp, 10) / 100) / 10);
42
+ }
43
+ if (line.startsWith('pch') && temp) {
44
+ result.chipset = Math.round(Number.parseInt(temp, 10) / 100) / 10;
45
+ }
46
+ if (cpuThermal === null && line.indexOf('cpu') !== -1 && temp) {
47
+ cpuThermal = Math.round(parseInt(temp, 10) / 100) / 10;
32
48
  }
33
49
  }
34
50
  }
35
51
  catch { }
36
- const cmd = 'for mon in /sys/class/hwmon/hwmon*; do for label in "$mon"/temp*_label; do if [ -f $label ]; then value=${label%_*}_input; echo $(cat "$label")___$(cat "$value"); fi; done; done;';
37
52
  try {
38
- let { stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux);
53
+ let stdout = (await readHwmonTemps()).join('\n');
39
54
  const tdiePos = stdout.toLowerCase().indexOf('tdie');
40
55
  if (tdiePos !== -1) {
41
56
  stdout = stdout.substring(tdiePos);
package/dist/linux/cpu.js CHANGED
@@ -8,6 +8,7 @@ const const_1 = require("../common/const");
8
8
  const cpu_1 = require("../common/cpu");
9
9
  const defaults_1 = require("../common/defaults");
10
10
  const exec_1 = require("../common/exec");
11
+ const files_1 = require("../common/files");
11
12
  const mappings_1 = require("../common/mappings");
12
13
  const parse_1 = require("../common/parse");
13
14
  const raspberry_1 = require("./../common/raspberry");
@@ -25,8 +26,9 @@ const cpu = async () => {
25
26
  if ((0, node_os_1.cpus)()[0] && (0, node_os_1.cpus)()[0].model) {
26
27
  modelline = (0, node_os_1.cpus)()[0].model;
27
28
  }
28
- let { stdout } = await (0, exec_1.exec)('export LC_ALL=C; lscpu; echo -n "Governor: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 2>/dev/null; echo; unset LC_ALL', const_1.execOptsLinux);
29
+ let { stdout } = await (0, exec_1.exec)('export LC_ALL=C; lscpu; unset LC_ALL', const_1.execOptsLinux);
29
30
  let lines = stdout.toString().split('\n');
31
+ lines.push(`Governor: ${await (0, files_1.readSysfs)('/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor')}`);
30
32
  modelline = (0, common_1.getValue)(lines, 'model name') || modelline;
31
33
  modelline = (0, common_1.getValue)(lines, 'bios model name') || modelline;
32
34
  modelline = (0, common_1.cleanString)(modelline);
@@ -4,6 +4,7 @@ exports.diskLayout = void 0;
4
4
  const common_1 = require("../common");
5
5
  const const_1 = require("../common/const");
6
6
  const exec_1 = require("../common/exec");
7
+ const files_1 = require("../common/files");
7
8
  const filesys_1 = require("../common/filesys");
8
9
  const mappings_1 = require("../common/mappings");
9
10
  const security_1 = require("../common/security");
@@ -51,11 +52,7 @@ const diskLayout = async () => {
51
52
  let mediumType = '';
52
53
  const logical = (0, security_1.sanitizeShellString)(device.name || '', true);
53
54
  const bsdName = '/dev/' + logical;
54
- try {
55
- ({ stdout } = await (0, exec_1.exec)('cat /sys/block/' + logical + '/queue/rotational 2>/dev/null', const_1.execOptsLinux));
56
- mediumType = stdout.split('\n')[0];
57
- }
58
- catch { }
55
+ mediumType = (0, security_1.isSafePathSegment)(logical) ? await (0, files_1.readSysfs)(`/sys/block/${logical}/queue/rotational`) : '';
59
56
  let interfaceType = device.tran ? device.tran.toUpperCase().trim() : '';
60
57
  if (interfaceType === 'NVME') {
61
58
  mediumType = '2';
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.disksIO = void 0;
4
4
  const defaults_1 = require("../common/defaults");
5
5
  const index_1 = require("../common/index");
6
- const exec_1 = require("../common/exec");
7
6
  const common_1 = require("../common");
8
7
  const filesys_1 = require("../common/filesys");
9
- const const_1 = require("../common/const");
8
+ const promises_1 = require("node:fs/promises");
9
+ const files_1 = require("../common/files");
10
+ const security_1 = require("../common/security");
10
11
  const disksIO = async () => {
11
12
  await (0, common_1.nextTick)();
12
13
  if ((filesys_1._disk_io && !filesys_1._disk_io.ms) || (filesys_1._disk_io && filesys_1._disk_io.ms && Date.now() - filesys_1._disk_io.ms >= 500)) {
@@ -17,14 +18,13 @@ const disksIO = async () => {
17
18
  let wWaitTime = 0;
18
19
  let tWaitTime = 0;
19
20
  try {
20
- const cmd = 'for mount in `lsblk 2>/dev/null | grep " disk " | sed "s/[│└─├]//g" | awk \'{$1=$1};1\' | cut -d " " -f 1 | sort -u`; do cat /sys/block/$mount/stat | sed -r "s/ +/;/g" | sed -r "s/^;//"; done';
21
- const { stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux);
22
- const lines = stdout.split('\n');
21
+ const disks = (await (0, promises_1.readdir)('/sys/block')).filter((dev) => !/^(loop|ram|dm-|md|sr|fd|nbd)/.test(dev) && (0, security_1.isSafePathSegment)(dev));
22
+ const lines = await Promise.all(disks.map((dev) => (0, files_1.readSysfs)(`/sys/block/${dev}/stat`)));
23
23
  lines.forEach(function (line) {
24
24
  if (!line) {
25
25
  return;
26
26
  }
27
- const stats = line.split(';');
27
+ const stats = line.trim().split(/\s+/);
28
28
  rIO += (0, common_1.toInt)(stats[0]);
29
29
  wIO += (0, common_1.toInt)(stats[4]);
30
30
  rWaitTime += (0, common_1.toInt)(stats[3]);
@@ -4,6 +4,7 @@ exports.fans = void 0;
4
4
  const promises_1 = require("fs/promises");
5
5
  const common_1 = require("../common");
6
6
  const files_1 = require("../common/files");
7
+ const security_1 = require("../common/security");
7
8
  const toNumber = (value) => {
8
9
  const result = Number.parseFloat(value);
9
10
  return Number.isNaN(result) ? null : result;
@@ -16,7 +17,7 @@ const hwmonFans = async (hwmonPath) => {
16
17
  const fans = [];
17
18
  let nodes = [];
18
19
  try {
19
- nodes = await (0, promises_1.readdir)(hwmonPath);
20
+ nodes = (await (0, promises_1.readdir)(hwmonPath)).filter(security_1.isSafePathSegment);
20
21
  }
21
22
  catch {
22
23
  return fans;
@@ -55,7 +56,7 @@ const coolingDeviceFans = async (thermalPath) => {
55
56
  const fans = [];
56
57
  let nodes = [];
57
58
  try {
58
- nodes = (await (0, promises_1.readdir)(thermalPath)).filter((entry) => entry.startsWith('cooling_device'));
59
+ nodes = (await (0, promises_1.readdir)(thermalPath)).filter((entry) => entry.startsWith('cooling_device') && (0, security_1.isSafePathSegment)(entry));
59
60
  }
60
61
  catch {
61
62
  return fans;
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fsSize = void 0;
4
+ const promises_1 = require("node:fs/promises");
4
5
  const common_1 = require("../common");
5
6
  const const_1 = require("../common/const");
6
7
  const exec_1 = require("../common/exec");
8
+ const files_1 = require("../common/files");
7
9
  let macOsDisks = [];
8
10
  let osMounts = {};
9
11
  const getmacOsFsType = (fs) => {
@@ -78,6 +80,107 @@ const parseNixFsSize = (lines) => {
78
80
  });
79
81
  return data;
80
82
  };
83
+ const unescapeMount = (value) => value.replace(/\\(\d{3})/g, (_, octal) => String.fromCharCode(parseInt(octal, 8)));
84
+ const statfsSafeTypes = [
85
+ 'bcachefs',
86
+ 'btrfs',
87
+ 'erofs',
88
+ 'exfat',
89
+ 'ext2',
90
+ 'ext3',
91
+ 'ext4',
92
+ 'efivarfs',
93
+ 'f2fs',
94
+ 'gfs2',
95
+ 'hfs',
96
+ 'hfsplus',
97
+ 'iso9660',
98
+ 'jffs2',
99
+ 'jfs',
100
+ 'msdos',
101
+ 'nilfs2',
102
+ 'ntfs',
103
+ 'ntfs3',
104
+ 'ocfs2',
105
+ 'overlay',
106
+ 'reiserfs',
107
+ 'tmpfs',
108
+ 'ubifs',
109
+ 'udf',
110
+ 'vfat',
111
+ 'xfs',
112
+ 'zfs'
113
+ ];
114
+ const linuxFsSize = async (drives) => {
115
+ const data = [];
116
+ const mounts = await (0, files_1.readFileLines)('/proc/mounts');
117
+ if (!mounts.length) {
118
+ return null;
119
+ }
120
+ const osMountsKnown = Object.keys(osMounts).length > 0;
121
+ for (const line of mounts) {
122
+ const parts = line.split(' ');
123
+ if (parts.length < 4) {
124
+ continue;
125
+ }
126
+ const fs = unescapeMount(parts[0]);
127
+ const mount = unescapeMount(parts[1]);
128
+ const type = parts[2];
129
+ if (type === 'squashfs') {
130
+ continue;
131
+ }
132
+ if (!(fs.startsWith('/') || mount === '/' || fs.indexOf('/') > 0 || fs.indexOf(':') === 1 || !isLinuxTmpFs(type))) {
133
+ continue;
134
+ }
135
+ try {
136
+ const [stats, { dev }] = await Promise.all([(0, promises_1.statfs)(mount), (0, promises_1.stat)(mount)]);
137
+ const size = stats.blocks * stats.bsize;
138
+ if (!size) {
139
+ continue;
140
+ }
141
+ const used = (stats.blocks - stats.bfree) * stats.bsize;
142
+ const available = stats.bavail * stats.bsize;
143
+ const item = {
144
+ dev,
145
+ entry: {
146
+ fs,
147
+ type,
148
+ size,
149
+ used,
150
+ available,
151
+ use: parseFloat((100.0 * (used / (used + available))).toFixed(2)),
152
+ mount,
153
+ rw: osMountsKnown ? osMounts[fs] || false : null
154
+ },
155
+ trusted: statfsSafeTypes.includes(type)
156
+ };
157
+ const duplicate = data.findIndex((el) => el.dev === dev);
158
+ if (duplicate >= 0) {
159
+ if (data[duplicate].entry.mount.length > mount.length) {
160
+ data[duplicate] = item;
161
+ }
162
+ continue;
163
+ }
164
+ data.push(item);
165
+ }
166
+ catch { }
167
+ }
168
+ if (!data.length) {
169
+ return null;
170
+ }
171
+ const requested = data.filter((item) => matchesDrives(item.entry.fs, item.entry.mount, drives));
172
+ if (requested.some((item) => !item.trusted)) {
173
+ return null;
174
+ }
175
+ return requested.map((item) => item.entry);
176
+ };
177
+ const matchesDrives = (fs, mount, drives) => {
178
+ if (!drives.length) {
179
+ return true;
180
+ }
181
+ return drives.some((drive) => fs.toLowerCase().indexOf(drive.toLowerCase()) >= 0 || mount.toLowerCase().indexOf(drive.toLowerCase()) >= 0);
182
+ };
183
+ const filterDrives = (data, drives) => data.filter((item) => matchesDrives(item.fs, item.mount, drives));
81
184
  const fsSize = async (drives) => {
82
185
  await (0, common_1.nextTick)();
83
186
  let data = [];
@@ -107,23 +210,21 @@ const fsSize = async (drives) => {
107
210
  catch { }
108
211
  }
109
212
  if (const_1.LINUX) {
110
- try {
111
- cmd = 'export LC_ALL=C; df -kPTx squashfs; unset LC_ALL';
112
- ({ stdout } = await (0, exec_1.exec)('cat /proc/mounts 2>/dev/null', const_1.execOptsLinux));
113
- stdout
114
- .split('\n')
115
- .filter((line) => {
116
- return line.startsWith('/');
117
- })
118
- .forEach((line) => {
119
- const fs = line.split(' ')[0].replace(/\\(\d{3})/g, (_, octal) => String.fromCharCode(parseInt(octal, 8)));
120
- osMounts[fs] = osMounts[fs] || false;
121
- if (line.indexOf('/snap/') === -1) {
122
- osMounts[fs] = line.toLowerCase().indexOf('rw,') >= 0 || line.toLowerCase().indexOf(' rw ') >= 0;
123
- }
124
- });
213
+ for (const line of await (0, files_1.readFileLines)('/proc/mounts')) {
214
+ if (!line.startsWith('/')) {
215
+ continue;
216
+ }
217
+ const fs = unescapeMount(line.split(' ')[0]);
218
+ osMounts[fs] = osMounts[fs] || false;
219
+ if (line.indexOf('/snap/') === -1) {
220
+ osMounts[fs] = line.toLowerCase().indexOf('rw,') >= 0 || line.toLowerCase().indexOf(' rw ') >= 0;
221
+ }
125
222
  }
126
- catch { }
223
+ const linuxData = await linuxFsSize(drives);
224
+ if (linuxData) {
225
+ return linuxData;
226
+ }
227
+ cmd = 'export LC_ALL=C; df -kPTx squashfs; unset LC_ALL';
127
228
  }
128
229
  if (const_1.FREEBSD || const_1.NETBSD || const_1.OPENBSD) {
129
230
  try {
@@ -135,23 +236,16 @@ const fsSize = async (drives) => {
135
236
  }
136
237
  catch { }
137
238
  }
138
- ({ stdout, stderr } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux));
239
+ ({ stdout, stderr } = await (0, exec_1.execSave)(cmd, const_1.execOptsLinux));
139
240
  if (!stderr) {
140
241
  lines = filterFsLines(stdout);
141
242
  data = parseNixFsSize(lines);
142
243
  }
143
244
  else {
144
- ({ stdout } = await (0, exec_1.exec)('df -kPT 2>/dev/null', const_1.execOptsLinux));
245
+ ({ stdout } = await (0, exec_1.execSave)('df -kPT 2>/dev/null', const_1.execOptsLinux));
145
246
  lines = filterFsLines(stdout);
146
247
  data = parseNixFsSize(lines);
147
248
  }
148
- if (drives.length) {
149
- data = data.filter((item) => {
150
- return drives.some((drive) => {
151
- return item.fs.toLowerCase().indexOf(drive.toLowerCase()) >= 0 || item.mount.toLowerCase().indexOf(drive.toLowerCase()) >= 0;
152
- });
153
- });
154
- }
155
- return data;
249
+ return filterDrives(data, drives);
156
250
  };
157
251
  exports.fsSize = fsSize;
@@ -6,6 +6,7 @@ const index_1 = require("../common/index");
6
6
  const exec_1 = require("../common/exec");
7
7
  const common_1 = require("../common");
8
8
  const filesys_1 = require("../common/filesys");
9
+ const files_1 = require("../common/files");
9
10
  const security_1 = require("../common/security");
10
11
  const const_1 = require("../common/const");
11
12
  const fsStats = async () => {
@@ -16,8 +17,8 @@ const fsStats = async () => {
16
17
  let rx = 0;
17
18
  let wx = 0;
18
19
  try {
19
- ({ stdout } = await (0, exec_1.exec)('lsblk -r 2>/dev/null | grep /', const_1.execOptsLinux));
20
- const lines = stdout.toString().split('\n');
20
+ ({ stdout } = await (0, exec_1.exec)('lsblk -r 2>/dev/null', const_1.execOptsLinux));
21
+ const lines = stdout.toString().split('\n').filter((line) => line.indexOf('/') >= 0);
21
22
  const fs_filter = [];
22
23
  lines.forEach((line) => {
23
24
  if (line !== '') {
@@ -28,14 +29,10 @@ const fsStats = async () => {
28
29
  }
29
30
  }
30
31
  });
31
- const output = fs_filter.join('|');
32
32
  try {
33
- ({ stdout } = await (0, exec_1.exec)('cat /proc/diskstats | egrep "' + output + '"', const_1.execOptsLinux));
34
- const lines = stdout.toString().split('\n');
35
- lines.forEach((line) => {
36
- line = line.trim();
37
- if (line !== '') {
38
- const lineParts = line.replace(/ +/g, ' ').split(' ');
33
+ (await (0, files_1.readFileLines)('/proc/diskstats')).forEach((line) => {
34
+ const lineParts = line.trim().split(/\s+/);
35
+ if (fs_filter.indexOf(lineParts[2]) >= 0) {
39
36
  rx += (0, common_1.toInt)(lineParts[5]) * 512;
40
37
  wx += (0, common_1.toInt)(lineParts[9]) * 512;
41
38
  }
package/dist/linux/gpu.js CHANGED
@@ -8,6 +8,7 @@ const exec_1 = require("../common/exec");
8
8
  const files_1 = require("../common/files");
9
9
  const nvidia_1 = require("../common/nvidia");
10
10
  const raspberry_1 = require("../common/raspberry");
11
+ const security_1 = require("../common/security");
11
12
  const readSysfsNumber = async (files, divisor = 1, preferNonZero = false) => {
12
13
  let fallback = null;
13
14
  for (const file of files) {
@@ -51,7 +52,7 @@ const drmDevices = async (drmPath = '/sys/class/drm') => {
51
52
  }
52
53
  let hwmon = [];
53
54
  try {
54
- hwmon = (await (0, promises_1.readdir)(`${devicePath}/hwmon`)).map((node) => `${devicePath}/hwmon/${node}`);
55
+ hwmon = (await (0, promises_1.readdir)(`${devicePath}/hwmon`)).filter(security_1.isSafePathSegment).map((node) => `${devicePath}/hwmon/${node}`);
55
56
  }
56
57
  catch { }
57
58
  const clockCore = await readSysfsNumber([
@@ -46,6 +46,7 @@ export { software } from './software';
46
46
  export { system } from './system';
47
47
  export { thunderbolt } from './thunderbolt';
48
48
  export { time } from '../time';
49
+ export { serialPorts } from './serial-ports';
49
50
  export { usb } from './usb';
50
51
  export { users } from './users';
51
52
  export { uuid } from './uuid';