added chassis()

This commit is contained in:
Sebastian Hildebrandt
2019-01-13 17:53:33 +01:00
parent d761c29e1f
commit ad2870c0a8
4 changed files with 201 additions and 4 deletions
+2
View File
@@ -77,6 +77,7 @@ function getStaticData(callback) {
system.system(),
system.bios(),
system.baseboard(),
system.chassis(),
osInfo.osInfo(),
osInfo.uuid(),
osInfo.versions(),
@@ -309,6 +310,7 @@ exports.version = version;
exports.system = system.system;
exports.bios = system.bios;
exports.baseboard = system.baseboard;
exports.chassis = system.chassis;
exports.time = osInfo.time;
exports.osInfo = osInfo.osInfo;
+107
View File
@@ -429,4 +429,111 @@ function baseboard(callback) {
exports.baseboard = baseboard;
function chassis(callback) {
const chassisTypes = ['Other',
'Unknown',
'Desktop',
'Low Profile Desktop',
'Pizza Box',
'Mini Tower',
'Tower',
'Portable',
'Laptop',
'Notebook',
'Hand Held',
'Docking Station',
'All in One',
'Sub Notebook',
'Space-Saving',
'Lunch Box',
'Main System Chassis',
'Expansion Chassis',
'SubChassis',
'Bus Expansion Chassis',
'Peripheral Chassis',
'Storage Chassis',
'Rack Mount Chassis',
'Sealed-Case PC']
return new Promise((resolve) => {
process.nextTick(() => {
let result = {
manufacturer: '',
model: '',
type: '',
version: '',
serial: '-',
assetTag: '-',
sku: '',
};
let cmd = '';
if (_linux || _freebsd || _openbsd) {
const cmd = `echo -n "chassis_asset_tag: "; cat /sys/devices/virtual/dmi/id/chassis_asset_tag 2>&1;
echo -n "chassis_serial: "; cat /sys/devices/virtual/dmi/id/chassis_serial 2>&1;
echo -n "chassis_type: "; cat /sys/devices/virtual/dmi/id/chassis_type 2>&1;
echo -n "chassis_vendor: "; cat /sys/devices/virtual/dmi/id/chassis_vendor 2>&1;
echo -n "chassis_version: "; cat /sys/devices/virtual/dmi/id/chassis_version 2>&1;`;
exec(cmd, function (error, stdout) {
let lines = stdout.toString().split('\n');
result.manufacturer = util.getValue(lines, 'chassis_vendor');
result.type = util.getValue(lines, 'chassis_type');
result.version = util.getValue(lines, 'chassis_version');
result.serial = util.getValue(lines, 'chassis_serial');
result.assetTag = util.getValue(lines, 'chassis_asset_tag');
if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) result.serial = '-';
if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) result.assetTag = '-';
if (callback) { callback(result); }
resolve(result);
});
}
if (_darwin) {
exec('ioreg -c IOPlatformExpertDevice -d 2', function (error, stdout) {
if (!error) {
let lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
result.manufacturer = util.getValue(lines, 'manufacturer', '=', true);
result.model = util.getValue(lines, 'model', '=', true);
result.version = util.getValue(lines, 'version', '=', true);
result.serial = util.getValue(lines, 'ioplatformserialnumber', '=', true);
result.assetTag = util.getValue(lines, 'board-id', '=', true);
}
if (callback) { callback(result); }
resolve(result);
});
}
if (_sunos) {
if (callback) { callback(result); }
resolve(result);
}
if (_windows) {
try {
exec(util.getWmic() + ' path Win32_SystemEnclosure get /value', util.execOptsWin, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\r\n');
result.manufacturer = util.getValue(lines, 'manufacturer', '=');
result.model = util.getValue(lines, 'model', '=');
const ctype = parseInt(util.getValue(lines, 'ChassisTypes', '='));
result.type = (ctype && !isNaN(ctype) && ctype < chassisTypes.length) ? chassisTypes[ctype] : '';
result.version = util.getValue(lines, 'version', '=');
result.serial = util.getValue(lines, 'serialnumber', '=');
result.assetTag = util.getValue(lines, 'partnumber', '=');
result.sku = util.getValue(lines, 'sku', '=');
}
if (callback) { callback(result); }
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
}
}
});
});
}
exports.chassis = chassis;