systeminformation 5.12.9 → 5.12.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014-2021 Sebastian Hildebrandt
3
+ Copyright (c) 2014-2022 Sebastian Hildebrandt
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
package/README.md CHANGED
@@ -1024,7 +1024,7 @@ All other trademarks are the property of their respective owners.
1024
1024
 
1025
1025
  >The [`MIT`][license-url] License (MIT)
1026
1026
  >
1027
- >Copyright © 2014-2021 Sebastian Hildebrandt, [+innovations](http://www.plus-innovations.com).
1027
+ >Copyright © 2014-2022 Sebastian Hildebrandt, [+innovations](http://www.plus-innovations.com).
1028
1028
  >
1029
1029
  >Permission is hereby granted, free of charge, to any person obtaining a copy
1030
1030
  >of this software and associated documentation files (the "Software"), to deal
package/lib/bluetooth.js CHANGED
@@ -37,6 +37,25 @@ function parseBluetoothType(str) {
37
37
  if (str.indexOf('speaker') >= 0) { result = 'Speaker'; }
38
38
  if (str.indexOf('headset') >= 0) { result = 'Headset'; }
39
39
  if (str.indexOf('phone') >= 0) { result = 'Phone'; }
40
+ if (str.indexOf('macbook') >= 0) { result = 'Computer'; }
41
+ if (str.indexOf('imac') >= 0) { result = 'Computer'; }
42
+ if (str.indexOf('ipad') >= 0) { result = 'Tablet'; }
43
+ if (str.indexOf('watch') >= 0) { result = 'Watch'; }
44
+ if (str.indexOf('headphone') >= 0) { result = 'Headset'; }
45
+ // to be continued ...
46
+
47
+ return result;
48
+ }
49
+
50
+ function parseBluetoothManufacturer(str) {
51
+ let result = str.split(' ')[0];
52
+ str = str.toLowerCase();
53
+ if (str.indexOf('apple') >= 0) { result = 'Apple'; }
54
+ if (str.indexOf('ipad') >= 0) { result = 'Apple'; }
55
+ if (str.indexOf('imac') >= 0) { result = 'Apple'; }
56
+ if (str.indexOf('iphone') >= 0) { result = 'Apple'; }
57
+ if (str.indexOf('magic mouse') >= 0) { result = 'Apple'; }
58
+ if (str.indexOf('macbook') >= 0) { result = 'Apple'; }
40
59
  // to be continued ...
41
60
 
42
61
  return result;
@@ -59,12 +78,12 @@ function parseLinuxBluetoothInfo(lines, macAddr1, macAddr2) {
59
78
 
60
79
  function parseDarwinBluetoothDevices(bluetoothObject, macAddr2) {
61
80
  const result = {};
62
- const typeStr = ((bluetoothObject.device_minorClassOfDevice_string || bluetoothObject.device_majorClassOfDevice_string || '') + (bluetoothObject.device_name || '')).toLowerCase();
81
+ const typeStr = ((bluetoothObject.device_minorClassOfDevice_string || bluetoothObject.device_majorClassOfDevice_string || bluetoothObject.device_minorType || '') + (bluetoothObject.device_name || '')).toLowerCase();
63
82
 
64
83
  result.device = bluetoothObject.device_services || '';
65
84
  result.name = bluetoothObject.device_name || '';
66
- result.manufacturer = bluetoothObject.device_manufacturer || '';
67
- result.macDevice = (bluetoothObject.device_addr || '').toLowerCase().replace(/-/g, ':');
85
+ result.manufacturer = bluetoothObject.device_manufacturer || parseBluetoothManufacturer(bluetoothObject.device_name || '') || '';
86
+ result.macDevice = (bluetoothObject.device_addr || bluetoothObject.device_address || '').toLowerCase().replace(/-/g, ':');
68
87
  result.macHost = macAddr2;
69
88
  result.batteryPercent = bluetoothObject.device_batteryPercent || null;
70
89
  result.type = parseBluetoothType(typeStr);
@@ -96,16 +115,16 @@ function bluetoothDevices(callback) {
96
115
  if (_linux) {
97
116
  // get files in /var/lib/bluetooth/ recursive
98
117
  const btFiles = util.getFilesInPath('/var/lib/bluetooth/');
99
- for (let i = 0; i < btFiles.length; i++) {
100
- const filename = path.basename(btFiles[i]);
101
- const pathParts = btFiles[i].split('/');
118
+ btFiles.forEach((element) => {
119
+ const filename = path.basename(element);
120
+ const pathParts = element.split('/');
102
121
  const macAddr1 = pathParts.length >= 6 ? pathParts[pathParts.length - 2] : null;
103
122
  const macAddr2 = pathParts.length >= 7 ? pathParts[pathParts.length - 3] : null;
104
123
  if (filename === 'info') {
105
- const infoFile = fs.readFileSync(btFiles[i], { encoding: 'utf8' }).split('\n');
124
+ const infoFile = fs.readFileSync(element, { encoding: 'utf8' }).split('\n');
106
125
  result.push(parseLinuxBluetoothInfo(infoFile, macAddr1, macAddr2));
107
126
  }
108
- }
127
+ });
109
128
  // determine "connected" with hcitool con
110
129
  try {
111
130
  const hdicon = execSync('hcitool con').toString().toLowerCase();
@@ -135,9 +154,8 @@ function bluetoothDevices(callback) {
135
154
  if (outObj.SPBluetoothDataType[0]['local_device_title'] && outObj.SPBluetoothDataType[0].local_device_title.general_address) {
136
155
  macAddr2 = outObj.SPBluetoothDataType[0].local_device_title.general_address.toLowerCase().replace(/-/g, ':');
137
156
  }
138
-
139
- for (let i = 0; i < outObj.SPBluetoothDataType[0]['device_title'].length; i++) {
140
- const obj = outObj.SPBluetoothDataType[0]['device_title'][i];
157
+ outObj.SPBluetoothDataType[0]['device_title'].forEach((element) => {
158
+ const obj = element;
141
159
  const objKey = Object.keys(obj);
142
160
  if (objKey && objKey.length === 1) {
143
161
  const innerObject = obj[objKey[0]];
@@ -145,7 +163,35 @@ function bluetoothDevices(callback) {
145
163
  const bluetoothDevice = parseDarwinBluetoothDevices(innerObject, macAddr2);
146
164
  result.push(bluetoothDevice);
147
165
  }
148
- }
166
+ });
167
+ }
168
+ if (outObj.SPBluetoothDataType && outObj.SPBluetoothDataType.length && outObj.SPBluetoothDataType[0] && outObj.SPBluetoothDataType[0]['device_connected'] && outObj.SPBluetoothDataType[0]['device_connected'].length) {
169
+ const macAddr2 = outObj.SPBluetoothDataType[0].controller_properties && outObj.SPBluetoothDataType[0].controller_properties.controller_address ? outObj.SPBluetoothDataType[0].controller_properties.controller_address.toLowerCase().replace(/-/g, ':') : null;
170
+ outObj.SPBluetoothDataType[0]['device_connected'].forEach((element) => {
171
+ const obj = element;
172
+ const objKey = Object.keys(obj);
173
+ if (objKey && objKey.length === 1) {
174
+ const innerObject = obj[objKey[0]];
175
+ innerObject.device_name = objKey[0];
176
+ innerObject.device_isconnected = 'attrib_Yes';
177
+ const bluetoothDevice = parseDarwinBluetoothDevices(innerObject, macAddr2);
178
+ result.push(bluetoothDevice);
179
+ }
180
+ });
181
+ }
182
+ if (outObj.SPBluetoothDataType && outObj.SPBluetoothDataType.length && outObj.SPBluetoothDataType[0] && outObj.SPBluetoothDataType[0]['device_not_connected'] && outObj.SPBluetoothDataType[0]['device_not_connected'].length) {
183
+ const macAddr2 = outObj.SPBluetoothDataType[0].controller_properties && outObj.SPBluetoothDataType[0].controller_properties.controller_address ? outObj.SPBluetoothDataType[0].controller_properties.controller_address.toLowerCase().replace(/-/g, ':') : null;
184
+ outObj.SPBluetoothDataType[0]['device_not_connected'].forEach((element) => {
185
+ const obj = element;
186
+ const objKey = Object.keys(obj);
187
+ if (objKey && objKey.length === 1) {
188
+ const innerObject = obj[objKey[0]];
189
+ innerObject.device_name = objKey[0];
190
+ innerObject.device_isconnected = 'attrib_No';
191
+ const bluetoothDevice = parseDarwinBluetoothDevices(innerObject, macAddr2);
192
+ result.push(bluetoothDevice);
193
+ }
194
+ });
149
195
  }
150
196
  } catch (e) {
151
197
  util.noop();
@@ -161,11 +207,11 @@ function bluetoothDevices(callback) {
161
207
  util.powerShell('Get-WmiObject Win32_PNPEntity | select PNPClass, Name, Manufacturer | fl').then((stdout, error) => {
162
208
  if (!error) {
163
209
  const parts = stdout.toString().split(/\n\s*\n/);
164
- for (let i = 0; i < parts.length; i++) {
165
- if (util.getValue(parts[i].split('\n'), 'PNPClass', ':') === 'Bluetooth') {
166
- result.push(parseWindowsBluetooth(parts[i].split('\n')));
210
+ parts.forEach((part) => {
211
+ if (util.getValue(part.split('\n'), 'PNPClass', ':') === 'Bluetooth') {
212
+ result.push(parseWindowsBluetooth(part.split('\n')));
167
213
  }
168
- }
214
+ });
169
215
  }
170
216
  if (callback) {
171
217
  callback(result);
package/lib/processes.js CHANGED
@@ -253,8 +253,8 @@ function services(srv, callback) {
253
253
  // process
254
254
  let list_new = {};
255
255
  let resultProcess = {};
256
- for (let i = 0; i < curr_processes.length; i++) {
257
- resultProcess = calcProcStatLinux(curr_processes[i], all, _services_cpu);
256
+ curr_processes.forEach((element) => {
257
+ resultProcess = calcProcStatLinux(element, all, _services_cpu);
258
258
 
259
259
  if (resultProcess.pid) {
260
260
  let listPos = -1;
@@ -279,7 +279,7 @@ function services(srv, callback) {
279
279
  cstime: resultProcess.cstime
280
280
  };
281
281
  }
282
- }
282
+ });
283
283
 
284
284
  // store old values
285
285
  _services_cpu.all = all;
@@ -338,18 +338,18 @@ function services(srv, callback) {
338
338
  let wincommand = 'Get-WmiObject Win32_Service';
339
339
  if (srvs[0] !== '*') {
340
340
  wincommand += ' -Filter "';
341
- for (let i = 0; i < srvs.length; i++) {
342
- wincommand += `Name='${srvs[i]}' or `;
343
- }
341
+ srvs.forEach((srv) => {
342
+ wincommand += `Name='${srv}' or `;
343
+ });
344
344
  wincommand = `${wincommand.slice(0, -4)}"`;
345
345
  }
346
346
  wincommand += ' | select Name,Caption,Started,StartMode,ProcessId | fl';
347
347
  util.powerShell(wincommand).then((stdout, error) => {
348
348
  if (!error) {
349
349
  let serviceSections = stdout.split(/\n\s*\n/);
350
- for (let i = 0; i < serviceSections.length; i++) {
351
- if (serviceSections[i].trim() !== '') {
352
- let lines = serviceSections[i].trim().split('\r\n');
350
+ serviceSections.forEach((element) => {
351
+ if (element.trim() !== '') {
352
+ let lines = element.trim().split('\r\n');
353
353
  let srvName = util.getValue(lines, 'Name', ':', true).toLowerCase();
354
354
  let srvCaption = util.getValue(lines, 'Caption', ':', true).toLowerCase();
355
355
  let started = util.getValue(lines, 'Started', ':', true);
@@ -368,7 +368,9 @@ function services(srv, callback) {
368
368
  dataSrv.push(srvCaption);
369
369
  }
370
370
  }
371
- }
371
+
372
+ });
373
+
372
374
  if (srvString !== '*') {
373
375
  let srvsMissing = srvs.filter(function (e) {
374
376
  return dataSrv.indexOf(e) === -1;
@@ -740,9 +742,9 @@ function processes(callback) {
740
742
  if (_linux) {
741
743
  // calc process_cpu - ps is not accurate in linux!
742
744
  cmd = 'cat /proc/stat | grep "cpu "';
743
- for (let i = 0; i < result.list.length; i++) {
744
- cmd += (';cat /proc/' + result.list[i].pid + '/stat');
745
- }
745
+ result.list.forEach((element) => {
746
+ cmd += (';cat /proc/' + element.pid + '/stat');
747
+ });
746
748
  exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
747
749
  let curr_processes = stdout.toString().split('\n');
748
750
 
@@ -752,8 +754,8 @@ function processes(callback) {
752
754
  // process
753
755
  let list_new = {};
754
756
  let resultProcess = {};
755
- for (let i = 0; i < curr_processes.length; i++) {
756
- resultProcess = calcProcStatLinux(curr_processes[i], all, _processes_cpu);
757
+ curr_processes.forEach((element) => {
758
+ resultProcess = calcProcStatLinux(element, all, _processes_cpu);
757
759
 
758
760
  if (resultProcess.pid) {
759
761
 
@@ -775,7 +777,7 @@ function processes(callback) {
775
777
  cstime: resultProcess.cstime
776
778
  };
777
779
  }
778
- }
780
+ });
779
781
 
780
782
  // store old values
781
783
  _processes_cpu.all = all;
@@ -829,9 +831,9 @@ function processes(callback) {
829
831
  let list_new = {};
830
832
  let allcpuu = 0;
831
833
  let allcpus = 0;
832
- for (let i = 0; i < processSections.length; i++) {
833
- if (processSections[i].trim() !== '') {
834
- let lines = processSections[i].trim().split('\r\n');
834
+ processSections.forEach((element) => {
835
+ if (element.trim() !== '') {
836
+ let lines = element.trim().split('\r\n');
835
837
  let pid = parseInt(util.getValue(lines, 'ProcessId', ':', true), 10);
836
838
  let parentPid = parseInt(util.getValue(lines, 'ParentProcessId', ':', true), 10);
837
839
  let statusValue = util.getValue(lines, 'ExecutionState', ':');
@@ -889,11 +891,12 @@ function processes(callback) {
889
891
  params: ''
890
892
  });
891
893
  }
892
- }
894
+ });
895
+
893
896
  result.sleeping = result.all - result.running - result.blocked - result.unknown;
894
897
  result.list = procs;
895
- for (let i = 0; i < procStats.length; i++) {
896
- let resultProcess = calcProcStatWin(procStats[i], allcpuu + allcpus, _processes_cpu);
898
+ procStats.forEach((element) => {
899
+ let resultProcess = calcProcStatWin(element, allcpuu + allcpus, _processes_cpu);
897
900
 
898
901
  // store pcpu in outer array
899
902
  let listPos = result.list.map(function (e) { return e.pid; }).indexOf(resultProcess.pid);
@@ -910,7 +913,8 @@ function processes(callback) {
910
913
  utime: resultProcess.utime,
911
914
  stime: resultProcess.stime
912
915
  };
913
- }
916
+ });
917
+
914
918
  // store old values
915
919
  _processes_cpu.all = allcpuu + allcpus;
916
920
  _processes_cpu.all_utime = allcpuu;
@@ -972,7 +976,7 @@ function processLoad(proc, callback) {
972
976
 
973
977
  const s = util.sanitizeShellString(proc);
974
978
  for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
975
- if (!(s[i] === undefined)) {
979
+ if (s[i] !== undefined) {
976
980
  processesString = processesString + s[i];
977
981
  }
978
982
  }
@@ -1008,9 +1012,9 @@ function processLoad(proc, callback) {
1008
1012
  let allcpus = 0;
1009
1013
 
1010
1014
  // go through all processes
1011
- for (let i = 0; i < processSections.length; i++) {
1012
- if (processSections[i].trim() !== '') {
1013
- let lines = processSections[i].trim().split('\r\n');
1015
+ processSections.forEach((element) => {
1016
+ if (element.trim() !== '') {
1017
+ let lines = element.trim().split('\r\n');
1014
1018
  let pid = parseInt(util.getValue(lines, 'ProcessId', ':', true), 10);
1015
1019
  let name = util.getValue(lines, 'Caption', ':', true);
1016
1020
  let utime = parseInt(util.getValue(lines, 'UserModeTime', ':', true), 10);
@@ -1058,7 +1062,8 @@ function processLoad(proc, callback) {
1058
1062
  }
1059
1063
  }
1060
1064
  }
1061
- }
1065
+ });
1066
+
1062
1067
  // add missing processes
1063
1068
  if (processesString !== '*') {
1064
1069
  let processesMissing = processes.filter(function (name) {
@@ -1077,8 +1082,8 @@ function processLoad(proc, callback) {
1077
1082
  }
1078
1083
 
1079
1084
  // calculate proc stats for each proc
1080
- for (let i = 0; i < procStats.length; i++) {
1081
- let resultProcess = calcProcStatWin(procStats[i], allcpuu + allcpus, _process_cpu);
1085
+ procStats.forEach((element) => {
1086
+ let resultProcess = calcProcStatWin(element, allcpuu + allcpus, _process_cpu);
1082
1087
 
1083
1088
  let listPos = -1;
1084
1089
  for (let j = 0; j < result.length; j++) {
@@ -1095,7 +1100,8 @@ function processLoad(proc, callback) {
1095
1100
  utime: resultProcess.utime,
1096
1101
  stime: resultProcess.stime
1097
1102
  };
1098
- }
1103
+ });
1104
+
1099
1105
  // store old values
1100
1106
  _process_cpu.all = allcpuu + allcpus;
1101
1107
  _process_cpu.all_utime = allcpuu;
@@ -1210,9 +1216,8 @@ function processLoad(proc, callback) {
1210
1216
  // process
1211
1217
  let list_new = {};
1212
1218
  let resultProcess = {};
1213
-
1214
- for (let i = 0; i < curr_processes.length; i++) {
1215
- resultProcess = calcProcStatLinux(curr_processes[i], all, _process_cpu);
1219
+ curr_processes.forEach((element) => {
1220
+ resultProcess = calcProcStatLinux(element, all, _process_cpu);
1216
1221
 
1217
1222
  if (resultProcess.pid) {
1218
1223
 
@@ -1238,7 +1243,7 @@ function processLoad(proc, callback) {
1238
1243
  cstime: resultProcess.cstime
1239
1244
  };
1240
1245
  }
1241
- }
1246
+ });
1242
1247
 
1243
1248
  result.forEach(function (item) {
1244
1249
  item.cpu = Math.round(item.cpu * 100) / 100;
package/lib/usb.js CHANGED
@@ -14,9 +14,7 @@
14
14
  // ----------------------------------------------------------------------------------
15
15
 
16
16
  const exec = require('child_process').exec;
17
- // const execSync = require('child_process').execSync;
18
17
  const util = require('./util');
19
- // const fs = require('fs');
20
18
 
21
19
  let _platform = process.platform;
22
20
 
@@ -91,16 +89,6 @@ function parseLinuxUsb(usb) {
91
89
  return result;
92
90
  }
93
91
 
94
- // bus
95
- // deviceId
96
- // id
97
- // name(product)
98
- // type(bInterfaceClass)
99
- // removable / hotplug
100
- // vendor
101
- // manufacturer
102
- // maxpower(linux)
103
-
104
92
  function getDarwinUsbType(name) {
105
93
  let result = '';
106
94
  if (name.indexOf('camera') >= 0) { result = 'Camera'; }
@@ -164,25 +152,6 @@ function parseDarwinUsb(usb, id) {
164
152
  }
165
153
  }
166
154
 
167
- // function getWindowsUsbType(service) {
168
- // let result = ''
169
- // if (service.indexOf('usbhub3') >= 0) { result = 'Hub'; }
170
- // else if (service.indexOf('usbstor') >= 0) { result = 'Storage'; }
171
- // else if (service.indexOf('hidusb') >= 0) { result = 'Input'; }
172
- // else if (service.indexOf('usbccgp') >= 0) { result = 'Controller'; }
173
- // else if (service.indexOf('usbxhci') >= 0) { result = 'Controller'; }
174
- // else if (service.indexOf('usbehci') >= 0) { result = 'Controller'; }
175
- // else if (service.indexOf('kbdhid') >= 0) { result = 'Keyboard'; }
176
- // else if (service.indexOf('keyboard') >= 0) { result = 'Keyboard'; }
177
- // else if (service.indexOf('pointing') >= 0) { result = 'Mouse'; }
178
- // else if (service.indexOf('disk') >= 0) { result = 'Storage'; }
179
- // else if (service.indexOf('usbhub') >= 0) { result = 'Hub'; }
180
- // else if (service.indexOf('bthusb') >= 0) { result = ''; }
181
- // else if (service.indexOf('bth') >= 0) { result = ''; }
182
- // else if (service.indexOf('rfcomm') >= 0) { result = ''; }
183
- // return result;
184
- // }
185
-
186
155
  function getWindowsUsbTypeCreation(creationclass, name) {
187
156
  let result = '';
188
157
  if (name.indexOf('storage') >= 0) { result = 'Storage'; }
@@ -216,7 +185,6 @@ function parseWindowsUsb(lines, id) {
216
185
  } else {
217
186
  return null;
218
187
  }
219
-
220
188
  }
221
189
 
222
190
  function usb(callback) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "5.12.9",
3
+ "version": "5.12.10",
4
4
  "description": "Advanced, lightweight system and OS information library",
5
5
  "license": "MIT",
6
6
  "author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",