code refactoring

This commit is contained in:
Sebastian Hildebrandt 2021-03-16 11:17:37 +01:00
parent cc15927a38
commit 2c54d64aed
6 changed files with 25 additions and 21 deletions

View File

@ -77,6 +77,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 5.6.6 | 2021-03-16 | code refactoring |
| 5.6.5 | 2021-03-15 | `cpuTemperature()` fix (linux) |
| 5.6.4 | 2021-03-15 | `sanitizeShellString()` and other security improvements |
| 5.6.3 | 2021-03-14 | `sanitizeShellString()` improvement |

View File

@ -56,6 +56,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">5.6.6</th>
<td>2021-03-16</td>
<td>code refactoring</td>
</tr>
<tr>
<th scope="row">5.6.5</th>
<td>2021-03-15</td>

View File

@ -170,7 +170,7 @@
<img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span>&nbsp;</div>
<div class="version">New Version: <span id="version">5.6.5</span></div>
<div class="version">New Version: <span id="version">5.6.6</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div>
<div class="down">
@ -201,7 +201,7 @@
</div>
<div class="row number-section">
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
<div class="numbers">14,185</div>
<div class="numbers">14,225</div>
<div class="title">Lines of code</div>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
@ -209,7 +209,7 @@
<div class="title">Downloads last month</div>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
<div class="numbers">397</div>
<div class="numbers">398</div>
<div class="title">Dependents</div>
</div>
</div>

View File

@ -67,7 +67,7 @@ function inetChecksite(url, callback) {
let args = ['-I', '--connect-timeout', '5', '-m', '5'];
args.push(urlSanitized);
let cmd = 'curl';
util.execSave(cmd, args).then((stdout) => {
util.execSafe(cmd, args).then((stdout) => {
const lines = stdout.split('\n');
let statusCode = lines[0] && lines[0].indexOf(' ') >= 0 ? parseInt(lines[0].split(' ')[1], 10) : 404;
result.status = statusCode || 404;
@ -161,18 +161,18 @@ function inetLatency(host, callback) {
let filt;
if (_linux || _freebsd || _openbsd || _netbsd || _darwin) {
if (_linux) {
params = '-c 2 -w 3 ' + hostSanitized;
params = ['-c', '2', '-w', '3', hostSanitized];
filt = 'rtt';
}
if (_freebsd || _openbsd || _netbsd) {
params = '-c 2 -t 3 ' + hostSanitized;
params = ['-c', '2', '-t', '3', hostSanitized];
filt = 'round-trip';
}
if (_darwin) {
params = '-c2 -t3 ' + hostSanitized;
params = ['-c2', '-t3', hostSanitized];
filt = 'avg';
}
util.execSave('ping', params.split(' ')).then((stdout) => {
util.execSafe('ping', params).then((stdout) => {
let result = null;
if (stdout) {
const lines = stdout.split('\n').filter(line => line.indexOf(filt) >= 0).join('\n');
@ -190,9 +190,9 @@ function inetLatency(host, callback) {
});
}
if (_sunos) {
const params = '-s -a ' + hostSanitized + ' 56 2';
const params = ['-s', '-a', hostSanitized, '56', '2'];
const filt = 'avg';
util.execSave('ping', params.split(' '), { timeout: 3000 }).then((stdout) => {
util.execSafe('ping', params, { timeout: 3000 }).then((stdout) => {
let result = null;
if (stdout) {
const lines = stdout.split('\n').filter(line => line.indexOf(filt) >= 0).join('\n');
@ -211,8 +211,8 @@ function inetLatency(host, callback) {
if (_windows) {
let result = null;
try {
const params = hostSanitized + ' -n 1';
util.execSave('ping', params.split(' '), util.execOptsWin).then((stdout) => {
const params = [hostSanitized, '-n', '1'];
util.execSafe('ping', params, util.execOptsWin).then((stdout) => {
if (stdout) {
let lines = stdout.split('\r\n');
lines.shift();

View File

@ -18,8 +18,6 @@ const fs = require('fs');
const path = require('path');
const exec = require('child_process').exec;
const execSync = require('child_process').execSync;
const execFile = require('child_process').execFile;
const util = require('./util');
@ -170,7 +168,7 @@ function services(srv, callback) {
}
let args = (_darwin) ? ['-caxo', 'pcpu,pmem,pid,command'] : ['-axo', 'pcpu,pmem,pid,command'];
if (srvString !== '' && srvs.length > 0) {
util.execSave('ps', args).then((stdout) => {
util.execSafe('ps', args).then((stdout) => {
if (stdout) {
let lines = stdout.replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
srvs.forEach(function (srv) {
@ -268,7 +266,7 @@ function services(srv, callback) {
}
} else {
args = ['-o', 'comm'];
util.execSave('ps', args).then((stdout) => {
util.execSafe('ps', args).then((stdout) => {
if (stdout) {
let lines = stdout.replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
srvs.forEach(function (srv) {
@ -1058,9 +1056,9 @@ function processLoad(proc, callback) {
}
if (_darwin || _linux || _freebsd || _openbsd || _netbsd) {
const params = '-axo pid,pcpu,pmem,comm';
execFile('ps', params.split(' '), { maxBuffer: 1024 * 20000 }, function (error, stdout) {
if (!error) {
const params = ['-axo', 'pid,pcpu,pmem,comm'];
util.execSafe('ps', params).then((stdout) => {
if (stdout) {
let procStats = [];
let lines = stdout.toString().split('\n').filter(function (line) {
if (processesString === '*') { return true; }

View File

@ -390,7 +390,7 @@ function powerShell(cmd) {
});
}
function execSave(cmd, args, options) {
function execSafe(cmd, args, options) {
let result = '';
options = options || {};
@ -962,7 +962,7 @@ exports.wmic = wmic;
exports.darwinXcodeExists = darwinXcodeExists;
exports.getVboxmanage = getVboxmanage;
exports.powerShell = powerShell;
exports.execSave = execSave;
exports.execSafe = execSafe;
exports.nanoSeconds = nanoSeconds;
exports.countUniqueLines = countUniqueLines;
exports.countLines = countLines;