Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. 'use strict';
  2. // @ts-check
  3. // ==================================================================================
  4. // system.js
  5. // ----------------------------------------------------------------------------------
  6. // Description: System Information - library
  7. // for Node.js
  8. // Copyright: (c) 2014 - 2020
  9. // Author: Sebastian Hildebrandt
  10. // ----------------------------------------------------------------------------------
  11. // License: MIT
  12. // ==================================================================================
  13. // 2. System (Hardware, BIOS, Base Board)
  14. // ----------------------------------------------------------------------------------
  15. const exec = require('child_process').exec;
  16. const execSync = require('child_process').execSync;
  17. const fs = require('fs');
  18. const util = require('./util');
  19. let _platform = process.platform;
  20. const _linux = (_platform === 'linux');
  21. const _darwin = (_platform === 'darwin');
  22. const _windows = (_platform === 'win32');
  23. const _freebsd = (_platform === 'freebsd');
  24. const _openbsd = (_platform === 'openbsd');
  25. const _netbsd = (_platform === 'netbsd');
  26. const _sunos = (_platform === 'sunos');
  27. function system(callback) {
  28. return new Promise((resolve) => {
  29. process.nextTick(() => {
  30. let result = {
  31. manufacturer: '',
  32. model: 'Computer',
  33. version: '',
  34. serial: '-',
  35. uuid: '-',
  36. sku: '-',
  37. };
  38. if (_linux || _freebsd || _openbsd || _netbsd) {
  39. exec('export LC_ALL=C; dmidecode -t system 2>/dev/null; unset LC_ALL', function (error, stdout) {
  40. // if (!error) {
  41. let lines = stdout.toString().split('\n');
  42. result.manufacturer = util.getValue(lines, 'manufacturer');
  43. result.model = util.getValue(lines, 'product name');
  44. result.version = util.getValue(lines, 'version');
  45. result.serial = util.getValue(lines, 'serial number');
  46. result.uuid = util.getValue(lines, 'uuid');
  47. result.sku = util.getValue(lines, 'sku number');
  48. // }
  49. // Non-Root values
  50. const cmd = `echo -n "product_name: "; cat /sys/devices/virtual/dmi/id/product_name 2>/dev/null; echo;
  51. echo -n "product_serial: "; cat /sys/devices/virtual/dmi/id/product_serial 2>/dev/null; echo;
  52. echo -n "product_uuid: "; cat /sys/devices/virtual/dmi/id/product_uuid 2>/dev/null; echo;
  53. echo -n "product_version: "; cat /sys/devices/virtual/dmi/id/product_version 2>/dev/null; echo;
  54. echo -n "sys_vendor: "; cat /sys/devices/virtual/dmi/id/sys_vendor 2>/dev/null; echo;`;
  55. try {
  56. lines = execSync(cmd).toString().split('\n');
  57. result.manufacturer = result.manufacturer === '' ? util.getValue(lines, 'sys_vendor') : result.manufacturer;
  58. result.model = result.model === '' ? util.getValue(lines, 'product_name') : result.model;
  59. result.version = result.version === '' ? util.getValue(lines, 'product_version') : result.version;
  60. result.serial = result.serial === '' ? util.getValue(lines, 'product_serial') : result.serial;
  61. result.uuid = result.uuid === '' ? util.getValue(lines, 'product_uuid') : result.uuid;
  62. } catch (e) {
  63. util.noop();
  64. }
  65. if (!result.serial || result.serial.toLowerCase().indexOf('o.e.m.') !== -1) result.serial = '-';
  66. if (!result.manufacturer || result.manufacturer.toLowerCase().indexOf('o.e.m.') !== -1) result.manufacturer = '';
  67. if (!result.model || result.model.toLowerCase().indexOf('o.e.m.') !== -1) result.model = 'Computer';
  68. if (!result.version || result.version.toLowerCase().indexOf('o.e.m.') !== -1) result.version = '';
  69. if (!result.sku || result.sku.toLowerCase().indexOf('o.e.m.') !== -1) result.sku = '-';
  70. // detect docker
  71. if (fs.existsSync('/.dockerenv') || fs.existsSync('/.dockerinit')) {
  72. result.model = 'Docker Container';
  73. }
  74. if (result.manufacturer === '' && result.model === 'Computer' && result.version === '') { // still default values
  75. exec('dmesg | grep -i virtual | grep -iE "vmware|qemu|kvm|xen"', function (error, stdout) {
  76. // detect virtual machines
  77. if (!error) {
  78. let lines = stdout.toString().split('\n');
  79. if (lines.length > 0) result.model = 'Virtual machine';
  80. }
  81. if (result.manufacturer === '' && result.model === 'Computer' && result.version === '') {
  82. // Check Raspberry Pi
  83. fs.readFile('/proc/cpuinfo', function (error, stdout) {
  84. if (!error) {
  85. let lines = stdout.toString().split('\n');
  86. result.model = util.getValue(lines, 'hardware', ':', true).toUpperCase();
  87. result.version = util.getValue(lines, 'revision', ':', true).toLowerCase();
  88. result.serial = util.getValue(lines, 'serial', ':', true);
  89. // reference values: https://elinux.org/RPi_HardwareHistory
  90. // https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
  91. if (result.model === 'BCM2835' || result.model === 'BCM2708' || result.model === 'BCM2709' || result.model === 'BCM2835' || result.model === 'BCM2837') {
  92. // Pi 4
  93. if (['c03112'].indexOf(result.version) >= 0) {
  94. result.model = result.model + ' - Pi 4 Model B';
  95. result.version = result.version + ' - Rev. 1.2';
  96. }
  97. if (['a03111', 'b03111', 'c03111'].indexOf(result.version) >= 0) {
  98. result.model = result.model + ' - Pi 4 Model B';
  99. result.version = result.version + ' - Rev. 1.1';
  100. }
  101. // Pi 3
  102. if (['a02082', 'a22082', 'a32082'].indexOf(result.version) >= 0) {
  103. result.model = result.model + ' - Pi 3 Model B';
  104. result.version = result.version + ' - Rev. 1.2';
  105. }
  106. if (['a020d3'].indexOf(result.version) >= 0) {
  107. result.model = result.model + ' - Pi 3 Model B+';
  108. result.version = result.version + ' - Rev. 1.3';
  109. }
  110. if (['9020e0'].indexOf(result.version) >= 0) {
  111. result.model = result.model + ' - Pi 3 Model A+';
  112. result.version = result.version + ' - Rev. 1.3';
  113. }
  114. // Pi 2 Model B
  115. if (['a01040'].indexOf(result.version) >= 0) {
  116. result.model = result.model + ' - Pi 2 Model B';
  117. result.version = result.version + ' - Rev. 1.0';
  118. }
  119. if (['a01041', 'a21041'].indexOf(result.version) >= 0) {
  120. result.model = result.model + ' - Pi 2 Model B';
  121. result.version = result.version + ' - Rev. 1.1';
  122. }
  123. if (['a22042'].indexOf(result.version) >= 0) {
  124. result.model = result.model + ' - Pi 2 Model B';
  125. result.version = result.version + ' - Rev. 1.2';
  126. }
  127. // Pi Zero
  128. if (['900092'].indexOf(result.version) >= 0) {
  129. result.model = result.model + ' - Pi Zero';
  130. result.version = result.version + ' - Rev 1.2';
  131. }
  132. if (['900093', '920093'].indexOf(result.version) >= 0) {
  133. result.model = result.model + ' - Pi Zero';
  134. result.version = result.version + ' - Rev 1.3';
  135. }
  136. if (['9000c1'].indexOf(result.version) >= 0) {
  137. result.model = result.model + ' - Pi Zero W';
  138. result.version = result.version + ' - Rev 1.1';
  139. }
  140. // A, B, A+ B+
  141. if (['0002', '0003'].indexOf(result.version) >= 0) {
  142. result.model = result.model + ' - Pi Model B';
  143. result.version = result.version + ' - Rev 1.0';
  144. }
  145. if (['0004', '0005', '0006', '000d', '000e', '000f'].indexOf(result.version) >= 0) {
  146. result.model = result.model + ' - Pi Model B';
  147. result.version = result.version + ' - Rev 2.0';
  148. }
  149. if (['0007', '0008', '0009'].indexOf(result.version) >= 0) {
  150. result.model = result.model + ' - Pi Model A';
  151. result.version = result.version + ' - Rev 2.0';
  152. }
  153. if (['0010'].indexOf(result.version) >= 0) {
  154. result.model = result.model + ' - Pi Model B+';
  155. result.version = result.version + ' - Rev 1.0';
  156. }
  157. if (['0012'].indexOf(result.version) >= 0) {
  158. result.model = result.model + ' - Pi Model A+';
  159. result.version = result.version + ' - Rev 1.0';
  160. }
  161. if (['0013'].indexOf(result.version) >= 0) {
  162. result.model = result.model + ' - Pi Model B+';
  163. result.version = result.version + ' - Rev 1.2';
  164. }
  165. if (['0015'].indexOf(result.version) >= 0) {
  166. result.model = result.model + ' - Pi Model A+';
  167. result.version = result.version + ' - Rev 1.1';
  168. }
  169. if (result.model.indexOf('Pi') !== -1 && result.version) { // Pi, Pi Zero
  170. result.manufacturer = 'Raspberry Pi Foundation';
  171. }
  172. }
  173. }
  174. if (callback) { callback(result); }
  175. resolve(result);
  176. });
  177. } else {
  178. if (callback) { callback(result); }
  179. resolve(result);
  180. }
  181. });
  182. } else {
  183. if (callback) { callback(result); }
  184. resolve(result);
  185. }
  186. });
  187. }
  188. if (_darwin) {
  189. exec('ioreg -c IOPlatformExpertDevice -d 2', function (error, stdout) {
  190. if (!error) {
  191. let lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
  192. result.manufacturer = util.getValue(lines, 'manufacturer', '=', true);
  193. result.model = util.getValue(lines, 'model', '=', true);
  194. result.version = util.getValue(lines, 'version', '=', true);
  195. result.serial = util.getValue(lines, 'ioplatformserialnumber', '=', true);
  196. result.uuid = util.getValue(lines, 'ioplatformuuid', '=', true);
  197. result.sku = util.getValue(lines, 'board-id', '=', true);
  198. }
  199. if (callback) { callback(result); }
  200. resolve(result);
  201. });
  202. }
  203. if (_sunos) {
  204. if (callback) { callback(result); }
  205. resolve(result);
  206. }
  207. if (_windows) {
  208. try {
  209. util.wmic('csproduct get /value').then((stdout, error) => {
  210. if (!error) {
  211. // let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0)[0].trim().split(/\s\s+/);
  212. let lines = stdout.split('\r\n');
  213. result.manufacturer = util.getValue(lines, 'vendor', '=');
  214. result.model = util.getValue(lines, 'name', '=');
  215. result.version = util.getValue(lines, 'version', '=');
  216. result.serial = util.getValue(lines, 'identifyingnumber', '=');
  217. result.uuid = util.getValue(lines, 'uuid', '=');
  218. util.wmic('/namespace:\\\\root\\wmi path MS_SystemInformation get /value').then((stdout, error) => {
  219. if (!error) {
  220. let lines = stdout.split('\r\n');
  221. result.sku = util.getValue(lines, 'systemsku', '=');
  222. }
  223. if (callback) { callback(result); }
  224. resolve(result);
  225. });
  226. } else {
  227. if (callback) { callback(result); }
  228. resolve(result);
  229. }
  230. });
  231. } catch (e) {
  232. if (callback) { callback(result); }
  233. resolve(result);
  234. }
  235. }
  236. });
  237. });
  238. }
  239. exports.system = system;
  240. function bios(callback) {
  241. return new Promise((resolve) => {
  242. process.nextTick(() => {
  243. let result = {
  244. vendor: '',
  245. version: '',
  246. releaseDate: '',
  247. revision: '',
  248. };
  249. let cmd = '';
  250. if (_linux || _freebsd || _openbsd || _netbsd) {
  251. if (process.arch === 'arm') {
  252. cmd = 'cat /proc/cpuinfo | grep Serial';
  253. } else {
  254. cmd = 'export LC_ALL=C; dmidecode --type 0 2>/dev/null; unset LC_ALL';
  255. }
  256. exec(cmd, function (error, stdout) {
  257. let lines = stdout.toString().split('\n');
  258. result.vendor = util.getValue(lines, 'Vendor');
  259. result.version = util.getValue(lines, 'Version');
  260. let datetime = util.getValue(lines, 'Release Date');
  261. result.releaseDate = util.parseDateTime(datetime).date;
  262. result.revision = util.getValue(lines, 'BIOS Revision');
  263. // Non-Root values
  264. const cmd = `echo -n "bios_date: "; cat /sys/devices/virtual/dmi/id/bios_date 2>/dev/null; echo;
  265. echo -n "bios_vendor: "; cat /sys/devices/virtual/dmi/id/bios_vendor 2>/dev/null; echo;
  266. echo -n "bios_version: "; cat /sys/devices/virtual/dmi/id/bios_version 2>/dev/null; echo;`;
  267. try {
  268. lines = execSync(cmd).toString().split('\n');
  269. result.vendor = !result.vendor ? util.getValue(lines, 'bios_vendor') : result.vendor;
  270. result.version = !result.version ? util.getValue(lines, 'bios_version') : result.version;
  271. datetime = util.getValue(lines, 'bios_date');
  272. result.releaseDate = !result.releaseDate ? util.parseDateTime(datetime).date : result.releaseDate;
  273. } catch (e) {
  274. util.noop();
  275. }
  276. if (callback) { callback(result); }
  277. resolve(result);
  278. });
  279. }
  280. if (_darwin) {
  281. result.vendor = 'Apple Inc.';
  282. if (callback) { callback(result); }
  283. resolve(result);
  284. }
  285. if (_sunos) {
  286. result.vendor = 'Sun Microsystems';
  287. if (callback) { callback(result); }
  288. resolve(result);
  289. }
  290. if (_windows) {
  291. try {
  292. util.wmic('bios get /value').then((stdout, error) => {
  293. if (!error) {
  294. let lines = stdout.toString().split('\r\n');
  295. const description = util.getValue(lines, 'description', '=');
  296. if (description.indexOf(' Version ') !== -1) {
  297. // ... Phoenix ROM BIOS PLUS Version 1.10 A04
  298. result.vendor = description.split(' Version ')[0].trim();
  299. result.version = description.split(' Version ')[1].trim();
  300. } else if (description.indexOf(' Ver: ') !== -1) {
  301. // ... BIOS Date: 06/27/16 17:50:16 Ver: 1.4.5
  302. result.vendor = util.getValue(lines, 'manufacturer', '=');
  303. result.version = description.split(' Ver: ')[1].trim();
  304. } else {
  305. result.vendor = util.getValue(lines, 'manufacturer', '=');
  306. result.version = util.getValue(lines, 'version', '=');
  307. }
  308. result.releaseDate = util.getValue(lines, 'releasedate', '=');
  309. if (result.releaseDate.length >= 10) {
  310. result.releaseDate = result.releaseDate.substr(0, 4) + '-' + result.releaseDate.substr(4, 2) + '-' + result.releaseDate.substr(6, 2);
  311. }
  312. result.revision = util.getValue(lines, 'buildnumber', '=');
  313. }
  314. if (callback) { callback(result); }
  315. resolve(result);
  316. });
  317. } catch (e) {
  318. if (callback) { callback(result); }
  319. resolve(result);
  320. }
  321. }
  322. });
  323. });
  324. }
  325. exports.bios = bios;
  326. function baseboard(callback) {
  327. return new Promise((resolve) => {
  328. process.nextTick(() => {
  329. let result = {
  330. manufacturer: '',
  331. model: '',
  332. version: '',
  333. serial: '-',
  334. assetTag: '-',
  335. };
  336. let cmd = '';
  337. if (_linux || _freebsd || _openbsd || _netbsd) {
  338. if (process.arch === 'arm') {
  339. cmd = 'cat /proc/cpuinfo | grep Serial';
  340. // 'BCM2709', 'BCM2835', 'BCM2708' -->
  341. } else {
  342. cmd = 'export LC_ALL=C; dmidecode -t 2 2>/dev/null; unset LC_ALL';
  343. }
  344. exec(cmd, function (error, stdout) {
  345. let lines = stdout.toString().split('\n');
  346. result.manufacturer = util.getValue(lines, 'Manufacturer');
  347. result.model = util.getValue(lines, 'Product Name');
  348. result.version = util.getValue(lines, 'Version');
  349. result.serial = util.getValue(lines, 'Serial Number');
  350. result.assetTag = util.getValue(lines, 'Asset Tag');
  351. // Non-Root values
  352. const cmd = `echo -n "board_asset_tag: "; cat /sys/devices/virtual/dmi/id/board_asset_tag 2>/dev/null; echo;
  353. echo -n "board_name: "; cat /sys/devices/virtual/dmi/id/board_name 2>/dev/null; echo;
  354. echo -n "board_serial: "; cat /sys/devices/virtual/dmi/id/board_serial 2>/dev/null; echo;
  355. echo -n "board_vendor: "; cat /sys/devices/virtual/dmi/id/board_vendor 2>/dev/null; echo;
  356. echo -n "board_version: "; cat /sys/devices/virtual/dmi/id/board_version 2>/dev/null; echo;`;
  357. try {
  358. lines = execSync(cmd).toString().split('\n');
  359. result.manufacturer = !result.manufacturer ? util.getValue(lines, 'board_vendor') : result.manufacturer;
  360. result.model = !result.model ? util.getValue(lines, 'board_name') : result.model;
  361. result.version = !result.version ? util.getValue(lines, 'board_version') : result.version;
  362. result.serial = !result.serial ? util.getValue(lines, 'board_serial') : result.serial;
  363. result.assetTag = !result.assetTag ? util.getValue(lines, 'board_asset_tag') : result.assetTag;
  364. } catch (e) {
  365. util.noop();
  366. }
  367. if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) result.serial = '-';
  368. if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) result.assetTag = '-';
  369. if (callback) { callback(result); }
  370. resolve(result);
  371. });
  372. }
  373. if (_darwin) {
  374. exec('ioreg -c IOPlatformExpertDevice -d 2', function (error, stdout) {
  375. if (!error) {
  376. let lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
  377. result.manufacturer = util.getValue(lines, 'manufacturer', '=', true);
  378. result.model = util.getValue(lines, 'model', '=', true);
  379. result.version = util.getValue(lines, 'version', '=', true);
  380. result.serial = util.getValue(lines, 'ioplatformserialnumber', '=', true);
  381. result.assetTag = util.getValue(lines, 'board-id', '=', true);
  382. }
  383. if (callback) { callback(result); }
  384. resolve(result);
  385. });
  386. }
  387. if (_sunos) {
  388. if (callback) { callback(result); }
  389. resolve(result);
  390. }
  391. if (_windows) {
  392. try {
  393. util.wmic('baseboard get /value').then((stdout, error) => {
  394. if (!error) {
  395. let lines = stdout.toString().split('\r\n');
  396. result.manufacturer = util.getValue(lines, 'manufacturer', '=');
  397. result.model = util.getValue(lines, 'model', '=');
  398. if (!result.model) {
  399. result.model = util.getValue(lines, 'product', '=');
  400. }
  401. result.version = util.getValue(lines, 'version', '=');
  402. result.serial = util.getValue(lines, 'serialnumber', '=');
  403. result.assetTag = util.getValue(lines, 'partnumber', '=');
  404. if (!result.assetTag) {
  405. result.assetTag = util.getValue(lines, 'sku', '=');
  406. }
  407. }
  408. if (callback) { callback(result); }
  409. resolve(result);
  410. });
  411. } catch (e) {
  412. if (callback) { callback(result); }
  413. resolve(result);
  414. }
  415. }
  416. });
  417. });
  418. }
  419. exports.baseboard = baseboard;
  420. function chassis(callback) {
  421. const chassisTypes = ['Other',
  422. 'Unknown',
  423. 'Desktop',
  424. 'Low Profile Desktop',
  425. 'Pizza Box',
  426. 'Mini Tower',
  427. 'Tower',
  428. 'Portable',
  429. 'Laptop',
  430. 'Notebook',
  431. 'Hand Held',
  432. 'Docking Station',
  433. 'All in One',
  434. 'Sub Notebook',
  435. 'Space-Saving',
  436. 'Lunch Box',
  437. 'Main System Chassis',
  438. 'Expansion Chassis',
  439. 'SubChassis',
  440. 'Bus Expansion Chassis',
  441. 'Peripheral Chassis',
  442. 'Storage Chassis',
  443. 'Rack Mount Chassis',
  444. 'Sealed-Case PC',
  445. 'Multi-System Chassis',
  446. 'Compact PCI',
  447. 'Advanced TCA',
  448. 'Blade',
  449. 'Blade Enclosure',
  450. 'Tablet',
  451. 'Concertible',
  452. 'Detachable',
  453. 'IoT Gateway ',
  454. 'Embedded PC',
  455. 'Mini PC',
  456. 'Stick PC',
  457. ];
  458. return new Promise((resolve) => {
  459. process.nextTick(() => {
  460. let result = {
  461. manufacturer: '',
  462. model: '',
  463. type: '',
  464. version: '',
  465. serial: '-',
  466. assetTag: '-',
  467. sku: '',
  468. };
  469. if (_linux || _freebsd || _openbsd || _netbsd) {
  470. const cmd = `echo -n "chassis_asset_tag: "; cat /sys/devices/virtual/dmi/id/chassis_asset_tag 2>/dev/null; echo;
  471. echo -n "chassis_serial: "; cat /sys/devices/virtual/dmi/id/chassis_serial 2>/dev/null; echo;
  472. echo -n "chassis_type: "; cat /sys/devices/virtual/dmi/id/chassis_type 2>/dev/null; echo;
  473. echo -n "chassis_vendor: "; cat /sys/devices/virtual/dmi/id/chassis_vendor 2>/dev/null; echo;
  474. echo -n "chassis_version: "; cat /sys/devices/virtual/dmi/id/chassis_version 2>/dev/null; echo;`;
  475. exec(cmd, function (error, stdout) {
  476. let lines = stdout.toString().split('\n');
  477. result.manufacturer = util.getValue(lines, 'chassis_vendor');
  478. const ctype = parseInt(util.getValue(lines, 'chassis_type').replace(/\D/g, ''));
  479. result.type = (ctype && !isNaN(ctype) && ctype < chassisTypes.length) ? chassisTypes[ctype - 1] : '';
  480. result.version = util.getValue(lines, 'chassis_version');
  481. result.serial = util.getValue(lines, 'chassis_serial');
  482. result.assetTag = util.getValue(lines, 'chassis_asset_tag');
  483. if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) result.serial = '-';
  484. if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) result.assetTag = '-';
  485. if (callback) { callback(result); }
  486. resolve(result);
  487. });
  488. }
  489. if (_darwin) {
  490. exec('ioreg -c IOPlatformExpertDevice -d 2', function (error, stdout) {
  491. if (!error) {
  492. let lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
  493. result.manufacturer = util.getValue(lines, 'manufacturer', '=', true);
  494. result.model = util.getValue(lines, 'model', '=', true);
  495. result.version = util.getValue(lines, 'version', '=', true);
  496. result.serial = util.getValue(lines, 'ioplatformserialnumber', '=', true);
  497. result.assetTag = util.getValue(lines, 'board-id', '=', true);
  498. }
  499. if (callback) { callback(result); }
  500. resolve(result);
  501. });
  502. }
  503. if (_sunos) {
  504. if (callback) { callback(result); }
  505. resolve(result);
  506. }
  507. if (_windows) {
  508. try {
  509. util.wmic('path Win32_SystemEnclosure get /value').then((stdout, error) => {
  510. if (!error) {
  511. let lines = stdout.toString().split('\r\n');
  512. result.manufacturer = util.getValue(lines, 'manufacturer', '=');
  513. result.model = util.getValue(lines, 'model', '=');
  514. const ctype = parseInt(util.getValue(lines, 'ChassisTypes', '=').replace(/\D/g, ''));
  515. result.type = (ctype && !isNaN(ctype) && ctype < chassisTypes.length) ? chassisTypes[ctype - 1] : '';
  516. result.version = util.getValue(lines, 'version', '=');
  517. result.serial = util.getValue(lines, 'serialnumber', '=');
  518. result.assetTag = util.getValue(lines, 'partnumber', '=');
  519. result.sku = util.getValue(lines, 'sku', '=');
  520. }
  521. if (callback) { callback(result); }
  522. resolve(result);
  523. });
  524. } catch (e) {
  525. if (callback) { callback(result); }
  526. resolve(result);
  527. }
  528. }
  529. });
  530. });
  531. }
  532. exports.chassis = chassis;