added test script, v5 improvements

This commit is contained in:
Sebastian Hildebrandt
2021-01-11 23:51:00 +01:00
parent fcdfa173f1
commit a10e0f909c
16 changed files with 197 additions and 116 deletions
+5 -19
View File
@@ -28,8 +28,6 @@ const _openbsd = (_platform === 'openbsd');
const _netbsd = (_platform === 'netbsd');
const _sunos = (_platform === 'sunos');
const NOT_SUPPORTED = 'not supported';
let _fs_speed = {};
let _disk_io = {};
@@ -463,14 +461,10 @@ function calcFsSpeed(rx, wx) {
function fsStats(callback) {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) {
callback(NOT_SUPPORTED);
}
reject(error);
resolve(null);
}
let result = {
@@ -609,21 +603,13 @@ function calcDiskIO(rIO, wIO) {
function disksIO(callback) {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) {
callback(NOT_SUPPORTED);
}
reject(error);
resolve(null);
}
if (_sunos) {
let error = new Error(NOT_SUPPORTED);
if (callback) {
callback(NOT_SUPPORTED);
}
reject(error);
resolve(null);
}
let result = {
+5
View File
@@ -181,12 +181,17 @@ function graphics(callback) {
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('framebufferdepth') !== -1) currentDisplay.pixeldepth = parseInt(parts[1]); // in BIT
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('maindisplay') !== -1 && parts[1].replace(/ +/g, '').toLowerCase() === 'yes') currentDisplay.main = true;
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('built-in') !== -1 && parts[1].replace(/ +/g, '').toLowerCase() === 'yes') {
currentDisplay.vendor = 'Apple';
currentDisplay.builtin = true;
currentDisplay.connection = '';
}
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('connectiontype') !== -1) {
currentDisplay.builtin = false;
currentDisplay.connection = parts[1].trim();
if (currentDisplay.connection === 'Internal') {
currentDisplay.vendor = 'Apple';
currentDisplay.builtin = true;
}
}
}
}
+10 -5
View File
@@ -131,21 +131,26 @@ function inetLatency(host, callback) {
return new Promise((resolve) => {
process.nextTick(() => {
let params;
let filt;
if (_linux || _freebsd || _openbsd || _netbsd || _darwin) {
if (_linux) {
params = '-c 2 -w 3 ' + hostSanitized + ' | grep rtt';
params = '-c 2 -w 3 ' + hostSanitized;
filt = 'rtt';
}
if (_freebsd || _openbsd || _netbsd) {
params = '-c 2 -t 3 ' + hostSanitized + ' | grep round-trip';
params = '-c 2 -t 3 ' + hostSanitized;
filt = 'round-trip';
}
if (_darwin) {
params = '-c 2 -t 3 ' + hostSanitized + ' | grep avg';
params = '-c2 -t3 ' + hostSanitized;
filt = 'avg';
}
execFile('ping', params.split(' '), function (error, stdout) {
let result = null;
if (!error) {
const line = stdout.toString().split('=');
const lines = stdout.toString().split('\n').filter(line => line.indexOf(filt) >= 0).join('\n');
const line = lines.split('=');
if (line.length > 1) {
const parts = line[1].split('/');
if (parts.length > 1) {
+5 -12
View File
@@ -29,8 +29,6 @@ const _openbsd = (_platform === 'openbsd');
const _netbsd = (_platform === 'netbsd');
const _sunos = (_platform === 'sunos');
const NOT_SUPPORTED = 'not supported';
// --------------------------
// Get current time and OS uptime
@@ -926,14 +924,10 @@ function versions(apps, callback) {
exports.versions = versions;
function shell(callback) {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) {
callback(NOT_SUPPORTED);
}
reject(error);
resolve(null);
}
let result = '';
@@ -969,7 +963,6 @@ function uuid(callback) {
const jsonObj = JSON.parse(stdout.toString());
if (jsonObj.SPHardwareDataType && jsonObj.SPHardwareDataType.length > 0) {
const spHardware = jsonObj.SPHardwareDataType[0];
console.log(spHardware);
// result.os = parts.length > 1 ? parts[1].trim().toLowerCase() : '';
result.os = spHardware.platform_UUID;
result.hardware = spHardware.serial_number;
@@ -987,9 +980,9 @@ function uuid(callback) {
if (_linux) {
const cmd = `echo -n "os: "; cat /var/lib/dbus/machine-id 2> /dev/null; echo;
echo -n "os: "; cat /etc/machine-id 2> /dev/null; echo;
echo -n "machine: "; cat /sys/class/dmi/id/product_uuid 2> /dev/null; echo;`;
echo -n "hardware: "; cat /sys/class/dmi/id/product_uuid 2> /dev/null; echo;`;
exec(cmd, function (error, stdout) {
const lines = stdout.toString.split('\n');
const lines = stdout.toString().split('\n');
result.os = util.getValue(lines, 'os').toLowerCase();
result.hardware = util.getValue(lines, 'hardware').toLowerCase();
if (callback) {
@@ -1002,7 +995,7 @@ echo -n "machine: "; cat /sys/class/dmi/id/product_uuid 2> /dev/null; echo;`;
const cmd = `echo -n "os: "; sysctl -n kern.hostid; echo;
echo -n "hardware: "; sysctl -n kern.hostuuid; echo;`;
exec(cmd, function (error, stdout) {
const lines = stdout.toString.split('\n');
const lines = stdout.toString().split('\n');
result.os = util.getValue(lines, 'os').toLowerCase();
result.hardware = util.getValue(lines, 'hardware').toLowerCase();
if (result.os.indexOf('unknown') >= 0) { result.os = ''; }
+6 -8
View File
@@ -28,8 +28,6 @@ const _openbsd = (_platform === 'openbsd');
const _netbsd = (_platform === 'netbsd');
const _sunos = (_platform === 'sunos');
const NOT_SUPPORTED = 'not supported';
const winPrinterStatus = {
1: 'Other',
2: 'Unknown',
@@ -117,7 +115,7 @@ function parseWindowsPrinters(lines, id) {
function printer(callback) {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
process.nextTick(() => {
let result = [];
if (_linux || _freebsd || _openbsd || _netbsd) {
@@ -145,6 +143,10 @@ function printer(callback) {
result.push(printers);
}
});
if (callback) {
callback(result);
}
resolve(result);
} else {
if (callback) {
callback(result);
@@ -196,11 +198,7 @@ function printer(callback) {
});
}
if (_sunos) {
let error = new Error(NOT_SUPPORTED);
if (callback) {
callback(NOT_SUPPORTED);
}
reject(error);
resolve(null);
}
});
});
+2 -2
View File
@@ -973,10 +973,10 @@ function processLoad(proc, callback) {
}
if (_darwin || _linux) {
const params = '-axo pid,pcpu,pmem,comm | grep -i ' + procSanitized + ' | grep -v grep';
const params = '-axo pid,pcpu,pmem,comm';
execFile('ps', params.split(' '), { maxBuffer: 1024 * 20000 }, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
let lines = stdout.toString().split('\n').filter(line => line.toLowerCase().indexOf(procSanitized.toLowerCase()) >= 0 && line.toLowerCase().indexOf('grep') === -1);
let pid = 0;
let pids = [];
+15 -2
View File
@@ -449,8 +449,21 @@ function bios(callback) {
}
if (_darwin) {
result.vendor = 'Apple Inc.';
if (callback) { callback(result); }
resolve(result);
exec(
'system_profiler SPHardwareDataType -json', function (error, stdout) {
try {
const hardwareData = JSON.parse(stdout.toString());
if (hardwareData && hardwareData.SPHardwareDataType && hardwareData.SPHardwareDataType.length) {
let bootRomVersion = hardwareData.SPHardwareDataType[0].boot_rom_version;
bootRomVersion = bootRomVersion ? bootRomVersion.split('(')[0].trim() : null
result.version = bootRomVersion;
}
} catch (e) {
util.noop()
}
if (callback) { callback(result); }
resolve(result);
});
}
if (_sunos) {
result.vendor = 'Sun Microsystems';
+34 -20
View File
@@ -28,7 +28,21 @@ const _openbsd = (_platform === 'openbsd');
const _netbsd = (_platform === 'netbsd');
const _sunos = (_platform === 'sunos');
const NOT_SUPPORTED = 'not supported';
function getLinuxUsbType(type, name) {
let result = type;
const str = (name + ' ' + type).toLowerCase();
if (str.indexOf('camera') >= 0) { result = 'Camera'; }
else if (str.indexOf('hub') >= 0) { result = 'Hub'; }
else if (str.indexOf('keybrd') >= 0) { result = 'Keyboard'; }
else if (str.indexOf('keybroard') >= 0) { result = 'Keyboard'; }
else if (str.indexOf('mouse') >= 0) { result = 'Mouse'; }
else if (str.indexOf('stora') >= 0) { result = 'Storage'; }
else if (str.indexOf('mic') >= 0) { result = 'Microphone'; }
else if (str.indexOf('headset') >= 0) { result = 'Audio'; }
else if (str.indexOf('audio') >= 0) { result = 'Audio'; }
return result;
}
function parseLinuxUsb(usb) {
const result = {};
@@ -45,29 +59,29 @@ function parseLinuxUsb(usb) {
result.bus = null;
result.deviceId = null;
}
const idVendor = util.getValue(lines, 'idVendor', ' ', true);
const idVendor = util.getValue(lines, 'idVendor', ' ', true).trim();
let vendorParts = idVendor.split(' ');
vendorParts.shift();
const vendor = vendorParts.join(' ');
const idProduct = util.getValue(lines, 'idProduct', ' ', true);
const idProduct = util.getValue(lines, 'idProduct', ' ', true).trim();
let productParts = idProduct.split(' ');
productParts.shift();
const product = productParts.join(' ');
const interfaceClass = util.getValue(lines, 'bInterfaceClass', ' ', true);
const interfaceClass = util.getValue(lines, 'bInterfaceClass', ' ', true).trim();
let interfaceClassParts = interfaceClass.split(' ');
interfaceClassParts.shift();
const usbType = interfaceClassParts.join(' ');
const iManufacturer = util.getValue(lines, 'iManufacturer', ' ', true);
const iManufacturer = util.getValue(lines, 'iManufacturer', ' ', true).trim();
let iManufacturerParts = iManufacturer.split(' ');
iManufacturerParts.shift();
const manufacturer = iManufacturerParts.join(' ');
result.id = idVendor.startWith('0x') ? idVendor.split(' ').substr(2, 10) : '' + ':' + idProduct.startWith('0x') ? idProduct.split(' ').substr(2, 10) : '';
result.id = (idVendor.startsWith('0x') ? idVendor.split(' ')[0].substr(2, 10) : '') + ':' + (idProduct.startsWith('0x') ? idProduct.split(' ')[0].substr(2, 10) : '');
result.name = product
result.type = usbType;
result.type = getLinuxUsbType(usbType, product);
result.removable = null;
result.vendor = vendor;
result.manufacturer = manufacturer
@@ -100,6 +114,9 @@ function getDarwinUsbType(name) {
else if (name.indexOf('bth') >= 0) { result = 'Bluetooth'; }
else if (name.indexOf('rfcomm') >= 0) { result = 'Bluetooth'; }
else if (name.indexOf('usbhub') >= 0) { result = 'Hub'; }
else if (name.indexOf(' hub') >= 0) { result = 'Hub'; }
else if (name.indexOf('mouse') >= 0) { result = 'Mouse'; }
else if (name.indexOf('mic') >= 0) { result = 'Microphone'; }
return result;
}
@@ -119,18 +136,19 @@ function parseDarwinUsb(usb, id) {
if (lines[i] !== '{' && lines[i] !== '}' && lines[i + 1] && lines[i + 1].trim() !== '}') {
lines[i] = lines[i] + ',';
}
lines[i] = lines[i].replace(' Yes,', '"Yes",');
lines[i] = lines[i].replace(': Yes,', ': "Yes",');
lines[i] = lines[i].replace(': No,', ': "No",');
}
const usbObj = JSON.parse(lines.join('\n'));
result.bus = null;
result.deviceId = null;
result.id = usbObj['USB Address'];
result.name = usbObj['kUSBProductString'];
result.type = getDarwinUsbType(usbObj['kUSBProductString'].toLowerCase());
result.id = usbObj['USB Address'] || null;
result.name = usbObj['kUSBProductString'] || usbObj['USB Product Name'] || null;
result.type = getDarwinUsbType((usbObj['kUSBProductString'] || usbObj['USB Product Name'] || '').toLowerCase());
result.removable = usbObj['Built-In'].toLowerCase() !== 'yes';
result.vendor = usbObj['kUSBVendorString'];
result.manufacturer = usbObj['kUSBVendorString'];
result.vendor = usbObj['kUSBVendorString'] || usbObj['USB Vendor Name'] || null;
result.manufacturer = usbObj['kUSBVendorString'] || usbObj['USB Vendor Name'] || null;
result.maxPower = null;
result.serialNumber = usbObj['kUSBSerialNumberString'] || null;
@@ -185,7 +203,7 @@ function parseWindowsUsb(lines, id) {
function usb(callback) {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
process.nextTick(() => {
let result = [];
if (_linux) {
@@ -209,7 +227,7 @@ function usb(callback) {
exec(cmd, {maxBuffer: 1024 * 1024 * 128}, function (error, stdout) {
if (!error) {
const parts = (stdout.toString()).split(' +-o ');
for (let i = 2; i < parts.length; i++) {
for (let i = 1; i < parts.length; i++) {
const usb = parseDarwinUsb(parts[i]);
if (usb) {
result.push(usb)
@@ -244,11 +262,7 @@ function usb(callback) {
});
}
if (_sunos || _freebsd || _openbsd || _netbsd) {
let error = new Error(NOT_SUPPORTED);
if (callback) {
callback(NOT_SUPPORTED);
}
reject(error);
resolve(null);
}
});
});
+1 -1
View File
@@ -109,7 +109,7 @@ function getValue(lines, property, separator, trimmed) {
line = line.trim();
}
if (line.startsWith(property)) {
const parts = lines[i].split(separator);
const parts = trimmed ? lines[i].trim().split(separator) : lines[i].split(separator);
if (parts.length >= 2) {
parts.shift();
return parts.join(separator).trim();