updated docs

This commit is contained in:
Sebastian Hildebrandt 2025-12-26 11:34:02 +01:00
parent d52fb6f520
commit f93e8a622f
4 changed files with 179 additions and 183 deletions

View File

@ -235,10 +235,10 @@ and above.
I was able to test it on several Debian, Raspbian, Ubuntu distributions as well I was able to test it on several Debian, Raspbian, Ubuntu distributions as well
as macOS (Mavericks, Yosemite, El Captain, Sierra, High Sierra, Mojave, as macOS (Mavericks, Yosemite, El Captain, Sierra, High Sierra, Mojave,
Catalina, Big Sur) and some Windows 7, Windows 8, Windows 10, FreeBSD, OpenBSD, Catalina, Big Sur, Monterey, Ventura, Sonoma, Sequoia, Tahoe) and some Windows 7,
NetBSD and SunOS machines. Not all functions are supported on all operating Windows 8, Windows 10, Windows 11, FreeBSD, OpenBSD, NetBSD and SunOS machines.
systems. Have a look at the function reference in the docs to get further Not all functions are supported on all operating systems. Have a look at the
details. function reference in the docs to get further details.
If you have comments, suggestions & reports, please feel free to contact me! If you have comments, suggestions & reports, please feel free to contact me!
@ -1018,21 +1018,27 @@ async function cpuData() {
#### macOS - Temperature Sensor #### macOS - Temperature Sensor
To be able to measure temperature on macOS I created a little additional To be able to measure temperature on macOS I created two little additional
package. Due to some difficulties in NPM with `optionalDependencies` I packages. Due to some difficulties in NPM with `optionalDependencies` I
unfortunately was getting unexpected warnings on other platforms. So I decided unfortunately was getting unexpected warnings on other platforms. So I decided
to drop this optional dependency for macOS - so by default, you will not get to drop this optional dependency for macOS - so by default, you will not get
correct values. correct values.
This additional package is now also supporting Apple Silicon M1/M2/M3 machines.
But if you need to detect macOS temperature just run the following additional But if you need to detect macOS temperature just run the following additional
installation command: installation command:
For Intel based machines (deprecated lib) install
```bash ```bash
$ npm install osx-temperature-sensor --save $ npm install osx-temperature-sensor --save
``` ```
For Apple Silicon (ARM) based machines install
```bash
$ npm install macos-temperature-sensor --save
```
`systeminformation` will then detect this additional library and return the `systeminformation` will then detect this additional library and return the
temperature when calling systeminformations standard function `cpuTemperature()` temperature when calling systeminformations standard function `cpuTemperature()`
@ -1163,7 +1169,7 @@ trademark of Fabrice Bellard, bochs is a trademark of The Bochs Project, USB and
USB Logo are trademarks of USB Implementation Forum, Bluetooth and Bluetooth USB Logo are trademarks of USB Implementation Forum, Bluetooth and Bluetooth
Logo are trademarks of Bluetooth SIG, Android is a trademark of Google LLC, Logo are trademarks of Bluetooth SIG, Android is a trademark of Google LLC,
Parallels is a trademarks of Parallels International GmbH. Bun is a trademark of Parallels is a trademarks of Parallels International GmbH. Bun is a trademark of
Codeblog Corp. Deno is a trademark of Deno Land Inc. Codeblog Corp. Deno is a trademark of Deno Land Inc. Arm is a trademark of Arm Limited.
All other trademarks are the property of their respective owners. All other trademarks are the property of their respective owners.

View File

@ -50,6 +50,7 @@
<li><strong>AMD</strong> is a trademark of Advanced Micro Devices Inc.</li> <li><strong>AMD</strong> is a trademark of Advanced Micro Devices Inc.</li>
<li><strong>Android</strong> is a trademark of Google LLC.</li> <li><strong>Android</strong> is a trademark of Google LLC.</li>
<li><strong>Apple, macOS, OS X, CUPS</strong> are registered trademarks of Apple Inc.</li> <li><strong>Apple, macOS, OS X, CUPS</strong> are registered trademarks of Apple Inc.</li>
<li><strong>Arm</strong> is a trademark of Arm Limited</li>
<li><strong>ASUS</strong> is a registered trademark of ASUSTeK Computer.</li> <li><strong>ASUS</strong> is a registered trademark of ASUSTeK Computer.</li>
<li><strong>Bluetooth and Bluetooth Logo</strong> are trademarks of Bluetooth SIG..</li> <li><strong>Bluetooth and Bluetooth Logo</strong> are trademarks of Bluetooth SIG..</li>
<li><strong>bochs</strong> is a trademark of The Bochs Project</li> <li><strong>bochs</strong> is a trademark of The Bochs Project</li>

View File

@ -42,12 +42,12 @@ const usb = require('./usb');
const audio = require('./audio'); const audio = require('./audio');
const bluetooth = require('./bluetooth'); const bluetooth = require('./bluetooth');
let _platform = process.platform; const _platform = process.platform;
const _windows = (_platform === 'win32'); const _windows = _platform === 'win32';
const _freebsd = (_platform === 'freebsd'); const _freebsd = _platform === 'freebsd';
const _openbsd = (_platform === 'openbsd'); const _openbsd = _platform === 'openbsd';
const _netbsd = (_platform === 'netbsd'); const _netbsd = _platform === 'netbsd';
const _sunos = (_platform === 'sunos'); const _sunos = _platform === 'sunos';
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
// init // init
@ -74,11 +74,9 @@ function version() {
// get static data - they should not change until restarted // get static data - they should not change until restarted
function getStaticData(callback) { function getStaticData(callback) {
return new Promise((resolve) => { return new Promise((resolve) => {
process.nextTick(() => { process.nextTick(() => {
const data = {};
let data = {};
data.version = version(); data.version = version();
@ -99,7 +97,7 @@ function getStaticData(callback) {
audio.audio(), audio.audio(),
bluetooth.bluetoothDevices(), bluetooth.bluetoothDevices(),
usb.usb(), usb.usb(),
printer.printer(), printer.printer()
]).then((res) => { ]).then((res) => {
data.system = res[0]; data.system = res[0];
data.bios = res[1]; data.bios = res[1];
@ -118,14 +116,15 @@ function getStaticData(callback) {
data.bluetooth = res[14]; data.bluetooth = res[14];
data.usb = res[15]; data.usb = res[15];
data.printer = res[16]; data.printer = res[16];
if (callback) { callback(data); } if (callback) {
callback(data);
}
resolve(data); resolve(data);
}); });
}); });
}); });
} }
// -------------------------- // --------------------------
// get all dynamic data - e.g. for monitoring agents // get all dynamic data - e.g. for monitoring agents
// may take some seconds to get all data // may take some seconds to get all data
@ -135,7 +134,6 @@ function getStaticData(callback) {
// - iface: define network interface for which you like to monitor network speed e.g. "eth0" // - iface: define network interface for which you like to monitor network speed e.g. "eth0"
function getDynamicData(srv, iface, callback) { function getDynamicData(srv, iface, callback) {
if (util.isFunction(iface)) { if (util.isFunction(iface)) {
callback = iface; callback = iface;
iface = ''; iface = '';
@ -147,16 +145,21 @@ function getDynamicData(srv, iface, callback) {
return new Promise((resolve) => { return new Promise((resolve) => {
process.nextTick(() => { process.nextTick(() => {
iface = iface || network.getDefaultNetworkInterface(); iface = iface || network.getDefaultNetworkInterface();
srv = srv || ''; srv = srv || '';
// use closure to track ƒ completion // use closure to track ƒ completion
let functionProcessed = (function () { let functionProcessed = (() => {
let totalFunctions = 15; let totalFunctions = 15;
if (_windows) { totalFunctions = 13; } if (_windows) {
if (_freebsd || _openbsd || _netbsd) { totalFunctions = 11; } totalFunctions = 13;
if (_sunos) { totalFunctions = 6; } }
if (_freebsd || _openbsd || _netbsd) {
totalFunctions = 11;
}
if (_sunos) {
totalFunctions = 6;
}
return function () { return function () {
if (--totalFunctions === 0) { if (--totalFunctions === 0) {
@ -168,7 +171,7 @@ function getDynamicData(srv, iface, callback) {
}; };
})(); })();
let data = {}; const data = {};
// get time // get time
data.time = osInfo.time(); data.time = osInfo.time();
@ -286,7 +289,6 @@ function getDynamicData(srv, iface, callback) {
// - iface: define network interface for which you like to monitor network speed e.g. "eth0" // - iface: define network interface for which you like to monitor network speed e.g. "eth0"
function getAllData(srv, iface, callback) { function getAllData(srv, iface, callback) {
return new Promise((resolve) => { return new Promise((resolve) => {
process.nextTick(() => { process.nextTick(() => {
let data = {}; let data = {};
@ -310,7 +312,9 @@ function getAllData(srv, iface, callback) {
data[key] = res[key]; data[key] = res[key];
} }
} }
if (callback) { callback(data); } if (callback) {
callback(data);
}
resolve(data); resolve(data);
}); });
}); });
@ -322,8 +326,8 @@ function get(valueObject, callback) {
return new Promise((resolve) => { return new Promise((resolve) => {
process.nextTick(() => { process.nextTick(() => {
const allPromises = Object.keys(valueObject) const allPromises = Object.keys(valueObject)
.filter(func => ({}.hasOwnProperty.call(exports, func))) .filter((func) => ({}).hasOwnProperty.call(exports, func))
.map(func => { .map((func) => {
const params = valueObject[func].substring(valueObject[func].lastIndexOf('(') + 1, valueObject[func].lastIndexOf(')')); const params = valueObject[func].substring(valueObject[func].lastIndexOf('(') + 1, valueObject[func].lastIndexOf(')'));
let funcWithoutParams = func.indexOf(')') >= 0 ? func.split(')')[1].trim() : func; let funcWithoutParams = func.indexOf(')') >= 0 ? func.split(')')[1].trim() : func;
funcWithoutParams = func.indexOf('|') >= 0 ? func.split('|')[0].trim() : funcWithoutParams; funcWithoutParams = func.indexOf('|') >= 0 ? func.split('|')[0].trim() : funcWithoutParams;
@ -361,12 +365,12 @@ function get(valueObject, callback) {
if (Array.isArray(data[i])) { if (Array.isArray(data[i])) {
// result is in an array, go through all elements of array and pick only the right ones // result is in an array, go through all elements of array and pick only the right ones
const partialArray = []; const partialArray = [];
data[i].forEach(element => { data[i].forEach((element) => {
let partialRes = {}; let partialRes = {};
if (keys.length === 1 && (keys[0] === '*' || keys[0] === 'all')) { if (keys.length === 1 && (keys[0] === '*' || keys[0] === 'all')) {
partialRes = element; partialRes = element;
} else { } else {
keys.forEach(k => { keys.forEach((k) => {
if ({}.hasOwnProperty.call(element, k)) { if ({}.hasOwnProperty.call(element, k)) {
partialRes[k] = element[k]; partialRes[k] = element[k];
} }
@ -376,11 +380,11 @@ function get(valueObject, callback) {
if (filter && filterParts.length === 2) { if (filter && filterParts.length === 2) {
if ({}.hasOwnProperty.call(partialRes, filterParts[0].trim())) { if ({}.hasOwnProperty.call(partialRes, filterParts[0].trim())) {
const val = partialRes[filterParts[0].trim()]; const val = partialRes[filterParts[0].trim()];
if (typeof val == 'number') { if (typeof val === 'number') {
if (val === parseFloat(filterParts[1].trim())) { if (val === parseFloat(filterParts[1].trim())) {
partialArray.push(partialRes); partialArray.push(partialRes);
} }
} else if (typeof val == 'string') { } else if (typeof val === 'string') {
if (val.toLowerCase() === filterParts[1].trim().toLowerCase()) { if (val.toLowerCase() === filterParts[1].trim().toLowerCase()) {
partialArray.push(partialRes); partialArray.push(partialRes);
} }
@ -389,12 +393,11 @@ function get(valueObject, callback) {
} else { } else {
partialArray.push(partialRes); partialArray.push(partialRes);
} }
}); });
result[key] = partialArray; result[key] = partialArray;
} else { } else {
const partialRes = {}; const partialRes = {};
keys.forEach(k => { keys.forEach((k) => {
if ({}.hasOwnProperty.call(data[i], k)) { if ({}.hasOwnProperty.call(data[i], k)) {
partialRes[k] = data[i][k]; partialRes[k] = data[i][k];
} }
@ -408,7 +411,9 @@ function get(valueObject, callback) {
i++; i++;
} }
} }
if (callback) { callback(result); } if (callback) {
callback(result);
}
resolve(result); resolve(result);
}); });
}); });

View File

@ -21,13 +21,13 @@ const execSync = require('child_process').execSync;
let _platform = process.platform; let _platform = process.platform;
const _linux = (_platform === 'linux' || _platform === 'android'); const _linux = _platform === 'linux' || _platform === 'android';
const _darwin = (_platform === 'darwin'); const _darwin = _platform === 'darwin';
const _windows = (_platform === 'win32'); const _windows = _platform === 'win32';
const _freebsd = (_platform === 'freebsd'); const _freebsd = _platform === 'freebsd';
const _openbsd = (_platform === 'openbsd'); const _openbsd = _platform === 'openbsd';
const _netbsd = (_platform === 'netbsd'); const _netbsd = _platform === 'netbsd';
const _sunos = (_platform === 'sunos'); const _sunos = _platform === 'sunos';
// -------------------------- // --------------------------
// Get current time and OS uptime // Get current time and OS uptime
@ -38,12 +38,12 @@ function time() {
try { try {
timezoneName = Intl.DateTimeFormat().resolvedOptions().timeZone; timezoneName = Intl.DateTimeFormat().resolvedOptions().timeZone;
} catch { } catch {
timezoneName = (t.length >= 7) ? t.slice(6).join(' ').replace(/\(/g, '').replace(/\)/g, '') : ''; timezoneName = t.length >= 7 ? t.slice(6).join(' ').replace(/\(/g, '').replace(/\)/g, '') : '';
} }
const result = { const result = {
current: Date.now(), current: Date.now(),
uptime: os.uptime(), uptime: os.uptime(),
timezone: (t.length >= 7) ? t[5] : '', timezone: t.length >= 7 ? t[5] : '',
timezoneName timezoneName
}; };
if (_darwin || _linux) { if (_darwin || _linux) {
@ -61,7 +61,7 @@ function time() {
current: Date.now(), current: Date.now(),
uptime: os.uptime(), uptime: os.uptime(),
timezone: lines[1] ? timezone + lines[1] : timezone, timezone: lines[1] ? timezone + lines[1] : timezone,
timezoneName: lines[2] && lines[2].indexOf('/zoneinfo/') > 0 ? (lines[2].split('/zoneinfo/')[1] || '') : '' timezoneName: lines[2] && lines[2].indexOf('/zoneinfo/') > 0 ? lines[2].split('/zoneinfo/')[1] || '' : ''
}; };
} catch (e) { } catch (e) {
util.noop(); util.noop();
@ -81,116 +81,79 @@ function getLogoFile(distro) {
let result = _platform; let result = _platform;
if (_windows) { if (_windows) {
result = 'windows'; result = 'windows';
} } else if (distro.indexOf('mac os') !== -1 || distro.indexOf('macos') !== -1) {
else if (distro.indexOf('mac os') !== -1 || distro.indexOf('macos') !== -1) {
result = 'apple'; result = 'apple';
} } else if (distro.indexOf('arch') !== -1) {
else if (distro.indexOf('arch') !== -1) {
result = 'arch'; result = 'arch';
} } else if (distro.indexOf('cachy') !== -1) {
else if (distro.indexOf('cachy') !== -1) {
result = 'cachy'; result = 'cachy';
} } else if (distro.indexOf('centos') !== -1) {
else if (distro.indexOf('centos') !== -1) {
result = 'centos'; result = 'centos';
} } else if (distro.indexOf('coreos') !== -1) {
else if (distro.indexOf('coreos') !== -1) {
result = 'coreos'; result = 'coreos';
} } else if (distro.indexOf('debian') !== -1) {
else if (distro.indexOf('debian') !== -1) {
result = 'debian'; result = 'debian';
} } else if (distro.indexOf('deepin') !== -1) {
else if (distro.indexOf('deepin') !== -1) {
result = 'deepin'; result = 'deepin';
} } else if (distro.indexOf('elementary') !== -1) {
else if (distro.indexOf('elementary') !== -1) {
result = 'elementary'; result = 'elementary';
} } else if (distro.indexOf('endeavour') !== -1) {
else if (distro.indexOf('endeavour') !== -1) {
result = 'endeavour'; result = 'endeavour';
} } else if (distro.indexOf('fedora') !== -1) {
else if (distro.indexOf('fedora') !== -1) {
result = 'fedora'; result = 'fedora';
} } else if (distro.indexOf('gentoo') !== -1) {
else if (distro.indexOf('gentoo') !== -1) {
result = 'gentoo'; result = 'gentoo';
} } else if (distro.indexOf('mageia') !== -1) {
else if (distro.indexOf('mageia') !== -1) {
result = 'mageia'; result = 'mageia';
} } else if (distro.indexOf('mandriva') !== -1) {
else if (distro.indexOf('mandriva') !== -1) {
result = 'mandriva'; result = 'mandriva';
} } else if (distro.indexOf('manjaro') !== -1) {
else if (distro.indexOf('manjaro') !== -1) {
result = 'manjaro'; result = 'manjaro';
} } else if (distro.indexOf('mint') !== -1) {
else if (distro.indexOf('mint') !== -1) {
result = 'mint'; result = 'mint';
} } else if (distro.indexOf('mx') !== -1) {
else if (distro.indexOf('mx') !== -1) {
result = 'mx'; result = 'mx';
} } else if (distro.indexOf('openbsd') !== -1) {
else if (distro.indexOf('openbsd') !== -1) {
result = 'openbsd'; result = 'openbsd';
} } else if (distro.indexOf('freebsd') !== -1) {
else if (distro.indexOf('freebsd') !== -1) {
result = 'freebsd'; result = 'freebsd';
} } else if (distro.indexOf('opensuse') !== -1) {
else if (distro.indexOf('opensuse') !== -1) {
result = 'opensuse'; result = 'opensuse';
} } else if (distro.indexOf('pclinuxos') !== -1) {
else if (distro.indexOf('pclinuxos') !== -1) {
result = 'pclinuxos'; result = 'pclinuxos';
} } else if (distro.indexOf('puppy') !== -1) {
else if (distro.indexOf('puppy') !== -1) {
result = 'puppy'; result = 'puppy';
} } else if (distro.indexOf('popos') !== -1) {
else if (distro.indexOf('popos') !== -1) {
result = 'popos'; result = 'popos';
} } else if (distro.indexOf('raspbian') !== -1) {
else if (distro.indexOf('raspbian') !== -1) {
result = 'raspbian'; result = 'raspbian';
} } else if (distro.indexOf('reactos') !== -1) {
else if (distro.indexOf('reactos') !== -1) {
result = 'reactos'; result = 'reactos';
} } else if (distro.indexOf('redhat') !== -1) {
else if (distro.indexOf('redhat') !== -1) {
result = 'redhat'; result = 'redhat';
} } else if (distro.indexOf('slackware') !== -1) {
else if (distro.indexOf('slackware') !== -1) {
result = 'slackware'; result = 'slackware';
} } else if (distro.indexOf('sugar') !== -1) {
else if (distro.indexOf('sugar') !== -1) {
result = 'sugar'; result = 'sugar';
} } else if (distro.indexOf('steam') !== -1) {
else if (distro.indexOf('steam') !== -1) {
result = 'steam'; result = 'steam';
} } else if (distro.indexOf('suse') !== -1) {
else if (distro.indexOf('suse') !== -1) {
result = 'suse'; result = 'suse';
} } else if (distro.indexOf('mate') !== -1) {
else if (distro.indexOf('mate') !== -1) {
result = 'ubuntu-mate'; result = 'ubuntu-mate';
} } else if (distro.indexOf('lubuntu') !== -1) {
else if (distro.indexOf('lubuntu') !== -1) {
result = 'lubuntu'; result = 'lubuntu';
} } else if (distro.indexOf('xubuntu') !== -1) {
else if (distro.indexOf('xubuntu') !== -1) {
result = 'xubuntu'; result = 'xubuntu';
} } else if (distro.indexOf('ubuntu') !== -1) {
else if (distro.indexOf('ubuntu') !== -1) {
result = 'ubuntu'; result = 'ubuntu';
} } else if (distro.indexOf('solaris') !== -1) {
else if (distro.indexOf('solaris') !== -1) {
result = 'solaris'; result = 'solaris';
} } else if (distro.indexOf('tails') !== -1) {
else if (distro.indexOf('tails') !== -1) {
result = 'tails'; result = 'tails';
} } else if (distro.indexOf('feren') !== -1) {
else if (distro.indexOf('feren') !== -1) {
result = 'ferenos'; result = 'ferenos';
} } else if (distro.indexOf('robolinux') !== -1) {
else if (distro.indexOf('robolinux') !== -1) {
result = 'robolinux'; result = 'robolinux';
} else if (_linux && distro) { } else if (_linux && distro) {
result = distro.toLowerCase().trim().replace(/\s+/g, '-'); result = distro.toLowerCase().trim().replace(/\s+/g, '-');
@ -234,12 +197,10 @@ function getFQDN() {
// OS Information // OS Information
function osInfo(callback) { function osInfo(callback) {
return new Promise((resolve) => { return new Promise((resolve) => {
process.nextTick(() => { process.nextTick(() => {
let result = { let result = {
platform: _platform === 'win32' ? 'Windows' : _platform,
platform: (_platform === 'win32' ? 'Windows' : _platform),
distro: 'unknown', distro: 'unknown',
release: 'unknown', release: 'unknown',
codename: '', codename: '',
@ -256,7 +217,6 @@ function osInfo(callback) {
}; };
if (_linux) { if (_linux) {
exec('cat /etc/*-release; cat /usr/lib/os-release; cat /etc/openwrt_release', function (error, stdout) { exec('cat /etc/*-release; cat /usr/lib/os-release; cat /etc/openwrt_release', function (error, stdout) {
/** /**
* @namespace * @namespace
@ -289,7 +249,7 @@ function osInfo(callback) {
result.codename = codename; result.codename = codename;
result.codepage = util.getCodepage(); result.codepage = util.getCodepage();
result.build = (release.BUILD_ID || '').replace(/"/g, '').trim(); result.build = (release.BUILD_ID || '').replace(/"/g, '').trim();
isUefiLinux().then(uefi => { isUefiLinux().then((uefi) => {
result.uefi = uefi; result.uefi = uefi;
uuid().then((data) => { uuid().then((data) => {
result.serial = data.os; result.serial = data.os;
@ -302,7 +262,6 @@ function osInfo(callback) {
}); });
} }
if (_freebsd || _openbsd || _netbsd) { if (_freebsd || _openbsd || _netbsd) {
exec('sysctl kern.ostype kern.osrelease kern.osrevision kern.hostuuid machdep.bootmethod kern.geom.confxml', function (error, stdout) { exec('sysctl kern.ostype kern.osrelease kern.osrevision kern.hostuuid machdep.bootmethod kern.geom.confxml', function (error, stdout) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
const distro = util.getValue(lines, 'kern.ostype'); const distro = util.getValue(lines, 'kern.ostype');
@ -311,7 +270,7 @@ function osInfo(callback) {
const serial = util.getValue(lines, 'kern.uuid'); const serial = util.getValue(lines, 'kern.uuid');
const bootmethod = util.getValue(lines, 'machdep.bootmethod'); const bootmethod = util.getValue(lines, 'machdep.bootmethod');
const uefiConf = stdout.toString().indexOf('<type>efi</type>') >= 0; const uefiConf = stdout.toString().indexOf('<type>efi</type>') >= 0;
const uefi = bootmethod ? bootmethod.toLowerCase().indexOf('uefi') >= 0 : (uefiConf ? uefiConf : null); const uefi = bootmethod ? bootmethod.toLowerCase().indexOf('uefi') >= 0 : uefiConf ? uefiConf : null;
result.distro = distro || result.distro; result.distro = distro || result.distro;
result.logofile = logofile || result.logofile; result.logofile = logofile || result.logofile;
result.release = release || result.release; result.release = release || result.release;
@ -334,25 +293,24 @@ function osInfo(callback) {
result.build = util.getValue(lines, 'BuildVersion'); result.build = util.getValue(lines, 'BuildVersion');
result.logofile = getLogoFile(result.distro); result.logofile = getLogoFile(result.distro);
result.codename = 'macOS'; result.codename = 'macOS';
result.codename = (result.release.indexOf('10.4') > -1 ? 'OS X Tiger' : result.codename); result.codename = result.release.indexOf('10.4') > -1 ? 'OS X Tiger' : result.codename;
result.codename = (result.release.indexOf('10.5') > -1 ? 'OS X Leopard' : result.codename); result.codename = result.release.indexOf('10.5') > -1 ? 'OS X Leopard' : result.codename;
result.codename = (result.release.indexOf('10.6') > -1 ? 'OS X Snow Leopard' : result.codename); result.codename = result.release.indexOf('10.6') > -1 ? 'OS X Snow Leopard' : result.codename;
result.codename = (result.release.indexOf('10.7') > -1 ? 'OS X Lion' : result.codename); result.codename = result.release.indexOf('10.7') > -1 ? 'OS X Lion' : result.codename;
result.codename = (result.release.indexOf('10.8') > -1 ? 'OS X Mountain Lion' : result.codename); result.codename = result.release.indexOf('10.8') > -1 ? 'OS X Mountain Lion' : result.codename;
result.codename = (result.release.indexOf('10.9') > -1 ? 'OS X Mavericks' : result.codename); result.codename = result.release.indexOf('10.9') > -1 ? 'OS X Mavericks' : result.codename;
result.codename = (result.release.indexOf('10.10') > -1 ? 'OS X Yosemite' : result.codename); result.codename = result.release.indexOf('10.10') > -1 ? 'OS X Yosemite' : result.codename;
result.codename = (result.release.indexOf('10.11') > -1 ? 'OS X El Capitan' : result.codename); result.codename = result.release.indexOf('10.11') > -1 ? 'OS X El Capitan' : result.codename;
result.codename = (result.release.indexOf('10.12') > -1 ? 'Sierra' : result.codename); result.codename = result.release.indexOf('10.12') > -1 ? 'Sierra' : result.codename;
result.codename = (result.release.indexOf('10.13') > -1 ? 'High Sierra' : result.codename); result.codename = result.release.indexOf('10.13') > -1 ? 'High Sierra' : result.codename;
result.codename = (result.release.indexOf('10.14') > -1 ? 'Mojave' : result.codename); result.codename = result.release.indexOf('10.14') > -1 ? 'Mojave' : result.codename;
result.codename = (result.release.indexOf('10.15') > -1 ? 'Catalina' : result.codename); result.codename = result.release.indexOf('10.15') > -1 ? 'Catalina' : result.codename;
result.codename = (result.release.startsWith('11.') ? 'Big Sur' : result.codename); result.codename = result.release.startsWith('11.') ? 'Big Sur' : result.codename;
result.codename = (result.release.startsWith('12.') ? 'Monterey' : result.codename); result.codename = result.release.startsWith('12.') ? 'Monterey' : result.codename;
result.codename = (result.release.startsWith('13.') ? 'Ventura' : result.codename); result.codename = result.release.startsWith('13.') ? 'Ventura' : result.codename;
result.codename = (result.release.startsWith('14.') ? 'Sonoma' : result.codename); result.codename = result.release.startsWith('14.') ? 'Sonoma' : result.codename;
result.codename = (result.release.startsWith('15.') ? 'Sequoia' : result.codename); result.codename = result.release.startsWith('15.') ? 'Sequoia' : result.codename;
result.codename = (result.release.startsWith('16.') ? 'Tahoe' : result.codename); result.codename = result.release.startsWith('26.') ? 'Tahoe' : result.codename;
result.codename = (result.release.startsWith('26.') ? 'Tahoe' : result.codename);
result.uefi = true; result.uefi = true;
result.codepage = util.getCodepage(); result.codepage = util.getCodepage();
if (callback) { if (callback) {
@ -367,7 +325,9 @@ function osInfo(callback) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
result.distro = lines[0]; result.distro = lines[0];
result.logofile = getLogoFile(result.distro); result.logofile = getLogoFile(result.distro);
if (callback) { callback(result); } if (callback) {
callback(result);
}
resolve(result); resolve(result);
}); });
} }
@ -379,9 +339,7 @@ function osInfo(callback) {
workload.push(util.powerShell('Get-CimInstance Win32_OperatingSystem | select Caption,SerialNumber,BuildNumber,ServicePackMajorVersion,ServicePackMinorVersion | fl')); workload.push(util.powerShell('Get-CimInstance Win32_OperatingSystem | select Caption,SerialNumber,BuildNumber,ServicePackMajorVersion,ServicePackMinorVersion | fl'));
workload.push(util.powerShell('(Get-CimInstance Win32_ComputerSystem).HypervisorPresent')); workload.push(util.powerShell('(Get-CimInstance Win32_ComputerSystem).HypervisorPresent'));
workload.push(util.powerShell('Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SystemInformation]::TerminalServerSession')); workload.push(util.powerShell('Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SystemInformation]::TerminalServerSession'));
util.promiseAll( util.promiseAll(workload).then((data) => {
workload
).then((data) => {
let lines = data.results[0] ? data.results[0].toString().split('\r\n') : ['']; let lines = data.results[0] ? data.results[0].toString().split('\r\n') : [''];
result.distro = util.getValue(lines, 'Caption', ':').trim(); result.distro = util.getValue(lines, 'Caption', ':').trim();
result.serial = util.getValue(lines, 'SerialNumber', ':').trim(); result.serial = util.getValue(lines, 'SerialNumber', ':').trim();
@ -391,8 +349,8 @@ function osInfo(callback) {
const hyperv = data.results[1] ? data.results[1].toString().toLowerCase() : ''; const hyperv = data.results[1] ? data.results[1].toString().toLowerCase() : '';
result.hypervisor = hyperv.indexOf('true') !== -1; result.hypervisor = hyperv.indexOf('true') !== -1;
const term = data.results[2] ? data.results[2].toString() : ''; const term = data.results[2] ? data.results[2].toString() : '';
result.remoteSession = (term.toString().toLowerCase().indexOf('true') >= 0); result.remoteSession = term.toString().toLowerCase().indexOf('true') >= 0;
isUefiWindows().then(uefi => { isUefiWindows().then((uefi) => {
result.uefi = uefi; result.uefi = uefi;
if (callback) { if (callback) {
callback(result); callback(result);
@ -401,7 +359,9 @@ function osInfo(callback) {
}); });
}); });
} catch (e) { } catch (e) {
if (callback) { callback(result); } if (callback) {
callback(result);
}
resolve(result); resolve(result);
} }
} }
@ -513,7 +473,7 @@ function versions(apps, callback) {
versions: {}, versions: {},
counter: 0 counter: 0
}; };
apps.forEach(el => { apps.forEach((el) => {
if (el) { if (el) {
for (let key in versionObject) { for (let key in versionObject) {
if ({}.hasOwnProperty.call(versionObject, key)) { if ({}.hasOwnProperty.call(versionObject, key)) {
@ -524,7 +484,9 @@ function versions(apps, callback) {
result.versions.systemOpensslLib = ''; result.versions.systemOpensslLib = '';
} }
if (!result.versions[key]) { result.counter++; } if (!result.versions[key]) {
result.counter++;
}
} }
} }
} }
@ -542,7 +504,9 @@ function versions(apps, callback) {
} else { } else {
apps = apps || '*'; apps = apps || '*';
if (typeof apps !== 'string') { if (typeof apps !== 'string') {
if (callback) { callback({}); } if (callback) {
callback({});
}
return resolve({}); return resolve({});
} }
} }
@ -684,7 +648,7 @@ function versions(apps, callback) {
exec('apachectl -v 2>&1', function (error, stdout) { exec('apachectl -v 2>&1', function (error, stdout) {
if (!error) { if (!error) {
const apache = (stdout.toString().split('\n')[0] || '').split(':'); const apache = (stdout.toString().split('\n')[0] || '').split(':');
appsObj.versions.apache = (apache.length > 1 ? apache[1].replace('Apache', '').replace('/', '').split('(')[0].trim() : ''); appsObj.versions.apache = apache.length > 1 ? apache[1].replace('Apache', '').replace('/', '').split('(')[0].trim() : '';
} }
functionProcessed(); functionProcessed();
}); });
@ -854,7 +818,7 @@ function versions(apps, callback) {
const gitHomebrewExists1 = fs.existsSync('/usr/local/Cellar/python'); const gitHomebrewExists1 = fs.existsSync('/usr/local/Cellar/python');
const gitHomebrewExists2 = fs.existsSync('/opt/homebrew/bin/python'); const gitHomebrewExists2 = fs.existsSync('/opt/homebrew/bin/python');
if ((util.darwinXcodeExists() && util.semverCompare('12.0.1', osVersion) < 0) || gitHomebrewExists1 || gitHomebrewExists2) { if ((util.darwinXcodeExists() && util.semverCompare('12.0.1', osVersion) < 0) || gitHomebrewExists1 || gitHomebrewExists2) {
const cmd = gitHomebrewExists1 ? '/usr/local/Cellar/python -V 2>&1' : (gitHomebrewExists2 ? '/opt/homebrew/bin/python -V 2>&1' : 'python -V 2>&1'); const cmd = gitHomebrewExists1 ? '/usr/local/Cellar/python -V 2>&1' : gitHomebrewExists2 ? '/opt/homebrew/bin/python -V 2>&1' : 'python -V 2>&1';
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
if (!error) { if (!error) {
const python = stdout.toString().split('\n')[0] || ''; const python = stdout.toString().split('\n')[0] || '';
@ -868,7 +832,6 @@ function versions(apps, callback) {
} catch (e) { } catch (e) {
functionProcessed(); functionProcessed();
} }
} else { } else {
exec('python -V 2>&1', function (error, stdout) { exec('python -V 2>&1', function (error, stdout) {
if (!error) { if (!error) {
@ -1080,7 +1043,9 @@ function versions(apps, callback) {
exec('node -v', function (error, stdout) { exec('node -v', function (error, stdout) {
if (!error) { if (!error) {
let line = stdout.toString().split('\n')[0].trim(); let line = stdout.toString().split('\n')[0].trim();
if (line.startsWith('v')) { line = line.slice(1); } if (line.startsWith('v')) {
line = line.slice(1);
}
appsObj.versions.node = line; appsObj.versions.node = line;
} }
functionProcessed(); functionProcessed();
@ -1088,8 +1053,12 @@ function versions(apps, callback) {
} }
if ({}.hasOwnProperty.call(appsObj.versions, 'powershell')) { if ({}.hasOwnProperty.call(appsObj.versions, 'powershell')) {
if (_windows) { if (_windows) {
util.powerShell('$PSVersionTable').then(stdout => { util.powerShell('$PSVersionTable').then((stdout) => {
const lines = stdout.toString().toLowerCase().split('\n').map(line => line.replace(/ +/g, ' ').replace(/ +/g, ':')); const lines = stdout
.toString()
.toLowerCase()
.split('\n')
.map((line) => line.replace(/ +/g, ' ').replace(/ +/g, ':'));
appsObj.versions.powershell = util.getValue(lines, 'psversion'); appsObj.versions.powershell = util.getValue(lines, 'psversion');
functionProcessed(); functionProcessed();
}); });
@ -1099,23 +1068,31 @@ function versions(apps, callback) {
} }
if ({}.hasOwnProperty.call(appsObj.versions, 'dotnet')) { if ({}.hasOwnProperty.call(appsObj.versions, 'dotnet')) {
if (_windows) { if (_windows) {
util.powerShell('gci "HKLM:\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP" -recurse | gp -name Version,Release -EA 0 | where { $_.PSChildName -match "^(?!S)\\p{L}"} | select PSChildName, Version, Release').then(stdout => { util
const lines = stdout.toString().split('\r\n'); .powerShell(
let dotnet = ''; 'gci "HKLM:\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP" -recurse | gp -name Version,Release -EA 0 | where { $_.PSChildName -match "^(?!S)\\p{L}"} | select PSChildName, Version, Release'
lines.forEach(line => { )
line = line.replace(/ +/g, ' '); .then((stdout) => {
const parts = line.split(' '); const lines = stdout.toString().split('\r\n');
dotnet = dotnet || (parts[0].toLowerCase().startsWith('client') && parts.length > 2 ? parts[1].trim() : (parts[0].toLowerCase().startsWith('full') && parts.length > 2 ? parts[1].trim() : '')); let dotnet = '';
lines.forEach((line) => {
line = line.replace(/ +/g, ' ');
const parts = line.split(' ');
dotnet =
dotnet ||
(parts[0].toLowerCase().startsWith('client') && parts.length > 2 ? parts[1].trim() : parts[0].toLowerCase().startsWith('full') && parts.length > 2 ? parts[1].trim() : '');
});
appsObj.versions.dotnet = dotnet.trim();
functionProcessed();
}); });
appsObj.versions.dotnet = dotnet.trim();
functionProcessed();
});
} else { } else {
functionProcessed(); functionProcessed();
} }
} }
} catch (e) { } catch (e) {
if (callback) { callback(appsObj.versions); } if (callback) {
callback(appsObj.versions);
}
resolve(appsObj.versions); resolve(appsObj.versions);
} }
}); });
@ -1130,7 +1107,7 @@ function shell(callback) {
if (_windows) { if (_windows) {
try { try {
const result = 'CMD'; const result = 'CMD';
util.powerShell(`Get-CimInstance -className win32_process | where-object {$_.ProcessId -eq ${process.ppid} } | select Name`).then(stdout => { util.powerShell(`Get-CimInstance -className win32_process | where-object {$_.ProcessId -eq ${process.ppid} } | select Name`).then((stdout) => {
let result = 'CMD'; let result = 'CMD';
if (stdout) { if (stdout) {
if (stdout.toString().toLowerCase().indexOf('powershell') >= 0) { if (stdout.toString().toLowerCase().indexOf('powershell') >= 0) {
@ -1183,8 +1160,12 @@ function getUniqueMacAdresses() {
} }
} }
macs = macs.sort(function (a, b) { macs = macs.sort(function (a, b) {
if (a < b) { return -1; } if (a < b) {
if (a > b) { return 1; } return -1;
}
if (a > b) {
return 1;
}
return 0; return 0;
}); });
} catch (e) { } catch (e) {
@ -1196,7 +1177,6 @@ function getUniqueMacAdresses() {
function uuid(callback) { function uuid(callback) {
return new Promise((resolve) => { return new Promise((resolve) => {
process.nextTick(() => { process.nextTick(() => {
let result = { let result = {
os: '', os: '',
hardware: '', hardware: '',
@ -1248,8 +1228,12 @@ echo -n "hardware: "; cat /sys/class/dmi/id/product_uuid 2> /dev/null; echo;`;
const lines = stdout.toString().split('\n'); const lines = stdout.toString().split('\n');
result.hardware = util.getValue(lines, 'kern.hostid', ':').toLowerCase(); result.hardware = util.getValue(lines, 'kern.hostid', ':').toLowerCase();
result.os = util.getValue(lines, 'kern.hostuuid', ':').toLowerCase(); result.os = util.getValue(lines, 'kern.hostuuid', ':').toLowerCase();
if (result.os.indexOf('unknown') >= 0) { result.os = ''; } if (result.os.indexOf('unknown') >= 0) {
if (result.hardware.indexOf('unknown') >= 0) { result.hardware = ''; } result.os = '';
}
if (result.hardware.indexOf('unknown') >= 0) {
result.hardware = '';
}
if (callback) { if (callback) {
callback(result); callback(result);
} }
@ -1266,7 +1250,7 @@ echo -n "hardware: "; cat /sys/class/dmi/id/product_uuid 2> /dev/null; echo;`;
result.hardware = util.getValue(lines, 'uuid', ':').toLowerCase(); result.hardware = util.getValue(lines, 'uuid', ':').toLowerCase();
exec(`${sysdir}\\reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid`, util.execOptsWin, function (error, stdout) { exec(`${sysdir}\\reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid`, util.execOptsWin, function (error, stdout) {
parts = stdout.toString().split('\n\r')[0].split('REG_SZ'); parts = stdout.toString().split('\n\r')[0].split('REG_SZ');
result.os = parts.length > 1 ? parts[1].replace(/\r+|\n+|\s+/ig, '').toLowerCase() : ''; result.os = parts.length > 1 ? parts[1].replace(/\r+|\n+|\s+/gi, '').toLowerCase() : '';
if (callback) { if (callback) {
callback(result); callback(result);
} }