diff --git a/lib/audio.js b/lib/audio.js index 4d80aaeb..f5f8859a 100644 --- a/lib/audio.js +++ b/lib/audio.js @@ -14,8 +14,8 @@ // ---------------------------------------------------------------------------------- const exec = require('child_process').exec; -const execSync = require('child_process').execSync; const util = require('./util'); +const execAsync = util.execAsync; let _platform = process.platform; @@ -55,11 +55,11 @@ function parseAudioType(str, input, output) { } -function getLinuxAudioPci() { +async function getLinuxAudioPci() { let cmd = 'lspci -v 2>/dev/null'; let result = []; try { - const parts = execSync(cmd, util.execOptsLinux).toString().split('\n\n'); + const parts = (await execAsync(cmd, util.execOptsLinux)).toString().split('\n\n'); parts.forEach(element => { const lines = element.split('\n'); if (lines && lines.length && lines[0].toLowerCase().indexOf('audio') >= 0) { @@ -154,10 +154,10 @@ function audio(callback) { let result = []; if (_linux || _freebsd || _openbsd || _netbsd) { let cmd = 'lspci -vmm 2>/dev/null'; - exec(cmd, function (error, stdout) { + exec(cmd, async function (error, stdout) { // PCI if (!error) { - const audioPCI = getLinuxAudioPci(); + const audioPCI = await getLinuxAudioPci(); const parts = stdout.toString().split('\n\n'); parts.forEach(element => { const lines = element.split('\n'); diff --git a/lib/battery.js b/lib/battery.js index b11318d1..b5bb09e0 100644 --- a/lib/battery.js +++ b/lib/battery.js @@ -64,7 +64,7 @@ function parseWinBatteryPart(lines, designedCapacity, fullChargeCapacity) { module.exports = function (callback) { return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { let result = { hasBattery: false, cycleCount: 0, @@ -100,7 +100,7 @@ module.exports = function (callback) { } if (acPath) { - const file = fs.readFileSync(acPath); + const file = await fs.promises.readFile(acPath); acConnected = file.toString().trim() === '1'; } diff --git a/lib/bluetooth.js b/lib/bluetooth.js index d01c32ce..9c14818b 100644 --- a/lib/bluetooth.js +++ b/lib/bluetooth.js @@ -14,9 +14,9 @@ // ---------------------------------------------------------------------------------- const exec = require('child_process').exec; -const execSync = require('child_process').execSync; const path = require('path'); const util = require('./util'); +const execAsync = util.execAsync; const fs = require('fs'); let _platform = process.platform; @@ -112,24 +112,24 @@ function parseWindowsBluetooth(lines) { function bluetoothDevices(callback) { return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { let result = []; if (_linux) { // get files in /var/lib/bluetooth/ recursive const btFiles = util.getFilesInPath('/var/lib/bluetooth/'); - btFiles.forEach((element) => { + btFiles.forEach(async (element) => { const filename = path.basename(element); const pathParts = element.split('/'); const macAddr1 = pathParts.length >= 6 ? pathParts[pathParts.length - 2] : null; const macAddr2 = pathParts.length >= 7 ? pathParts[pathParts.length - 3] : null; if (filename === 'info') { - const infoFile = fs.readFileSync(element, { encoding: 'utf8' }).split('\n'); + const infoFile = (await fs.promises.readFile(element, { encoding: 'utf8' })).split('\n'); result.push(parseLinuxBluetoothInfo(infoFile, macAddr1, macAddr2)); } }); // determine "connected" with hcitool con try { - const hdicon = execSync('hcitool con', util.execOptsLinux).toString().toLowerCase(); + const hdicon = (await execAsync('hcitool con', util.execOptsLinux)).toString().toLowerCase(); for (let i = 0; i < result.length; i++) { if (result[i].macDevice && result[i].macDevice.length > 10 && hdicon.indexOf(result[i].macDevice.toLowerCase()) >= 0) { result[i].connected = true; diff --git a/lib/cpu.js b/lib/cpu.js index 4fc146e1..823c4a1d 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -15,9 +15,9 @@ const os = require('os'); const exec = require('child_process').exec; -const execSync = require('child_process').execSync; const fs = require('fs'); const util = require('./util'); +const execAsync = util.execAsync; let _platform = process.platform; @@ -676,7 +676,7 @@ function getCpu() { result.flags = flags; result.virtualization = flags.indexOf('vmx') > -1 || flags.indexOf('svm') > -1; if (_darwin) { - exec('sysctl machdep.cpu hw.cpufrequency_max hw.cpufrequency_min hw.packages hw.physicalcpu_max hw.ncpu hw.tbfrequency hw.cpufamily hw.cpusubfamily', function (error, stdout) { + exec('sysctl machdep.cpu hw.cpufrequency_max hw.cpufrequency_min hw.packages hw.physicalcpu_max hw.ncpu hw.tbfrequency hw.cpufamily hw.cpusubfamily', async function (error, stdout) { let lines = stdout.toString().split('\n'); const modelline = util.getValue(lines, 'machdep.cpu.brand_string'); const modellineParts = modelline.split('@'); @@ -702,7 +702,7 @@ function getCpu() { if (os.arch() === 'arm64') { result.socket = 'SOC'; try { - const clusters = execSync('ioreg -c IOPlatformDevice -d 3 -r | grep cluster-type').toString().split('\n'); + const clusters = (await execAsync('ioreg -c IOPlatformDevice -d 3 -r | grep cluster-type')).toString().split('\n'); const efficiencyCores = clusters.filter(line => line.indexOf('"E"') >= 0).length; const performanceCores = clusters.filter(line => line.indexOf('"P"') >= 0).length; result.efficiencyCores = efficiencyCores; @@ -728,7 +728,7 @@ function getCpu() { let modelline = ''; let lines = []; if (os.cpus()[0] && os.cpus()[0].model) { modelline = os.cpus()[0].model; } - exec('export LC_ALL=C; lscpu; echo -n "Governor: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 2>/dev/null; echo; unset LC_ALL', function (error, stdout) { + exec('export LC_ALL=C; lscpu; echo -n "Governor: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 2>/dev/null; echo; unset LC_ALL', async function (error, stdout) { if (!error) { lines = stdout.toString().split('\n'); } @@ -777,7 +777,7 @@ function getCpu() { // Test Raspberry if (result.vendor === 'ARM') { - const linesRpi = fs.readFileSync('/proc/cpuinfo').toString().split('\n'); + const linesRpi = (await fs.promises.readFile('/proc/cpuinfo')).toString().split('\n'); const rPIRevision = util.decodePiCpuinfo(linesRpi); if (rPIRevision.model.toLowerCase().indexOf('raspberry') >= 0) { result.family = result.manufacturer; @@ -1037,7 +1037,7 @@ exports.cpuCurrentSpeed = cpuCurrentSpeed; function cpuTemperature(callback) { return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { let result = { main: null, cores: [], @@ -1049,7 +1049,7 @@ function cpuTemperature(callback) { // CPU Chipset, Socket try { const cmd = 'cat /sys/class/thermal/thermal_zone*/type 2>/dev/null; echo "-----"; cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null;'; - const parts = execSync(cmd, util.execOptsLinux).toString().split('-----\n'); + const parts = (await execAsync(cmd, util.execOptsLinux)).toString().split('-----\n'); if (parts.length === 2) { const lines = parts[0].split('\n'); const lines2 = parts[1].split('\n'); @@ -1579,7 +1579,7 @@ exports.cpuCache = cpuCache; function getLoad() { return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { let loads = os.loadavg().map(function (x) { return x / util.cores(); }); let avgLoad = parseFloat((Math.max.apply(Math, loads)).toFixed(2)); let result = {}; @@ -1605,7 +1605,7 @@ function getLoad() { // linux: try to get other cpu stats if (_linux) { try { - const lines = execSync('cat /proc/stat 2>/dev/null | grep cpu', util.execOptsLinux).toString().split('\n'); + const lines = (await execAsync('cat /proc/stat 2>/dev/null | grep cpu', util.execOptsLinux)).toString().split('\n'); if (lines.length > 1) { lines.shift(); if (lines.length === cpus.length) { diff --git a/lib/filesystem.js b/lib/filesystem.js index 15e6a87e..0c8d92bf 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -17,8 +17,7 @@ const util = require('./util'); const fs = require('fs'); const exec = require('child_process').exec; -const execSync = require('child_process').execSync; -const execPromiseSave = util.promisifySave(require('child_process').exec); +const execAsync = util.execAsync; let _platform = process.platform; @@ -115,7 +114,7 @@ function fsSize(drive, callback) { } return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { let data = []; if (_linux || _freebsd || _openbsd || _netbsd || _darwin) { let cmd = ''; @@ -124,10 +123,10 @@ function fsSize(drive, callback) { if (_darwin) { cmd = 'df -kP'; try { - macOsDisks = execSync('diskutil list').toString().split('\n').filter(line => { + macOsDisks = (await execAsync('diskutil list')).toString().split('\n').filter(line => { return !line.startsWith('/') && line.indexOf(':') > 0; }); - execSync('mount').toString().split('\n').filter(line => { + (await execAsync('mount')).toString().split('\n').filter(line => { return line.startsWith('/'); }).forEach((line) => { osMounts[line.split(' ')[0]] = line.toLowerCase().indexOf('read-only') === -1; @@ -139,7 +138,7 @@ function fsSize(drive, callback) { if (_linux) { try { cmd = 'export LC_ALL=C; df -lkPTx squashfs; unset LC_ALL'; - execSync('cat /proc/mounts 2>/dev/null', util.execOptsLinux).toString().split('\n').filter(line => { + (await execAsync('cat /proc/mounts 2>/dev/null', util.execOptsLinux)).toString().split('\n').filter(line => { return line.startsWith('/'); }).forEach((line) => { osMounts[line.split(' ')[0]] = osMounts[line.split(' ')[0]] || false; @@ -154,7 +153,7 @@ function fsSize(drive, callback) { if (_freebsd || _openbsd || _netbsd) { try { cmd = 'df -lkPT'; - execSync('mount').toString().split('\n').forEach((line) => { + (await execAsync('mount')).toString().split('\n').forEach((line) => { osMounts[line.split(' ')[0]] = line.toLowerCase().indexOf('read-only') === -1; }); } catch (e) { @@ -420,13 +419,13 @@ function decodeMdabmData(lines) { }; } -function raidMatchLinux(data) { +async function raidMatchLinux(data) { // for all block devices of type "raid%" let result = data; try { - data.forEach(element => { + for (let element of data) { if (element.type.startsWith('raid')) { - const lines = execSync(`mdadm --export --detail /dev/${element.name}`, util.execOptsLinux).toString().split('\n'); + const lines = (await execAsync(`mdadm --export --detail /dev/${element.name}`, util.execOptsLinux)).toString().split('\n'); const mdData = decodeMdabmData(lines); element.label = mdData.label; // <- assign label info @@ -441,7 +440,7 @@ function raidMatchLinux(data) { }); } } - }); + } } catch (e) { util.noop(); } @@ -570,27 +569,27 @@ function blkStdoutToObject(stdout) { function blockDevices(callback) { return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { let data = []; if (_linux) { // see https://wiki.ubuntuusers.de/lsblk/ // exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,TRAN,SERIAL,LABEL,MODEL,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,SCHED,RQ-SIZE,RA,WSAME", function (error, stdout) { - exec('lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,TRAN,SERIAL,LABEL,MODEL,OWNER 2>/dev/null', { maxBuffer: 1024 * 1024 }, function (error, stdout) { + exec('lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,TRAN,SERIAL,LABEL,MODEL,OWNER 2>/dev/null', { maxBuffer: 1024 * 1024 }, async function (error, stdout) { if (!error) { let lines = blkStdoutToObject(stdout).split('\n'); data = parseBlk(lines); - data = raidMatchLinux(data); + data = await raidMatchLinux(data); data = matchDevicesLinux(data); if (callback) { callback(data); } resolve(data); } else { - exec('lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER 2>/dev/null', { maxBuffer: 1024 * 1024 }, function (error, stdout) { + exec('lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER 2>/dev/null', { maxBuffer: 1024 * 1024 }, async function (error, stdout) { if (!error) { let lines = blkStdoutToObject(stdout).split('\n'); data = parseBlk(lines); - data = raidMatchLinux(data); + data = await raidMatchLinux(data); } if (callback) { callback(data); @@ -1056,7 +1055,7 @@ function diskLayout(callback) { } return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { const commitResult = res => { for (let i = 0; i < res.length; i++) { @@ -1074,7 +1073,7 @@ function diskLayout(callback) { if (_linux) { let cmdFullSmart = ''; - exec('export LC_ALL=C; lsblk -ablJO 2>/dev/null; unset LC_ALL', { maxBuffer: 1024 * 1024 }, function (error, stdout) { + exec('export LC_ALL=C; lsblk -ablJO 2>/dev/null; unset LC_ALL', { maxBuffer: 1024 * 1024 }, async function (error, stdout) { if (!error) { try { const out = stdout.toString().trim(); @@ -1087,7 +1086,7 @@ function diskLayout(callback) { } catch (e) { // fallback to older version of lsblk try { - const out2 = execSync('export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP 2>/dev/null; unset LC_ALL', util.execOptsLinux).toString(); + const out2 = (await execAsync('export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP 2>/dev/null; unset LC_ALL', util.execOptsLinux)).toString(); let lines = blkStdoutToObject(out2).split('\n'); const data = parseBlk(lines); devices = data.filter(item => { return (item.type === 'disk') && item.size > 0 && ((item.model !== null && item.model !== '') || (item.mount === '' && item.label === '' && item.fsType === '')); }); @@ -1095,12 +1094,12 @@ function diskLayout(callback) { util.noop(); } } - devices.forEach((device) => { + for (let device of devices) { let mediumType = ''; const BSDName = '/dev/' + device.name; const logical = device.name; try { - mediumType = execSync('cat /sys/block/' + logical + '/queue/rotational 2>/dev/null', util.execOptsLinux).toString().split('\n')[0]; + mediumType = (await execAsync('cat /sys/block/' + logical + '/queue/rotational 2>/dev/null', util.execOptsLinux)).toString().split('\n')[0]; } catch (e) { util.noop(); } @@ -1131,7 +1130,7 @@ function diskLayout(callback) { }); cmd += `printf "\n${BSDName}|"; smartctl -H ${BSDName} | grep overall;`; cmdFullSmart += `${cmdFullSmart ? 'printf ",";' : ''}smartctl -a -j ${BSDName};`; - }); + } } catch (e) { util.noop(); } @@ -1406,10 +1405,10 @@ function diskLayout(callback) { workload.push(util.powerShell('Get-PhysicalDisk | select BusType,MediaType,FriendlyName,Model,SerialNumber,Size | fl')); if (util.smartMonToolsInstalled()) { try { - const smartDev = JSON.parse(execSync('smartctl --scan -j').toString()); + const smartDev = JSON.parse((await execAsync('smartctl --scan -j')).toString()); if (smartDev && smartDev.devices && smartDev.devices.length > 0) { smartDev.devices.forEach((dev) => { - workload.push(execPromiseSave(`smartctl -j -a ${dev.name}`, util.execOptsWin)); + workload.push(execAsync(`smartctl -j -a ${dev.name}`, util.execOptsWin).catch(() => '')); }); } } catch (e) { diff --git a/lib/graphics.js b/lib/graphics.js index 07904668..37d079d4 100644 --- a/lib/graphics.js +++ b/lib/graphics.js @@ -15,8 +15,8 @@ const fs = require('fs'); const exec = require('child_process').exec; -const execSync = require('child_process').execSync; const util = require('./util'); +const execAsync = util.execAsync; let _platform = process.platform; let _nvidiaSmiPath = ''; @@ -200,7 +200,7 @@ function graphics(callback) { } } - function parseLinesLinuxControllers(lines) { + async function parseLinesLinuxControllers(lines) { let controllers = []; let currentController = { vendor: '', @@ -216,7 +216,7 @@ function graphics(callback) { // PCI bus IDs let pciIDs = []; try { - pciIDs = execSync('export LC_ALL=C; dmidecode -t 9 2>/dev/null; unset LC_ALL | grep "Bus Address: "', util.execOptsLinux).toString().split('\n'); + pciIDs = (await execAsync('export LC_ALL=C; dmidecode -t 9 2>/dev/null; unset LC_ALL | grep "Bus Address: "', util.execOptsLinux)).toString().split('\n'); for (let i = 0; i < pciIDs.length; i++) { pciIDs[i] = pciIDs[i].replace('Bus Address:', '').replace('0000:', '').trim(); } @@ -415,7 +415,7 @@ function graphics(callback) { return _nvidiaSmiPath; } - function nvidiaSmi(options) { + async function nvidiaSmi(options) { const nvidiaSmiExe = getNvidiaSmi(); options = options || util.execOptsWin; if (nvidiaSmiExe) { @@ -425,7 +425,7 @@ function graphics(callback) { options.stdio = ['pipe', 'pipe', 'ignore']; } try { - const res = execSync(cmd, options).toString(); + const res = (await execAsync(cmd, options)).toString(); return res; } catch (e) { util.noop(); @@ -434,7 +434,7 @@ function graphics(callback) { return ''; } - function nvidiaDevices() { + async function nvidiaDevices() { function safeParseNumber(value) { if ([null, undefined].includes(value)) { @@ -443,7 +443,7 @@ function graphics(callback) { return parseFloat(value); } - const stdout = nvidiaSmi(); + const stdout = await nvidiaSmi(); if (!stdout) { return []; } @@ -673,14 +673,14 @@ function graphics(callback) { // function starts here return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { let result = { controllers: [], displays: [] }; if (_darwin) { let cmd = 'system_profiler -xml -detailLevel full SPDisplaysDataType'; - exec(cmd, function (error, stdout) { + exec(cmd, async function (error, stdout) { if (!error) { try { const output = stdout.toString(); @@ -689,7 +689,7 @@ function graphics(callback) { util.noop(); } try { - stdout = execSync('defaults read /Library/Preferences/com.apple.windowserver.plist 2>/dev/null;defaults read /Library/Preferences/com.apple.windowserver.displays.plist 2>/dev/null; echo ""', { maxBuffer: 1024 * 20000 }); + stdout = await execAsync('defaults read /Library/Preferences/com.apple.windowserver.plist 2>/dev/null;defaults read /Library/Preferences/com.apple.windowserver.displays.plist 2>/dev/null; echo ""', { maxBuffer: 1024 * 20000 }); const output = (stdout || '').toString(); const obj = util.plistReader(output); if (obj['DisplayAnyUserSets'] && obj['DisplayAnyUserSets']['Configs'] && obj['DisplayAnyUserSets']['Configs'][0] && obj['DisplayAnyUserSets']['Configs'][0]['DisplayConfig']) { @@ -733,9 +733,9 @@ function graphics(callback) { } if (_linux) { // Raspberry: https://elinux.org/RPI_vcgencmd_usage - if (util.isRaspberry() && util.isRaspbian()) { + if (await util.isRaspberry() && await util.isRaspbian()) { let cmd = 'fbset -s | grep \'mode "\'; vcgencmd get_mem gpu; tvservice -s; tvservice -n;'; - exec(cmd, function (error, stdout) { + exec(cmd, async function (error, stdout) { let lines = stdout.toString().split('\n'); if (lines.length > 3 && lines[0].indexOf('mode "') >= -1 && lines[2].indexOf('0x12000a') > -1) { const parts = lines[0].replace('mode', '').replace(/"/g, '').trim().split('x'); @@ -762,7 +762,7 @@ function graphics(callback) { if (lines.length > 1 && stdout.toString().indexOf('gpu=') >= -1) { result.controllers.push({ vendor: 'Broadcom', - model: util.getRpiGpu(), + model: await util.getRpiGpu(), bus: '', vram: util.getValue(lines, 'gpu', '=').replace('M', ''), vramDynamic: true @@ -775,11 +775,11 @@ function graphics(callback) { }); } else { let cmd = 'lspci -vvv 2>/dev/null'; - exec(cmd, function (error, stdout) { + exec(cmd, async function (error, stdout) { if (!error) { let lines = stdout.toString().split('\n'); - result.controllers = parseLinesLinuxControllers(lines); - const nvidiaData = nvidiaDevices(); + result.controllers = await parseLinesLinuxControllers(lines); + const nvidiaData = await nvidiaDevices(); // needs to be rewritten ... using no spread operators result.controllers = result.controllers.map((controller) => { // match by busAddress return mergeControllerNvidia(controller, nvidiaData.find((contr) => contr.pciBus.toLowerCase().endsWith(controller.busAddress.toLowerCase())) || {}); @@ -836,7 +836,7 @@ function graphics(callback) { workload.push(util.powerShell('Get-CimInstance -Namespace root\\wmi -ClassName WmiMonitorConnectionParams | fl')); workload.push(util.powerShell('gwmi WmiMonitorID -Namespace root\\wmi | ForEach-Object {(($_.ManufacturerName -notmatch 0 | foreach {[char]$_}) -join "") + "|" + (($_.ProductCodeID -notmatch 0 | foreach {[char]$_}) -join "") + "|" + (($_.UserFriendlyName -notmatch 0 | foreach {[char]$_}) -join "") + "|" + (($_.SerialNumberID -notmatch 0 | foreach {[char]$_}) -join "") + "|" + $_.InstanceName}')); - const nvidiaData = nvidiaDevices(); + const nvidiaData = await nvidiaDevices(); Promise.all( workload diff --git a/lib/memory.js b/lib/memory.js index d70a44f7..f1d1be8a 100644 --- a/lib/memory.js +++ b/lib/memory.js @@ -14,9 +14,9 @@ // ---------------------------------------------------------------------------------- const os = require('os'); -const exec = require('child_process').exec; -const execSync = require('child_process').execSync; const util = require('./util'); +const exec = require('child_process').exec; +const execAsync = util.execAsync; const fs = require('fs'); let _platform = process.platform; @@ -146,7 +146,7 @@ const LINUX_RAM_manufacturers = { function mem(callback) { return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { let result = { total: os.totalmem(), @@ -244,7 +244,7 @@ function mem(callback) { if (_darwin) { let pageSize = 4096; try { - let sysPpageSize = util.toInt(execSync('sysctl -n vm.pagesize').toString()); + let sysPpageSize = util.toInt((await execAsync('sysctl -n vm.pagesize')).toString()); pageSize = sysPpageSize || pageSize; } catch (e) { util.noop(); @@ -331,12 +331,12 @@ function memLayout(callback) { } return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { let result = []; if (_linux || _freebsd || _openbsd || _netbsd) { - exec('export LC_ALL=C; dmidecode -t memory 2>/dev/null | grep -iE "Size:|Type|Speed|Manufacturer|Form Factor|Locator|Memory Device|Serial Number|Voltage|Part Number"; unset LC_ALL', function (error, stdout) { + exec('export LC_ALL=C; dmidecode -t memory 2>/dev/null | grep -iE "Size:|Type|Speed|Manufacturer|Form Factor|Locator|Memory Device|Serial Number|Voltage|Part Number"; unset LC_ALL', async function (error, stdout) { if (!error) { let devices = stdout.toString().split('Memory Device'); devices.shift(); @@ -399,7 +399,7 @@ function memLayout(callback) { // Try Raspberry PI try { - let stdout = execSync('cat /proc/cpuinfo 2>/dev/null', util.execOptsLinux); + let stdout = await execAsync('cat /proc/cpuinfo 2>/dev/null', util.execOptsLinux); let lines = stdout.toString().split('\n'); let model = util.getValue(lines, 'hardware', ':', true).toUpperCase(); let version = util.getValue(lines, 'revision', ':', true).toLowerCase(); @@ -419,14 +419,14 @@ function memLayout(callback) { result[0].clockSpeed = version && version[4] && version[4] === 'd' ? 500 : result[0].clockSpeed; result[0].formFactor = 'SoC'; - stdout = execSync('vcgencmd get_config sdram_freq 2>/dev/null', util.execOptsLinux); + stdout = await execAsync('vcgencmd get_config sdram_freq 2>/dev/null', util.execOptsLinux); lines = stdout.toString().split('\n'); let freq = parseInt(util.getValue(lines, 'sdram_freq', '=', true), 10) || 0; if (freq) { result[0].clockSpeed = freq; } - stdout = execSync('vcgencmd measure_volts sdram_p 2>/dev/null', util.execOptsLinux); + stdout = await execAsync('vcgencmd measure_volts sdram_p 2>/dev/null', util.execOptsLinux); lines = stdout.toString().split('\n'); let voltage = parseFloat(util.getValue(lines, 'volt', '=', true)) || 0; if (voltage) { diff --git a/lib/network.js b/lib/network.js index 86c45131..ec863f71 100644 --- a/lib/network.js +++ b/lib/network.js @@ -15,9 +15,9 @@ const os = require('os'); const exec = require('child_process').exec; -const execSync = require('child_process').execSync; const fs = require('fs'); const util = require('./util'); +const execAsync = util.execAsync; let _platform = process.platform; @@ -37,7 +37,7 @@ let _networkInterfaces = []; let _mac = {}; let pathToIp; -function getDefaultNetworkInterface() { +async function getDefaultNetworkInterface() { let ifacename = ''; let ifacenameFirst = ''; @@ -66,7 +66,7 @@ function getDefaultNetworkInterface() { // https://www.inetdaemon.com/tutorials/internet/ip/routing/default_route.shtml let defaultIp = ''; const cmd = 'netstat -r'; - const result = execSync(cmd, util.execOptsWin); + const result = await execAsync(cmd, util.execOptsWin); const lines = result.toString().split(os.EOL); lines.forEach(line => { line = line.replace(/\s+/g, ' ').trim(); @@ -91,7 +91,7 @@ function getDefaultNetworkInterface() { } if (_linux) { let cmd = 'ip route 2> /dev/null | grep default'; - let result = execSync(cmd, util.execOptsLinux); + let result = await execAsync(cmd, util.execOptsLinux); let parts = result.toString().split('\n')[0].split(/\s+/); if (parts[0] === 'none' && parts[5]) { ifacename = parts[5]; @@ -108,7 +108,7 @@ function getDefaultNetworkInterface() { if (_linux) { cmd = 'ip route 2> /dev/null | grep default | awk \'{print $5}\''; } if (_darwin) { cmd = 'route -n get default 2>/dev/null | grep interface: | awk \'{print $2}\''; } if (_freebsd || _openbsd || _netbsd || _sunos) { cmd = 'route get 0.0.0.0 | grep interface:'; } - let result = execSync(cmd); + let result = await execAsync(cmd); ifacename = result.toString().split('\n')[0]; if (ifacename.indexOf(':') > -1) { ifacename = ifacename.split(':')[1].trim(); @@ -123,14 +123,14 @@ function getDefaultNetworkInterface() { exports.getDefaultNetworkInterface = getDefaultNetworkInterface; -function getMacAddresses() { +async function getMacAddresses() { let iface = ''; let mac = ''; let result = {}; if (_linux || _freebsd || _openbsd || _netbsd) { if (typeof pathToIp === 'undefined') { try { - const lines = execSync('which ip', util.execOptsLinux).toString().split('\n'); + const lines = (await execAsync('which ip', util.execOptsLinux)).toString().split('\n'); if (lines.length && lines[0].indexOf(':') === -1 && lines[0].indexOf('/') === 0) { pathToIp = lines[0]; } else { @@ -142,7 +142,7 @@ function getMacAddresses() { } try { const cmd = 'export LC_ALL=C; ' + ((pathToIp) ? pathToIp + ' link show up' : '/sbin/ifconfig') + '; unset LC_ALL'; - let res = execSync(cmd, util.execOptsLinux); + let res = await execAsync(cmd, util.execOptsLinux); const lines = res.toString().split('\n'); for (let i = 0; i < lines.length; i++) { if (lines[i] && lines[i][0] !== ' ') { @@ -172,7 +172,7 @@ function getMacAddresses() { if (_darwin) { try { const cmd = '/sbin/ifconfig'; - let res = execSync(cmd); + let res = await execAsync(cmd); const lines = res.toString().split('\n'); for (let i = 0; i < lines.length; i++) { if (lines[i] && lines[i][0] !== '\t' && lines[i].indexOf(':') > 0) { @@ -196,8 +196,8 @@ function getMacAddresses() { function networkInterfaceDefault(callback) { return new Promise((resolve) => { - process.nextTick(() => { - let result = getDefaultNetworkInterface(); + process.nextTick(async () => { + let result = await getDefaultNetworkInterface(); if (callback) { callback(result); } resolve(result); }); @@ -263,7 +263,7 @@ function getWindowsNics() { }); } -function getWindowsDNSsuffixes() { +async function getWindowsDNSsuffixes() { let iface = {}; @@ -274,7 +274,7 @@ function getWindowsDNSsuffixes() { }; try { - const ipconfig = execSync('ipconfig /all', util.execOptsWin); + const ipconfig = await execAsync('ipconfig /all', util.execOptsWin); const ipconfigArray = ipconfig.split('\r\n\r\n'); ipconfigArray.forEach((element, index) => { @@ -331,9 +331,9 @@ function getWindowsIfaceDNSsuffix(ifaces, ifacename) { } } -function getWindowsWiredProfilesInformation() { +async function getWindowsWiredProfilesInformation() { try { - const result = execSync('netsh lan show profiles', util.execOptsWin); + const result = await execAsync('netsh lan show profiles', util.execOptsWin); const profileList = result.split('\r\nProfile on interface'); return profileList; } catch (error) { @@ -344,9 +344,9 @@ function getWindowsWiredProfilesInformation() { } } -function getWindowsWirelessIfaceSSID(interfaceName) { +async function getWindowsWirelessIfaceSSID(interfaceName) { try { - const result = execSync(`netsh wlan show interface name="${interfaceName}" | findstr "SSID"`, util.execOptsWin); + const result = await execAsync(`netsh wlan show interface name="${interfaceName}" | findstr "SSID"`, util.execOptsWin); const SSID = result.split('\r\n').shift(); const parseSSID = SSID.split(':').pop(); return parseSSID; @@ -354,7 +354,7 @@ function getWindowsWirelessIfaceSSID(interfaceName) { return 'Unknown'; } } -function getWindowsIEEE8021x(connectionType, iface, ifaces) { +async function getWindowsIEEE8021x(connectionType, iface, ifaces) { let i8021x = { state: 'Unknown', protocol: 'Unknown', @@ -398,10 +398,10 @@ function getWindowsIEEE8021x(connectionType, iface, ifaces) { try { - const SSID = getWindowsWirelessIfaceSSID(iface); + const SSID = await getWindowsWirelessIfaceSSID(iface); if (SSID !== 'Unknown') { - i8021xState = execSync(`netsh wlan show profiles "${SSID}" | findstr "802.1X"`, util.execOptsWin); - i8021xProtocol = execSync(`netsh wlan show profiles "${SSID}" | findstr "EAP"`, util.execOptsWin); + i8021xState = await execAsync(`netsh wlan show profiles "${SSID}" | findstr "802.1X"`, util.execOptsWin); + i8021xProtocol = await execAsync(`netsh wlan show profiles "${SSID}" | findstr "EAP"`, util.execOptsWin); } if (i8021xState.includes(':') && i8021xProtocol.includes(':')) { @@ -496,10 +496,10 @@ function parseLinesDarwinNics(sections) { return nics; } -function getDarwinNics() { +async function getDarwinNics() { const cmd = '/sbin/ifconfig -v'; try { - const lines = execSync(cmd, { maxBuffer: 1024 * 20000 }).toString().split('\n'); + const lines = (await execAsync(cmd, { maxBuffer: 1024 * 20000 })).toString().split('\n'); const nsections = splitSectionsNics(lines); return (parseLinesDarwinNics(nsections)); } catch (e) { @@ -507,11 +507,11 @@ function getDarwinNics() { } } -function getLinuxIfaceConnectionName(interfaceName) { +async function getLinuxIfaceConnectionName(interfaceName) { const cmd = `nmcli device status 2>/dev/null | grep ${interfaceName}`; try { - const result = execSync(cmd, util.execOptsLinux).toString(); + const result = (await execAsync(cmd, util.execOptsLinux)).toString(); const resultFormat = result.replace(/\s+/g, ' ').trim(); const connectionNameLines = resultFormat.split(' ').slice(3); const connectionName = connectionNameLines.join(' '); @@ -521,13 +521,13 @@ function getLinuxIfaceConnectionName(interfaceName) { } } -function checkLinuxDCHPInterfaces(file) { +async function checkLinuxDCHPInterfaces(file) { let result = []; try { let cmd = `cat ${file} 2> /dev/null | grep 'iface\\|source'`; - const lines = execSync(cmd, util.execOptsLinux).toString().split('\n'); + const lines = (await execAsync(cmd, util.execOptsLinux)).toString().split('\n'); - lines.forEach(line => { + for (let line of lines) { const parts = line.replace(/\s+/g, ' ').trim().split(' '); if (parts.length >= 4) { if (line.toLowerCase().indexOf(' inet ') >= 0 && line.toLowerCase().indexOf('dhcp') >= 0) { @@ -536,28 +536,28 @@ function checkLinuxDCHPInterfaces(file) { } if (line.toLowerCase().includes('source')) { let file = line.split(' ')[1]; - result = result.concat(checkLinuxDCHPInterfaces(file)); + result = result.concat(await checkLinuxDCHPInterfaces(file)); } - }); + } } catch (e) { util.noop(); } return result; } -function getLinuxDHCPNics() { +async function getLinuxDHCPNics() { // alternate methods getting interfaces using DHCP let cmd = 'ip a 2> /dev/null'; let result = []; try { - const lines = execSync(cmd, util.execOptsLinux).toString().split('\n'); + const lines = (await execAsync(cmd, util.execOptsLinux)).toString().split('\n'); const nsections = splitSectionsNics(lines); result = (parseLinuxDHCPNics(nsections)); } catch (e) { util.noop(); } try { - result = checkLinuxDCHPInterfaces('/etc/network/interfaces'); + result = await checkLinuxDCHPInterfaces('/etc/network/interfaces'); } catch (e) { util.noop(); } @@ -586,12 +586,12 @@ function parseLinuxDHCPNics(sections) { return result; } -function getLinuxIfaceDHCPstatus(iface, connectionName, DHCPNics) { +async function getLinuxIfaceDHCPstatus(iface, connectionName, DHCPNics) { let result = false; if (connectionName) { const cmd = `nmcli connection show "${connectionName}" 2>/dev/null | grep ipv4.method;`; try { - const lines = execSync(cmd, util.execOptsLinux).toString(); + const lines = (await execAsync(cmd, util.execOptsLinux)).toString(); const resultFormat = lines.replace(/\s+/g, ' ').trim(); let dhcStatus = resultFormat.split(' ').slice(1).toString(); @@ -613,11 +613,11 @@ function getLinuxIfaceDHCPstatus(iface, connectionName, DHCPNics) { } } -function getDarwinIfaceDHCPstatus(iface) { +async function getDarwinIfaceDHCPstatus(iface) { let result = false; const cmd = `ipconfig getpacket "${iface}" 2>/dev/null | grep lease_time;`; try { - const lines = execSync(cmd).toString().split('\n'); + const lines = (await execAsync(cmd)).toString().split('\n'); if (lines.length && lines[0].startsWith('lease_time')) { result = true; } @@ -627,11 +627,11 @@ function getDarwinIfaceDHCPstatus(iface) { return result; } -function getLinuxIfaceDNSsuffix(connectionName) { +async function getLinuxIfaceDNSsuffix(connectionName) { if (connectionName) { const cmd = `nmcli connection show "${connectionName}" 2>/dev/null | grep ipv4.dns-search;`; try { - const result = execSync(cmd, util.execOptsLinux).toString(); + const result = (await execAsync(cmd, util.execOptsLinux)).toString(); const resultFormat = result.replace(/\s+/g, ' ').trim(); const dnsSuffix = resultFormat.split(' ').slice(1).toString(); return dnsSuffix == '--' ? 'Not defined' : dnsSuffix; @@ -643,11 +643,11 @@ function getLinuxIfaceDNSsuffix(connectionName) { } } -function getLinuxIfaceIEEE8021xAuth(connectionName) { +async function getLinuxIfaceIEEE8021xAuth(connectionName) { if (connectionName) { const cmd = `nmcli connection show "${connectionName}" 2>/dev/null | grep 802-1x.eap;`; try { - const result = execSync(cmd, util.execOptsLinux).toString(); + const result = (await execAsync(cmd, util.execOptsLinux)).toString(); const resultFormat = result.replace(/\s+/g, ' ').trim(); const authenticationProtocol = resultFormat.split(' ').slice(1).toString(); @@ -707,7 +707,7 @@ function networkInterfaces(callback, rescan, defaultString) { defaultString = '' + defaultString; return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { let ifaces = os.networkInterfaces(); @@ -724,13 +724,13 @@ function networkInterfaces(callback, rescan, defaultString) { if (callback) { callback(result); } resolve(result); } else { - const defaultInterface = getDefaultNetworkInterface(); + const defaultInterface = await getDefaultNetworkInterface(); _ifaces = JSON.parse(JSON.stringify(ifaces)); - nics = getDarwinNics(); + nics = await getDarwinNics(); - nics.forEach(nic => { + for (let nic of nics) { if ({}.hasOwnProperty.call(ifaces, nic.iface)) { ifaces[nic.iface].forEach(function (details) { @@ -768,13 +768,13 @@ function networkInterfaces(callback, rescan, defaultString) { duplex: nic.duplex, mtu: nic.mtu, speed: nic.speed, - dhcp: getDarwinIfaceDHCPstatus(ifaceSanitized), + dhcp: await getDarwinIfaceDHCPstatus(ifaceSanitized), dnsSuffix: '', ieee8021xAuth: '', ieee8021xState: '', carrierChanges: 0 }); - }); + } _networkInterfaces = result; if (defaultString.toLowerCase().indexOf('default') >= 0) { result = result.filter(item => item.default); @@ -797,8 +797,8 @@ function networkInterfaces(callback, rescan, defaultString) { resolve(result); } else { _ifaces = JSON.parse(JSON.stringify(ifaces)); - _dhcpNics = getLinuxDHCPNics(); - const defaultInterface = getDefaultNetworkInterface(); + _dhcpNics = await getLinuxDHCPNics(); + const defaultInterface = await getDefaultNetworkInterface(); for (let dev in ifaces) { let ip4 = ''; let ip4subnet = ''; @@ -817,7 +817,7 @@ function networkInterfaces(callback, rescan, defaultString) { if ({}.hasOwnProperty.call(ifaces, dev)) { let ifaceName = dev; - ifaces[dev].forEach(function (details) { + for (let details of ifaces[dev]) { if (details.family === 'IPv4' || details.family === 4) { ip4 = details.address; ip4subnet = details.netmask; @@ -833,11 +833,11 @@ function networkInterfaces(callback, rescan, defaultString) { const nodeMainVersion = parseInt(process.versions.node.split('.'), 10); if (mac.indexOf('00:00:0') > -1 && (_linux || _darwin) && (!details.internal) && nodeMainVersion >= 8 && nodeMainVersion <= 11) { if (Object.keys(_mac).length === 0) { - _mac = getMacAddresses(); + _mac = await getMacAddresses(); } mac = _mac[dev] || ''; } - }); + } let iface = dev.split(':')[0].trim().toLowerCase(); let ifaceSanitized = ''; const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(iface); @@ -875,11 +875,11 @@ function networkInterfaces(callback, rescan, defaultString) { let lines = []; try { - lines = execSync(cmd, util.execOptsLinux).toString().split('\n'); - const connectionName = getLinuxIfaceConnectionName(ifaceSanitized); - dhcp = getLinuxIfaceDHCPstatus(ifaceSanitized, connectionName, _dhcpNics); - dnsSuffix = getLinuxIfaceDNSsuffix(connectionName); - ieee8021xAuth = getLinuxIfaceIEEE8021xAuth(connectionName); + lines = (await execAsync(cmd, util.execOptsLinux)).toString().split('\n'); + const connectionName = await getLinuxIfaceConnectionName(ifaceSanitized); + dhcp = await getLinuxIfaceDHCPstatus(ifaceSanitized, connectionName, _dhcpNics); + dnsSuffix = await getLinuxIfaceDNSsuffix(connectionName); + ieee8021xAuth = await getLinuxIfaceIEEE8021xAuth(connectionName); ieee8021xState = getLinuxIfaceIEEE8021xState(ieee8021xAuth); } catch (e) { util.noop(); @@ -950,9 +950,9 @@ function networkInterfaces(callback, rescan, defaultString) { resolve(result); } else { _ifaces = JSON.parse(JSON.stringify(ifaces)); - const defaultInterface = getDefaultNetworkInterface(); + const defaultInterface = await getDefaultNetworkInterface(); - getWindowsNics().then(function (nics) { + getWindowsNics().then(async function (nics) { nics.forEach(nic => { let found = false; Object.keys(ifaces).forEach(key => { @@ -969,8 +969,8 @@ function networkInterfaces(callback, rescan, defaultString) { ifaces[nic.name] = [{ mac: nic.mac }]; } }); - nics8021xInfo = getWindowsWiredProfilesInformation(); - dnsSuffixes = getWindowsDNSsuffixes(); + nics8021xInfo = await getWindowsWiredProfilesInformation(); + dnsSuffixes = await getWindowsDNSsuffixes(); for (let dev in ifaces) { let ifaceSanitized = ''; @@ -1001,7 +1001,7 @@ function networkInterfaces(callback, rescan, defaultString) { if ({}.hasOwnProperty.call(ifaces, dev)) { let ifaceName = dev; - ifaces[dev].forEach(function (details) { + for (let details of ifaces[dev]) { if (details.family === 'IPv4' || details.family === 4) { ip4 = details.address; ip4subnet = details.netmask; @@ -1017,15 +1017,15 @@ function networkInterfaces(callback, rescan, defaultString) { const nodeMainVersion = parseInt(process.versions.node.split('.'), 10); if (mac.indexOf('00:00:0') > -1 && (_linux || _darwin) && (!details.internal) && nodeMainVersion >= 8 && nodeMainVersion <= 11) { if (Object.keys(_mac).length === 0) { - _mac = getMacAddresses(); + _mac = await getMacAddresses(); } mac = _mac[dev] || ''; } - }); + } - dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, ifaceSanitized); + dnsSuffix = await getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, ifaceSanitized); let foundFirst = false; nics.forEach(detail => { if (detail.mac === mac && !foundFirst) { @@ -1043,7 +1043,7 @@ function networkInterfaces(callback, rescan, defaultString) { type = 'wireless'; } - const IEEE8021x = getWindowsIEEE8021x(type, ifaceSanitized, nics8021xInfo); + const IEEE8021x = await getWindowsIEEE8021x(type, ifaceSanitized, nics8021xInfo); ieee8021xAuth = IEEE8021x.protocol; ieee8021xState = IEEE8021x.state; let internal = (ifaces[dev] && ifaces[dev][0]) ? ifaces[dev][0].internal : false; @@ -1142,18 +1142,18 @@ function networkStats(ifaces, callback) { let ifacesArray = []; return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { // fallback - if only callback is given if (util.isFunction(ifaces) && !callback) { callback = ifaces; - ifacesArray = [getDefaultNetworkInterface()]; + ifacesArray = [await getDefaultNetworkInterface()]; } else { if (typeof ifaces !== 'string' && ifaces !== undefined) { if (callback) { callback([]); } return resolve([]); } - ifaces = ifaces || getDefaultNetworkInterface(); + ifaces = ifaces || await getDefaultNetworkInterface(); ifaces.__proto__.toLowerCase = util.stringToLower; ifaces.__proto__.replace = util.stringReplace; diff --git a/lib/osinfo.js b/lib/osinfo.js index 33aa0c15..c02d9cf9 100644 --- a/lib/osinfo.js +++ b/lib/osinfo.js @@ -17,7 +17,7 @@ const os = require('os'); const fs = require('fs'); const util = require('./util'); const exec = require('child_process').exec; -const execSync = require('child_process').execSync; +const execAsync = util.execAsync; let _platform = process.platform; @@ -164,17 +164,17 @@ function getLogoFile(distro) { // -------------------------- // FQDN -function getFQDN() { +async function getFQDN() { let fqdn = os.hostname; if (_linux || _darwin) { try { - const stdout = execSync('hostnamectl --json short 2>/dev/null', util.execOptsLinux); + const stdout = await execAsync('hostnamectl --json short 2>/dev/null', util.execOptsLinux); const json = JSON.parse(stdout.toString()); fqdn = json['StaticHostname']; } catch (e) { try { - const stdout = execSync('hostname -f 2>/dev/null', util.execOptsLinux); + const stdout = await execAsync('hostname -f 2>/dev/null', util.execOptsLinux); fqdn = stdout.toString().split(os.EOL)[0]; } catch (e) { util.noop(); @@ -183,7 +183,7 @@ function getFQDN() { } if (_freebsd || _openbsd || _netbsd) { try { - const stdout = execSync('hostname 2>/dev/null'); + const stdout = await execAsync('hostname 2>/dev/null'); fqdn = stdout.toString().split(os.EOL)[0]; } catch (e) { util.noop(); @@ -191,7 +191,7 @@ function getFQDN() { } if (_windows) { try { - const stdout = execSync('echo %COMPUTERNAME%.%USERDNSDOMAIN%', util.execOptsWin); + const stdout = await execAsync('echo %COMPUTERNAME%.%USERDNSDOMAIN%', util.execOptsWin); fqdn = stdout.toString().replace('.%USERDNSDOMAIN%', '').split(os.EOL)[0]; } catch (e) { util.noop(); @@ -206,7 +206,7 @@ function getFQDN() { function osInfo(callback) { return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { let result = { platform: (_platform === 'win32' ? 'Windows' : _platform), @@ -216,7 +216,7 @@ function osInfo(callback) { kernel: os.release(), arch: os.arch(), hostname: os.hostname(), - fqdn: getFQDN(), + fqdn: await getFQDN(), codepage: '', logofile: '', serial: '', @@ -227,7 +227,7 @@ function osInfo(callback) { if (_linux) { - exec('cat /etc/*-release; cat /usr/lib/os-release; cat /etc/openwrt_release', function (error, stdout) { + exec('cat /etc/*-release; cat /usr/lib/os-release; cat /etc/openwrt_release', async function (error, stdout) { /** * @namespace * @property {string} DISTRIB_ID @@ -257,7 +257,7 @@ function osInfo(callback) { } result.release = (releaseVersion || release.DISTRIB_RELEASE || release.VERSION_ID || 'unknown').replace(/"/g, ''); result.codename = codename; - result.codepage = util.getCodepage(); + result.codepage = await util.getCodepage(); result.build = (release.BUILD_ID || '').replace(/"/g, '').trim(); isUefiLinux().then(uefi => { result.uefi = uefi; @@ -273,7 +273,7 @@ function osInfo(callback) { } if (_freebsd || _openbsd || _netbsd) { - exec('sysctl kern.ostype kern.osrelease kern.osrevision kern.hostuuid machdep.bootmethod kern.geom.confxml', function (error, stdout) { + exec('sysctl kern.ostype kern.osrelease kern.osrevision kern.hostuuid machdep.bootmethod kern.geom.confxml', async function (error, stdout) { let lines = stdout.toString().split('\n'); const distro = util.getValue(lines, 'kern.ostype'); const logofile = getLogoFile(distro); @@ -287,7 +287,7 @@ function osInfo(callback) { result.release = release || result.release; result.serial = serial || result.serial; result.codename = ''; - result.codepage = util.getCodepage(); + result.codepage = await util.getCodepage(); result.uefi = uefi || null; if (callback) { callback(result); @@ -296,7 +296,7 @@ function osInfo(callback) { }); } if (_darwin) { - exec('sw_vers; sysctl kern.ostype kern.osrelease kern.osrevision kern.uuid', function (error, stdout) { + exec('sw_vers; sysctl kern.ostype kern.osrelease kern.osrevision kern.uuid', async function (error, stdout) { let lines = stdout.toString().split('\n'); result.serial = util.getValue(lines, 'kern.uuid'); result.distro = util.getValue(lines, 'ProductName'); @@ -322,7 +322,7 @@ function osInfo(callback) { result.codename = (result.release.startsWith('14.') ? 'macOS Sonoma' : result.codename); result.codename = (result.release.startsWith('15.') ? 'macOS Sequoia' : result.codename); result.uefi = true; - result.codepage = util.getCodepage(); + result.codepage = await util.getCodepage(); if (callback) { callback(result); } @@ -349,13 +349,13 @@ function osInfo(callback) { workload.push(util.powerShell('Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SystemInformation]::TerminalServerSession')); util.promiseAll( workload - ).then((data) => { + ).then(async (data) => { let lines = data.results[0] ? data.results[0].toString().split('\r\n') : ['']; result.distro = util.getValue(lines, 'Caption', ':').trim(); result.serial = util.getValue(lines, 'SerialNumber', ':').trim(); result.build = util.getValue(lines, 'BuildNumber', ':').trim(); result.servicepack = util.getValue(lines, 'ServicePackMajorVersion', ':').trim() + '.' + util.getValue(lines, 'ServicePackMinorVersion', ':').trim(); - result.codepage = util.getCodepage(); + result.codepage = await util.getCodepage(); const hyperv = data.results[1] ? data.results[1].toString().toLowerCase() : ''; result.hypervisor = hyperv.indexOf('true') !== -1; const term = data.results[2] ? data.results[2].toString() : ''; @@ -500,7 +500,7 @@ function versions(apps, callback) { } return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { if (util.isFunction(apps) && !callback) { callback = apps; apps = '*'; @@ -796,7 +796,7 @@ function versions(apps, callback) { if ({}.hasOwnProperty.call(appsObj.versions, 'python')) { if (_darwin) { try { - const stdout = execSync('sw_vers'); + const stdout = await execAsync('sw_vers'); const lines = stdout.toString().split('\n'); const osVersion = util.getValue(lines, 'ProductVersion', ':'); const gitHomebrewExists1 = fs.existsSync('/usr/local/Cellar/python'); @@ -1126,12 +1126,12 @@ function uuid(callback) { const cmd = `echo -n "os: "; cat /var/lib/dbus/machine-id 2> /dev/null || cat /etc/machine-id 2> /dev/null; echo; echo -n "hardware: "; cat /sys/class/dmi/id/product_uuid 2> /dev/null; echo;`; - exec(cmd, function (error, stdout) { + exec(cmd, async function (error, stdout) { const lines = stdout.toString().split('\n'); result.os = util.getValue(lines, 'os').toLowerCase(); result.hardware = util.getValue(lines, 'hardware').toLowerCase(); if (!result.hardware) { - const lines = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n'); + const lines = (await fs.promises.readFile('/proc/cpuinfo', { encoding: 'utf8' })).toString().split('\n'); const serial = util.getValue(lines, 'serial'); result.hardware = serial || ''; } diff --git a/lib/processes.js b/lib/processes.js index 3ee5a60d..739ac3bf 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -17,9 +17,8 @@ const os = require('os'); const fs = require('fs'); const path = require('path'); const exec = require('child_process').exec; -const execSync = require('child_process').execSync; - const util = require('./util'); +const execAsync = util.execAsync; let _platform = process.platform; @@ -118,7 +117,7 @@ function services(srv, callback) { } return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { if (typeof srv !== 'string') { if (callback) { callback([]); } return resolve([]); @@ -152,7 +151,7 @@ function services(srv, callback) { if (_linux || _freebsd || _openbsd || _netbsd || _darwin) { if ((_linux || _freebsd || _openbsd || _netbsd) && srvString === '*') { try { - const tmpsrv = execSync('systemctl --all --type=service --no-legend 2> /dev/null', util.execOptsLinux).toString().split('\n'); + const tmpsrv = (await execAsync('systemctl --all --type=service --no-legend 2> /dev/null', util.execOptsLinux)).toString().split('\n'); srvs = []; for (const s of tmpsrv) { const name = s.split('.service')[0]; @@ -164,7 +163,7 @@ function services(srv, callback) { } catch (d) { try { srvString = ''; - const tmpsrv = execSync('service --status-all 2> /dev/null', util.execOptsLinux).toString().split('\n'); + const tmpsrv = (await execAsync('service --status-all 2> /dev/null', util.execOptsLinux)).toString().split('\n'); for (const s of tmpsrv) { const parts = s.split(']'); if (parts.length === 2) { @@ -174,7 +173,7 @@ function services(srv, callback) { srvs = srvString.split('|'); } catch (e) { try { - const srvStr = execSync('ls /etc/init.d/ -m 2> /dev/null', util.execOptsLinux).toString().split('\n').join(''); + const srvStr = (await execAsync('ls /etc/init.d/ -m 2> /dev/null', util.execOptsLinux)).toString().split('\n').join(''); srvString = ''; if (srvStr) { const tmpsrv = srvStr.split(','); diff --git a/lib/system.js b/lib/system.js index a4f9677b..107185e8 100644 --- a/lib/system.js +++ b/lib/system.js @@ -17,8 +17,7 @@ const fs = require('fs'); const os = require('os'); const util = require('./util'); const exec = require('child_process').exec; -const execSync = require('child_process').execSync; -const execPromise = util.promisify(require('child_process').exec); +const execAsync = util.execAsync; let _platform = process.platform; @@ -33,7 +32,7 @@ const _sunos = (_platform === 'sunos'); function system(callback) { return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { let result = { manufacturer: '', @@ -46,7 +45,7 @@ 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', async function (error, stdout) { let lines = stdout.toString().split('\n'); result.manufacturer = util.getValue(lines, 'manufacturer'); result.model = util.getValue(lines, 'product name'); @@ -61,7 +60,7 @@ function system(callback) { echo -n "product_version: "; cat /sys/devices/virtual/dmi/id/product_version 2>/dev/null; echo; echo -n "sys_vendor: "; cat /sys/devices/virtual/dmi/id/sys_vendor 2>/dev/null; echo;`; try { - lines = execSync(cmd, util.execOptsLinux).toString().split('\n'); + lines = (await execAsync(cmd, util.execOptsLinux)).toString().split('\n'); result.manufacturer = result.manufacturer === '' ? util.getValue(lines, 'sys_vendor') : result.manufacturer; result.model = result.model === '' ? util.getValue(lines, 'product_name') : result.model; result.version = result.version === '' ? util.getValue(lines, 'product_version') : result.version; @@ -107,7 +106,7 @@ function system(callback) { } if (!result.virtual) { try { - const disksById = execSync('ls -1 /dev/disk/by-id/ 2>/dev/null', util.execOptsLinux).toString(); + const disksById = (await execAsync('ls -1 /dev/disk/by-id/ 2>/dev/null', util.execOptsLinux)).toString(); if (disksById.indexOf('_QEMU_') >= 0) { result.virtual = true; result.virtualHost = 'QEMU'; @@ -129,7 +128,7 @@ function system(callback) { } if ((_freebsd || _openbsd || _netbsd) && !result.virtualHost) { try { - const procInfo = execSync('dmidecode -t 4', util.execOptsLinux); + const procInfo = await execAsync('dmidecode -t 4', util.execOptsLinux); const procLines = procInfo.toString().split('\n'); const procManufacturer = util.getValue(procLines, 'manufacturer', ':', true); switch (procManufacturer.toLowerCase()) { @@ -155,7 +154,7 @@ function system(callback) { result.model = 'Docker Container'; } try { - const stdout = execSync('dmesg 2>/dev/null | grep -iE "virtual|hypervisor" | grep -iE "vmware|qemu|kvm|xen" | grep -viE "Nested Virtualization|/virtual/"'); + const stdout = await execAsync('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'); if (lines.length > 0) { @@ -344,7 +343,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, async function (error, stdout) { let lines = stdout.toString().split('\n'); result.vendor = util.getValue(lines, 'Vendor'); result.version = util.getValue(lines, 'Version'); @@ -371,7 +370,7 @@ function bios(callback) { echo -n "bios_vendor: "; cat /sys/devices/virtual/dmi/id/bios_vendor 2>/dev/null; echo; echo -n "bios_version: "; cat /sys/devices/virtual/dmi/id/bios_version 2>/dev/null; echo;`; try { - lines = execSync(cmd, util.execOptsLinux).toString().split('\n'); + lines = (await execAsync(cmd, util.execOptsLinux)).toString().split('\n'); result.vendor = !result.vendor ? util.getValue(lines, 'bios_vendor') : result.vendor; result.version = !result.version ? util.getValue(lines, 'bios_version') : result.version; datetime = util.getValue(lines, 'bios_date'); @@ -467,11 +466,11 @@ function baseboard(callback) { cmd = 'export LC_ALL=C; dmidecode -t 2 2>/dev/null; unset LC_ALL'; } const workload = []; - workload.push(execPromise(cmd)); - workload.push(execPromise('export LC_ALL=C; dmidecode -t memory 2>/dev/null')); + workload.push(execAsync(cmd)); + workload.push(execAsync('export LC_ALL=C; dmidecode -t memory 2>/dev/null')); util.promiseAll( workload - ).then((data) => { + ).then(async (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')); @@ -485,7 +484,7 @@ function baseboard(callback) { echo -n "board_vendor: "; cat /sys/devices/virtual/dmi/id/board_vendor 2>/dev/null; echo; echo -n "board_version: "; cat /sys/devices/virtual/dmi/id/board_version 2>/dev/null; echo;`; try { - lines = execSync(cmd, util.execOptsLinux).toString().split('\n'); + lines = (await execAsync(cmd, util.execOptsLinux)).toString().split('\n'); result.manufacturer = cleanDefaults(!result.manufacturer ? util.getValue(lines, 'board_vendor') : result.manufacturer); result.model = cleanDefaults(!result.model ? util.getValue(lines, 'board_name') : result.model); result.version = cleanDefaults(!result.version ? util.getValue(lines, 'board_version') : result.version); @@ -503,7 +502,7 @@ function baseboard(callback) { // raspberry let linesRpi = ''; try { - linesRpi = fs.readFileSync('/proc/cpuinfo').toString().split('\n'); + linesRpi = (await fs.promises.readFile('/proc/cpuinfo')).toString().split('\n'); } catch (e) { util.noop(); } @@ -526,8 +525,8 @@ function baseboard(callback) { } if (_darwin) { const workload = []; - workload.push(execPromise('ioreg -c IOPlatformExpertDevice -d 2')); - workload.push(execPromise('system_profiler SPMemoryDataType')); + workload.push(execAsync('ioreg -c IOPlatformExpertDevice -d 2')); + workload.push(execAsync('system_profiler SPMemoryDataType')); util.promiseAll( workload ).then((data) => { diff --git a/lib/util.js b/lib/util.js index 3c59d0de..3fb0886f 100644 --- a/lib/util.js +++ b/lib/util.js @@ -18,7 +18,7 @@ const fs = require('fs'); const path = require('path'); const spawn = require('child_process').spawn; const exec = require('child_process').exec; -const execSync = require('child_process').execSync; +const execAsync = promisify(exec); const util = require('util'); let _platform = process.platform; @@ -330,12 +330,12 @@ function findObjectByKey(array, key, value) { return -1; } -function getWmic() { +async function getWmic() { if (os.type() === 'Windows_NT' && !wmicPath) { wmicPath = WINDIR + '\\system32\\wbem\\wmic.exe'; if (!fs.existsSync(wmicPath)) { try { - const wmicPathArray = execSync('WHERE WMIC', execOptsWin).toString().split('\r\n'); + const wmicPathArray = (await execAsync('WHERE WMIC', execOptsWin)).toString().split('\r\n'); if (wmicPathArray && wmicPathArray.length) { wmicPath = wmicPathArray[0]; } else { @@ -351,9 +351,9 @@ function getWmic() { function wmic(command) { return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { try { - powerShell(getWmic() + ' ' + command).then(stdout => { + powerShell((await getWmic()) + ' ' + command).then(stdout => { resolve(stdout, ''); }); } catch (e) { @@ -562,11 +562,11 @@ function execSafe(cmd, args, options) { }); } -function getCodepage() { +async function getCodepage() { if (_windows) { if (!codepage) { try { - const stdout = execSync('chcp', execOptsWin); + const stdout = await execAsync('chcp', execOptsWin); const lines = stdout.toString().split('\r\n'); const parts = lines[0].split(':'); codepage = parts.length > 1 ? parts[1].replace('.', '').trim() : ''; @@ -579,7 +579,7 @@ function getCodepage() { if (_linux || _darwin || _freebsd || _openbsd || _netbsd) { if (!codepage) { try { - const stdout = execSync('echo $LANG', util.execOptsLinux); + const stdout = await execAsync('echo $LANG', util.execOptsLinux); const lines = stdout.toString().split('\r\n'); const parts = lines[0].split('.'); codepage = parts.length > 1 ? parts[1].trim() : ''; @@ -594,14 +594,14 @@ function getCodepage() { } } -function smartMonToolsInstalled() { +async function smartMonToolsInstalled() { if (_smartMonToolsInstalled !== null) { return _smartMonToolsInstalled; } _smartMonToolsInstalled = false; if (_windows) { try { - const pathArray = execSync('WHERE smartctl 2>nul', execOptsWin).toString().split('\r\n'); + const pathArray = (await execAsync('WHERE smartctl 2>nul', execOptsWin)).toString().split('\r\n'); if (pathArray && pathArray.length) { _smartMonToolsInstalled = pathArray[0].indexOf(':\\') >= 0; } else { @@ -613,7 +613,7 @@ function smartMonToolsInstalled() { } if (_linux || _darwin || _freebsd || _openbsd || _netbsd) { try { - const pathArray = execSync('which smartctl 2>/dev/null', execOptsLinux).toString().split('\r\n'); + const pathArray = (await execAsync('which smartctl 2>/dev/null', execOptsLinux)).toString().split('\r\n'); _smartMonToolsInstalled = pathArray.length > 0; } catch (e) { util.noop(); @@ -622,7 +622,7 @@ function smartMonToolsInstalled() { return _smartMonToolsInstalled; } -function isRaspberry() { +async function isRaspberry() { const PI_MODEL_NO = [ 'BCM2708', 'BCM2709', @@ -640,7 +640,7 @@ function isRaspberry() { cpuinfo = _rpi_cpuinfo; } else { try { - cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n'); + cpuinfo = (await fs.promises.readFile('/proc/cpuinfo', { encoding: 'utf8' })).toString().split('\n'); _rpi_cpuinfo = cpuinfo; } catch (e) { return false; @@ -651,10 +651,10 @@ function isRaspberry() { return (hardware && PI_MODEL_NO.indexOf(hardware) > -1); } -function isRaspbian() { +async function isRaspbian() { let osrelease = []; try { - osrelease = fs.readFileSync('/etc/os-release', { encoding: 'utf8' }).toString().split('\n'); + osrelease = (await fs.promises.readFile('/etc/os-release', { encoding: 'utf8' })).toString().split('\n'); } catch (e) { return false; } @@ -1062,13 +1062,13 @@ function decodePiCpuinfo(lines) { return result; } -function getRpiGpu() { +async function getRpiGpu() { let cpuinfo = null; if (_rpi_cpuinfo !== null) { cpuinfo = _rpi_cpuinfo; } else { try { - cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n'); + cpuinfo = (await fs.promises.readFile('/proc/cpuinfo', { encoding: 'utf8' })).toString().split('\n'); _rpi_cpuinfo = cpuinfo; } catch (e) { return false; @@ -1136,23 +1136,11 @@ function promisify(nodeStyleFunction) { }; } -function promisifySave(nodeStyleFunction) { - return function () { - const args = Array.prototype.slice.call(arguments); - return new Promise(function (resolve) { - args.push(function (err, data) { - resolve(data); - }); - nodeStyleFunction.apply(null, args); - }); - }; -} - -function linuxVersion() { +async function linuxVersion() { let result = ''; if (_linux) { try { - result = execSync('uname -v', util.execOptsLinux).toString(); + result = (await execAsync('uname -v', util.execOptsLinux)).toString(); } catch (e) { result = ''; } @@ -1356,7 +1344,6 @@ exports.decodePiCpuinfo = decodePiCpuinfo; exports.getRpiGpu = getRpiGpu; exports.promiseAll = promiseAll; exports.promisify = promisify; -exports.promisifySave = promisifySave; exports.smartMonToolsInstalled = smartMonToolsInstalled; exports.linuxVersion = linuxVersion; exports.plistParser = plistParser; @@ -1371,3 +1358,4 @@ exports.mathMin = mathMin; exports.WINDIR = WINDIR; exports.getFilesInPath = getFilesInPath; exports.semverCompare = semverCompare; +exports.execAsync = execAsync; diff --git a/lib/wifi.js b/lib/wifi.js index 40764f79..e803d109 100644 --- a/lib/wifi.js +++ b/lib/wifi.js @@ -15,8 +15,8 @@ const os = require('os'); const exec = require('child_process').exec; -const execSync = require('child_process').execSync; const util = require('./util'); +const execAsync = util.execAsync let _platform = process.platform; @@ -126,11 +126,11 @@ function wifiChannelFromFrequencs(frequency) { return channel; } -function ifaceListLinux() { +async 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 = (await execAsync(cmd, util.execOptsLinux)).toString().split('\n').map(line => line.trim()).join('\n'); const parts = all.split('\nInterface '); parts.shift(); parts.forEach(ifaceDetails => { @@ -149,7 +149,7 @@ function ifaceListLinux() { return result; } catch (e) { try { - const all = execSync('nmcli -t -f general,wifi-properties,wired-properties,interface-flags,capabilities,nsp device show 2>/dev/null', util.execOptsLinux).toString(); + const all = (await execAsync('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 => { @@ -175,10 +175,10 @@ function ifaceListLinux() { } } -function nmiDeviceLinux(iface) { +async function nmiDeviceLinux(iface) { const cmd = `nmcli -t -f general,wifi-properties,capabilities,ip4,ip6 device show ${iface} 2>/dev/null`; try { - const lines = execSync(cmd, util.execOptsLinux).toString().split('\n'); + const lines = (await execAsync(cmd, util.execOptsLinux)).toString().split('\n'); const ssid = util.getValue(lines, 'GENERAL.CONNECTION'); return { iface, @@ -193,10 +193,10 @@ function nmiDeviceLinux(iface) { } } -function nmiConnectionLinux(ssid) { +async function nmiConnectionLinux(ssid) { const cmd = `nmcli -t --show-secrets connection show ${ssid} 2>/dev/null`; try { - const lines = execSync(cmd, util.execOptsLinux).toString().split('\n'); + const lines = (await execAsync(cmd, util.execOptsLinux)).toString().split('\n'); const bssid = util.getValue(lines, '802-11-wireless.seen-bssids').toLowerCase(); return { ssid: ssid !== '--' ? ssid : null, @@ -211,13 +211,13 @@ function nmiConnectionLinux(ssid) { } } -function wpaConnectionLinux(iface) { +async function wpaConnectionLinux(iface) { if (!iface) { return {}; } const cmd = `wpa_cli -i ${iface} status 2>&1`; try { - const lines = execSync(cmd, util.execOptsLinux).toString().split('\n'); + const lines = (await execAsync(cmd, util.execOptsLinux)).toString().split('\n'); const freq = util.toInt(util.getValue(lines, 'freq', '=')); return { ssid: util.getValue(lines, 'ssid', '='), @@ -232,11 +232,11 @@ function wpaConnectionLinux(iface) { } } -function getWifiNetworkListNmi() { +async function getWifiNetworkListNmi() { const result = []; const cmd = 'nmcli -t -m multiline --fields active,ssid,bssid,mode,chan,freq,signal,security,wpa-flags,rsn-flags device wifi list 2>/dev/null'; try { - const stdout = execSync(cmd, util.execOptsLinux); + const stdout = await execAsync(cmd, util.execOptsLinux); const parts = stdout.toString().split('ACTIVE:'); parts.shift(); parts.forEach(part => { @@ -267,10 +267,10 @@ function getWifiNetworkListNmi() { } } -function getWifiNetworkListIw(iface) { +async 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 '); + let iwlistParts = (await execAsync(`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.length > 1) { iwlistParts.shift(); @@ -398,13 +398,13 @@ function parseWifiDarwin(wifiObj) { } function wifiNetworks(callback) { return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { let result = []; if (_linux) { - result = getWifiNetworkListNmi(); + result = await getWifiNetworkListNmi(); if (result.length === 0) { try { - const iwconfigParts = execSync('export LC_ALL=C; iwconfig 2>/dev/null; unset LC_ALL', util.execOptsLinux).toString().split('\n\n'); + const iwconfigParts = (await execAsync('export LC_ALL=C; iwconfig 2>/dev/null; unset LC_ALL', util.execOptsLinux)).toString().split('\n\n'); let iface = ''; iwconfigParts.forEach(element => { if (element.indexOf('no wireless') === -1 && element.trim() !== '') { @@ -422,11 +422,11 @@ function wifiNetworks(callback) { } } - const res = getWifiNetworkListIw(ifaceSanitized); + const res = await getWifiNetworkListIw(ifaceSanitized); if (res === -1) { // try again after 4 secs - setTimeout(function (iface) { - const res = getWifiNetworkListIw(iface); + setTimeout(async function (iface) { + const res = await getWifiNetworkListIw(iface); if (res != -1) { result = res; } if (callback) { callback(result); @@ -548,13 +548,13 @@ function formatBssid(s) { function wifiConnections(callback) { return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { const result = []; if (_linux) { - const ifaces = ifaceListLinux(); - const networkList = getWifiNetworkListNmi(); - ifaces.forEach(ifaceDetail => { + const ifaces = await ifaceListLinux(); + const networkList = await getWifiNetworkListNmi(); + for (let ifaceDetail of ifaces) { let ifaceSanitized = ''; const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(ifaceDetail.iface, true); const ll = util.mathMin(s.length, 2000); @@ -565,8 +565,8 @@ function wifiConnections(callback) { } } - const nmiDetails = nmiDeviceLinux(ifaceSanitized); - const wpaDetails = wpaConnectionLinux(ifaceSanitized); + const nmiDetails = await nmiDeviceLinux(ifaceSanitized); + const wpaDetails = await wpaConnectionLinux(ifaceSanitized); const ssid = nmiDetails.ssid || wpaDetails.ssid; const network = networkList.filter(nw => nw.ssid === ssid); let ssidSanitized = ''; @@ -578,7 +578,7 @@ function wifiConnections(callback) { } } - const nmiConnection = nmiConnectionLinux(ssidSanitized); + const nmiConnection = await 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 signalLevel = network && network.length && network[0].signalLevel ? network[0].signalLevel : null; @@ -598,7 +598,7 @@ function wifiConnections(callback) { txRate: null }); } - }); + } if (callback) { callback(result); } @@ -745,13 +745,13 @@ exports.wifiConnections = wifiConnections; function wifiInterfaces(callback) { return new Promise((resolve) => { - process.nextTick(() => { + process.nextTick(async () => { const result = []; if (_linux) { - const ifaces = ifaceListLinux(); - ifaces.forEach(ifaceDetail => { - const nmiDetails = nmiDeviceLinux(ifaceDetail.iface); + const ifaces = await ifaceListLinux(); + for (let ifaceDetail of ifaces) { + const nmiDetails = await nmiDeviceLinux(ifaceDetail.iface); result.push({ id: ifaceDetail.id, iface: ifaceDetail.iface, @@ -759,7 +759,7 @@ function wifiInterfaces(callback) { vendor: nmiDetails.vendor ? nmiDetails.vendor : null, mac: ifaceDetail.mac, }); - }); + } if (callback) { callback(result); }