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 | | Version | Date | Comment |
| -------------- | -------------- | -------- | | -------------- | -------------- | -------- |
| 5.6.6 | 2021-03-16 | code refactoring |
| 5.6.5 | 2021-03-15 | `cpuTemperature()` fix (linux) | | 5.6.5 | 2021-03-15 | `cpuTemperature()` fix (linux) |
| 5.6.4 | 2021-03-15 | `sanitizeShellString()` and other security improvements | | 5.6.4 | 2021-03-15 | `sanitizeShellString()` and other security improvements |
| 5.6.3 | 2021-03-14 | `sanitizeShellString()` improvement | | 5.6.3 | 2021-03-14 | `sanitizeShellString()` improvement |

View File

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

View File

@ -170,7 +170,7 @@
<img class="logo" src="assets/logo.png"> <img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div> <div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span>&nbsp;</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> <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>
<div class="down"> <div class="down">
@ -201,7 +201,7 @@
</div> </div>
<div class="row number-section"> <div class="row number-section">
<div class="col-xl-4 col-lg-4 col-md-4 col-12"> <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 class="title">Lines of code</div>
</div> </div>
<div class="col-xl-4 col-lg-4 col-md-4 col-12"> <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 class="title">Downloads last month</div>
</div> </div>
<div class="col-xl-4 col-lg-4 col-md-4 col-12"> <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 class="title">Dependents</div>
</div> </div>
</div> </div>

View File

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

View File

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