systeminformation 6.0.0-beta.8 → 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 (40) hide show
  1. package/README.md +1 -0
  2. package/dist/common/files.d.ts +8 -0
  3. package/dist/common/files.js +58 -3
  4. package/dist/common/nvidia.js +2 -1
  5. package/dist/common/parse.d.ts +4 -6
  6. package/dist/common/parse.js +24 -69
  7. package/dist/common/security.d.ts +1 -0
  8. package/dist/common/security.js +3 -1
  9. package/dist/common/types.d.ts +1 -2
  10. package/dist/cpu-current-load.js +5 -5
  11. package/dist/cpu-current-speed.js +5 -3
  12. package/dist/darwin/serial-ports.js +2 -1
  13. package/dist/linux/audio.js +11 -2
  14. package/dist/linux/baseboard.js +9 -20
  15. package/dist/linux/bios.js +6 -15
  16. package/dist/linux/camera.js +2 -1
  17. package/dist/linux/chassis.js +4 -10
  18. package/dist/linux/cpu-temperature.js +34 -19
  19. package/dist/linux/cpu.js +3 -1
  20. package/dist/linux/disk-layout.js +2 -5
  21. package/dist/linux/disks-io.js +6 -6
  22. package/dist/linux/fans.js +3 -2
  23. package/dist/linux/fs-size.js +120 -26
  24. package/dist/linux/fs-stats.js +6 -9
  25. package/dist/linux/gpu.js +2 -1
  26. package/dist/linux/mem-layout.js +2 -2
  27. package/dist/linux/network-interfaces.js +10 -29
  28. package/dist/linux/network-stats.js +1 -1
  29. package/dist/linux/npu.js +2 -1
  30. package/dist/linux/os-info.js +19 -4
  31. package/dist/linux/printer.js +4 -4
  32. package/dist/linux/process-load.js +9 -12
  33. package/dist/linux/processes.js +88 -79
  34. package/dist/linux/serial-ports.js +3 -2
  35. package/dist/linux/services.js +12 -12
  36. package/dist/linux/system.js +1 -7
  37. package/dist/linux/uuid.js +4 -10
  38. package/dist/windows/process-load.js +5 -4
  39. package/dist/windows/processes.js +10 -6
  40. package/package.json +1 -1
package/README.md CHANGED
@@ -480,6 +480,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
480
480
  | | ...[0].cpu | X | X | X | X | X | process % CPU usage |
481
481
  | | ...[0].cpuu | X | X | | X | | process % CPU usage (user) |
482
482
  | | ...[0].cpus | X | X | | X | | process % CPU usage (system) |
483
+ | | ...[0].cpuTime | X | X | X | X | X | process cpu time in seconds (own, without reaped children); null if not available |
483
484
  | | ...[0].mem | X | X | X | X | X | process memory % |
484
485
  | | ...[0].priority | X | X | X | X | X | process priority |
485
486
  | | ...[0].memVsz | X | X | X | X | X | process virtual memory size |
@@ -1,3 +1,11 @@
1
1
  export declare const getFilesInPath: (source: string) => Promise<string[]>;
2
2
  export declare const fileExists: (file: string) => Promise<boolean>;
3
3
  export declare const readSysfs: (file: string) => Promise<string>;
4
+ export declare const readFileLines: (file: string) => Promise<string[]>;
5
+ export declare const readSysfsMany: (dir: string, names: string[]) => Promise<string[]>;
6
+ export declare const readProcStats: (pids: any[]) => Promise<{
7
+ all: string;
8
+ procs: string[];
9
+ }>;
10
+ export declare const readFileMax: (file: string, maxBytes?: number) => Promise<string>;
11
+ export declare const DMI_PATH = "/sys/devices/virtual/dmi/id";
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readSysfs = exports.fileExists = exports.getFilesInPath = void 0;
3
+ exports.DMI_PATH = exports.readFileMax = exports.readProcStats = exports.readSysfsMany = exports.readFileLines = exports.readSysfs = exports.fileExists = exports.getFilesInPath = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const promises_1 = require("fs/promises");
6
6
  const path_1 = require("path");
7
+ const security_1 = require("./security");
7
8
  const getFilesInPath = async (source) => {
8
9
  const fetchedFiles = [];
9
10
  try {
10
- const files = await (0, promises_1.readdir)(source);
11
+ const files = (await (0, promises_1.readdir)(source)).filter(security_1.isSafePathSegment);
11
12
  for (const file of files) {
12
13
  try {
13
14
  const filepath = (0, path_1.join)(source, file);
@@ -17,7 +18,7 @@ const getFilesInPath = async (source) => {
17
18
  }
18
19
  if (stats.isDirectory()) {
19
20
  const childFiles = await (0, promises_1.readdir)(filepath);
20
- files.push(...childFiles.map((f) => (0, path_1.join)(file, f)));
21
+ files.push(...childFiles.filter(security_1.isSafePathSegment).map((f) => (0, path_1.join)(file, f)));
21
22
  }
22
23
  }
23
24
  catch { }
@@ -46,3 +47,57 @@ const readSysfs = async (file) => {
46
47
  }
47
48
  };
48
49
  exports.readSysfs = readSysfs;
50
+ const readFileLines = async (file) => {
51
+ try {
52
+ return (await (0, promises_1.readFile)(file, 'utf8')).split('\n');
53
+ }
54
+ catch {
55
+ return [];
56
+ }
57
+ };
58
+ exports.readFileLines = readFileLines;
59
+ const readSysfsMany = async (dir, names) => {
60
+ return Promise.all(names.map(async (name) => `${name}: ${await (0, exports.readSysfs)((0, path_1.join)(dir, name))}`));
61
+ };
62
+ exports.readSysfsMany = readSysfsMany;
63
+ const PROC_READ_BATCH = 64;
64
+ const readProcStats = async (pids) => {
65
+ const paths = [];
66
+ for (const pid of pids) {
67
+ const id = String(pid);
68
+ if (/^\d+$/.test(id)) {
69
+ paths.push(`/proc/${id}/stat`);
70
+ }
71
+ }
72
+ const statLines = await (0, exports.readFileLines)('/proc/stat');
73
+ const procs = [];
74
+ for (let i = 0; i < paths.length; i += PROC_READ_BATCH) {
75
+ procs.push(...(await Promise.all(paths.slice(i, i + PROC_READ_BATCH).map((path) => (0, exports.readSysfs)(path)))));
76
+ }
77
+ return {
78
+ all: statLines.find((line) => line.startsWith('cpu ')) || '',
79
+ procs: procs.filter((line) => line)
80
+ };
81
+ };
82
+ exports.readProcStats = readProcStats;
83
+ const readFileMax = async (file, maxBytes = 1024 * 1024) => {
84
+ let handle;
85
+ try {
86
+ handle = await (0, promises_1.open)(file, 'r');
87
+ const { size } = await handle.stat();
88
+ const buffer = Buffer.alloc(Math.min(size || maxBytes, maxBytes));
89
+ const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
90
+ return buffer.toString('utf8', 0, bytesRead).trim();
91
+ }
92
+ catch {
93
+ return '';
94
+ }
95
+ finally {
96
+ try {
97
+ await handle?.close();
98
+ }
99
+ catch { }
100
+ }
101
+ };
102
+ exports.readFileMax = readFileMax;
103
+ exports.DMI_PATH = '/sys/devices/virtual/dmi/id';
@@ -4,6 +4,7 @@ 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");
7
8
  let _nvidiaSmiPath = null;
8
9
  const getNvidiaSmi = async () => {
9
10
  if (_nvidiaSmiPath !== null) {
@@ -21,7 +22,7 @@ const getNvidiaSmi = async () => {
21
22
  const basePath = String.raw `${const_1.WINDIR}\System32\DriverStore\FileRepository`;
22
23
  let lastMod = 0;
23
24
  for (const dir of await (0, promises_1.readdir)(basePath)) {
24
- if (!dir.toLowerCase().startsWith('nv')) {
25
+ if (!dir.toLowerCase().startsWith('nv') || !(0, security_1.isSafePathSegment)(dir)) {
25
26
  continue;
26
27
  }
27
28
  const smiPath = [basePath, dir, 'nvidia-smi.exe'].join('\\');
@@ -1,11 +1,9 @@
1
1
  import type { CpuData, ProcStatData } from './types';
2
- export type headerType = {
3
- from: number;
4
- to: number;
5
- cap: string;
6
- };
7
- export declare const parseHead: (head: string, rights: number) => headerType[];
8
2
  export declare const parseProcStat: (line: string) => number;
3
+ export declare const clampCpuPair: (cpuu: number, cpus: number) => {
4
+ cpuu: number;
5
+ cpus: number;
6
+ };
9
7
  export declare const calcProcStatLinux: (line: string, all: number, _cpu_old: CpuData) => ProcStatData;
10
8
  export declare const parseJsonArray: (data: string) => any[];
11
9
  export declare const cleanDefaults: (str: string) => string;
@@ -1,63 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.splitByNumber = exports.kFactor = exports.cleanDefaults = exports.parseJsonArray = exports.calcProcStatLinux = exports.parseProcStat = exports.parseHead = void 0;
3
+ exports.splitByNumber = exports.kFactor = exports.cleanDefaults = exports.parseJsonArray = exports.calcProcStatLinux = exports.clampCpuPair = exports.parseProcStat = void 0;
4
4
  const index_1 = require("./index");
5
- const parseHead = (head, rights) => {
6
- let space = rights > 0;
7
- let count = 1;
8
- let from = 0;
9
- let to = 0;
10
- const result = [];
11
- for (let i = 0; i < head.length; i++) {
12
- if (count <= rights) {
13
- if (/\s/.test(head[i]) && !space) {
14
- to = i - 1;
15
- result.push({
16
- from: from,
17
- to: to + 1,
18
- cap: head.substring(from, to + 1)
19
- });
20
- from = to + 2;
21
- count++;
22
- }
23
- space = head[i] === ' ';
24
- }
25
- else {
26
- if (!/\s/.test(head[i]) && space) {
27
- to = i - 1;
28
- if (from < to) {
29
- result.push({
30
- from: from,
31
- to: to,
32
- cap: head.substring(from, to)
33
- });
34
- }
35
- from = to + 1;
36
- count++;
37
- }
38
- space = head[i] === ' ';
39
- }
40
- }
41
- to = 5000;
42
- result.push({
43
- from: from,
44
- to: to,
45
- cap: head.substring(from, to)
46
- });
47
- let len = result.length;
48
- for (let i = 0; i < len; i++) {
49
- if (result[i].cap.replace(/\s/g, '').length === 0) {
50
- if (i + 1 < len) {
51
- result[i].to = result[i + 1].to;
52
- result[i].cap = result[i].cap + result[i + 1].cap;
53
- result.splice(i + 1, 1);
54
- len = len - 1;
55
- }
56
- }
57
- }
58
- return result;
59
- };
60
- exports.parseHead = parseHead;
61
5
  const parseProcStat = (line) => {
62
6
  const parts = line.replace(/ +/g, ' ').split(' ');
63
7
  const user = parts.length >= 2 ? (0, index_1.toInt)(parts[1]) : 0;
@@ -73,6 +17,21 @@ const parseProcStat = (line) => {
73
17
  return user + nice + system + idle + iowait + irq + softirq + steal + guest + guest_nice;
74
18
  };
75
19
  exports.parseProcStat = parseProcStat;
20
+ const clampCpuPair = (cpuu, cpus) => {
21
+ if (!Number.isFinite(cpuu) || cpuu < 0) {
22
+ cpuu = 0;
23
+ }
24
+ if (!Number.isFinite(cpus) || cpus < 0) {
25
+ cpus = 0;
26
+ }
27
+ const total = cpuu + cpus;
28
+ if (total > 100) {
29
+ cpuu = (cpuu / total) * 100;
30
+ cpus = (cpus / total) * 100;
31
+ }
32
+ return { cpuu, cpus };
33
+ };
34
+ exports.clampCpuPair = clampCpuPair;
76
35
  const calcProcStatLinux = (line, all, _cpu_old) => {
77
36
  const statparts = line.replace(/ +/g, ' ').split(')');
78
37
  if (statparts.length >= 2) {
@@ -81,27 +40,25 @@ const calcProcStatLinux = (line, all, _cpu_old) => {
81
40
  const pid = (0, index_1.toInt)(statparts[0].split(' ')[0]);
82
41
  const utime = (0, index_1.toInt)(parts[12]);
83
42
  const stime = (0, index_1.toInt)(parts[13]);
84
- const cutime = (0, index_1.toInt)(parts[14]);
85
- const cstime = (0, index_1.toInt)(parts[15]);
86
43
  let cpuu = 0;
87
44
  let cpus = 0;
88
45
  if (_cpu_old.all > 0 && _cpu_old.list[pid]) {
89
- cpuu = ((utime + cutime - _cpu_old.list[pid].utime - _cpu_old.list[pid].cutime) / (all - _cpu_old.all)) * 100;
90
- cpus = ((stime + cstime - _cpu_old.list[pid].stime - _cpu_old.list[pid].cstime) / (all - _cpu_old.all)) * 100;
46
+ const delta = all - _cpu_old.all;
47
+ cpuu = delta > 0 ? ((utime - _cpu_old.list[pid].utime) / delta) * 100 : 0;
48
+ cpus = delta > 0 ? ((stime - _cpu_old.list[pid].stime) / delta) * 100 : 0;
91
49
  }
92
50
  else {
93
- cpuu = ((utime + cutime) / all) * 100;
94
- cpus = ((stime + cstime) / all) * 100;
51
+ cpuu = all > 0 ? (utime / all) * 100 : 0;
52
+ cpus = all > 0 ? (stime / all) * 100 : 0;
95
53
  }
54
+ const clamped = (0, exports.clampCpuPair)(cpuu, cpus);
96
55
  return {
97
56
  pid: pid,
98
57
  name: '',
99
58
  utime: utime,
100
59
  stime: stime,
101
- cutime: cutime,
102
- cstime: cstime,
103
- cpuu: cpuu,
104
- cpus: cpus
60
+ cpuu: clamped.cpuu,
61
+ cpus: clamped.cpus
105
62
  };
106
63
  }
107
64
  }
@@ -110,8 +67,6 @@ const calcProcStatLinux = (line, all, _cpu_old) => {
110
67
  name: '',
111
68
  utime: 0,
112
69
  stime: 0,
113
- cutime: 0,
114
- cstime: 0,
115
70
  cpuu: 0,
116
71
  cpus: 0
117
72
  };
@@ -22,6 +22,7 @@ export declare const stringSplit: {
22
22
  export declare const stringStartWith: (searchString: string, position?: number) => boolean;
23
23
  export declare const mathMin: (...values: number[]) => number;
24
24
  export declare const sanitizeShellString: (str: string, strict?: any) => string;
25
+ export declare const isSafePathSegment: (segment: string) => boolean;
25
26
  export declare const sanitizeContainerID: (str: string) => string;
26
27
  export declare const sanitizeImageID: (str: string) => string;
27
28
  export declare const isPrototypePolluted: () => boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sanitizeString = exports.sanitizeInterfacesString = exports.sanitizeServiceString = exports.sanitizeUrl = exports.isPrototypePolluted = exports.sanitizeImageID = exports.sanitizeContainerID = exports.sanitizeShellString = exports.mathMin = exports.stringStartWith = exports.stringSplit = exports.stringTrim = exports.stringSubstring = exports.stringSubstr = exports.stringToString = exports.stringToLower = exports.stringReplace = void 0;
3
+ exports.sanitizeString = exports.sanitizeInterfacesString = exports.sanitizeServiceString = exports.sanitizeUrl = exports.isPrototypePolluted = exports.sanitizeImageID = exports.sanitizeContainerID = exports.isSafePathSegment = exports.sanitizeShellString = exports.mathMin = exports.stringStartWith = exports.stringSplit = exports.stringTrim = exports.stringSubstring = exports.stringSubstr = exports.stringToString = exports.stringToLower = exports.stringReplace = void 0;
4
4
  exports.stringReplace = new String().replace;
5
5
  exports.stringToLower = new String().toLowerCase;
6
6
  exports.stringToString = new String().toString;
@@ -56,6 +56,8 @@ const sanitizeShellString = (str, strict) => {
56
56
  return result;
57
57
  };
58
58
  exports.sanitizeShellString = sanitizeShellString;
59
+ const isSafePathSegment = (segment) => !!segment && segment.indexOf('/') === -1 && segment.indexOf('\0') === -1 && segment !== '.' && segment !== '..';
60
+ exports.isSafePathSegment = isSafePathSegment;
59
61
  const sanitizeContainerID = (str) => {
60
62
  const s = String(str || '')
61
63
  .substring(0, 2000)
@@ -867,8 +867,6 @@ export type ProcStatData = {
867
867
  name: string;
868
868
  utime: number;
869
869
  stime: number;
870
- cutime?: number;
871
- cstime?: number;
872
870
  cpu?: number;
873
871
  cpuu: number;
874
872
  cpus: number;
@@ -905,6 +903,7 @@ export type ProcessesProcessData = {
905
903
  cpu: number;
906
904
  cpuu: number;
907
905
  cpus: number;
906
+ cpuTime: number | null;
908
907
  mem: number;
909
908
  priority: number;
910
909
  memVsz: number;
@@ -4,7 +4,8 @@ exports.currentLoad = 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 exec_1 = require("./common/exec");
7
+ const files_1 = require("./common/files");
8
+ const JIFFY_MS = 10;
8
9
  let _current_cpu = {
9
10
  user: 0,
10
11
  nice: 0,
@@ -81,8 +82,7 @@ const currentLoad = async () => {
81
82
  _corecount = cpus && cpus.length ? cpus.length : 0;
82
83
  if (const_1.LINUX) {
83
84
  try {
84
- const { stdout } = await (0, exec_1.exec)('cat /proc/stat 2>/dev/null | grep cpu');
85
- const lines = stdout.split('\n');
85
+ const lines = (await (0, files_1.readFileLines)('/proc/stat')).filter((line) => line.startsWith('cpu'));
86
86
  if (lines.length > 1) {
87
87
  lines.shift();
88
88
  if (lines.length === cpus.length) {
@@ -91,8 +91,8 @@ const currentLoad = async () => {
91
91
  if (parts.length >= 10) {
92
92
  const steal = parseFloat(parts[8]) || 0;
93
93
  const guest = parseFloat(parts[9]) || 0;
94
- cpus[i].times.steal = steal;
95
- cpus[i].times.guest = guest;
94
+ cpus[i].times.steal = steal * JIFFY_MS;
95
+ cpus[i].times.guest = guest * JIFFY_MS;
96
96
  }
97
97
  }
98
98
  }
@@ -5,7 +5,7 @@ const node_os_1 = require("node:os");
5
5
  const common_1 = require("./common");
6
6
  const const_1 = require("./common/const");
7
7
  const cpu_1 = require("./common/cpu");
8
- const exec_1 = require("./common/exec");
8
+ const files_1 = require("./common/files");
9
9
  const getCpuCurrentSpeed = async () => {
10
10
  const oscpus = (0, node_os_1.cpus)();
11
11
  let minFreq = 999999999;
@@ -20,8 +20,10 @@ const getCpuCurrentSpeed = async () => {
20
20
  }
21
21
  else if (const_1.LINUX) {
22
22
  try {
23
- const { stdout } = await (0, exec_1.exec)('cat /proc/cpuinfo | grep "cpu MHz" | cut -d " " -f 3', const_1.execOptsLinux);
24
- const speedStrings = stdout.split('\n').filter((line) => line.length > 0);
23
+ const speedStrings = (await (0, files_1.readFileLines)('/proc/cpuinfo'))
24
+ .filter((line) => line.toLowerCase().startsWith('cpu mhz'))
25
+ .map((line) => (line.split(':')[1] || '').trim())
26
+ .filter((line) => line.length > 0);
25
27
  for (const i in speedStrings) {
26
28
  speeds.push(Math.floor(parseInt(speedStrings[i], 10) / 10) / 100);
27
29
  }
@@ -5,6 +5,7 @@ const promises_1 = require("fs/promises");
5
5
  const common_1 = require("../common");
6
6
  const defaults_1 = require("../common/defaults");
7
7
  const exec_1 = require("../common/exec");
8
+ const security_1 = require("../common/security");
8
9
  const toHex4 = (value) => {
9
10
  const num = Number.parseInt(value, 10);
10
11
  return Number.isNaN(num) ? null : num.toString(16).padStart(4, '0');
@@ -68,7 +69,7 @@ const serialPorts = async () => {
68
69
  const result = [];
69
70
  let devices = [];
70
71
  try {
71
- devices = (await (0, promises_1.readdir)('/dev')).filter((device) => device.startsWith('cu.'));
72
+ devices = (await (0, promises_1.readdir)('/dev')).filter((device) => device.startsWith('cu.') && (0, security_1.isSafePathSegment)(device));
72
73
  }
73
74
  catch {
74
75
  return result;
@@ -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);