Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhildebrandt committed Mar 16, 2021
1 parent cc15927 commit 2c54d64
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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 |
Expand Down
5 changes: 5 additions & 0 deletions docs/history.html
Expand Up @@ -56,6 +56,11 @@ <h3>Full version history</h3>
</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>
Expand Down
6 changes: 3 additions & 3 deletions docs/index.html
Expand Up @@ -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">
Expand Down Expand Up @@ -201,15 +201,15 @@
</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">
<div id="downloads" class="numbers">...</div>
<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>
Expand Down
18 changes: 9 additions & 9 deletions lib/internet.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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();
Expand Down
12 changes: 5 additions & 7 deletions lib/processes.js
Expand Up @@ -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');

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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; }
Expand Down
4 changes: 2 additions & 2 deletions lib/util.js
Expand Up @@ -390,7 +390,7 @@ function powerShell(cmd) {
});
}

function execSave(cmd, args, options) {
function execSafe(cmd, args, options) {
let result = '';
options = options || {};

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2c54d64

Please sign in to comment.