| 5.27.16 |
2025-12-23 |
diff --git a/docs/index.html b/docs/index.html
index a36f6e0..514439a 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -170,7 +170,7 @@
systeminformation
- New Version: 5.27.16
+ New Version: 5.27.17
diff --git a/lib/graphics.js b/lib/graphics.js
index 00a697b..12483cc 100644
--- a/lib/graphics.js
+++ b/lib/graphics.js
@@ -147,7 +147,7 @@ function graphics(callback) {
displays: []
};
try {
- graphicsArr.forEach( (item) => {
+ graphicsArr.forEach((item) => {
// controllers
const bus = (item.sppci_bus || '').indexOf('builtin') > -1 ? 'Built-In' : (item.sppci_bus || '').indexOf('pcie') > -1 ? 'PCIe' : '';
const vram = (parseInt(item.spdisplays_vram || '', 10) || 0) * ((item.spdisplays_vram || '').indexOf('GB') > -1 ? 1024 : 1);
@@ -168,7 +168,7 @@ function graphics(callback) {
// displays
if (item.spdisplays_ndrvs && item.spdisplays_ndrvs.length) {
- item.spdisplays_ndrvs.forEach( (displayItem) => {
+ item.spdisplays_ndrvs.forEach((displayItem) => {
const connectionType = displayItem['spdisplays_connection_type'] || '';
const currentResolutionParts = (displayItem['_spdisplays_resolution'] || '').split('@');
const currentResolution = currentResolutionParts[0].split('x');
@@ -457,12 +457,12 @@ function graphics(callback) {
if (nvidiaSmiExe) {
const nvidiaSmiOpts =
'--query-gpu=driver_version,pci.sub_device_id,name,pci.bus_id,fan.speed,memory.total,memory.used,memory.free,utilization.gpu,utilization.memory,temperature.gpu,temperature.memory,power.draw,power.limit,clocks.gr,clocks.mem --format=csv,noheader,nounits';
- const cmd = nvidiaSmiExe + ' ' + nvidiaSmiOpts + (_linux ? ' 2>/dev/null' : '');
+ const cmd = nvidiaSmiExe + ' ' + nvidiaSmiOpts;
if (_linux) {
options.stdio = ['pipe', 'pipe', 'ignore'];
}
try {
- const sanitized = util.sanitizeShellString(cmd);
+ const sanitized = util.sanitizeShellString(cmd) + (_linux ? ' 2>/dev/null' : '');
const res = execSync(sanitized, options).toString();
return res;
} catch {
@@ -863,7 +863,7 @@ function graphics(callback) {
}
// } else {
const cmd = 'lspci -vvv 2>/dev/null';
- exec(cmd, (error, stdout) => {
+ exec(cmd, (error, stdout) => {
if (!error) {
const lines = stdout.toString().split('\n');
if (result.controllers.length === 0) {
diff --git a/lib/system.js b/lib/system.js
index 2eebd71..ba7e01b 100644
--- a/lib/system.js
+++ b/lib/system.js
@@ -21,21 +21,19 @@ const exec = require('child_process').exec;
const execSync = require('child_process').execSync;
const execPromise = util.promisify(require('child_process').exec);
-let _platform = process.platform;
+const _platform = process.platform;
-const _linux = (_platform === 'linux' || _platform === 'android');
-const _darwin = (_platform === 'darwin');
-const _windows = (_platform === 'win32');
-const _freebsd = (_platform === 'freebsd');
-const _openbsd = (_platform === 'openbsd');
-const _netbsd = (_platform === 'netbsd');
-const _sunos = (_platform === 'sunos');
+const _linux = _platform === 'linux' || _platform === 'android';
+const _darwin = _platform === 'darwin';
+const _windows = _platform === 'win32';
+const _freebsd = _platform === 'freebsd';
+const _openbsd = _platform === 'openbsd';
+const _netbsd = _platform === 'netbsd';
+const _sunos = _platform === 'sunos';
function system(callback) {
-
return new Promise((resolve) => {
process.nextTick(() => {
-
let result = {
manufacturer: '',
model: 'Computer',
@@ -47,13 +45,13 @@ function system(callback) {
};
if (_linux || _freebsd || _openbsd || _netbsd) {
- exec('export LC_ALL=C; dmidecode -t system 2>/dev/null; unset LC_ALL', function (error, stdout) {
+ exec('export LC_ALL=C; dmidecode -t system 2>/dev/null; unset LC_ALL', (error, stdout) => {
let lines = stdout.toString().split('\n');
result.manufacturer = cleanDefaults(util.getValue(lines, 'manufacturer'));
result.model = cleanDefaults(util.getValue(lines, 'product name'));
result.version = cleanDefaults(util.getValue(lines, 'version'));
result.serial = cleanDefaults(util.getValue(lines, 'serial number'));
- result.uuid = cleanDefaults((util.getValue(lines, 'uuid'))).toLowerCase();
+ result.uuid = cleanDefaults(util.getValue(lines, 'uuid')).toLowerCase();
result.sku = cleanDefaults(util.getValue(lines, 'sku number'));
// Non-Root values
const cmd = `echo -n "product_name: "; cat /sys/devices/virtual/dmi/id/product_name 2>/dev/null; echo;
@@ -68,17 +66,34 @@ function system(callback) {
result.version = cleanDefaults(result.version === '' ? util.getValue(lines, 'product_version') : result.version);
result.serial = cleanDefaults(result.serial === '' ? util.getValue(lines, 'product_serial') : result.serial);
result.uuid = cleanDefaults(result.uuid === '' ? util.getValue(lines, 'product_uuid').toLowerCase() : result.uuid);
- } catch (e) {
+ } catch {
util.noop();
}
- if (!result.serial) { result.serial = '-'; }
- if (!result.manufacturer) { result.manufacturer = ''; }
- if (!result.model) { result.model = 'Computer'; }
- if (!result.version) { result.version = ''; }
- if (!result.sku) { result.sku = '-'; }
+ if (!result.serial) {
+ result.serial = '-';
+ }
+ if (!result.manufacturer) {
+ result.manufacturer = '';
+ }
+ if (!result.model) {
+ result.model = 'Computer';
+ }
+ if (!result.version) {
+ result.version = '';
+ }
+ if (!result.sku) {
+ result.sku = '-';
+ }
// detect virtual (1)
- if (result.model.toLowerCase() === 'virtualbox' || result.model.toLowerCase() === 'kvm' || result.model.toLowerCase() === 'virtual machine' || result.model.toLowerCase() === 'bochs' || result.model.toLowerCase().startsWith('vmware') || result.model.toLowerCase().startsWith('droplet')) {
+ if (
+ result.model.toLowerCase() === 'virtualbox' ||
+ result.model.toLowerCase() === 'kvm' ||
+ result.model.toLowerCase() === 'virtual machine' ||
+ result.model.toLowerCase() === 'bochs' ||
+ result.model.toLowerCase().startsWith('vmware') ||
+ result.model.toLowerCase().startsWith('droplet')
+ ) {
result.virtual = true;
switch (result.model.toLowerCase()) {
case 'virtualbox':
@@ -117,7 +132,7 @@ function system(callback) {
result.virtual = true;
result.virtualHost = 'VirtualBox';
}
- } catch (e) {
+ } catch {
util.noop();
}
}
@@ -133,7 +148,7 @@ function system(callback) {
if (!result.model || result.model === 'Computer') {
result.model = util.getValue(lines, 'hw.model', ':').trim();
}
- } catch (e) {
+ } catch {
util.noop();
}
}
@@ -163,7 +178,7 @@ function system(callback) {
result.virtualHost = 'bochs';
break;
}
- } catch (e) {
+ } catch {
util.noop();
}
}
@@ -174,9 +189,11 @@ function system(callback) {
try {
const stdout = execSync('dmesg 2>/dev/null | grep -iE "virtual|hypervisor" | grep -iE "vmware|qemu|kvm|xen" | grep -viE "Nested Virtualization|/virtual/"');
// detect virtual machines
- let lines = stdout.toString().split('\n');
+ const lines = stdout.toString().split('\n');
if (lines.length > 0) {
- if (result.model === 'Computer') { result.model = 'Virtual machine'; }
+ if (result.model === 'Computer') {
+ result.model = 'Virtual machine';
+ }
result.virtual = true;
if (stdout.toString().toLowerCase().indexOf('vmware') >= 0 && !result.virtualHost) {
result.virtualHost = 'VMware';
@@ -191,13 +208,13 @@ function system(callback) {
result.virtualHost = 'KVM';
}
}
- } catch (e) {
+ } catch {
util.noop();
}
if (result.manufacturer === '' && result.model === 'Computer' && result.version === '') {
// Check Raspberry Pi
- fs.readFile('/proc/cpuinfo', function (error, stdout) {
+ fs.readFile('/proc/cpuinfo', (error, stdout) => {
if (!error) {
let lines = stdout.toString().split('\n');
result.model = util.getValue(lines, 'hardware', ':', true).toUpperCase();
@@ -219,23 +236,25 @@ function system(callback) {
};
}
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
} else {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
});
}
if (_darwin) {
- exec('ioreg -c IOPlatformExpertDevice -d 2', function (error, stdout) {
+ exec('ioreg -c IOPlatformExpertDevice -d 2', (error, stdout) => {
if (!error) {
- let lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
+ const lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
const model = util.getAppleModel(util.getValue(lines, 'model', '=', true));
- // const modelParts = util.splitByNumber(model);
- // const version = util.getValue(lines, 'version', '=', true);
result.manufacturer = util.getValue(lines, 'manufacturer', '=', true);
result.model = model.key;
result.type = macOsChassisType(model.version);
@@ -244,19 +263,23 @@ function system(callback) {
result.uuid = util.getValue(lines, 'ioplatformuuid', '=', true).toLowerCase();
result.sku = util.getValue(lines, 'board-id', '=', true) || util.getValue(lines, 'target-sub-type', '=', true);
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
}
if (_sunos) {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
if (_windows) {
try {
util.powerShell('Get-CimInstance Win32_ComputerSystemProduct | select Name,Vendor,Version,IdentifyingNumber,UUID | fl').then((stdout, error) => {
if (!error) {
- let lines = stdout.split('\r\n');
+ const lines = stdout.split('\r\n');
result.manufacturer = util.getValue(lines, 'vendor', ':');
result.model = util.getValue(lines, 'name', ':');
result.version = util.getValue(lines, 'version', ':');
@@ -264,33 +287,68 @@ function system(callback) {
result.uuid = util.getValue(lines, 'uuid', ':').toLowerCase();
// detect virtual (1)
const model = result.model.toLowerCase();
- if (model === 'virtualbox' || model === 'kvm' || model === 'virtual machine' || model === 'bochs' || model.startsWith('vmware') || model.startsWith('qemu') || model.startsWith('parallels')) {
+ if (
+ model === 'virtualbox' ||
+ model === 'kvm' ||
+ model === 'virtual machine' ||
+ model === 'bochs' ||
+ model.startsWith('vmware') ||
+ model.startsWith('qemu') ||
+ model.startsWith('parallels')
+ ) {
result.virtual = true;
- if (model.startsWith('virtualbox')) { result.virtualHost = 'VirtualBox'; }
- if (model.startsWith('vmware')) { result.virtualHost = 'VMware'; }
- if (model.startsWith('kvm')) { result.virtualHost = 'KVM'; }
- if (model.startsWith('bochs')) { result.virtualHost = 'bochs'; }
- if (model.startsWith('qemu')) { result.virtualHost = 'KVM'; }
- if (model.startsWith('parallels')) { result.virtualHost = 'Parallels'; }
+ if (model.startsWith('virtualbox')) {
+ result.virtualHost = 'VirtualBox';
+ }
+ if (model.startsWith('vmware')) {
+ result.virtualHost = 'VMware';
+ }
+ if (model.startsWith('kvm')) {
+ result.virtualHost = 'KVM';
+ }
+ if (model.startsWith('bochs')) {
+ result.virtualHost = 'bochs';
+ }
+ if (model.startsWith('qemu')) {
+ result.virtualHost = 'KVM';
+ }
+ if (model.startsWith('parallels')) {
+ result.virtualHost = 'Parallels';
+ }
}
const manufacturer = result.manufacturer.toLowerCase();
if (manufacturer.startsWith('vmware') || manufacturer.startsWith('qemu') || manufacturer === 'xen' || manufacturer.startsWith('parallels')) {
result.virtual = true;
- if (manufacturer.startsWith('vmware')) { result.virtualHost = 'VMware'; }
- if (manufacturer.startsWith('xen')) { result.virtualHost = 'Xen'; }
- if (manufacturer.startsWith('qemu')) { result.virtualHost = 'KVM'; }
- if (manufacturer.startsWith('parallels')) { result.virtualHost = 'Parallels'; }
+ if (manufacturer.startsWith('vmware')) {
+ result.virtualHost = 'VMware';
+ }
+ if (manufacturer.startsWith('xen')) {
+ result.virtualHost = 'Xen';
+ }
+ if (manufacturer.startsWith('qemu')) {
+ result.virtualHost = 'KVM';
+ }
+ if (manufacturer.startsWith('parallels')) {
+ result.virtualHost = 'Parallels';
+ }
}
util.powerShell('Get-CimInstance MS_Systeminformation -Namespace "root/wmi" | select systemsku | fl ').then((stdout, error) => {
if (!error) {
- let lines = stdout.split('\r\n');
+ const lines = stdout.split('\r\n');
result.sku = util.getValue(lines, 'systemsku', ':');
}
if (!result.virtual) {
util.powerShell('Get-CimInstance Win32_bios | select Version, SerialNumber, SMBIOSBIOSVersion').then((stdout, error) => {
if (!error) {
let lines = stdout.toString();
- if (lines.indexOf('VRTUAL') >= 0 || lines.indexOf('A M I ') >= 0 || lines.indexOf('VirtualBox') >= 0 || lines.indexOf('VMWare') >= 0 || lines.indexOf('Xen') >= 0 || lines.indexOf('Parallels') >= 0) {
+ if (
+ lines.indexOf('VRTUAL') >= 0 ||
+ lines.indexOf('A M I ') >= 0 ||
+ lines.indexOf('VirtualBox') >= 0 ||
+ lines.indexOf('VMWare') >= 0 ||
+ lines.indexOf('Xen') >= 0 ||
+ lines.indexOf('Parallels') >= 0
+ ) {
result.virtual = true;
if (lines.indexOf('VirtualBox') >= 0 && !result.virtualHost) {
result.virtualHost = 'VirtualBox';
@@ -311,25 +369,35 @@ function system(callback) {
result.virtualHost = 'Parallels';
}
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
} else {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
});
} else {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
});
} else {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
});
- } catch (e) {
- if (callback) { callback(result); }
+ } catch {
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
}
@@ -347,15 +415,13 @@ function cleanDefaults(s) {
return '';
}
function bios(callback) {
-
return new Promise((resolve) => {
process.nextTick(() => {
-
let result = {
vendor: '',
version: '',
releaseDate: '',
- revision: '',
+ revision: ''
};
let cmd = '';
if (_linux || _freebsd || _openbsd || _netbsd) {
@@ -364,7 +430,7 @@ function bios(callback) {
} else {
cmd = 'export LC_ALL=C; dmidecode -t bios 2>/dev/null; unset LC_ALL';
}
- exec(cmd, function (error, stdout) {
+ exec(cmd, (error, stdout) => {
let lines = stdout.toString().split('\n');
result.vendor = util.getValue(lines, 'Vendor');
result.version = util.getValue(lines, 'Version');
@@ -378,7 +444,7 @@ function bios(callback) {
}
if (lines.length && stdout.toString().indexOf('Characteristics:') >= 0) {
const features = [];
- lines.forEach(line => {
+ lines.forEach((line) => {
if (line.indexOf(' is supported') >= 0) {
const feature = line.split(' is supported')[0].trim();
features.push(feature);
@@ -399,62 +465,75 @@ function bios(callback) {
} catch (e) {
util.noop();
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
}
if (_darwin) {
result.vendor = 'Apple Inc.';
- exec(
- 'system_profiler SPHardwareDataType -json', function (error, stdout) {
- try {
- const hardwareData = JSON.parse(stdout.toString());
- if (hardwareData && hardwareData.SPHardwareDataType && hardwareData.SPHardwareDataType.length) {
- let bootRomVersion = hardwareData.SPHardwareDataType[0].boot_rom_version;
- bootRomVersion = bootRomVersion ? bootRomVersion.split('(')[0].trim() : null;
- result.version = bootRomVersion;
- }
- } catch (e) {
- util.noop();
+ exec('system_profiler SPHardwareDataType -json', (error, stdout) => {
+ try {
+ const hardwareData = JSON.parse(stdout.toString());
+ if (hardwareData && hardwareData.SPHardwareDataType && hardwareData.SPHardwareDataType.length) {
+ let bootRomVersion = hardwareData.SPHardwareDataType[0].boot_rom_version;
+ bootRomVersion = bootRomVersion ? bootRomVersion.split('(')[0].trim() : null;
+ result.version = bootRomVersion;
}
- if (callback) { callback(result); }
- resolve(result);
- });
+ } catch (e) {
+ util.noop();
+ }
+ if (callback) {
+ callback(result);
+ }
+ resolve(result);
+ });
}
if (_sunos) {
result.vendor = 'Sun Microsystems';
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
if (_windows) {
try {
- util.powerShell('Get-CimInstance Win32_bios | select Description,Version,Manufacturer,@{n="ReleaseDate";e={$_.ReleaseDate.ToString("yyyy-MM-dd")}},BuildNumber,SerialNumber,SMBIOSBIOSVersion | fl').then((stdout, error) => {
- if (!error) {
- let lines = stdout.toString().split('\r\n');
- const description = util.getValue(lines, 'description', ':');
- const version = util.getValue(lines, 'SMBIOSBIOSVersion', ':');
- if (description.indexOf(' Version ') !== -1) {
- // ... Phoenix ROM BIOS PLUS Version 1.10 A04
- result.vendor = description.split(' Version ')[0].trim();
- result.version = description.split(' Version ')[1].trim();
- } else if (description.indexOf(' Ver: ') !== -1) {
- // ... BIOS Date: 06/27/16 17:50:16 Ver: 1.4.5
- result.vendor = util.getValue(lines, 'manufacturer', ':');
- result.version = description.split(' Ver: ')[1].trim();
- } else {
- result.vendor = util.getValue(lines, 'manufacturer', ':');
- result.version = version || util.getValue(lines, 'version', ':');
+ util
+ .powerShell(
+ 'Get-CimInstance Win32_bios | select Description,Version,Manufacturer,@{n="ReleaseDate";e={$_.ReleaseDate.ToString("yyyy-MM-dd")}},BuildNumber,SerialNumber,SMBIOSBIOSVersion | fl'
+ )
+ .then((stdout, error) => {
+ if (!error) {
+ let lines = stdout.toString().split('\r\n');
+ const description = util.getValue(lines, 'description', ':');
+ const version = util.getValue(lines, 'SMBIOSBIOSVersion', ':');
+ if (description.indexOf(' Version ') !== -1) {
+ // ... Phoenix ROM BIOS PLUS Version 1.10 A04
+ result.vendor = description.split(' Version ')[0].trim();
+ result.version = description.split(' Version ')[1].trim();
+ } else if (description.indexOf(' Ver: ') !== -1) {
+ // ... BIOS Date: 06/27/16 17:50:16 Ver: 1.4.5
+ result.vendor = util.getValue(lines, 'manufacturer', ':');
+ result.version = description.split(' Ver: ')[1].trim();
+ } else {
+ result.vendor = util.getValue(lines, 'manufacturer', ':');
+ result.version = version || util.getValue(lines, 'version', ':');
+ }
+ result.releaseDate = util.getValue(lines, 'releasedate', ':');
+ result.revision = util.getValue(lines, 'buildnumber', ':');
+ result.serial = cleanDefaults(util.getValue(lines, 'serialnumber', ':'));
}
- result.releaseDate = util.getValue(lines, 'releasedate', ':');
- result.revision = util.getValue(lines, 'buildnumber', ':');
- result.serial = cleanDefaults(util.getValue(lines, 'serialnumber', ':'));
- }
- if (callback) { callback(result); }
- resolve(result);
- });
+ if (callback) {
+ callback(result);
+ }
+ resolve(result);
+ });
} catch (e) {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
}
@@ -465,11 +544,9 @@ function bios(callback) {
exports.bios = bios;
function baseboard(callback) {
-
return new Promise((resolve) => {
process.nextTick(() => {
-
- let result = {
+ const result = {
manufacturer: '',
model: '',
version: '',
@@ -489,9 +566,7 @@ function baseboard(callback) {
const workload = [];
workload.push(execPromise(cmd));
workload.push(execPromise('export LC_ALL=C; dmidecode -t memory 2>/dev/null'));
- util.promiseAll(
- workload
- ).then((data) => {
+ util.promiseAll(workload).then((data) => {
let lines = data.results[0] ? data.results[0].toString().split('\n') : [''];
result.manufacturer = cleanDefaults(util.getValue(lines, 'Manufacturer'));
result.model = cleanDefaults(util.getValue(lines, 'Product Name'));
@@ -511,7 +586,7 @@ function baseboard(callback) {
result.version = cleanDefaults(!result.version ? util.getValue(lines, 'board_version') : result.version);
result.serial = cleanDefaults(!result.serial ? util.getValue(lines, 'board_serial') : result.serial);
result.assetTag = cleanDefaults(!result.assetTag ? util.getValue(lines, 'board_asset_tag') : result.assetTag);
- } catch (e) {
+ } catch {
util.noop();
}
@@ -531,7 +606,9 @@ function baseboard(callback) {
result.memSlots = 0;
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
}
@@ -539,10 +616,8 @@ function baseboard(callback) {
const workload = [];
workload.push(execPromise('ioreg -c IOPlatformExpertDevice -d 2'));
workload.push(execPromise('system_profiler SPMemoryDataType'));
- util.promiseAll(
- workload
- ).then((data) => {
- let lines = data.results[0] ? data.results[0].toString().replace(/[<>"]/g, '').split('\n') : [''];
+ util.promiseAll(workload).then((data) => {
+ const lines = data.results[0] ? data.results[0].toString().replace(/[<>"]/g, '').split('\n') : [''];
result.manufacturer = util.getValue(lines, 'manufacturer', '=', true);
result.model = util.getValue(lines, 'model', '=', true);
result.version = util.getValue(lines, 'version', '=', true);
@@ -562,12 +637,16 @@ function baseboard(callback) {
result.memMax = os.totalmem();
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
}
if (_sunos) {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
if (_windows) {
@@ -577,9 +656,7 @@ function baseboard(callback) {
const maxCapacityAttribute = win10plus ? 'MaxCapacityEx' : 'MaxCapacity';
workload.push(util.powerShell('Get-CimInstance Win32_baseboard | select Model,Manufacturer,Product,Version,SerialNumber,PartNumber,SKU | fl'));
workload.push(util.powerShell(`Get-CimInstance Win32_physicalmemoryarray | select ${maxCapacityAttribute}, MemoryDevices | fl`));
- util.promiseAll(
- workload
- ).then((data) => {
+ util.promiseAll(workload).then((data) => {
let lines = data.results[0] ? data.results[0].toString().split('\r\n') : [''];
result.manufacturer = cleanDefaults(util.getValue(lines, 'manufacturer', ':'));
@@ -599,11 +676,15 @@ function baseboard(callback) {
result.memMax = util.toInt(util.getValue(lines, maxCapacityAttribute, ':')) * (win10plus ? 1024 : 1) || null;
result.memSlots = util.toInt(util.getValue(lines, 'MemoryDevices', ':')) || null;
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
- } catch (e) {
- if (callback) { callback(result); }
+ } catch {
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
}
@@ -615,18 +696,33 @@ exports.baseboard = baseboard;
function macOsChassisType(model) {
model = model.toLowerCase();
- if (model.indexOf('macbookair') >= 0 || model.indexOf('macbook air') >= 0) { return 'Notebook'; }
- if (model.indexOf('macbookpro') >= 0 || model.indexOf('macbook pro') >= 0) { return 'Notebook'; }
- if (model.indexOf('macbook') >= 0) { return 'Notebook'; }
- if (model.indexOf('macmini') >= 0 || model.indexOf('mac mini') >= 0) { return 'Desktop'; }
- if (model.indexOf('imac') >= 0) { return 'Desktop'; }
- if (model.indexOf('macstudio') >= 0 || model.indexOf('mac studio') >= 0) { return 'Desktop'; }
- if (model.indexOf('macpro') >= 0 || model.indexOf('mac pro') >= 0) { return 'Tower'; }
+ if (model.indexOf('macbookair') >= 0 || model.indexOf('macbook air') >= 0) {
+ return 'Notebook';
+ }
+ if (model.indexOf('macbookpro') >= 0 || model.indexOf('macbook pro') >= 0) {
+ return 'Notebook';
+ }
+ if (model.indexOf('macbook') >= 0) {
+ return 'Notebook';
+ }
+ if (model.indexOf('macmini') >= 0 || model.indexOf('mac mini') >= 0) {
+ return 'Desktop';
+ }
+ if (model.indexOf('imac') >= 0) {
+ return 'Desktop';
+ }
+ if (model.indexOf('macstudio') >= 0 || model.indexOf('mac studio') >= 0) {
+ return 'Desktop';
+ }
+ if (model.indexOf('macpro') >= 0 || model.indexOf('mac pro') >= 0) {
+ return 'Tower';
+ }
return 'Other';
}
function chassis(callback) {
- const chassisTypes = ['Other',
+ const chassisTypes = [
+ 'Other',
'Unknown',
'Desktop',
'Low Profile Desktop',
@@ -661,12 +757,11 @@ function chassis(callback) {
'IoT Gateway ',
'Embedded PC',
'Mini PC',
- 'Stick PC',
+ 'Stick PC'
];
return new Promise((resolve) => {
process.nextTick(() => {
-
let result = {
manufacturer: '',
model: '',
@@ -674,7 +769,7 @@ function chassis(callback) {
version: '',
serial: '-',
assetTag: '-',
- sku: '',
+ sku: ''
};
if (_linux || _freebsd || _openbsd || _netbsd) {
const cmd = `echo -n "chassis_asset_tag: "; cat /sys/devices/virtual/dmi/id/chassis_asset_tag 2>/dev/null; echo;
@@ -682,26 +777,26 @@ function chassis(callback) {
echo -n "chassis_type: "; cat /sys/devices/virtual/dmi/id/chassis_type 2>/dev/null; echo;
echo -n "chassis_vendor: "; cat /sys/devices/virtual/dmi/id/chassis_vendor 2>/dev/null; echo;
echo -n "chassis_version: "; cat /sys/devices/virtual/dmi/id/chassis_version 2>/dev/null; echo;`;
- exec(cmd, function (error, stdout) {
+ exec(cmd, (error, stdout) => {
let lines = stdout.toString().split('\n');
result.manufacturer = cleanDefaults(util.getValue(lines, 'chassis_vendor'));
const ctype = parseInt(util.getValue(lines, 'chassis_type').replace(/\D/g, ''));
- result.type = cleanDefaults((ctype && !isNaN(ctype) && ctype < chassisTypes.length) ? chassisTypes[ctype - 1] : '');
+ result.type = cleanDefaults(ctype && !isNaN(ctype) && ctype < chassisTypes.length ? chassisTypes[ctype - 1] : '');
result.version = cleanDefaults(util.getValue(lines, 'chassis_version'));
result.serial = cleanDefaults(util.getValue(lines, 'chassis_serial'));
result.assetTag = cleanDefaults(util.getValue(lines, 'chassis_asset_tag'));
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
}
if (_darwin) {
- exec('ioreg -c IOPlatformExpertDevice -d 2', function (error, stdout) {
+ exec('ioreg -c IOPlatformExpertDevice -d 2', (error, stdout) => {
if (!error) {
- let lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
+ const lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
const model = util.getAppleModel(util.getValue(lines, 'model', '=', true));
- // const modelParts = util.splitByNumber(model);
- // const version = util.getValue(lines, 'version', '=', true);
result.manufacturer = util.getValue(lines, 'manufacturer', '=', true);
result.model = model.key;
result.type = macOsChassisType(model.model);
@@ -711,12 +806,16 @@ function chassis(callback) {
result.sku = util.getValue(lines, 'target-sub-type', '=', true);
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
}
if (_sunos) {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
if (_windows) {
@@ -728,7 +827,7 @@ function chassis(callback) {
result.manufacturer = cleanDefaults(util.getValue(lines, 'manufacturer', ':'));
result.model = cleanDefaults(util.getValue(lines, 'model', ':'));
const ctype = parseInt(util.getValue(lines, 'ChassisTypes', ':').replace(/\D/g, ''));
- result.type = (ctype && !isNaN(ctype) && ctype < chassisTypes.length) ? chassisTypes[ctype - 1] : '';
+ result.type = ctype && !isNaN(ctype) && ctype < chassisTypes.length ? chassisTypes[ctype - 1] : '';
result.version = cleanDefaults(util.getValue(lines, 'version', ':'));
result.serial = cleanDefaults(util.getValue(lines, 'serialnumber', ':'));
result.assetTag = cleanDefaults(util.getValue(lines, 'partnumber', ':'));
@@ -738,11 +837,15 @@ function chassis(callback) {
result.sku = cleanDefaults(util.getValue(lines, 'sku', ':'));
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
- } catch (e) {
- if (callback) { callback(result); }
+ } catch {
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
}
diff --git a/lib/util.js b/lib/util.js
index 9c4a840..f8844c2 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -101,11 +101,11 @@ function isFunction(functionToCheck) {
}
function unique(obj) {
- let uniques = [];
- let stringify = {};
+ const uniques = [];
+ const stringify = {};
for (let i = 0; i < obj.length; i++) {
let keys = Object.keys(obj[i]);
- keys.sort(function (a, b) {
+ keys.sort((a, b) => {
return a - b;
});
let str = '';
@@ -122,10 +122,10 @@ function unique(obj) {
}
function sortByKey(array, keys) {
- return array.sort(function (a, b) {
+ return array.sort((a, b) => {
let x = '';
let y = '';
- keys.forEach(function (key) {
+ keys.forEach((key) => {
x = x + a[key];
y = y + b[key];
});
@@ -159,6 +159,7 @@ function getValue(lines, property, separator, trimmed, lineMatch) {
return true;
}
}
+ return false;
});
return result;
}
@@ -195,8 +196,8 @@ function parseTime(t, pmDesignator) {
t = t.toUpperCase();
let hour = 0;
let min = 0;
- let splitter = detectSplit(t);
- let parts = t.split(splitter);
+ const splitter = detectSplit(t);
+ const parts = t.split(splitter);
if (parts.length >= 2) {
if (parts[2]) {
parts[1] += parts[2];
@@ -222,8 +223,8 @@ function parseDateTime(dt, culture) {
time: ''
};
culture = culture || {};
- let dateFormat = (culture.dateFormat || '').toLowerCase();
- let pmDesignator = culture.pmDesignator || '';
+ const dateFormat = (culture.dateFormat || '').toLowerCase();
+ const pmDesignator = culture.pmDesignator || '';
const parts = dt.split(' ');
if (parts[0]) {
@@ -283,7 +284,7 @@ function parseDateTime(dt, culture) {
}
if (parts[1]) {
parts.shift();
- let time = parts.join(' ');
+ const time = parts.join(' ');
result.time = parseTime(time, pmDesignator);
}
return result;
@@ -294,7 +295,7 @@ function parseHead(head, rights) {
let count = 1;
let from = 0;
let to = 0;
- let result = [];
+ const result = [];
for (let i = 0; i < head.length; i++) {
if (count <= rights) {
if (/\s/.test(head[i]) && !space) {
@@ -441,20 +442,20 @@ function powerShellStart() {
});
if (_psChild && _psChild.pid) {
_psPersistent = true;
- _psChild.stdout.on('data', function (data) {
+ _psChild.stdout.on('data', (data) => {
_psResult = _psResult + data.toString('utf8');
if (data.indexOf(_psCmdSeperator) >= 0) {
powerShellProceedResults(_psResult);
_psResult = '';
}
});
- _psChild.stderr.on('data', function () {
+ _psChild.stderr.on('data', () => {
powerShellProceedResults(_psResult + _psError);
});
- _psChild.on('error', function () {
+ _psChild.on('error', () => {
powerShellProceedResults(_psResult + _psError);
});
- _psChild.on('close', function () {
+ _psChild.on('close', () => {
if (_psChild) {
_psChild.kill();
}
@@ -521,24 +522,24 @@ function powerShell(cmd) {
});
if (child && !child.pid) {
- child.on('error', function () {
+ child.on('error', () => {
resolve(result);
});
}
if (child && child.pid) {
- child.stdout.on('data', function (data) {
+ child.stdout.on('data', (data) => {
result = result + data.toString('utf8');
});
- child.stderr.on('data', function () {
+ child.stderr.on('data', () => {
child.kill();
resolve(result);
});
- child.on('close', function () {
+ child.on('close', () => {
child.kill();
resolve(result);
});
- child.on('error', function () {
+ child.on('error', () => {
child.kill();
resolve(result);
});
@@ -571,26 +572,26 @@ function execSafe(cmd, args, options) {
const child = spawn(cmd, args, options);
if (child && !child.pid) {
- child.on('error', function () {
+ child.on('error', () => {
resolve(result);
});
}
if (child && child.pid) {
- child.stdout.on('data', function (data) {
+ child.stdout.on('data', (data) => {
result += data.toString();
});
- child.on('close', function () {
+ child.on('close', () => {
child.kill();
resolve(result);
});
- child.on('error', function () {
+ child.on('error', () => {
child.kill();
resolve(result);
});
} else {
resolve(result);
}
- } catch (e) {
+ } catch {
resolve(result);
}
});
@@ -605,7 +606,7 @@ function getCodepage() {
const lines = stdout.toString().split('\r\n');
const parts = lines[0].split(':');
codepage = parts.length > 1 ? parts[1].replace('.', '').trim() : '';
- } catch (err) {
+ } catch {
codepage = '437';
}
}
@@ -621,7 +622,7 @@ function getCodepage() {
if (!codepage) {
codepage = 'UTF-8';
}
- } catch (err) {
+ } catch {
codepage = 'UTF-8';
}
}
@@ -642,7 +643,7 @@ function smartMonToolsInstalled() {
} else {
_smartMonToolsInstalled = false;
}
- } catch (e) {
+ } catch {
_smartMonToolsInstalled = false;
}
}
@@ -650,7 +651,7 @@ function smartMonToolsInstalled() {
try {
const pathArray = execSync('which smartctl 2>/dev/null', execOptsLinux).toString().split('\r\n');
_smartMonToolsInstalled = pathArray.length > 0;
- } catch (e) {
+ } catch {
util.noop();
}
}
@@ -669,7 +670,7 @@ function isRaspberry(cpuinfo) {
try {
cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
_rpi_cpuinfo = cpuinfo;
- } catch (e) {
+ } catch {
return false;
}
}
@@ -683,7 +684,7 @@ function isRaspbian() {
let osrelease = [];
try {
osrelease = fs.readFileSync('/etc/os-release', { encoding: 'utf8' }).toString().split('\n');
- } catch (e) {
+ } catch {
return false;
}
const id = getValue(osrelease, 'id', '=');
@@ -696,7 +697,7 @@ function execWin(cmd, opts, callback) {
opts = execOptsWin;
}
let newCmd = 'chcp 65001 > nul && cmd /C ' + cmd + ' && chcp ' + codepage + ' > nul';
- exec(newCmd, opts, function (error, stdout) {
+ exec(newCmd, opts, (error, stdout) => {
callback(error, stdout);
});
}
@@ -849,7 +850,7 @@ function isPrototypePolluted() {
const s1 = st[i];
try {
s1.__proto__.toLowerCase = stringToLower;
- } catch (e) {
+ } catch {
Object.setPrototypeOf(st, stringObj);
}
const s2 = stl ? stl[i] : '';
@@ -878,14 +879,14 @@ function getFilesInPath(source) {
function getDirectories(source) {
return readdirSync(source)
- .map(function (name) {
+ .map((name) => {
return join(source, name);
})
.filter(isDirectory);
}
function getFiles(source) {
return readdirSync(source)
- .map(function (name) {
+ .map((name) => {
return join(source, name);
})
.filter(isFile);
@@ -893,16 +894,16 @@ function getFilesInPath(source) {
function getFilesRecursively(source) {
try {
- let dirs = getDirectories(source);
- let files = dirs
- .map(function (dir) {
+ const dirs = getDirectories(source);
+ const files = dirs
+ .map((dir) => {
return getFilesRecursively(dir);
})
- .reduce(function (a, b) {
+ .reduce((a, b) => {
return a.concat(b);
}, []);
return files.concat(getFiles(source));
- } catch (e) {
+ } catch {
return [];
}
}
@@ -1159,8 +1160,8 @@ function promiseAll(promises) {
const results = [];
// Execute all wrapped Promises
- return Promise.all(resolvingPromises).then(function (items) {
- items.forEach(function (payload) {
+ return Promise.all(resolvingPromises).then((items) => {
+ items.forEach((payload) => {
if (payload[1]) {
errors.push(payload[1]);
results.push(null);
@@ -1178,10 +1179,10 @@ function promiseAll(promises) {
}
function promisify(nodeStyleFunction) {
- return function () {
+ return () => {
const args = Array.prototype.slice.call(arguments);
- return new Promise(function (resolve, reject) {
- args.push(function (err, data) {
+ return new Promise((resolve, reject) => {
+ args.push((err, data) => {
if (err) {
reject(err);
} else {
@@ -1194,10 +1195,10 @@ function promisify(nodeStyleFunction) {
}
function promisifySave(nodeStyleFunction) {
- return function () {
+ return () => {
const args = Array.prototype.slice.call(arguments);
- return new Promise(function (resolve) {
- args.push(function (err, data) {
+ return new Promise((resolve) => {
+ args.push((err, data) => {
resolve(data);
});
nodeStyleFunction.apply(null, args);
@@ -1210,7 +1211,7 @@ function linuxVersion() {
if (_linux) {
try {
result = execSync('uname -v', execOptsLinux).toString();
- } catch (e) {
+ } catch {
result = '';
}
}
@@ -2617,7 +2618,7 @@ function checkWebsite(url, timeout = 5000) {
const t = Date.now();
return new Promise((resolve) => {
const request = http
- .get(url, function (res) {
+ .get(url, (res) => {
res.on('data', () => {});
res.on('end', () => {
resolve({
@@ -2628,7 +2629,7 @@ function checkWebsite(url, timeout = 5000) {
});
});
})
- .on('error', function (e) {
+ .on('error', (e) => {
resolve({
url,
statusCode: 404,
diff --git a/lib/wifi.js b/lib/wifi.js
index 4b62185..0c4c093 100644
--- a/lib/wifi.js
+++ b/lib/wifi.js
@@ -20,15 +20,19 @@ const util = require('./util');
let _platform = process.platform;
-const _linux = (_platform === 'linux' || _platform === 'android');
-const _darwin = (_platform === 'darwin');
-const _windows = (_platform === 'win32');
+const _linux = _platform === 'linux' || _platform === 'android';
+const _darwin = _platform === 'darwin';
+const _windows = _platform === 'win32';
function wifiDBFromQuality(quality) {
const qual = parseFloat(quality);
- if (qual < 0) { return 0; }
- if (qual >= 100) { return -50; }
- return (qual / 2 - 100);
+ if (qual < 0) {
+ return 0;
+ }
+ if (qual >= 100) {
+ return -50;
+ }
+ return qual / 2 - 100;
}
function wifiQualityFromDB(db) {
@@ -120,7 +124,9 @@ function wifiChannelFromFrequencs(frequency) {
let channel = 0;
for (let key in _wifi_frequencies) {
if ({}.hasOwnProperty.call(_wifi_frequencies, key)) {
- if (_wifi_frequencies[key] === frequency) { channel = util.toInt(key); }
+ if (_wifi_frequencies[key] === frequency) {
+ channel = util.toInt(key);
+ }
}
}
return channel;
@@ -130,10 +136,14 @@ function ifaceListLinux() {
const result = [];
const cmd = 'iw dev 2>/dev/null';
try {
- const all = execSync(cmd, util.execOptsLinux).toString().split('\n').map(line => line.trim()).join('\n');
+ const all = execSync(cmd, util.execOptsLinux)
+ .toString()
+ .split('\n')
+ .map((line) => line.trim())
+ .join('\n');
const parts = all.split('\nInterface ');
parts.shift();
- parts.forEach(ifaceDetails => {
+ parts.forEach((ifaceDetails) => {
const lines = ifaceDetails.split('\n');
const iface = lines[0];
const id = util.toInt(util.getValue(lines, 'ifindex', ' '));
@@ -152,7 +162,7 @@ function ifaceListLinux() {
const all = execSync('nmcli -t -f general,wifi-properties,wired-properties,interface-flags,capabilities,nsp device show 2>/dev/null', util.execOptsLinux).toString();
const parts = all.split('\n\n');
let i = 1;
- parts.forEach(ifaceDetails => {
+ parts.forEach((ifaceDetails) => {
const lines = ifaceDetails.split('\n');
const iface = util.getValue(lines, 'GENERAL.DEVICE');
const type = util.getValue(lines, 'GENERAL.TYPE');
@@ -239,7 +249,7 @@ function getWifiNetworkListNmi() {
const stdout = execSync(cmd, util.execOptsLinux);
const parts = stdout.toString().split('ACTIVE:');
parts.shift();
- parts.forEach(part => {
+ parts.forEach((part) => {
part = 'ACTIVE:' + part;
const lines = part.split(os.EOL);
const channel = util.getValue(lines, 'CHAN');
@@ -271,13 +281,15 @@ function getWifiNetworkListIw(iface) {
const result = [];
try {
let iwlistParts = execSync(`export LC_ALL=C; iwlist ${iface} scan 2>&1; unset LC_ALL`, util.execOptsLinux).toString().split(' Cell ');
- if (iwlistParts[0].indexOf('resource busy') >= 0) { return -1; }
+ if (iwlistParts[0].indexOf('resource busy') >= 0) {
+ return -1;
+ }
if (iwlistParts.length > 1) {
iwlistParts.shift();
- iwlistParts.forEach(element => {
+ iwlistParts.forEach((element) => {
const lines = element.split('\n');
const channel = util.getValue(lines, 'channel', ':', true);
- const address = (lines && lines.length && lines[0].indexOf('Address:') >= 0 ? lines[0].split('Address:')[1].trim().toLowerCase() : '');
+ const address = lines && lines.length && lines[0].indexOf('Address:') >= 0 ? lines[0].split('Address:')[1].trim().toLowerCase() : '';
const mode = util.getValue(lines, 'mode', ':', true);
const frequency = util.getValue(lines, 'frequency', ':', true);
const qualityString = util.getValue(lines, 'Quality', '=', true);
@@ -290,11 +302,15 @@ function getWifiNetworkListIw(iface) {
const isWpa = element.indexOf(' WPA ') >= 0;
const isWpa2 = element.indexOf('WPA2 ') >= 0;
const security = [];
- if (isWpa) { security.push('WPA'); }
- if (isWpa2) { security.push('WPA2'); }
+ if (isWpa) {
+ security.push('WPA');
+ }
+ if (isWpa2) {
+ security.push('WPA2');
+ }
const wpaFlags = [];
let wpaFlag = '';
- lines.forEach(function (line) {
+ lines.forEach((line) => {
const l = line.trim().toLowerCase();
if (l.indexOf('group cipher') >= 0) {
if (wpaFlag) {
@@ -308,16 +324,23 @@ function getWifiNetworkListIw(iface) {
if (l.indexOf('pairwise cipher') >= 0) {
const parts = l.split(':');
if (parts.length > 1) {
- if (parts[1].indexOf('tkip')) { wpaFlag = (wpaFlag ? 'TKIP/' + wpaFlag : 'TKIP'); }
- else if (parts[1].indexOf('ccmp')) { wpaFlag = (wpaFlag ? 'CCMP/' + wpaFlag : 'CCMP'); }
- else if (parts[1].indexOf('proprietary')) { wpaFlag = (wpaFlag ? 'PROP/' + wpaFlag : 'PROP'); }
+ if (parts[1].indexOf('tkip')) {
+ wpaFlag = wpaFlag ? 'TKIP/' + wpaFlag : 'TKIP';
+ } else if (parts[1].indexOf('ccmp')) {
+ wpaFlag = wpaFlag ? 'CCMP/' + wpaFlag : 'CCMP';
+ } else if (parts[1].indexOf('proprietary')) {
+ wpaFlag = wpaFlag ? 'PROP/' + wpaFlag : 'PROP';
+ }
}
}
if (l.indexOf('authentication suites') >= 0) {
const parts = l.split(':');
if (parts.length > 1) {
- if (parts[1].indexOf('802.1x')) { wpaFlag = (wpaFlag ? '802.1x/' + wpaFlag : '802.1x'); }
- else if (parts[1].indexOf('psk')) { wpaFlag = (wpaFlag ? 'PSK/' + wpaFlag : 'PSK'); }
+ if (parts[1].indexOf('802.1x')) {
+ wpaFlag = wpaFlag ? '802.1x/' + wpaFlag : '802.1x';
+ } else if (parts[1].indexOf('psk')) {
+ wpaFlag = wpaFlag ? 'PSK/' + wpaFlag : 'PSK';
+ }
}
}
});
@@ -345,66 +368,13 @@ function getWifiNetworkListIw(iface) {
}
}
-function parseWifiDarwinXX(wifiObj) {
- const result = [];
- if (wifiObj) {
- wifiObj.forEach(function (wifiItem) {
- const signalLevel = wifiItem.RSSI;
- let security = [];
- let wpaFlags = [];
- let ssid = wifiItem.SSID_STR || '';
- if (wifiItem.WPA_IE) {
- security.push('WPA');
- if (wifiItem.WPA_IE.IE_KEY_WPA_UCIPHERS) {
- wifiItem.WPA_IE.IE_KEY_WPA_UCIPHERS.forEach(function (ciphers) {
- if (ciphers === 0 && wpaFlags.indexOf('unknown/TKIP') === -1) { wpaFlags.push('unknown/TKIP'); }
- if (ciphers === 2 && wpaFlags.indexOf('PSK/TKIP') === -1) { wpaFlags.push('PSK/TKIP'); }
- if (ciphers === 4 && wpaFlags.indexOf('PSK/AES') === -1) { wpaFlags.push('PSK/AES'); }
- });
- }
- }
- if (wifiItem.RSN_IE) {
- security.push('WPA2');
- if (wifiItem.RSN_IE.IE_KEY_RSN_UCIPHERS) {
- wifiItem.RSN_IE.IE_KEY_RSN_UCIPHERS.forEach(function (ciphers) {
- if (ciphers === 0 && wpaFlags.indexOf('unknown/TKIP') === -1) { wpaFlags.push('unknown/TKIP'); }
- if (ciphers === 2 && wpaFlags.indexOf('TKIP/TKIP') === -1) { wpaFlags.push('TKIP/TKIP'); }
- if (ciphers === 4 && wpaFlags.indexOf('PSK/AES') === -1) { wpaFlags.push('PSK/AES'); }
- });
- }
- }
- if (wifiItem.SSID && ssid === '') {
- try {
- ssid = Buffer.from(wifiItem.SSID, 'base64').toString('utf8');
- } catch (err) {
- util.noop();
- }
- }
- result.push({
- ssid,
- bssid: wifiItem.BSSID || '',
- mode: '',
- channel: wifiItem.CHANNEL,
- frequency: wifiFrequencyFromChannel(wifiItem.CHANNEL),
- signalLevel: signalLevel ? parseInt(signalLevel, 10) : null,
- quality: wifiQualityFromDB(signalLevel),
- security,
- wpaFlags,
- rsnFlags: []
- });
- });
- }
- return result;
-}
-
function parseWifiDarwin(wifiStr) {
const result = [];
try {
let wifiObj = JSON.parse(wifiStr);
wifiObj = wifiObj.SPAirPortDataType[0].spairport_airport_interfaces[0].spairport_airport_other_local_wireless_networks;
- wifiObj.forEach(function (wifiItem) {
-
- let security = [];
+ wifiObj.forEach((wifiItem) => {
+ const security = [];
const sm = wifiItem.spairport_security_mode || '';
if (sm === 'spairport_security_mode_wep') {
security.push('WEP');
@@ -437,7 +407,7 @@ function parseWifiDarwin(wifiStr) {
} catch (e) {
return result;
}
-};
+}
function wifiNetworks(callback) {
return new Promise((resolve) => {
process.nextTick(() => {
@@ -448,7 +418,7 @@ function wifiNetworks(callback) {
try {
const iwconfigParts = execSync('export LC_ALL=C; iwconfig 2>/dev/null; unset LC_ALL', util.execOptsLinux).toString().split('\n\n');
let iface = '';
- iwconfigParts.forEach(element => {
+ iwconfigParts.forEach((element) => {
if (element.indexOf('no wireless') === -1 && element.trim() !== '') {
iface = element.split(' ')[0];
}
@@ -467,9 +437,11 @@ function wifiNetworks(callback) {
const res = getWifiNetworkListIw(ifaceSanitized);
if (res === -1) {
// try again after 4 secs
- setTimeout(function (iface) {
+ setTimeout((iface) => {
const res = getWifiNetworkListIw(iface);
- if (res != -1) { result = res; }
+ if (res !== -1) {
+ result = res;
+ }
if (callback) {
callback(result);
}
@@ -501,8 +473,8 @@ function wifiNetworks(callback) {
resolve(result);
}
} else if (_darwin) {
- let cmd = 'system_profiler SPAirPortDataType -json 2>/dev/null';
- exec(cmd, { maxBuffer: 1024 * 40000 }, function (error, stdout) {
+ const cmd = 'system_profiler SPAirPortDataType -json 2>/dev/null';
+ exec(cmd, { maxBuffer: 1024 * 40000 }, (error, stdout) => {
result = parseWifiDarwin(stdout.toString());
if (callback) {
callback(result);
@@ -510,12 +482,12 @@ function wifiNetworks(callback) {
resolve(result);
});
} else if (_windows) {
- let cmd = 'netsh wlan show networks mode=Bssid';
+ const cmd = 'netsh wlan show networks mode=Bssid';
util.powerShell(cmd).then((stdout) => {
const ssidParts = stdout.toString('utf8').split(os.EOL + os.EOL + 'SSID ');
ssidParts.shift();
- ssidParts.forEach(ssidPart => {
+ ssidParts.forEach((ssidPart) => {
const ssidLines = ssidPart.split(os.EOL);
if (ssidLines && ssidLines.length >= 8 && ssidLines[0].indexOf(':') >= 0) {
const bssidsParts = ssidPart.split(' BSSID');
@@ -565,29 +537,46 @@ exports.wifiNetworks = wifiNetworks;
function getVendor(model) {
model = model.toLowerCase();
let result = '';
- if (model.indexOf('intel') >= 0) { result = 'Intel'; }
- else if (model.indexOf('realtek') >= 0) { result = 'Realtek'; }
- else if (model.indexOf('qualcom') >= 0) { result = 'Qualcom'; }
- else if (model.indexOf('broadcom') >= 0) { result = 'Broadcom'; }
- else if (model.indexOf('cavium') >= 0) { result = 'Cavium'; }
- else if (model.indexOf('cisco') >= 0) { result = 'Cisco'; }
- else if (model.indexOf('marvel') >= 0) { result = 'Marvel'; }
- else if (model.indexOf('zyxel') >= 0) { result = 'Zyxel'; }
- else if (model.indexOf('melanox') >= 0) { result = 'Melanox'; }
- else if (model.indexOf('d-link') >= 0) { result = 'D-Link'; }
- else if (model.indexOf('tp-link') >= 0) { result = 'TP-Link'; }
- else if (model.indexOf('asus') >= 0) { result = 'Asus'; }
- else if (model.indexOf('linksys') >= 0) { result = 'Linksys'; }
+ if (model.indexOf('intel') >= 0) {
+ result = 'Intel';
+ } else if (model.indexOf('realtek') >= 0) {
+ result = 'Realtek';
+ } else if (model.indexOf('qualcom') >= 0) {
+ result = 'Qualcom';
+ } else if (model.indexOf('broadcom') >= 0) {
+ result = 'Broadcom';
+ } else if (model.indexOf('cavium') >= 0) {
+ result = 'Cavium';
+ } else if (model.indexOf('cisco') >= 0) {
+ result = 'Cisco';
+ } else if (model.indexOf('marvel') >= 0) {
+ result = 'Marvel';
+ } else if (model.indexOf('zyxel') >= 0) {
+ result = 'Zyxel';
+ } else if (model.indexOf('melanox') >= 0) {
+ result = 'Melanox';
+ } else if (model.indexOf('d-link') >= 0) {
+ result = 'D-Link';
+ } else if (model.indexOf('tp-link') >= 0) {
+ result = 'TP-Link';
+ } else if (model.indexOf('asus') >= 0) {
+ result = 'Asus';
+ } else if (model.indexOf('linksys') >= 0) {
+ result = 'Linksys';
+ }
return result;
}
function formatBssid(s) {
- s = s.replace(//g, '').match(/.{1,2}/g) || [];
+ s =
+ s
+ .replace(//g, '')
+ .match(/.{1,2}/g) || [];
return s.join(':');
}
function wifiConnections(callback) {
-
return new Promise((resolve) => {
process.nextTick(() => {
const result = [];
@@ -595,7 +584,7 @@ function wifiConnections(callback) {
if (_linux) {
const ifaces = ifaceListLinux();
const networkList = getWifiNetworkListNmi();
- ifaces.forEach(ifaceDetail => {
+ ifaces.forEach((ifaceDetail) => {
let ifaceSanitized = '';
const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(ifaceDetail.iface, true);
const ll = util.mathMin(s.length, 2000);
@@ -609,7 +598,7 @@ function wifiConnections(callback) {
const nmiDetails = nmiDeviceLinux(ifaceSanitized);
const wpaDetails = wpaConnectionLinux(ifaceSanitized);
const ssid = nmiDetails.ssid || wpaDetails.ssid;
- const network = networkList.filter(nw => nw.ssid === ssid);
+ const network = networkList.filter((nw) => nw.ssid === ssid);
let ssidSanitized = '';
const t = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(ssid, true);
const l = util.mathMin(t.length, 32);
@@ -620,8 +609,8 @@ function wifiConnections(callback) {
}
const nmiConnection = nmiConnectionLinux(ssidSanitized);
- const channel = network && network.length && network[0].channel ? network[0].channel : (wpaDetails.channel ? wpaDetails.channel : null);
- const bssid = network && network.length && network[0].bssid ? network[0].bssid : (wpaDetails.bssid ? wpaDetails.bssid : null);
+ const channel = network && network.length && network[0].channel ? network[0].channel : wpaDetails.channel ? wpaDetails.channel : null;
+ const bssid = network && network.length && network[0].bssid ? network[0].bssid : wpaDetails.bssid ? wpaDetails.bssid : null;
const signalLevel = network && network.length && network[0].signalLevel ? network[0].signalLevel : null;
if (ssid && bssid) {
result.push({
@@ -629,11 +618,11 @@ function wifiConnections(callback) {
iface: ifaceDetail.iface,
model: nmiDetails.product,
ssid,
- bssid: network && network.length && network[0].bssid ? network[0].bssid : (wpaDetails.bssid ? wpaDetails.bssid : null),
+ bssid: network && network.length && network[0].bssid ? network[0].bssid : wpaDetails.bssid ? wpaDetails.bssid : null,
channel,
frequency: channel ? wifiFrequencyFromChannel(channel) : null,
type: nmiConnection.type ? nmiConnection.type : '802.11',
- security: nmiConnection.security ? nmiConnection.security : (wpaDetails.security ? wpaDetails.security : null),
+ security: nmiConnection.security ? nmiConnection.security : wpaDetails.security ? wpaDetails.security : null,
signalLevel,
quality: wifiQualityFromDB(signalLevel),
txRate: null
@@ -645,13 +634,14 @@ function wifiConnections(callback) {
}
resolve(result);
} else if (_darwin) {
- let cmd = 'system_profiler SPNetworkDataType SPAirPortDataType -xml 2>/dev/null; echo "######" ; ioreg -n AppleBCMWLANSkywalkInterface -r 2>/dev/null';
- exec(cmd, function (error, stdout) {
+ const cmd = 'system_profiler SPNetworkDataType SPAirPortDataType -xml 2>/dev/null; echo "######" ; ioreg -n AppleBCMWLANSkywalkInterface -r 2>/dev/null';
+ exec(cmd, (error, stdout) => {
try {
const parts = stdout.toString().split('######');
const profilerObj = util.plistParser(parts[0]);
const networkObj = profilerObj[0]._SPCommandLineArguments.indexOf('SPNetworkDataType') >= 0 ? profilerObj[0]._items : profilerObj[1]._items;
- const airportObj = profilerObj[0]._SPCommandLineArguments.indexOf('SPAirPortDataType') >= 0 ? profilerObj[0]._items[0].spairport_airport_interfaces : profilerObj[1]._items[0].spairport_airport_interfaces;
+ const airportObj =
+ profilerObj[0]._SPCommandLineArguments.indexOf('SPAirPortDataType') >= 0 ? profilerObj[0]._items[0].spairport_airport_interfaces : profilerObj[1]._items[0].spairport_airport_interfaces;
// parts[1] : ioreg
let lines3 = [];
@@ -659,13 +649,15 @@ function wifiConnections(callback) {
lines3 = parts[1].split(' | {')[1].split(' | }')[0].replace(/ \| /g, '').replace(/"/g, '').split('\n');
}
- const networkWifiObj = networkObj.find((item) => { return item._name === 'Wi-Fi'; });
+ const networkWifiObj = networkObj.find((item) => {
+ return item._name === 'Wi-Fi';
+ });
const airportWifiObj = airportObj[0].spairport_current_network_information;
- const channel = parseInt(('' + airportWifiObj.spairport_network_channel).split(' ')[0]) || 0;
+ const channel = parseInt(('' + airportWifiObj.spairport_network_channel).split(' ')[0], 10) || 0;
const signalLevel = airportWifiObj.spairport_signal_noise || null;
- let security = [];
+ const security = [];
const sm = airportWifiObj.spairport_security_mode || '';
if (sm === 'spairport_security_mode_wep') {
security.push('WEP');
@@ -683,7 +675,7 @@ function wifiConnections(callback) {
id: networkWifiObj._name || 'Wi-Fi',
iface: networkWifiObj.interface || '',
model: networkWifiObj.hardware || '',
- ssid: airportWifiObj._name || '',
+ ssid: (airportWifiObj._name || '').replace('<', '<').replace('>', '>'),
bssid: airportWifiObj.spairport_network_bssid || '',
channel,
frequency: channel ? wifiFrequencyFromChannel(channel) : null,
@@ -691,10 +683,9 @@ function wifiConnections(callback) {
security,
signalLevel: signalLevel ? parseInt(signalLevel, 10) : null,
quality: wifiQualityFromDB(signalLevel),
- txRate: airportWifiObj.spairport_network_rate || null,
+ txRate: airportWifiObj.spairport_network_rate || null
});
-
- } catch (e) {
+ } catch {
util.noop();
}
if (callback) {
@@ -703,15 +694,15 @@ function wifiConnections(callback) {
resolve(result);
});
} else if (_windows) {
- let cmd = 'netsh wlan show interfaces';
- util.powerShell(cmd).then(function (stdout) {
+ const cmd = 'netsh wlan show interfaces';
+ util.powerShell(cmd).then((stdout) => {
const allLines = stdout.toString().split('\r\n');
for (let i = 0; i < allLines.length; i++) {
allLines[i] = allLines[i].trim();
}
const parts = allLines.join('\r\n').split(':\r\n\r\n');
parts.shift();
- parts.forEach(part => {
+ parts.forEach((part) => {
const lines = part.split('\r\n');
if (lines.length >= 5) {
const iface = lines[0].indexOf(':') >= 0 ? lines[0].split(':')[1].trim() : '';
@@ -724,7 +715,8 @@ function wifiConnections(callback) {
const type = util.getValue(lines, 'Radio type', ':', true) || util.getValue(lines, 'Type de radio', ':', true) || util.getValue(lines, 'Funktyp', ':', true) || null;
const security = util.getValue(lines, 'authentication', ':', true) || util.getValue(lines, 'Authentification', ':', true) || util.getValue(lines, 'Authentifizierung', ':', true) || null;
const channel = util.getValue(lines, 'Channel', ':', true) || util.getValue(lines, 'Canal', ':', true) || util.getValue(lines, 'Kanal', ':', true) || null;
- const txRate = util.getValue(lines, 'Transmit rate (mbps)', ':', true) || util.getValue(lines, 'Transmission (mbit/s)', ':', true) || util.getValue(lines, 'Empfangsrate (MBit/s)', ':', true) || null;
+ const txRate =
+ util.getValue(lines, 'Transmit rate (mbps)', ':', true) || util.getValue(lines, 'Transmission (mbit/s)', ':', true) || util.getValue(lines, 'Empfangsrate (MBit/s)', ':', true) || null;
if (model && id && ssid && bssid) {
result.push({
id,
@@ -761,21 +753,20 @@ function wifiConnections(callback) {
exports.wifiConnections = wifiConnections;
function wifiInterfaces(callback) {
-
return new Promise((resolve) => {
process.nextTick(() => {
const result = [];
if (_linux) {
const ifaces = ifaceListLinux();
- ifaces.forEach(ifaceDetail => {
+ ifaces.forEach((ifaceDetail) => {
const nmiDetails = nmiDeviceLinux(ifaceDetail.iface);
result.push({
id: ifaceDetail.id,
iface: ifaceDetail.iface,
model: nmiDetails.product ? nmiDetails.product : null,
vendor: nmiDetails.vendor ? nmiDetails.vendor : null,
- mac: ifaceDetail.mac,
+ mac: ifaceDetail.mac
});
});
if (callback) {
@@ -783,8 +774,8 @@ function wifiInterfaces(callback) {
}
resolve(result);
} else if (_darwin) {
- let cmd = 'system_profiler SPNetworkDataType';
- exec(cmd, function (error, stdout) {
+ const cmd = 'system_profiler SPNetworkDataType';
+ exec(cmd, (error, stdout) => {
const parts1 = stdout.toString().split('\n\n Wi-Fi:\n\n');
if (parts1.length > 1) {
const lines = parts1[1].split('\n\n')[0].split('\n');
@@ -805,15 +796,15 @@ function wifiInterfaces(callback) {
resolve(result);
});
} else if (_windows) {
- let cmd = 'netsh wlan show interfaces';
- util.powerShell(cmd).then(function (stdout) {
+ const cmd = 'netsh wlan show interfaces';
+ util.powerShell(cmd).then((stdout) => {
const allLines = stdout.toString().split('\r\n');
for (let i = 0; i < allLines.length; i++) {
allLines[i] = allLines[i].trim();
}
const parts = allLines.join('\r\n').split(':\r\n\r\n');
parts.shift();
- parts.forEach(part => {
+ parts.forEach((part) => {
const lines = part.split('\r\n');
if (lines.length >= 5) {
const iface = lines[0].indexOf(':') >= 0 ? lines[0].split(':')[1].trim() : '';
@@ -829,7 +820,7 @@ function wifiInterfaces(callback) {
iface,
model,
vendor,
- mac,
+ mac
});
}
}