code cleanup
This commit is contained in:
parent
cecf398b01
commit
515163eff4
@ -161,7 +161,7 @@ function mem(callback) {
|
||||
|
||||
if (_linux) {
|
||||
try {
|
||||
fs.readFile('/proc/meminfo', function (error, stdout) {
|
||||
fs.readFile('/proc/meminfo', (error, stdout) => {
|
||||
if (!error) {
|
||||
const lines = stdout.toString().split('\n');
|
||||
result.total = parseInt(util.getValue(lines, 'memtotal'), 10);
|
||||
@ -199,7 +199,7 @@ function mem(callback) {
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
} catch (e) {
|
||||
} catch {
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
@ -210,9 +210,9 @@ function mem(callback) {
|
||||
try {
|
||||
exec(
|
||||
'/sbin/sysctl hw.realmem hw.physmem vm.stats.vm.v_page_count vm.stats.vm.v_wire_count vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count vm.stats.vm.v_page_size',
|
||||
function (error, stdout) {
|
||||
(error, stdout) => {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
const lines = stdout.toString().split('\n');
|
||||
const pagesize = parseInt(util.getValue(lines, 'vm.stats.vm.v_page_size'), 10);
|
||||
const inactive = parseInt(util.getValue(lines, 'vm.stats.vm.v_inactive_count'), 10) * pagesize;
|
||||
const cache = parseInt(util.getValue(lines, 'vm.stats.vm.v_cache_count'), 10) * pagesize;
|
||||
@ -236,7 +236,7 @@ function mem(callback) {
|
||||
resolve(result);
|
||||
}
|
||||
);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
@ -254,11 +254,11 @@ function mem(callback) {
|
||||
try {
|
||||
let sysPpageSize = util.toInt(execSync('sysctl -n vm.pagesize').toString());
|
||||
pageSize = sysPpageSize || pageSize;
|
||||
} catch (e) {
|
||||
} catch {
|
||||
util.noop();
|
||||
}
|
||||
try {
|
||||
exec('vm_stat 2>/dev/null | egrep "Pages active|Pages inactive"', function (error, stdout) {
|
||||
exec('vm_stat 2>/dev/null | egrep "Pages active|Pages inactive"', (error, stdout) => {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
result.active = (parseInt(util.getValue(lines, 'Pages active'), 10) || 0) * pageSize;
|
||||
@ -266,7 +266,7 @@ function mem(callback) {
|
||||
result.buffcache = result.used - result.active;
|
||||
result.available = result.free + result.buffcache;
|
||||
}
|
||||
exec('sysctl -n vm.swapusage 2>/dev/null', function (error, stdout) {
|
||||
exec('sysctl -n vm.swapusage 2>/dev/null', (error, stdout) => {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
if (lines.length > 0) {
|
||||
@ -291,7 +291,7 @@ function mem(callback) {
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
} catch {
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
@ -308,7 +308,7 @@ function mem(callback) {
|
||||
.split('\r\n')
|
||||
.filter((line) => line.trim() !== '')
|
||||
.filter((line, idx) => idx > 0);
|
||||
lines.forEach(function (line) {
|
||||
lines.forEach((line) => {
|
||||
if (line !== '') {
|
||||
line = line.trim().split(/\s\s+/);
|
||||
swaptotal = swaptotal + (parseInt(line[0], 10) || 0);
|
||||
@ -325,7 +325,7 @@ function mem(callback) {
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
} catch (e) {
|
||||
} catch {
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
@ -354,12 +354,12 @@ function memLayout(callback) {
|
||||
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) {
|
||||
(error, stdout) => {
|
||||
if (!error) {
|
||||
let devices = stdout.toString().split('Memory Device');
|
||||
const devices = stdout.toString().split('Memory Device');
|
||||
devices.shift();
|
||||
devices.forEach(function (device) {
|
||||
let lines = device.split('\n');
|
||||
devices.forEach((device) => {
|
||||
const lines = device.split('\n');
|
||||
const sizeString = util.getValue(lines, 'Size');
|
||||
const size = sizeString.indexOf('GB') >= 0 ? parseInt(sizeString, 10) * 1024 * 1024 * 1024 : parseInt(sizeString, 10) * 1024 * 1024;
|
||||
let bank = util.getValue(lines, 'Bank Locator');
|
||||
@ -457,7 +457,7 @@ function memLayout(callback) {
|
||||
result[0].voltageMax = voltage;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
@ -470,7 +470,7 @@ function memLayout(callback) {
|
||||
}
|
||||
|
||||
if (_darwin) {
|
||||
exec('system_profiler SPMemoryDataType', function (error, stdout) {
|
||||
exec('system_profiler SPMemoryDataType', (error, stdout) => {
|
||||
if (!error) {
|
||||
const allLines = stdout.toString().split('\n');
|
||||
const eccStatus = util.getValue(allLines, 'ecc', ':', true).toLowerCase();
|
||||
@ -481,8 +481,8 @@ function memLayout(callback) {
|
||||
hasBank = false;
|
||||
}
|
||||
devices.shift();
|
||||
devices.forEach(function (device) {
|
||||
let lines = device.split('\n');
|
||||
devices.forEach((device) => {
|
||||
const lines = device.split('\n');
|
||||
const bank = (hasBank ? 'BANK ' : 'DIMM') + lines[0].trim().split('/')[0];
|
||||
const size = parseInt(util.getValue(lines, ' Size'));
|
||||
if (size) {
|
||||
@ -567,10 +567,10 @@ function memLayout(callback) {
|
||||
)
|
||||
.then((stdout, error) => {
|
||||
if (!error) {
|
||||
let devices = stdout.toString().split(/\n\s*\n/);
|
||||
const devices = stdout.toString().split(/\n\s*\n/);
|
||||
devices.shift();
|
||||
devices.forEach(function (device) {
|
||||
let lines = device.split('\r\n');
|
||||
devices.forEach((device) => {
|
||||
const lines = device.split('\r\n');
|
||||
const dataWidth = util.toInt(util.getValue(lines, 'DataWidth', ':'));
|
||||
const totalWidth = util.toInt(util.getValue(lines, 'TotalWidth', ':'));
|
||||
const size = parseInt(util.getValue(lines, 'Capacity', ':'), 10) || 0;
|
||||
@ -599,7 +599,7 @@ function memLayout(callback) {
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
} catch (e) {
|
||||
} catch {
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ function getDefaultNetworkInterface() {
|
||||
ifacename = ifacename.split(':')[1].trim();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
util.noop();
|
||||
}
|
||||
if (ifacename) {
|
||||
@ -143,7 +143,7 @@ function getMacAddresses() {
|
||||
} else {
|
||||
pathToIp = '';
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
pathToIp = '';
|
||||
}
|
||||
}
|
||||
@ -172,14 +172,14 @@ function getMacAddresses() {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
if (_darwin) {
|
||||
try {
|
||||
const cmd = '/sbin/ifconfig';
|
||||
let res = execSync(cmd);
|
||||
const res = execSync(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) {
|
||||
@ -193,7 +193,7 @@ function getMacAddresses() {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
@ -223,11 +223,11 @@ function parseLinesWindowsNics(sections, nconfigsections) {
|
||||
try {
|
||||
if ({}.hasOwnProperty.call(sections, i)) {
|
||||
if (sections[i].trim() !== '') {
|
||||
let lines = sections[i].trim().split('\r\n');
|
||||
const lines = sections[i].trim().split('\r\n');
|
||||
let linesNicConfig = null;
|
||||
try {
|
||||
linesNicConfig = nconfigsections && nconfigsections[i] ? nconfigsections[i].trim().split('\r\n') : [];
|
||||
} catch (e) {
|
||||
} catch {
|
||||
util.noop();
|
||||
}
|
||||
const netEnabled = util.getValue(lines, 'NetEnabled', ':');
|
||||
@ -252,7 +252,7 @@ function parseLinesWindowsNics(sections, nconfigsections) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
@ -271,7 +271,7 @@ function getWindowsNics() {
|
||||
const nconfigsections = (data[1] || '').split(/\n\s*\n/);
|
||||
resolve(parseLinesWindowsNics(nsections, nconfigsections));
|
||||
});
|
||||
} catch (e) {
|
||||
} catch {
|
||||
resolve([]);
|
||||
}
|
||||
});
|
||||
@ -319,7 +319,7 @@ function getWindowsDNSsuffixes() {
|
||||
});
|
||||
|
||||
return dnsSuffixes;
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return {
|
||||
primaryDNS: '',
|
||||
exitCode: 0,
|
||||
@ -345,7 +345,7 @@ function getWindowsIfaceDNSsuffix(ifaces, ifacename) {
|
||||
dnsSuffix = '';
|
||||
}
|
||||
return dnsSuffix;
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return 'Unknown';
|
||||
}
|
||||
}
|
||||
@ -355,7 +355,7 @@ function getWindowsWiredProfilesInformation() {
|
||||
const result = execSync('netsh lan show profiles', util.execOptsWin);
|
||||
const profileList = result.split('\r\nProfile on interface');
|
||||
return profileList;
|
||||
} catch (error) {
|
||||
} catch {
|
||||
if (error.status === 1 && error.stdout.includes('AutoConfig')) {
|
||||
return 'Disabled';
|
||||
}
|
||||
@ -369,7 +369,7 @@ function getWindowsWirelessIfaceSSID(interfaceName) {
|
||||
const SSID = result.split('\r\n').shift();
|
||||
const parseSSID = SSID.split(':').pop().trim();
|
||||
return parseSSID;
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return 'Unknown';
|
||||
}
|
||||
}
|
||||
@ -406,7 +406,7 @@ function getWindowsIEEE8021x(connectionType, iface, ifaces) {
|
||||
i8021x.protocol = protocol8021x.split(':').pop();
|
||||
i8021x.state = 'Enabled';
|
||||
}
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return i8021x;
|
||||
}
|
||||
} else if (connectionType === 'wireless') {
|
||||
@ -434,7 +434,7 @@ function getWindowsIEEE8021x(connectionType, iface, ifaces) {
|
||||
i8021x.state = i8021xState.split(':').pop();
|
||||
i8021x.protocol = i8021xProtocol.split(':').pop();
|
||||
}
|
||||
} catch (error) {
|
||||
} catch {
|
||||
if (error.status === 1 && error.stdout.includes('AutoConfig')) {
|
||||
i8021x.state = 'Disabled';
|
||||
i8021x.protocol = 'Not defined';
|
||||
@ -465,9 +465,9 @@ function splitSectionsNics(lines) {
|
||||
}
|
||||
|
||||
function parseLinesDarwinNics(sections) {
|
||||
let nics = [];
|
||||
const nics = [];
|
||||
sections.forEach((section) => {
|
||||
let nic = {
|
||||
const nic = {
|
||||
iface: '',
|
||||
mtu: null,
|
||||
mac: '',
|
||||
@ -1477,7 +1477,7 @@ function networkStatsSingle(iface) {
|
||||
result.operstate = (result.operstate || '').toLowerCase();
|
||||
result.operstate = result.operstate === 'active' ? 'up' : result.operstate === 'inactive' ? 'down' : 'unknown';
|
||||
cmd = 'netstat -bdI ' + ifaceSanitized; // lgtm [js/shell-command-constructed-from-input]
|
||||
exec(cmd, function (error, stdout) {
|
||||
exec(cmd, (error, stdout) => {
|
||||
if (!error) {
|
||||
lines = stdout.toString().split('\n');
|
||||
// if there is less than 2 lines, no information for this interface was found
|
||||
|
||||
@ -117,7 +117,7 @@ function printer(callback) {
|
||||
let result = [];
|
||||
if (_linux || _freebsd || _openbsd || _netbsd) {
|
||||
let cmd = 'cat /etc/cups/printers.conf 2>/dev/null';
|
||||
exec(cmd, function (error, stdout) {
|
||||
exec(cmd, (error, stdout) => {
|
||||
// printers.conf
|
||||
if (!error) {
|
||||
const parts = stdout.toString().split('<Printer ');
|
||||
@ -135,7 +135,7 @@ function printer(callback) {
|
||||
if (_linux) {
|
||||
cmd = 'export LC_ALL=C; lpstat -lp 2>/dev/null; unset LC_ALL';
|
||||
// lpstat
|
||||
exec(cmd, function (error, stdout) {
|
||||
exec(cmd, (error, stdout) => {
|
||||
const parts = ('\n' + stdout.toString()).split('\nprinter ');
|
||||
for (let i = 1; i < parts.length; i++) {
|
||||
const printers = parseLinuxLpstatPrinter(parts[i].split('\n'), i);
|
||||
@ -162,7 +162,7 @@ function printer(callback) {
|
||||
}
|
||||
if (_darwin) {
|
||||
let cmd = 'system_profiler SPPrintersDataType -json';
|
||||
exec(cmd, function (error, stdout) {
|
||||
exec(cmd, (error, stdout) => {
|
||||
if (!error) {
|
||||
try {
|
||||
const outObj = JSON.parse(stdout.toString());
|
||||
@ -172,7 +172,7 @@ function printer(callback) {
|
||||
result.push(printer);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user