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