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

system.js 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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. const model = util.getValue(lines, 'model:', ':', true);
  90. // reference values: https://elinux.org/RPi_HardwareHistory
  91. // https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
  92. if ((result.model === 'BCM2835' || result.model === 'BCM2708' || result.model === 'BCM2709' || result.model === 'BCM2835' || result.model === 'BCM2837') && model.toLowerCase().indexOf('raspberry') >= 0) {
  93. const rPIRevision = util.decodePiCpuinfo(lines);
  94. result.model = rPIRevision.model;
  95. result.version = rPIRevision.revisionCode;
  96. result.manufacturer = 'Raspberry Pi Foundation';
  97. result.raspberry = {
  98. manufacturer: rPIRevision.manufacturer,
  99. processor: rPIRevision.processor,
  100. type: rPIRevision.type,
  101. revision: rPIRevision.revision
  102. };
  103. }
  104. // if (result.model === 'BCM2835' || result.model === 'BCM2708' || result.model === 'BCM2709' || result.model === 'BCM2835' || result.model === 'BCM2837') {
  105. // // Pi 4
  106. // if (['d03114'].indexOf(result.version) >= 0) {
  107. // result.model = result.model + ' - Pi 4 Model B';
  108. // result.version = result.version + ' - Rev. 1.4';
  109. // }
  110. // if (['b03112', 'c03112'].indexOf(result.version) >= 0) {
  111. // result.model = result.model + ' - Pi 4 Model B';
  112. // result.version = result.version + ' - Rev. 1.2';
  113. // }
  114. // if (['a03111', 'b03111', 'c03111'].indexOf(result.version) >= 0) {
  115. // result.model = result.model + ' - Pi 4 Model B';
  116. // result.version = result.version + ' - Rev. 1.1';
  117. // }
  118. // // Pi 3
  119. // if (['a02082', 'a22082', 'a32082', 'a52082'].indexOf(result.version) >= 0) {
  120. // result.model = result.model + ' - Pi 3 Model B';
  121. // result.version = result.version + ' - Rev. 1.2';
  122. // }
  123. // if (['a22083'].indexOf(result.version) >= 0) {
  124. // result.model = result.model + ' - Pi 3 Model B';
  125. // result.version = result.version + ' - Rev. 1.3';
  126. // }
  127. // if (['a020d3'].indexOf(result.version) >= 0) {
  128. // result.model = result.model + ' - Pi 3 Model B+';
  129. // result.version = result.version + ' - Rev. 1.3';
  130. // }
  131. // if (['9020e0'].indexOf(result.version) >= 0) {
  132. // result.model = result.model + ' - Pi 3 Model A+';
  133. // result.version = result.version + ' - Rev. 1.3';
  134. // }
  135. // // Pi 2 Model B
  136. // if (['a01040'].indexOf(result.version) >= 0) {
  137. // result.model = result.model + ' - Pi 2 Model B';
  138. // result.version = result.version + ' - Rev. 1.0';
  139. // }
  140. // if (['a01041', 'a21041'].indexOf(result.version) >= 0) {
  141. // result.model = result.model + ' - Pi 2 Model B';
  142. // result.version = result.version + ' - Rev. 1.1';
  143. // }
  144. // if (['a22042', 'a02042'].indexOf(result.version) >= 0) {
  145. // result.model = result.model + ' - Pi 2 Model B';
  146. // result.version = result.version + ' - Rev. 1.2';
  147. // }
  148. // // Compute Model
  149. // if (['a02100'].indexOf(result.version) >= 0) {
  150. // result.model = result.model + ' - Pi CM3+';
  151. // result.version = result.version + ' - Rev 1.0';
  152. // }
  153. // if (['a020a0', 'a220a0'].indexOf(result.version) >= 0) {
  154. // result.model = result.model + ' - Pi CM3';
  155. // result.version = result.version + ' - Rev 1.0';
  156. // }
  157. // if (['900061'].indexOf(result.version) >= 0) {
  158. // result.model = result.model + ' - Pi CM';
  159. // result.version = result.version + ' - Rev 1.1';
  160. // }
  161. // // Pi Zero
  162. // if (['900092', '920092'].indexOf(result.version) >= 0) {
  163. // result.model = result.model + ' - Pi Zero';
  164. // result.version = result.version + ' - Rev 1.2';
  165. // }
  166. // if (['900093', '920093'].indexOf(result.version) >= 0) {
  167. // result.model = result.model + ' - Pi Zero';
  168. // result.version = result.version + ' - Rev 1.3';
  169. // }
  170. // if (['9000c1'].indexOf(result.version) >= 0) {
  171. // result.model = result.model + ' - Pi Zero W';
  172. // result.version = result.version + ' - Rev 1.1';
  173. // }
  174. // // A, B, A+ B+
  175. // if (['0002', '0003'].indexOf(result.version) >= 0) {
  176. // result.model = result.model + ' - Pi Model B';
  177. // result.version = result.version + ' - Rev 1.0';
  178. // }
  179. // if (['0004', '0005', '0006', '000d', '000e', '000f'].indexOf(result.version) >= 0) {
  180. // result.model = result.model + ' - Pi Model B';
  181. // result.version = result.version + ' - Rev 2.0';
  182. // }
  183. // if (['0007', '0008', '0009'].indexOf(result.version) >= 0) {
  184. // result.model = result.model + ' - Pi Model A';
  185. // result.version = result.version + ' - Rev 2.0';
  186. // }
  187. // if (['0010'].indexOf(result.version) >= 0) {
  188. // result.model = result.model + ' - Pi Model B+';
  189. // result.version = result.version + ' - Rev 1.0';
  190. // }
  191. // if (['0012'].indexOf(result.version) >= 0) {
  192. // result.model = result.model + ' - Pi Model A+';
  193. // result.version = result.version + ' - Rev 1.0';
  194. // }
  195. // if (['0013', '900032'].indexOf(result.version) >= 0) {
  196. // result.model = result.model + ' - Pi Model B+';
  197. // result.version = result.version + ' - Rev 1.2';
  198. // }
  199. // if (['0015', '900021'].indexOf(result.version) >= 0) {
  200. // result.model = result.model + ' - Pi Model A+';
  201. // result.version = result.version + ' - Rev 1.1';
  202. // }
  203. // if (result.model.indexOf('Pi') !== -1 && result.version) { // Pi, Pi Zero
  204. // result.manufacturer = 'Raspberry Pi Foundation';
  205. // }
  206. // }
  207. }
  208. if (callback) { callback(result); }
  209. resolve(result);
  210. });
  211. } else {
  212. if (callback) { callback(result); }
  213. resolve(result);
  214. }
  215. });
  216. } else {
  217. if (callback) { callback(result); }
  218. resolve(result);
  219. }
  220. });
  221. }
  222. if (_darwin) {
  223. exec('ioreg -c IOPlatformExpertDevice -d 2', function (error, stdout) {
  224. if (!error) {
  225. let lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
  226. result.manufacturer = util.getValue(lines, 'manufacturer', '=', true);
  227. result.model = util.getValue(lines, 'model', '=', true);
  228. result.version = util.getValue(lines, 'version', '=', true);
  229. result.serial = util.getValue(lines, 'ioplatformserialnumber', '=', true);
  230. result.uuid = util.getValue(lines, 'ioplatformuuid', '=', true);
  231. result.sku = util.getValue(lines, 'board-id', '=', true);
  232. }
  233. if (callback) { callback(result); }
  234. resolve(result);
  235. });
  236. }
  237. if (_sunos) {
  238. if (callback) { callback(result); }
  239. resolve(result);
  240. }
  241. if (_windows) {
  242. try {
  243. util.wmic('csproduct get /value').then((stdout, error) => {
  244. if (!error) {
  245. // let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0)[0].trim().split(/\s\s+/);
  246. let lines = stdout.split('\r\n');
  247. result.manufacturer = util.getValue(lines, 'vendor', '=');
  248. result.model = util.getValue(lines, 'name', '=');
  249. result.version = util.getValue(lines, 'version', '=');
  250. result.serial = util.getValue(lines, 'identifyingnumber', '=');
  251. result.uuid = util.getValue(lines, 'uuid', '=');
  252. util.wmic('/namespace:\\\\root\\wmi path MS_SystemInformation get /value').then((stdout, error) => {
  253. if (!error) {
  254. let lines = stdout.split('\r\n');
  255. result.sku = util.getValue(lines, 'systemsku', '=');
  256. }
  257. if (callback) { callback(result); }
  258. resolve(result);
  259. });
  260. } else {
  261. if (callback) { callback(result); }
  262. resolve(result);
  263. }
  264. });
  265. } catch (e) {
  266. if (callback) { callback(result); }
  267. resolve(result);
  268. }
  269. }
  270. });
  271. });
  272. }
  273. exports.system = system;
  274. function bios(callback) {
  275. return new Promise((resolve) => {
  276. process.nextTick(() => {
  277. let result = {
  278. vendor: '',
  279. version: '',
  280. releaseDate: '',
  281. revision: '',
  282. };
  283. let cmd = '';
  284. if (_linux || _freebsd || _openbsd || _netbsd) {
  285. if (process.arch === 'arm') {
  286. cmd = 'cat /proc/cpuinfo | grep Serial';
  287. } else {
  288. cmd = 'export LC_ALL=C; dmidecode --type 0 2>/dev/null; unset LC_ALL';
  289. }
  290. exec(cmd, function (error, stdout) {
  291. let lines = stdout.toString().split('\n');
  292. result.vendor = util.getValue(lines, 'Vendor');
  293. result.version = util.getValue(lines, 'Version');
  294. let datetime = util.getValue(lines, 'Release Date');
  295. result.releaseDate = util.parseDateTime(datetime).date;
  296. result.revision = util.getValue(lines, 'BIOS Revision');
  297. // Non-Root values
  298. const cmd = `echo -n "bios_date: "; cat /sys/devices/virtual/dmi/id/bios_date 2>/dev/null; echo;
  299. echo -n "bios_vendor: "; cat /sys/devices/virtual/dmi/id/bios_vendor 2>/dev/null; echo;
  300. echo -n "bios_version: "; cat /sys/devices/virtual/dmi/id/bios_version 2>/dev/null; echo;`;
  301. try {
  302. lines = execSync(cmd).toString().split('\n');
  303. result.vendor = !result.vendor ? util.getValue(lines, 'bios_vendor') : result.vendor;
  304. result.version = !result.version ? util.getValue(lines, 'bios_version') : result.version;
  305. datetime = util.getValue(lines, 'bios_date');
  306. result.releaseDate = !result.releaseDate ? util.parseDateTime(datetime).date : result.releaseDate;
  307. } catch (e) {
  308. util.noop();
  309. }
  310. if (callback) { callback(result); }
  311. resolve(result);
  312. });
  313. }
  314. if (_darwin) {
  315. result.vendor = 'Apple Inc.';
  316. if (callback) { callback(result); }
  317. resolve(result);
  318. }
  319. if (_sunos) {
  320. result.vendor = 'Sun Microsystems';
  321. if (callback) { callback(result); }
  322. resolve(result);
  323. }
  324. if (_windows) {
  325. try {
  326. util.wmic('bios get /value').then((stdout, error) => {
  327. if (!error) {
  328. let lines = stdout.toString().split('\r\n');
  329. const description = util.getValue(lines, 'description', '=');
  330. if (description.indexOf(' Version ') !== -1) {
  331. // ... Phoenix ROM BIOS PLUS Version 1.10 A04
  332. result.vendor = description.split(' Version ')[0].trim();
  333. result.version = description.split(' Version ')[1].trim();
  334. } else if (description.indexOf(' Ver: ') !== -1) {
  335. // ... BIOS Date: 06/27/16 17:50:16 Ver: 1.4.5
  336. result.vendor = util.getValue(lines, 'manufacturer', '=');
  337. result.version = description.split(' Ver: ')[1].trim();
  338. } else {
  339. result.vendor = util.getValue(lines, 'manufacturer', '=');
  340. result.version = util.getValue(lines, 'version', '=');
  341. }
  342. result.releaseDate = util.getValue(lines, 'releasedate', '=');
  343. if (result.releaseDate.length >= 10) {
  344. result.releaseDate = result.releaseDate.substr(0, 4) + '-' + result.releaseDate.substr(4, 2) + '-' + result.releaseDate.substr(6, 2);
  345. }
  346. result.revision = util.getValue(lines, 'buildnumber', '=');
  347. }
  348. if (callback) { callback(result); }
  349. resolve(result);
  350. });
  351. } catch (e) {
  352. if (callback) { callback(result); }
  353. resolve(result);
  354. }
  355. }
  356. });
  357. });
  358. }
  359. exports.bios = bios;
  360. function baseboard(callback) {
  361. return new Promise((resolve) => {
  362. process.nextTick(() => {
  363. let result = {
  364. manufacturer: '',
  365. model: '',
  366. version: '',
  367. serial: '-',
  368. assetTag: '-',
  369. };
  370. let cmd = '';
  371. if (_linux || _freebsd || _openbsd || _netbsd) {
  372. if (process.arch === 'arm') {
  373. cmd = 'cat /proc/cpuinfo | grep Serial';
  374. // 'BCM2709', 'BCM2835', 'BCM2708' -->
  375. } else {
  376. cmd = 'export LC_ALL=C; dmidecode -t 2 2>/dev/null; unset LC_ALL';
  377. }
  378. exec(cmd, function (error, stdout) {
  379. let lines = stdout.toString().split('\n');
  380. result.manufacturer = util.getValue(lines, 'Manufacturer');
  381. result.model = util.getValue(lines, 'Product Name');
  382. result.version = util.getValue(lines, 'Version');
  383. result.serial = util.getValue(lines, 'Serial Number');
  384. result.assetTag = util.getValue(lines, 'Asset Tag');
  385. // Non-Root values
  386. const cmd = `echo -n "board_asset_tag: "; cat /sys/devices/virtual/dmi/id/board_asset_tag 2>/dev/null; echo;
  387. echo -n "board_name: "; cat /sys/devices/virtual/dmi/id/board_name 2>/dev/null; echo;
  388. echo -n "board_serial: "; cat /sys/devices/virtual/dmi/id/board_serial 2>/dev/null; echo;
  389. echo -n "board_vendor: "; cat /sys/devices/virtual/dmi/id/board_vendor 2>/dev/null; echo;
  390. echo -n "board_version: "; cat /sys/devices/virtual/dmi/id/board_version 2>/dev/null; echo;`;
  391. try {
  392. lines = execSync(cmd).toString().split('\n');
  393. result.manufacturer = !result.manufacturer ? util.getValue(lines, 'board_vendor') : result.manufacturer;
  394. result.model = !result.model ? util.getValue(lines, 'board_name') : result.model;
  395. result.version = !result.version ? util.getValue(lines, 'board_version') : result.version;
  396. result.serial = !result.serial ? util.getValue(lines, 'board_serial') : result.serial;
  397. result.assetTag = !result.assetTag ? util.getValue(lines, 'board_asset_tag') : result.assetTag;
  398. } catch (e) {
  399. util.noop();
  400. }
  401. if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) result.serial = '-';
  402. if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) result.assetTag = '-';
  403. if (callback) { callback(result); }
  404. resolve(result);
  405. });
  406. }
  407. if (_darwin) {
  408. exec('ioreg -c IOPlatformExpertDevice -d 2', function (error, stdout) {
  409. if (!error) {
  410. let lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
  411. result.manufacturer = util.getValue(lines, 'manufacturer', '=', true);
  412. result.model = util.getValue(lines, 'model', '=', true);
  413. result.version = util.getValue(lines, 'version', '=', true);
  414. result.serial = util.getValue(lines, 'ioplatformserialnumber', '=', true);
  415. result.assetTag = util.getValue(lines, 'board-id', '=', true);
  416. }
  417. if (callback) { callback(result); }
  418. resolve(result);
  419. });
  420. }
  421. if (_sunos) {
  422. if (callback) { callback(result); }
  423. resolve(result);
  424. }
  425. if (_windows) {
  426. try {
  427. util.wmic('baseboard get /value').then((stdout, error) => {
  428. if (!error) {
  429. let lines = stdout.toString().split('\r\n');
  430. result.manufacturer = util.getValue(lines, 'manufacturer', '=');
  431. result.model = util.getValue(lines, 'model', '=');
  432. if (!result.model) {
  433. result.model = util.getValue(lines, 'product', '=');
  434. }
  435. result.version = util.getValue(lines, 'version', '=');
  436. result.serial = util.getValue(lines, 'serialnumber', '=');
  437. result.assetTag = util.getValue(lines, 'partnumber', '=');
  438. if (!result.assetTag) {
  439. result.assetTag = util.getValue(lines, 'sku', '=');
  440. }
  441. }
  442. if (callback) { callback(result); }
  443. resolve(result);
  444. });
  445. } catch (e) {
  446. if (callback) { callback(result); }
  447. resolve(result);
  448. }
  449. }
  450. });
  451. });
  452. }
  453. exports.baseboard = baseboard;
  454. function chassis(callback) {
  455. const chassisTypes = ['Other',
  456. 'Unknown',
  457. 'Desktop',
  458. 'Low Profile Desktop',
  459. 'Pizza Box',
  460. 'Mini Tower',
  461. 'Tower',
  462. 'Portable',
  463. 'Laptop',
  464. 'Notebook',
  465. 'Hand Held',
  466. 'Docking Station',
  467. 'All in One',
  468. 'Sub Notebook',
  469. 'Space-Saving',
  470. 'Lunch Box',
  471. 'Main System Chassis',
  472. 'Expansion Chassis',
  473. 'SubChassis',
  474. 'Bus Expansion Chassis',
  475. 'Peripheral Chassis',
  476. 'Storage Chassis',
  477. 'Rack Mount Chassis',
  478. 'Sealed-Case PC',
  479. 'Multi-System Chassis',
  480. 'Compact PCI',
  481. 'Advanced TCA',
  482. 'Blade',
  483. 'Blade Enclosure',
  484. 'Tablet',
  485. 'Concertible',
  486. 'Detachable',
  487. 'IoT Gateway ',
  488. 'Embedded PC',
  489. 'Mini PC',
  490. 'Stick PC',
  491. ];
  492. return new Promise((resolve) => {
  493. process.nextTick(() => {
  494. let result = {
  495. manufacturer: '',
  496. model: '',
  497. type: '',
  498. version: '',
  499. serial: '-',
  500. assetTag: '-',
  501. sku: '',
  502. };
  503. if (_linux || _freebsd || _openbsd || _netbsd) {
  504. const cmd = `echo -n "chassis_asset_tag: "; cat /sys/devices/virtual/dmi/id/chassis_asset_tag 2>/dev/null; echo;
  505. echo -n "chassis_serial: "; cat /sys/devices/virtual/dmi/id/chassis_serial 2>/dev/null; echo;
  506. echo -n "chassis_type: "; cat /sys/devices/virtual/dmi/id/chassis_type 2>/dev/null; echo;
  507. echo -n "chassis_vendor: "; cat /sys/devices/virtual/dmi/id/chassis_vendor 2>/dev/null; echo;
  508. echo -n "chassis_version: "; cat /sys/devices/virtual/dmi/id/chassis_version 2>/dev/null; echo;`;
  509. exec(cmd, function (error, stdout) {
  510. let lines = stdout.toString().split('\n');
  511. result.manufacturer = util.getValue(lines, 'chassis_vendor');
  512. const ctype = parseInt(util.getValue(lines, 'chassis_type').replace(/\D/g, ''));
  513. result.type = (ctype && !isNaN(ctype) && ctype < chassisTypes.length) ? chassisTypes[ctype - 1] : '';
  514. result.version = util.getValue(lines, 'chassis_version');
  515. result.serial = util.getValue(lines, 'chassis_serial');
  516. result.assetTag = util.getValue(lines, 'chassis_asset_tag');
  517. if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) result.serial = '-';
  518. if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) result.assetTag = '-';
  519. if (callback) { callback(result); }
  520. resolve(result);
  521. });
  522. }
  523. if (_darwin) {
  524. exec('ioreg -c IOPlatformExpertDevice -d 2', function (error, stdout) {
  525. if (!error) {
  526. let lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
  527. result.manufacturer = util.getValue(lines, 'manufacturer', '=', true);
  528. result.model = util.getValue(lines, 'model', '=', true);
  529. result.version = util.getValue(lines, 'version', '=', true);
  530. result.serial = util.getValue(lines, 'ioplatformserialnumber', '=', true);
  531. result.assetTag = util.getValue(lines, 'board-id', '=', true);
  532. }
  533. if (callback) { callback(result); }
  534. resolve(result);
  535. });
  536. }
  537. if (_sunos) {
  538. if (callback) { callback(result); }
  539. resolve(result);
  540. }
  541. if (_windows) {
  542. try {
  543. util.wmic('path Win32_SystemEnclosure get /value').then((stdout, error) => {
  544. if (!error) {
  545. let lines = stdout.toString().split('\r\n');
  546. result.manufacturer = util.getValue(lines, 'manufacturer', '=');
  547. result.model = util.getValue(lines, 'model', '=');
  548. const ctype = parseInt(util.getValue(lines, 'ChassisTypes', '=').replace(/\D/g, ''));
  549. result.type = (ctype && !isNaN(ctype) && ctype < chassisTypes.length) ? chassisTypes[ctype - 1] : '';
  550. result.version = util.getValue(lines, 'version', '=');
  551. result.serial = util.getValue(lines, 'serialnumber', '=');
  552. result.assetTag = util.getValue(lines, 'partnumber', '=');
  553. result.sku = util.getValue(lines, 'sku', '=');
  554. }
  555. if (callback) { callback(result); }
  556. resolve(result);
  557. });
  558. } catch (e) {
  559. if (callback) { callback(result); }
  560. resolve(result);
  561. }
  562. }
  563. });
  564. });
  565. }
  566. exports.chassis = chassis;