systeminformation 6.0.0-beta.2 → 6.0.0-beta.20

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 (136) hide show
  1. package/README.md +67 -18
  2. package/dist/bsd/mem.js +8 -3
  3. package/dist/bsd/network-stats.d.ts +1 -1
  4. package/dist/bsd/network-stats.js +14 -7
  5. package/dist/bsd/os-info.d.ts +1 -0
  6. package/dist/common/darwin.d.ts +2 -0
  7. package/dist/common/darwin.js +17 -1
  8. package/dist/common/defaults.d.ts +2 -1
  9. package/dist/common/defaults.js +36 -6
  10. package/dist/common/exec.js +29 -13
  11. package/dist/common/files.d.ts +9 -0
  12. package/dist/common/files.js +67 -3
  13. package/dist/common/filesys.d.ts +30 -0
  14. package/dist/common/filesys.js +228 -11
  15. package/dist/common/host.js +55 -3
  16. package/dist/common/internet.js +31 -20
  17. package/dist/common/mappings.d.ts +0 -3
  18. package/dist/common/mappings.js +35 -14
  19. package/dist/common/network.d.ts +15 -2
  20. package/dist/common/network.js +18 -22
  21. package/dist/common/nvidia.d.ts +1 -1
  22. package/dist/common/nvidia.js +4 -5
  23. package/dist/common/parse.d.ts +4 -6
  24. package/dist/common/parse.js +24 -69
  25. package/dist/common/security.d.ts +2 -0
  26. package/dist/common/security.js +18 -3
  27. package/dist/common/types.d.ts +53 -5
  28. package/dist/common/windows.d.ts +4 -0
  29. package/dist/common/windows.js +57 -1
  30. package/dist/cpu-current-load.d.ts +1 -0
  31. package/dist/cpu-current-load.js +54 -8
  32. package/dist/cpu-current-speed.js +5 -3
  33. package/dist/darwin/battery.d.ts +1 -1
  34. package/dist/darwin/battery.js +15 -5
  35. package/dist/darwin/camera.js +3 -3
  36. package/dist/darwin/disk-layout.js +16 -12
  37. package/dist/darwin/disks-io.js +3 -3
  38. package/dist/darwin/displays.d.ts +1 -0
  39. package/dist/darwin/displays.js +64 -2
  40. package/dist/darwin/fans.d.ts +2 -0
  41. package/dist/darwin/fans.js +28 -0
  42. package/dist/darwin/gpu.js +1 -1
  43. package/dist/darwin/index.d.ts +3 -0
  44. package/dist/darwin/index.js +8 -2
  45. package/dist/darwin/keyboard.js +4 -4
  46. package/dist/darwin/mouse.js +4 -4
  47. package/dist/darwin/network-interfaces.d.ts +3 -0
  48. package/dist/darwin/network-interfaces.js +81 -14
  49. package/dist/darwin/network-stats.d.ts +1 -1
  50. package/dist/darwin/network-stats.js +14 -7
  51. package/dist/darwin/os-info.d.ts +2 -0
  52. package/dist/darwin/os-info.js +24 -2
  53. package/dist/darwin/process-focused.d.ts +3 -0
  54. package/dist/darwin/process-focused.js +26 -0
  55. package/dist/darwin/serial-ports.d.ts +2 -0
  56. package/dist/darwin/serial-ports.js +94 -0
  57. package/dist/darwin/users.js +1 -1
  58. package/dist/fans.d.ts +1 -0
  59. package/dist/fans.js +17 -0
  60. package/dist/get-data.d.ts +4 -0
  61. package/dist/get-data.js +6 -2
  62. package/dist/get.js +6 -1
  63. package/dist/index.d.ts +3 -0
  64. package/dist/index.js +8 -2
  65. package/dist/inet-public-ip.js +2 -1
  66. package/dist/linux/audio.js +59 -0
  67. package/dist/linux/baseboard.js +9 -20
  68. package/dist/linux/bios.js +6 -15
  69. package/dist/linux/block-devices.js +3 -1
  70. package/dist/linux/camera.js +2 -1
  71. package/dist/linux/chassis.js +4 -10
  72. package/dist/linux/cpu-temperature.js +34 -19
  73. package/dist/linux/cpu.js +3 -1
  74. package/dist/linux/disk-layout.js +9 -12
  75. package/dist/linux/disks-io.js +9 -9
  76. package/dist/linux/displays.d.ts +8 -0
  77. package/dist/linux/displays.js +151 -4
  78. package/dist/linux/fans.d.ts +2 -0
  79. package/dist/linux/fans.js +92 -0
  80. package/dist/linux/fs-size.d.ts +1 -1
  81. package/dist/linux/fs-size.js +164 -37
  82. package/dist/linux/fs-stats.js +6 -9
  83. package/dist/linux/gpu.d.ts +2 -0
  84. package/dist/linux/gpu.js +97 -22
  85. package/dist/linux/index.d.ts +3 -0
  86. package/dist/linux/index.js +8 -2
  87. package/dist/linux/mem-layout.js +3 -7
  88. package/dist/linux/mem.d.ts +1 -0
  89. package/dist/linux/mem.js +21 -1
  90. package/dist/linux/network-interfaces.d.ts +1 -0
  91. package/dist/linux/network-interfaces.js +154 -113
  92. package/dist/linux/network-stats.d.ts +1 -1
  93. package/dist/linux/network-stats.js +14 -40
  94. package/dist/linux/npu.js +2 -1
  95. package/dist/linux/os-info.js +56 -5
  96. package/dist/linux/printer.js +4 -4
  97. package/dist/linux/process-focused.d.ts +4 -0
  98. package/dist/linux/process-focused.js +32 -0
  99. package/dist/linux/process-load.js +11 -13
  100. package/dist/linux/processes.js +89 -80
  101. package/dist/linux/serial-ports.d.ts +2 -0
  102. package/dist/linux/serial-ports.js +102 -0
  103. package/dist/linux/services.js +182 -49
  104. package/dist/linux/system.js +1 -7
  105. package/dist/linux/users.js +1 -1
  106. package/dist/linux/uuid.js +4 -10
  107. package/dist/linux/wifi-networks.js +2 -2
  108. package/dist/network-interfaces.js +1 -1
  109. package/dist/process-focused.d.ts +1 -0
  110. package/dist/process-focused.js +17 -0
  111. package/dist/serial-ports.d.ts +1 -0
  112. package/dist/serial-ports.js +17 -0
  113. package/dist/versions.js +34 -80
  114. package/dist/windows/audio.d.ts +29 -0
  115. package/dist/windows/audio.js +151 -11
  116. package/dist/windows/disk-layout.js +3 -0
  117. package/dist/windows/disks-io.js +3 -3
  118. package/dist/windows/displays.d.ts +5 -0
  119. package/dist/windows/displays.js +101 -16
  120. package/dist/windows/fans.d.ts +2 -0
  121. package/dist/windows/fans.js +71 -0
  122. package/dist/windows/fs-size.js +1 -4
  123. package/dist/windows/gpu.js +3 -2
  124. package/dist/windows/index.d.ts +3 -0
  125. package/dist/windows/index.js +8 -2
  126. package/dist/windows/network-interfaces.js +36 -41
  127. package/dist/windows/network-stats.js +20 -6
  128. package/dist/windows/process-focused.d.ts +3 -0
  129. package/dist/windows/process-focused.js +36 -0
  130. package/dist/windows/process-load.js +7 -5
  131. package/dist/windows/processes.d.ts +1 -0
  132. package/dist/windows/processes.js +54 -26
  133. package/dist/windows/serial-ports.d.ts +3 -0
  134. package/dist/windows/serial-ports.js +73 -0
  135. package/dist/windows/services.js +4 -1
  136. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.networkInterfaces = exports.checkLinuxDCHPInterfaces = void 0;
3
+ exports.networkInterfaces = exports.pciSlotFromPath = exports.checkLinuxDCHPInterfaces = void 0;
4
4
  const promises_1 = require("node:fs/promises");
5
5
  const node_os_1 = require("node:os");
6
6
  const node_path_1 = require("node:path");
@@ -8,10 +8,16 @@ const common_1 = require("../common");
8
8
  const const_1 = require("../common/const");
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 index_1 = require("../common/index");
12
13
  const network_1 = require("../common/network");
13
14
  const security_1 = require("../common/security");
14
15
  const network_interface_default_1 = require("./network-interface-default");
16
+ const pci_1 = require("./pci");
17
+ const EXEC_OPTS = { timeout: 5000 };
18
+ const EXEC_OPTS_LINUX = { ...const_1.execOptsLinux, ...EXEC_OPTS };
19
+ const EXEC_OPTS_NMCLI = { ...EXEC_OPTS_LINUX, env: { ...process.env, LC_ALL: 'C.UTF-8' } };
20
+ const SCAN_CONCURRENCY = 8;
15
21
  let _interfaces = {};
16
22
  let _networkInterfaces = [];
17
23
  const splitSectionsNics = (lines) => {
@@ -31,24 +37,42 @@ const splitSectionsNics = (lines) => {
31
37
  }
32
38
  return result;
33
39
  };
34
- const getLinuxIfaceConnectionName = async (interfaceName) => {
40
+ const getLinuxDeviceStatus = async () => {
41
+ const result = new Map();
35
42
  try {
36
- const { stdout } = await (0, exec_1.execFile)('nmcli', ['device', 'status'], const_1.execOptsLinux);
37
- const result = (0, common_1.grep)(stdout, interfaceName);
38
- const resultFormat = result.replace(/\s+/g, ' ').trim();
39
- const connectionNameLines = resultFormat.split(' ').slice(3);
40
- const connectionName = connectionNameLines.join(' ');
41
- return connectionName !== '--' ? connectionName : '';
43
+ const { stdout } = await (0, exec_1.execFile)('nmcli', ['-t', '-f', 'DEVICE,STATE,CONNECTION', 'device', 'status'], EXEC_OPTS_NMCLI);
44
+ for (const line of stdout.split('\n')) {
45
+ const [device, state, connection] = line.split(/(?<!\\):/).map((part) => part.replace(/\\:/g, ':'));
46
+ if (device && state !== undefined) {
47
+ result.set(device, { state, connection: connection && connection !== '--' ? connection : '' });
48
+ }
49
+ }
50
+ }
51
+ catch { }
52
+ return result;
53
+ };
54
+ const getLinuxIfaceConnectionName = (deviceStatus, interfaceName) => {
55
+ const device = deviceStatus.get(interfaceName);
56
+ return device && !device.state.includes('externally') ? device.connection : '';
57
+ };
58
+ const getLinuxConnectionDetails = async (connectionName) => {
59
+ if (!connectionName) {
60
+ return null;
61
+ }
62
+ try {
63
+ const { stdout } = await (0, exec_1.execFile)('nmcli', ['connection', 'show', 'id', connectionName], EXEC_OPTS_NMCLI);
64
+ return stdout;
42
65
  }
43
66
  catch {
44
- return '';
67
+ return null;
45
68
  }
46
69
  };
70
+ const getNmcliValue = (stdout, property) => (0, common_1.grep)(stdout, property).replace(/\s+/g, ' ').trim().split(' ').slice(1).toString();
47
71
  const readInterfacesLines = async (file) => {
48
72
  if (file.includes('*') || file.includes('?')) {
49
73
  try {
50
74
  const rx = new RegExp(`^${(0, node_path_1.basename)(file).replace(/\./g, '\\.').replace(/\*/g, '.*').replace(/\?/g, '.')}$`);
51
- const names = (await (0, promises_1.readdir)((0, node_path_1.dirname)(file))).filter((n) => rx.test(n)).sort();
75
+ const names = (await (0, promises_1.readdir)((0, node_path_1.dirname)(file))).filter((n) => rx.test(n) && (0, security_1.isSafePathSegment)(n)).sort();
52
76
  const out = [];
53
77
  for (const n of names) {
54
78
  out.push(...(await readInterfacesLines((0, node_path_1.join)((0, node_path_1.dirname)(file), n))));
@@ -88,7 +112,7 @@ exports.checkLinuxDCHPInterfaces = checkLinuxDCHPInterfaces;
88
112
  const getLinuxDHCPNics = async () => {
89
113
  let result = [];
90
114
  try {
91
- const { stdout } = await (0, exec_1.exec)('ip a 2> /dev/null', const_1.execOptsLinux);
115
+ const { stdout } = await (0, exec_1.exec)('ip a 2> /dev/null', EXEC_OPTS_LINUX);
92
116
  const lines = stdout.split('\n');
93
117
  const nsections = splitSectionsNics(lines);
94
118
  result = parseLinuxDHCPNics(nsections);
@@ -119,65 +143,25 @@ const parseLinuxDHCPNics = (sections) => {
119
143
  }
120
144
  return result;
121
145
  };
122
- const getLinuxIfaceDHCPstatus = async (iface, connectionName, DHCPNics) => {
123
- let result = false;
124
- if (connectionName) {
125
- try {
126
- const { stdout } = await (0, exec_1.execFile)('nmcli', ['connection', 'show', connectionName], const_1.execOptsLinux);
127
- const res = (0, common_1.grep)(stdout, 'ipv4.method');
128
- const resultFormat = res.replace(/\s+/g, ' ').trim();
129
- const dhcStatus = resultFormat.split(' ').slice(1).toString();
130
- switch (dhcStatus) {
131
- case 'auto':
132
- result = true;
133
- break;
134
- default:
135
- result = false;
136
- break;
137
- }
138
- return result;
139
- }
140
- catch {
141
- return DHCPNics.indexOf(iface) >= 0;
142
- }
143
- }
144
- else {
146
+ const getLinuxIfaceDHCPstatus = (iface, details, DHCPNics) => {
147
+ if (details === null) {
145
148
  return DHCPNics.indexOf(iface) >= 0;
146
149
  }
150
+ return getNmcliValue(details, 'ipv4.method') === 'auto';
147
151
  };
148
- const getLinuxIfaceDNSsuffix = async (connectionName) => {
149
- if (connectionName) {
150
- try {
151
- const { stdout } = await (0, exec_1.execFile)('nmcli', ['connection', 'show', connectionName], const_1.execOptsLinux);
152
- const res = (0, common_1.grep)(stdout, 'ipv4.dns-search');
153
- const resultFormat = res.replace(/\s+/g, ' ').trim();
154
- const dnsSuffix = resultFormat.split(' ').slice(1).toString();
155
- return dnsSuffix === '--' ? 'Not defined' : dnsSuffix;
156
- }
157
- catch {
158
- return 'Unknown';
159
- }
160
- }
161
- else {
152
+ const getLinuxIfaceDNSsuffix = (details) => {
153
+ if (details === null) {
162
154
  return 'Unknown';
163
155
  }
156
+ const dnsSuffix = getNmcliValue(details, 'ipv4.dns-search');
157
+ return dnsSuffix === '--' ? 'Not defined' : dnsSuffix;
164
158
  };
165
- const getLinuxIfaceIEEE8021xAuth = async (connectionName) => {
166
- if (connectionName) {
167
- try {
168
- const { stdout } = await (0, exec_1.execFile)('nmcli', ['connection', 'show', connectionName], const_1.execOptsLinux);
169
- const res = (0, common_1.grep)(stdout, '802-1x.eap');
170
- const resultFormat = res.replace(/\s+/g, ' ').trim();
171
- const authenticationProtocol = resultFormat.split(' ').slice(1).toString();
172
- return authenticationProtocol === '--' ? '' : authenticationProtocol;
173
- }
174
- catch {
175
- return 'Not defined';
176
- }
177
- }
178
- else {
159
+ const getLinuxIfaceIEEE8021xAuth = (details) => {
160
+ if (details === null) {
179
161
  return 'Not defined';
180
162
  }
163
+ const authenticationProtocol = getNmcliValue(details, '802-1x.eap');
164
+ return authenticationProtocol === '--' ? '' : authenticationProtocol;
181
165
  };
182
166
  const getLinuxIfaceIEEE8021xState = (authenticationProtocol) => {
183
167
  if (authenticationProtocol) {
@@ -190,18 +174,91 @@ const getLinuxIfaceIEEE8021xState = (authenticationProtocol) => {
190
174
  return 'Unknown';
191
175
  }
192
176
  };
177
+ const getLinuxGateways = async () => {
178
+ const result = {};
179
+ try {
180
+ const { stdout } = await (0, exec_1.exec)('ip -4 route show default 2> /dev/null', EXEC_OPTS_LINUX);
181
+ for (const line of stdout.split('\n')) {
182
+ for (const match of line.matchAll(/(?:via\s+(\S+)\s+)?dev\s+(\S+)/g)) {
183
+ if (!result[match[2]]) {
184
+ result[match[2]] = match[1] || '';
185
+ }
186
+ }
187
+ }
188
+ }
189
+ catch { }
190
+ return result;
191
+ };
192
+ const PCI_SLOT = /^[0-9a-f]{4}:[0-9a-f]{2}:[0-9a-f]{2}\.[0-9a-f]$/i;
193
+ const pciSlotFromPath = (path) => {
194
+ const segments = path.split('/');
195
+ return segments.slice(-2).reverse().find((segment) => PCI_SLOT.test(segment)) || null;
196
+ };
197
+ exports.pciSlotFromPath = pciSlotFromPath;
198
+ const _nicHardware = {};
199
+ const _nicHardwareChecked = new Set();
200
+ const getLinuxNicHardware = async (devices) => {
201
+ let pciDevices = null;
202
+ for (const device of devices) {
203
+ const dev = device.split(':')[0];
204
+ if (!(0, security_1.isSafePathSegment)(dev) || _nicHardwareChecked.has(dev)) {
205
+ continue;
206
+ }
207
+ let target = '';
208
+ try {
209
+ target = await (0, promises_1.realpath)(`/sys/class/net/${dev}/device`);
210
+ }
211
+ catch {
212
+ continue;
213
+ }
214
+ const [vendor, model] = await Promise.all([(0, files_1.readSysfs)((0, node_path_1.join)(target, '..', 'manufacturer')), (0, files_1.readSysfs)((0, node_path_1.join)(target, '..', 'product'))]);
215
+ if (vendor || model) {
216
+ _nicHardware[dev] = { vendor, model };
217
+ _nicHardwareChecked.add(dev);
218
+ continue;
219
+ }
220
+ const slot = (0, exports.pciSlotFromPath)(target);
221
+ if (!slot) {
222
+ _nicHardwareChecked.add(dev);
223
+ continue;
224
+ }
225
+ pciDevices = pciDevices || (await (0, pci_1.pci)());
226
+ if (!pciDevices.length) {
227
+ continue;
228
+ }
229
+ const entry = pciDevices.find((item) => item.slot && slot.endsWith(item.slot));
230
+ if (entry) {
231
+ _nicHardware[dev] = { vendor: entry.vendor, model: entry.model };
232
+ }
233
+ _nicHardwareChecked.add(dev);
234
+ }
235
+ return _nicHardware;
236
+ };
193
237
  const networkInterfaces = async (defaultString = '', rescan = true) => {
194
238
  await (0, common_1.nextTick)();
195
239
  const interfaces = (0, node_os_1.networkInterfaces)();
196
240
  if (JSON.stringify(interfaces) === JSON.stringify(_interfaces) && !rescan) {
197
- return _networkInterfaces;
241
+ return (0, network_1.filterDefaultInterface)(_networkInterfaces, defaultString);
198
242
  }
199
243
  _interfaces = (0, index_1.cloneObj)(interfaces);
200
244
  let result = [];
201
245
  try {
202
- const _dhcpNics = await getLinuxDHCPNics();
203
- const defaultInterface = await (0, network_interface_default_1.networkInterfaceDefault)();
204
- for (const dev in interfaces) {
246
+ const [_dhcpNics, defaultInterface, deviceStatus, gateways, sysfsDevices, wirelessLines] = await Promise.all([
247
+ getLinuxDHCPNics(),
248
+ (0, network_interface_default_1.networkInterfaceDefault)(),
249
+ getLinuxDeviceStatus(),
250
+ getLinuxGateways(),
251
+ (0, promises_1.readdir)('/sys/class/net').catch(() => []),
252
+ (0, files_1.readFileLines)('/proc/net/wireless')
253
+ ]);
254
+ const devices = Object.keys(interfaces);
255
+ for (const dev of sysfsDevices) {
256
+ if (!devices.some((device) => device.split(':')[0] === dev)) {
257
+ devices.push(dev);
258
+ }
259
+ }
260
+ const hardware = await getLinuxNicHardware(devices);
261
+ const scanInterface = async (dev) => {
205
262
  const iface = dev;
206
263
  let ip4 = '';
207
264
  let ip4subnet = '';
@@ -254,45 +311,29 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
254
311
  ip6subnet = ip6linksubnet;
255
312
  }
256
313
  const ifaceDevName = dev.split(':')[0].trim();
257
- const ifaceSanitized = (0, security_1.sanitizeString)(ifaceDevName);
258
- const cmd = `echo -n "addr_assign_type: "; cat /sys/class/net/${ifaceSanitized}/addr_assign_type 2>/dev/null; echo;
259
- echo -n "address: "; cat /sys/class/net/${ifaceSanitized}/address 2>/dev/null; echo;
260
- echo -n "addr_len: "; cat /sys/class/net/${ifaceSanitized}/addr_len 2>/dev/null; echo;
261
- echo -n "broadcast: "; cat /sys/class/net/${ifaceSanitized}/broadcast 2>/dev/null; echo;
262
- echo -n "carrier: "; cat /sys/class/net/${ifaceSanitized}/carrier 2>/dev/null; echo;
263
- echo -n "carrier_changes: "; cat /sys/class/net/${ifaceSanitized}/carrier_changes 2>/dev/null; echo;
264
- echo -n "dev_id: "; cat /sys/class/net/${ifaceSanitized}/dev_id 2>/dev/null; echo;
265
- echo -n "dev_port: "; cat /sys/class/net/${ifaceSanitized}/dev_port 2>/dev/null; echo;
266
- echo -n "dormant: "; cat /sys/class/net/${ifaceSanitized}/dormant 2>/dev/null; echo;
267
- echo -n "duplex: "; cat /sys/class/net/${ifaceSanitized}/duplex 2>/dev/null; echo;
268
- echo -n "flags: "; cat /sys/class/net/${ifaceSanitized}/flags 2>/dev/null; echo;
269
- echo -n "gro_flush_timeout: "; cat /sys/class/net/${ifaceSanitized}/gro_flush_timeout 2>/dev/null; echo;
270
- echo -n "ifalias: "; cat /sys/class/net/${ifaceSanitized}/ifalias 2>/dev/null; echo;
271
- echo -n "ifindex: "; cat /sys/class/net/${ifaceSanitized}/ifindex 2>/dev/null; echo;
272
- echo -n "iflink: "; cat /sys/class/net/${ifaceSanitized}/iflink 2>/dev/null; echo;
273
- echo -n "link_mode: "; cat /sys/class/net/${ifaceSanitized}/link_mode 2>/dev/null; echo;
274
- echo -n "mtu: "; cat /sys/class/net/${ifaceSanitized}/mtu 2>/dev/null; echo;
275
- echo -n "netdev_group: "; cat /sys/class/net/${ifaceSanitized}/netdev_group 2>/dev/null; echo;
276
- echo -n "operstate: "; cat /sys/class/net/${ifaceSanitized}/operstate 2>/dev/null; echo;
277
- echo -n "proto_down: "; cat /sys/class/net/${ifaceSanitized}/proto_down 2>/dev/null; echo;
278
- echo -n "speed: "; cat /sys/class/net/${ifaceSanitized}/speed 2>/dev/null; echo;
279
- echo -n "tx_queue_len: "; cat /sys/class/net/${ifaceSanitized}/tx_queue_len 2>/dev/null; echo;
280
- echo -n "type: "; cat /sys/class/net/${ifaceSanitized}/type 2>/dev/null; echo;
281
- echo -n "wireless: "; cat /proc/net/wireless 2>/dev/null | grep ${ifaceSanitized}; echo;
282
- echo -n "wirelessspeed: "; iw dev ${ifaceSanitized} link 2>&1 | grep bitrate; echo;`;
314
+ const ifaceSanitized = (0, security_1.sanitizeString)(ifaceDevName, true);
283
315
  let lines = [];
316
+ let hasDevice = true;
284
317
  try {
285
- const { stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux);
286
- lines = stdout.split('\n');
287
- const connectionName = await getLinuxIfaceConnectionName(ifaceSanitized);
288
- dhcp = await getLinuxIfaceDHCPstatus(ifaceSanitized, connectionName, _dhcpNics);
289
- dnsSuffix = await getLinuxIfaceDNSsuffix(connectionName);
290
- ieee8021xAuth = await getLinuxIfaceIEEE8021xAuth(connectionName);
318
+ const safe = (0, security_1.isSafePathSegment)(ifaceSanitized);
319
+ const connectionName = getLinuxIfaceConnectionName(deviceStatus, ifaceSanitized);
320
+ const [sysfsLines, iwOut, details, device] = await Promise.all([
321
+ safe ? (0, files_1.readSysfsMany)(`/sys/class/net/${ifaceSanitized}`, ['address', 'carrier_changes', 'duplex', 'mtu', 'operstate', 'speed', 'type']) : [],
322
+ safe ? (0, files_1.fileExists)(`/sys/class/net/${ifaceSanitized}/phy80211`).then((wifi) => (wifi ? (0, exec_1.execSecure)('iw', ['dev', ifaceSanitized, 'link'], EXEC_OPTS) : '')) : '',
323
+ getLinuxConnectionDetails(connectionName),
324
+ safe ? (0, files_1.fileExists)(`/sys/class/net/${ifaceSanitized}/device`) : true
325
+ ]);
326
+ hasDevice = device;
327
+ lines = sysfsLines;
328
+ lines.push(`wireless: ${wirelessLines.find((line) => line.indexOf(ifaceSanitized) >= 0) || ''}`);
329
+ lines.push(...iwOut.split('\n').filter((line) => line.indexOf('bitrate') >= 0).map((line) => line.trim()));
330
+ dhcp = getLinuxIfaceDHCPstatus(ifaceSanitized, details, _dhcpNics);
331
+ dnsSuffix = getLinuxIfaceDNSsuffix(details);
332
+ ieee8021xAuth = getLinuxIfaceIEEE8021xAuth(details);
291
333
  ieee8021xState = getLinuxIfaceIEEE8021xState(ieee8021xAuth);
292
334
  }
293
335
  catch { }
294
336
  duplex = (0, common_1.getValue)(lines, 'duplex');
295
- duplex = duplex.startsWith('cat') ? '' : duplex;
296
337
  mtu = (0, common_1.toInt)((0, common_1.getValue)(lines, 'mtu'));
297
338
  let myspeed = (0, common_1.toInt)((0, common_1.getValue)(lines, 'speed'));
298
339
  speed = Number.isNaN(myspeed) ? null : myspeed;
@@ -301,9 +342,12 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
301
342
  myspeed = Number.parseFloat(wirelessspeed);
302
343
  speed = Number.isNaN(myspeed) ? null : myspeed;
303
344
  }
345
+ if (!mac) {
346
+ mac = (0, common_1.getValue)(lines, 'address');
347
+ }
304
348
  carrierChanges = (0, common_1.toInt)((0, common_1.getValue)(lines, 'carrier_changes'));
305
349
  const operstate = (0, common_1.getValue)(lines, 'operstate');
306
- type = operstate === 'up' ? ((0, common_1.getValue)(lines, 'wireless').trim() ? 'wireless' : 'wired') : 'unknown';
350
+ type = (0, common_1.getValue)(lines, 'wireless').trim() ? 'wireless' : (0, common_1.toInt)((0, common_1.getValue)(lines, 'type')) === 1 ? 'wired' : 'unknown';
307
351
  if (ifaceSanitized === 'lo' || ifaceSanitized.startsWith('bond')) {
308
352
  type = 'virtual';
309
353
  }
@@ -311,16 +355,19 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
311
355
  if (dev.toLowerCase().indexOf('loopback') > -1 || ifaceName.toLowerCase().indexOf('loopback') > -1) {
312
356
  internal = true;
313
357
  }
314
- const virtual = internal ? false : (0, network_1.testVirtualNic)(dev, ifaceName, mac);
315
- result.push({
358
+ const virtual = internal ? false : !hasDevice || (0, network_1.testVirtualNic)(dev, ifaceName, mac);
359
+ return {
316
360
  ...defaults_1.initNetworkInterface,
317
361
  iface: ifaceSanitized,
318
362
  ifaceName,
363
+ vendor: hardware[ifaceSanitized]?.vendor || '',
364
+ model: hardware[ifaceSanitized]?.model || '',
319
365
  default: iface === defaultInterface,
320
366
  ip4,
321
367
  ip4subnet,
322
368
  ip6,
323
369
  ip6subnet,
370
+ gateway: gateways[ifaceSanitized] || '',
324
371
  mac,
325
372
  internal,
326
373
  virtual,
@@ -334,20 +381,14 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
334
381
  ieee8021xAuth,
335
382
  ieee8021xState,
336
383
  carrierChanges
337
- });
384
+ };
385
+ };
386
+ for (let i = 0; i < devices.length; i += SCAN_CONCURRENCY) {
387
+ result.push(...(await Promise.all(devices.slice(i, i + SCAN_CONCURRENCY).map(scanInterface))));
338
388
  }
339
389
  }
340
390
  catch { }
341
391
  _networkInterfaces = result;
342
- if (defaultString.toLowerCase().indexOf('default') >= 0) {
343
- result = result.filter((item) => item.default);
344
- if (result.length > 0) {
345
- return [result[0]];
346
- }
347
- else {
348
- result = [];
349
- }
350
- }
351
- return result;
392
+ return (0, network_1.filterDefaultInterface)(result, defaultString);
352
393
  };
353
394
  exports.networkInterfaces = networkInterfaces;
@@ -1,2 +1,2 @@
1
- import { NetworkStatsData } from '../common/types';
1
+ import type { NetworkStatsData } from '../common/types';
2
2
  export declare const networkStats: (interfaces?: string) => Promise<NetworkStatsData[]>;
@@ -1,52 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.networkStats = void 0;
4
- const files_1 = require("../common/files");
5
- const exec_1 = require("../common/exec");
6
4
  const common_1 = require("../common");
7
- const security_1 = require("../common/security");
8
5
  const defaults_1 = require("../common/defaults");
9
- const index_1 = require("./index");
6
+ const files_1 = require("../common/files");
10
7
  const network_1 = require("../common/network");
11
- const _network = {};
8
+ const security_1 = require("../common/security");
9
+ const index_1 = require("./index");
10
+ const _network = Object.create(null);
12
11
  const networkStatsSingle = async (iface) => {
13
12
  await (0, common_1.nextTick)();
14
- const defaults = defaults_1.initNetworkSpeed;
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 ((0, security_1.isSafePathSegment)(iface) && (await (0, files_1.fileExists)(dir))) {
17
+ const [operstate, rx_bytes, tx_bytes, rx_packets, tx_packets, rx_dropped, rx_errors, tx_dropped, tx_errors] = await Promise.all([
18
+ (0, files_1.readSysfs)(dir + '/operstate'),
19
+ ...['rx_bytes', 'tx_bytes', 'rx_packets', 'tx_packets', '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_packets, tx_packets, rx_dropped, rx_errors, tx_dropped, tx_errors, operstate }, _network);
50
22
  }
51
23
  return defaults;
52
24
  }
@@ -55,6 +27,8 @@ const networkStatsSingle = async (iface) => {
55
27
  ...defaults,
56
28
  rx_bytes: _network[iface].rx_bytes,
57
29
  tx_bytes: _network[iface].tx_bytes,
30
+ rx_packets: _network[iface].rx_packets,
31
+ tx_packets: _network[iface].tx_packets,
58
32
  rx_sec: _network[iface].rx_sec,
59
33
  tx_sec: _network[iface].tx_sec,
60
34
  rx_dropped: _network[iface].rx_dropped,
package/dist/linux/npu.js CHANGED
@@ -4,6 +4,7 @@ exports.npu = void 0;
4
4
  const promises_1 = require("node:fs/promises");
5
5
  const common_1 = require("../common");
6
6
  const defaults_1 = require("../common/defaults");
7
+ const security_1 = require("../common/security");
7
8
  const ACCEL_PATH = '/sys/class/accel';
8
9
  const readAttr = async (path) => {
9
10
  try {
@@ -41,7 +42,7 @@ const npu = async () => {
41
42
  const result = [];
42
43
  const seen = new Set();
43
44
  try {
44
- const nodes = (await (0, promises_1.readdir)(ACCEL_PATH)).filter((node) => node.startsWith('accel')).sort();
45
+ const nodes = (await (0, promises_1.readdir)(ACCEL_PATH)).filter((node) => node.startsWith('accel') && (0, security_1.isSafePathSegment)(node)).sort();
45
46
  for (const node of nodes) {
46
47
  let dev;
47
48
  try {
@@ -6,9 +6,11 @@ const codepage_1 = require("../common/codepage");
6
6
  const const_1 = require("../common/const");
7
7
  const defaults_1 = require("../common/defaults");
8
8
  const exec_1 = require("../common/exec");
9
+ const promises_1 = require("node:fs/promises");
9
10
  const files_1 = require("../common/files");
10
11
  const mappings_1 = require("../common/mappings");
11
12
  const uuid_1 = require("./uuid");
13
+ const security_1 = require("../common/security");
12
14
  const getInstallDate = async () => {
13
15
  try {
14
16
  const { stdout } = await (0, exec_1.exec)('stat -c %W / 2>/dev/null', const_1.execOptsLinux);
@@ -19,8 +21,8 @@ const getInstallDate = async () => {
19
21
  }
20
22
  catch { }
21
23
  try {
22
- const { stdout: dfOut } = await (0, exec_1.exec)('df -P / 2>/dev/null', const_1.execOptsLinux);
23
- const dev = (dfOut.toString().split('\n')[1] || '').split(/\s+/)[0] || '';
24
+ const rootMount = (await (0, files_1.readFileLines)('/proc/mounts')).filter((line) => line.split(' ')[1] === '/').pop() || '';
25
+ const dev = rootMount.split(' ')[0] || '';
24
26
  if (/^\/dev\/[\w./-]+$/.test(dev)) {
25
27
  const { stdout } = await (0, exec_1.exec)(`tune2fs -l ${dev} 2>/dev/null`, const_1.execOptsLinux);
26
28
  const line = stdout
@@ -67,6 +69,41 @@ const linuxIsUefi = async () => {
67
69
  return stdout.split('\n').length > 0 && stdout.indexOf('EFI') >= 0;
68
70
  }
69
71
  };
72
+ const getSecurity = async () => {
73
+ const enforce = await (0, files_1.readSysfs)('/sys/fs/selinux/enforce');
74
+ if (enforce === '0' || enforce === '1') {
75
+ const config = await (0, files_1.readFileLines)('/etc/selinux/config');
76
+ const policy = config.find((line) => line.trim().startsWith('SELINUXTYPE='));
77
+ return {
78
+ module: 'selinux',
79
+ enabled: true,
80
+ mode: enforce === '1' ? 'enforcing' : 'permissive',
81
+ policy: policy ? policy.split('=')[1].trim() : ''
82
+ };
83
+ }
84
+ const apparmor = await (0, files_1.readSysfs)('/sys/module/apparmor/parameters/enabled');
85
+ if (apparmor) {
86
+ const enabled = apparmor.toUpperCase() === 'Y';
87
+ const mode = await (0, files_1.readSysfs)('/sys/module/apparmor/parameters/mode');
88
+ return {
89
+ module: 'apparmor',
90
+ enabled,
91
+ mode: enabled ? mode || 'enforce' : 'disabled',
92
+ policy: ''
93
+ };
94
+ }
95
+ const config = await (0, files_1.readFileLines)('/etc/selinux/config');
96
+ const configured = config.find((line) => line.trim().startsWith('SELINUX='));
97
+ if (configured) {
98
+ return {
99
+ module: 'selinux',
100
+ enabled: false,
101
+ mode: 'disabled',
102
+ policy: ''
103
+ };
104
+ }
105
+ return { module: '', enabled: false, mode: '', policy: '' };
106
+ };
70
107
  const parseOsInfo = async (stdout, defaults) => {
71
108
  const release = {};
72
109
  const lines = stdout.toString().split('\n');
@@ -98,15 +135,29 @@ const parseOsInfo = async (stdout, defaults) => {
98
135
  serial: (await (0, uuid_1.uuid)()).os,
99
136
  installDate: await getInstallDate(),
100
137
  lastUpdate: await getLastUpdate(),
101
- displayServer: await getDisplayServer()
138
+ displayServer: await getDisplayServer(),
139
+ security: await getSecurity()
102
140
  };
103
141
  };
104
142
  const osInfo = async () => {
105
143
  await (0, common_1.nextTick)();
106
144
  const defaults = (0, common_1.cloneObj)(await (0, defaults_1.initOsInfo)());
107
145
  try {
108
- const { stdout } = await (0, exec_1.execSave)('cat /etc/*-release 2>/dev/null; cat /usr/lib/os-release 2>/dev/null; cat /etc/openwrt_release 2>/dev/null');
109
- return await parseOsInfo(stdout, defaults);
146
+ const releaseFiles = (await (0, promises_1.readdir)('/etc').catch(() => [])).filter((file) => file.endsWith('-release') && (0, security_1.isSafePathSegment)(file)).sort();
147
+ const files = [...releaseFiles.map((file) => `/etc/${file}`), '/usr/lib/os-release', '/etc/openwrt_release'];
148
+ let budget = 1024 * 1024;
149
+ const parts = [];
150
+ for (const file of files) {
151
+ if (budget <= 0) {
152
+ break;
153
+ }
154
+ const content = await (0, files_1.readFileMax)(file, budget);
155
+ if (content) {
156
+ parts.push(content);
157
+ budget -= content.length;
158
+ }
159
+ }
160
+ return await parseOsInfo(parts.join('\n') + '\n', defaults);
110
161
  }
111
162
  catch { }
112
163
  return defaults;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.printer = void 0;
4
- const exec_1 = require("./../common/exec");
4
+ const exec_1 = require("../common/exec");
5
+ const files_1 = require("../common/files");
5
6
  const common_1 = require("../common");
6
7
  const const_1 = require("../common/const");
7
8
  const parseLinuxCupsHeader = (lines) => {
@@ -48,8 +49,7 @@ const parseLinuxLpstatPrinter = (lines, id) => {
48
49
  const printer = async () => {
49
50
  await (0, common_1.nextTick)();
50
51
  const result = [];
51
- let { stdout } = await (0, exec_1.execSave)('cat /etc/cups/printers.conf 2>/dev/null');
52
- const parts = stdout.toString().split('<Printer ');
52
+ const parts = (await (0, files_1.readFileMax)('/etc/cups/printers.conf')).split('<Printer ');
53
53
  const printerHeader = parseLinuxCupsHeader(parts[0].split('\n'));
54
54
  for (let i = 1; i < parts.length; i++) {
55
55
  const printers = parseLinuxCupsPrinter(parts[i].split('\n'));
@@ -61,7 +61,7 @@ const printer = async () => {
61
61
  }
62
62
  if (result.length === 0) {
63
63
  if (const_1.LINUX) {
64
- ({ stdout } = await (0, exec_1.execSave)('export LC_ALL=C; lpstat -lp 2>/dev/null; unset LC_ALL'));
64
+ const { stdout } = await (0, exec_1.execSave)('export LC_ALL=C.UTF-8; lpstat -lp 2>/dev/null; unset LC_ALL');
65
65
  const parts = ('\n' + stdout.toString()).split('\nprinter ');
66
66
  for (let i = 1; i < parts.length; i++) {
67
67
  const printers = parseLinuxLpstatPrinter(parts[i].split('\n'), i);
@@ -0,0 +1,4 @@
1
+ import type { ProcessFocusedData } from '../common/types';
2
+ export declare const parseXpropWindowId: (stdout: string) => string;
3
+ export declare const parseXpropPid: (stdout: string) => number;
4
+ export declare const processFocused: () => Promise<ProcessFocusedData | null>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processFocused = exports.parseXpropPid = exports.parseXpropWindowId = void 0;
4
+ const promises_1 = require("node:fs/promises");
5
+ const common_1 = require("../common");
6
+ const exec_1 = require("../common/exec");
7
+ const EXEC_OPTS = { timeout: 5000 };
8
+ const parseXpropWindowId = (stdout) => {
9
+ const id = (stdout.match(/window id # (0x[0-9a-f]+)/i) || [])[1] || '';
10
+ return Number(id) ? id : '';
11
+ };
12
+ exports.parseXpropWindowId = parseXpropWindowId;
13
+ const parseXpropPid = (stdout) => (0, common_1.toInt)((stdout.match(/_NET_WM_PID\(CARDINAL\) = (\d+)/) || [])[1]);
14
+ exports.parseXpropPid = parseXpropPid;
15
+ const activeWindowPid = async () => {
16
+ const pid = (0, common_1.toInt)(await (0, exec_1.execSecure)('xdotool', ['getactivewindow', 'getwindowpid'], EXEC_OPTS));
17
+ if (pid) {
18
+ return pid;
19
+ }
20
+ const windowId = (0, exports.parseXpropWindowId)(await (0, exec_1.execSecure)('xprop', ['-root', '_NET_ACTIVE_WINDOW'], EXEC_OPTS));
21
+ return windowId ? (0, exports.parseXpropPid)(await (0, exec_1.execSecure)('xprop', ['-id', windowId, '_NET_WM_PID'], EXEC_OPTS)) : 0;
22
+ };
23
+ const processFocused = async () => {
24
+ const pid = await activeWindowPid();
25
+ if (!pid) {
26
+ return null;
27
+ }
28
+ const path = await (0, promises_1.readlink)(`/proc/${pid}/exe`).catch(() => '');
29
+ const name = path ? path.split('/').pop() || '' : (await (0, promises_1.readFile)(`/proc/${pid}/comm`, 'utf8').catch(() => '')).trim();
30
+ return { pid, name, path };
31
+ };
32
+ exports.processFocused = processFocused;