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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. 'use strict';
  2. // @ts-check
  3. // ==================================================================================
  4. // osinfo.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. // 3. Operating System
  14. // ----------------------------------------------------------------------------------
  15. const os = require('os');
  16. const exec = require('child_process').exec;
  17. const util = require('./util');
  18. const fs = require('fs');
  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. const NOT_SUPPORTED = 'not supported';
  28. // --------------------------
  29. // Get current time and OS uptime
  30. function time() {
  31. let t = new Date().toString().split(' ');
  32. return {
  33. current: Date.now(),
  34. uptime: os.uptime(),
  35. timezone: (t.length >= 7) ? t[5] : '',
  36. timezoneName: (t.length >= 7) ? t.slice(6).join(' ').replace(/\(/g, '').replace(/\)/g, '') : ''
  37. };
  38. }
  39. exports.time = time;
  40. // --------------------------
  41. // Get logo filename of OS distribution
  42. function getLogoFile(distro) {
  43. distro = distro || '';
  44. distro = distro.toLowerCase();
  45. let result = _platform;
  46. if (_windows) {
  47. result = 'windows';
  48. }
  49. else if (distro.indexOf('mac os') !== -1) {
  50. result = 'apple';
  51. }
  52. else if (distro.indexOf('arch') !== -1) {
  53. result = 'arch';
  54. }
  55. else if (distro.indexOf('centos') !== -1) {
  56. result = 'centos';
  57. }
  58. else if (distro.indexOf('coreos') !== -1) {
  59. result = 'coreos';
  60. }
  61. else if (distro.indexOf('debian') !== -1) {
  62. result = 'debian';
  63. }
  64. else if (distro.indexOf('deepin') !== -1) {
  65. result = 'deepin';
  66. }
  67. else if (distro.indexOf('elementary') !== -1) {
  68. result = 'elementary';
  69. }
  70. else if (distro.indexOf('fedora') !== -1) {
  71. result = 'fedora';
  72. }
  73. else if (distro.indexOf('gentoo') !== -1) {
  74. result = 'gentoo';
  75. }
  76. else if (distro.indexOf('mageia') !== -1) {
  77. result = 'mageia';
  78. }
  79. else if (distro.indexOf('mandriva') !== -1) {
  80. result = 'mandriva';
  81. }
  82. else if (distro.indexOf('manjaro') !== -1) {
  83. result = 'manjaro';
  84. }
  85. else if (distro.indexOf('mint') !== -1) {
  86. result = 'mint';
  87. }
  88. else if (distro.indexOf('mx') !== -1) {
  89. result = 'mx';
  90. }
  91. else if (distro.indexOf('openbsd') !== -1) {
  92. result = 'openbsd';
  93. }
  94. else if (distro.indexOf('freebsd') !== -1) {
  95. result = 'freebsd';
  96. }
  97. else if (distro.indexOf('opensuse') !== -1) {
  98. result = 'opensuse';
  99. }
  100. else if (distro.indexOf('pclinuxos') !== -1) {
  101. result = 'pclinuxos';
  102. }
  103. else if (distro.indexOf('puppy') !== -1) {
  104. result = 'puppy';
  105. }
  106. else if (distro.indexOf('raspbian') !== -1) {
  107. result = 'raspbian';
  108. }
  109. else if (distro.indexOf('reactos') !== -1) {
  110. result = 'reactos';
  111. }
  112. else if (distro.indexOf('redhat') !== -1) {
  113. result = 'redhat';
  114. }
  115. else if (distro.indexOf('slackware') !== -1) {
  116. result = 'slackware';
  117. }
  118. else if (distro.indexOf('sugar') !== -1) {
  119. result = 'sugar';
  120. }
  121. else if (distro.indexOf('steam') !== -1) {
  122. result = 'steam';
  123. }
  124. else if (distro.indexOf('suse') !== -1) {
  125. result = 'suse';
  126. }
  127. else if (distro.indexOf('mate') !== -1) {
  128. result = 'ubuntu-mate';
  129. }
  130. else if (distro.indexOf('lubuntu') !== -1) {
  131. result = 'lubuntu';
  132. }
  133. else if (distro.indexOf('xubuntu') !== -1) {
  134. result = 'xubuntu';
  135. }
  136. else if (distro.indexOf('ubuntu') !== -1) {
  137. result = 'ubuntu';
  138. }
  139. else if (distro.indexOf('solaris') !== -1) {
  140. result = 'solaris';
  141. }
  142. else if (distro.indexOf('tails') !== -1) {
  143. result = 'tails';
  144. }
  145. else if (distro.indexOf('robolinux') !== -1) {
  146. result = 'robolinux';
  147. } else if (_linux && distro) {
  148. result = distro.toLowerCase().trim().replace(/\s+/g, '-');
  149. }
  150. return result;
  151. }
  152. // --------------------------
  153. // OS Information
  154. function osInfo(callback) {
  155. return new Promise((resolve) => {
  156. process.nextTick(() => {
  157. let result = {
  158. platform: (_platform === 'Windows_NT' ? 'Windows' : _platform),
  159. distro: 'unknown',
  160. release: 'unknown',
  161. codename: '',
  162. kernel: os.release(),
  163. arch: os.arch(),
  164. hostname: os.hostname(),
  165. codepage: '',
  166. logofile: '',
  167. serial: '',
  168. build: '',
  169. servicepack: '',
  170. uefi: false
  171. };
  172. if (_linux) {
  173. exec('cat /etc/*-release; cat /usr/lib/os-release; cat /etc/openwrt_release', function (error, stdout) {
  174. //if (!error) {
  175. /**
  176. * @namespace
  177. * @property {string} DISTRIB_ID
  178. * @property {string} NAME
  179. * @property {string} DISTRIB_RELEASE
  180. * @property {string} VERSION_ID
  181. * @property {string} DISTRIB_CODENAME
  182. */
  183. let release = {};
  184. let lines = stdout.toString().split('\n');
  185. lines.forEach(function (line) {
  186. if (line.indexOf('=') !== -1) {
  187. release[line.split('=')[0].trim().toUpperCase()] = line.split('=')[1].trim();
  188. }
  189. });
  190. let releaseVersion = (release.VERSION || '').replace(/"/g, '');
  191. let codename = (release.DISTRIB_CODENAME || release.VERSION_CODENAME || '').replace(/"/g, '');
  192. if (releaseVersion.indexOf('(') >= 0) {
  193. codename = releaseVersion.split('(')[1].replace(/[()]/g, '').trim();
  194. releaseVersion = releaseVersion.split('(')[0].trim();
  195. }
  196. result.distro = (release.DISTRIB_ID || release.NAME || 'unknown').replace(/"/g, '');
  197. result.logofile = getLogoFile(result.distro);
  198. result.release = (releaseVersion || release.DISTRIB_RELEASE || release.VERSION_ID || 'unknown').replace(/"/g, '');
  199. result.codename = codename;
  200. result.codepage = util.getCodepage();
  201. result.build = (release.BUILD_ID || '').replace(/"/g, '').trim();
  202. isUefiLinux().then(uefi => {
  203. result.uefi = uefi;
  204. uuid().then(data => {
  205. result.serial = data.os;
  206. if (callback) {
  207. callback(result);
  208. }
  209. resolve(result);
  210. });
  211. });
  212. //}
  213. });
  214. }
  215. if (_freebsd || _openbsd || _netbsd) {
  216. exec('sysctl kern.ostype kern.osrelease kern.osrevision kern.hostuuid machdep.bootmethod', function (error, stdout) {
  217. if (!error) {
  218. let lines = stdout.toString().split('\n');
  219. result.distro = util.getValue(lines, 'kern.ostype');
  220. result.logofile = getLogoFile(result.distro);
  221. result.release = util.getValue(lines, 'kern.osrelease').split('-')[0];
  222. result.serial = util.getValue(lines, 'kern.uuid');
  223. result.codename = '';
  224. result.codepage = util.getCodepage();
  225. result.uefi = util.getValue(lines, 'machdep.bootmethod').toLowerCase().indexOf('uefi') >= 0;
  226. }
  227. if (callback) {
  228. callback(result);
  229. }
  230. resolve(result);
  231. });
  232. }
  233. if (_darwin) {
  234. exec('sw_vers; sysctl kern.ostype kern.osrelease kern.osrevision kern.uuid', function (error, stdout) {
  235. let lines = stdout.toString().split('\n');
  236. result.serial = util.getValue(lines, 'kern.uuid');
  237. result.distro = util.getValue(lines, 'ProductName');
  238. result.release = util.getValue(lines, 'ProductVersion');
  239. result.build = util.getValue(lines, 'BuildVersion');
  240. result.logofile = getLogoFile(result.distro);
  241. result.codename = 'macOS';
  242. result.codename = (result.release.indexOf('10.4') > -1 ? 'Mac OS X Tiger' : result.codename);
  243. result.codename = (result.release.indexOf('10.4') > -1 ? 'Mac OS X Tiger' : result.codename);
  244. result.codename = (result.release.indexOf('10.4') > -1 ? 'Mac OS X Tiger' : result.codename);
  245. result.codename = (result.release.indexOf('10.5') > -1 ? 'Mac OS X Leopard' : result.codename);
  246. result.codename = (result.release.indexOf('10.6') > -1 ? 'Mac OS X Snow Leopard' : result.codename);
  247. result.codename = (result.release.indexOf('10.7') > -1 ? 'Mac OS X Lion' : result.codename);
  248. result.codename = (result.release.indexOf('10.8') > -1 ? 'OS X Mountain Lion' : result.codename);
  249. result.codename = (result.release.indexOf('10.9') > -1 ? 'OS X Mavericks' : result.codename);
  250. result.codename = (result.release.indexOf('10.10') > -1 ? 'OS X Yosemite' : result.codename);
  251. result.codename = (result.release.indexOf('10.11') > -1 ? 'OS X El Capitan' : result.codename);
  252. result.codename = (result.release.indexOf('10.12') > -1 ? 'macOS Sierra' : result.codename);
  253. result.codename = (result.release.indexOf('10.13') > -1 ? 'macOS High Sierra' : result.codename);
  254. result.codename = (result.release.indexOf('10.14') > -1 ? 'macOS Mojave' : result.codename);
  255. result.codename = (result.release.indexOf('10.15') > -1 ? 'macOS Catalina' : result.codename);
  256. result.uefi = true;
  257. result.codepage = util.getCodepage();
  258. if (callback) {
  259. callback(result);
  260. }
  261. resolve(result);
  262. });
  263. }
  264. if (_sunos) {
  265. result.release = result.kernel;
  266. exec('uname -o', function (error, stdout) {
  267. let lines = stdout.toString().split('\n');
  268. result.distro = lines[0];
  269. result.logofile = getLogoFile(result.distro);
  270. if (callback) { callback(result); }
  271. resolve(result);
  272. });
  273. }
  274. if (_windows) {
  275. result.logofile = getLogoFile();
  276. result.release = result.kernel;
  277. try {
  278. util.wmic('os get /value').then((stdout) => {
  279. let lines = stdout.toString().split('\r\n');
  280. result.distro = util.getValue(lines, 'Caption', '=').trim();
  281. result.serial = util.getValue(lines, 'SerialNumber', '=').trim();
  282. result.build = util.getValue(lines, 'BuildNumber', '=').trim();
  283. result.servicepack = util.getValue(lines, 'ServicePackMajorVersion', '=').trim() + '.' + util.getValue(lines, 'ServicePackMinorVersion', '=').trim();
  284. result.codepage = util.getCodepage();
  285. isUefiWindows().then(uefi => {
  286. result.uefi = uefi;
  287. if (callback) {
  288. callback(result);
  289. }
  290. resolve(result);
  291. });
  292. });
  293. } catch (e) {
  294. if (callback) { callback(result); }
  295. resolve(result);
  296. }
  297. }
  298. });
  299. });
  300. }
  301. exports.osInfo = osInfo;
  302. function isUefiLinux() {
  303. return new Promise((resolve) => {
  304. process.nextTick(() => {
  305. fs.stat('/sys/firmware/efi', function (err) {
  306. if (!err) {
  307. resolve(true);
  308. } else {
  309. resolve(false);
  310. }
  311. });
  312. });
  313. });
  314. }
  315. function isUefiWindows() {
  316. return new Promise((resolve) => {
  317. process.nextTick(() => {
  318. try {
  319. exec('findstr /C:"Detected boot environment" "%windir%\\Panther\\setupact.log"', util.execOptsWin, function (error, stdout) {
  320. if (!error) {
  321. const line = stdout.toString().split('\n\r')[0];
  322. resolve(line.toLowerCase().indexOf('uefi') >= 0);
  323. return;
  324. }
  325. resolve(false);
  326. });
  327. } catch (e) {
  328. resolve(false);
  329. }
  330. });
  331. });
  332. }
  333. function versions(apps, callback) {
  334. let versionObject = {
  335. kernel: os.release(),
  336. openssl: '',
  337. systemOpenssl: '',
  338. systemOpensslLib: '',
  339. node: process.versions.node,
  340. v8: process.versions.v8,
  341. npm: '',
  342. yarn: '',
  343. pm2: '',
  344. gulp: '',
  345. grunt: '',
  346. git: '',
  347. tsc: '',
  348. mysql: '',
  349. redis: '',
  350. mongodb: '',
  351. apache: '',
  352. nginx: '',
  353. php: '',
  354. docker: '',
  355. postfix: '',
  356. postgresql: '',
  357. perl: '',
  358. python: '',
  359. python3: '',
  360. pip: '',
  361. pip3: '',
  362. java: '',
  363. gcc: '',
  364. virtualbox: '',
  365. dotnet: ''
  366. };
  367. function checkVersionParam(apps) {
  368. if (apps === '*') {
  369. return {
  370. versions: versionObject,
  371. counter: 26
  372. };
  373. }
  374. if (!Array.isArray(apps)) {
  375. apps = apps.trim().toLowerCase().replace(/,+/g, '|').replace(/ /g, '|');
  376. apps = apps.split('|');
  377. const result = {
  378. versions: {},
  379. counter: 0
  380. };
  381. apps.forEach(el => {
  382. if (el) {
  383. for (let key in versionObject) {
  384. if ({}.hasOwnProperty.call(versionObject, key)) {
  385. if (key.toLowerCase() === el.toLowerCase() && !{}.hasOwnProperty.call(result.versions, key)) {
  386. result.versions[key] = versionObject[key];
  387. if (key === 'openssl') {
  388. result.versions.systemOpenssl = '';
  389. result.versions.systemOpensslLib = '';
  390. }
  391. if (!result.versions[key]) { result.counter++; }
  392. }
  393. }
  394. }
  395. }
  396. });
  397. return result;
  398. }
  399. }
  400. return new Promise((resolve) => {
  401. process.nextTick(() => {
  402. if (util.isFunction(apps) && !callback) {
  403. callback = apps;
  404. apps = '*';
  405. } else {
  406. apps = apps || '*';
  407. }
  408. const appsObj = checkVersionParam(apps);
  409. let totalFunctions = appsObj.counter;
  410. let functionProcessed = (function () {
  411. return function () {
  412. if (--totalFunctions === 0) {
  413. if (callback) {
  414. callback(appsObj.versions);
  415. }
  416. resolve(appsObj.versions);
  417. }
  418. };
  419. })();
  420. let cmd = '';
  421. try {
  422. if ({}.hasOwnProperty.call(appsObj.versions, 'openssl')) {
  423. appsObj.versions.openssl = process.versions.openssl;
  424. exec('openssl version', function (error, stdout) {
  425. if (!error) {
  426. let openssl_string = stdout.toString().split('\n')[0].trim();
  427. let openssl = openssl_string.split(' ');
  428. appsObj.versions.systemOpenssl = openssl.length > 0 ? openssl[1] : openssl[0];
  429. appsObj.versions.systemOpensslLib = openssl.length > 0 ? openssl[0] : 'openssl';
  430. }
  431. functionProcessed();
  432. });
  433. }
  434. if ({}.hasOwnProperty.call(appsObj.versions, 'npm')) {
  435. exec('npm -v', function (error, stdout) {
  436. if (!error) {
  437. appsObj.versions.npm = stdout.toString().split('\n')[0];
  438. }
  439. functionProcessed();
  440. });
  441. }
  442. if ({}.hasOwnProperty.call(appsObj.versions, 'pm2')) {
  443. cmd = 'pm2';
  444. if (_windows) {
  445. cmd += '.cmd';
  446. }
  447. exec(`${cmd} -v`, function (error, stdout) {
  448. if (!error) {
  449. let pm2 = stdout.toString().split('\n')[0].trim();
  450. if (!pm2.startsWith('[PM2]')) {
  451. appsObj.versions.pm2 = pm2;
  452. }
  453. }
  454. functionProcessed();
  455. });
  456. }
  457. if ({}.hasOwnProperty.call(appsObj.versions, 'yarn')) {
  458. exec('yarn --version', function (error, stdout) {
  459. if (!error) {
  460. appsObj.versions.yarn = stdout.toString().split('\n')[0];
  461. }
  462. functionProcessed();
  463. });
  464. }
  465. if ({}.hasOwnProperty.call(appsObj.versions, 'gulp')) {
  466. cmd = 'gulp';
  467. if (_windows) {
  468. cmd += '.cmd';
  469. }
  470. exec(`${cmd} --version`, function (error, stdout) {
  471. if (!error) {
  472. const gulp = stdout.toString().split('\n')[0] || '';
  473. appsObj.versions.gulp = (gulp.toLowerCase().split('version')[1] || '').trim();
  474. }
  475. functionProcessed();
  476. });
  477. }
  478. if ({}.hasOwnProperty.call(appsObj.versions, 'tsc')) {
  479. cmd = 'tsc';
  480. if (_windows) {
  481. cmd += '.cmd';
  482. }
  483. exec(`${cmd} --version`, function (error, stdout) {
  484. if (!error) {
  485. const tsc = stdout.toString().split('\n')[0] || '';
  486. appsObj.versions.tsc = (tsc.toLowerCase().split('version')[1] || '').trim();
  487. }
  488. functionProcessed();
  489. });
  490. }
  491. if ({}.hasOwnProperty.call(appsObj.versions, 'grunt')) {
  492. cmd = 'grunt';
  493. if (_windows) {
  494. cmd += '.cmd';
  495. }
  496. exec(`${cmd} --version`, function (error, stdout) {
  497. if (!error) {
  498. const grunt = stdout.toString().split('\n')[0] || '';
  499. appsObj.versions.grunt = (grunt.toLowerCase().split('cli v')[1] || '').trim();
  500. }
  501. functionProcessed();
  502. });
  503. }
  504. if ({}.hasOwnProperty.call(appsObj.versions, 'git')) {
  505. if (_darwin) {
  506. const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/git');
  507. if (util.darwinXcodeExists() || gitHomebrewExists) {
  508. exec('git --version', function (error, stdout) {
  509. if (!error) {
  510. let git = stdout.toString().split('\n')[0] || '';
  511. git = (git.toLowerCase().split('version')[1] || '').trim();
  512. appsObj.versions.git = (git.split(' ')[0] || '').trim();
  513. }
  514. functionProcessed();
  515. });
  516. } else {
  517. functionProcessed();
  518. }
  519. } else {
  520. exec('git --version', function (error, stdout) {
  521. if (!error) {
  522. let git = stdout.toString().split('\n')[0] || '';
  523. git = (git.toLowerCase().split('version')[1] || '').trim();
  524. appsObj.versions.git = (git.split(' ')[0] || '').trim();
  525. }
  526. functionProcessed();
  527. });
  528. }
  529. }
  530. if ({}.hasOwnProperty.call(appsObj.versions, 'apache')) {
  531. exec('apachectl -v 2>&1', function (error, stdout) {
  532. if (!error) {
  533. const apache = (stdout.toString().split('\n')[0] || '').split(':');
  534. appsObj.versions.apache = (apache.length > 1 ? apache[1].replace('Apache', '').replace('/', '').trim() : '');
  535. }
  536. functionProcessed();
  537. });
  538. }
  539. if ({}.hasOwnProperty.call(appsObj.versions, 'nginx')) {
  540. exec('nginx -v 2>&1', function (error, stdout) {
  541. if (!error) {
  542. const nginx = stdout.toString().split('\n')[0] || '';
  543. appsObj.versions.nginx = (nginx.toLowerCase().split('/')[1] || '').trim();
  544. }
  545. functionProcessed();
  546. });
  547. }
  548. if ({}.hasOwnProperty.call(appsObj.versions, 'mysql')) {
  549. exec('mysql -V', function (error, stdout) {
  550. if (!error) {
  551. let mysql = stdout.toString().split('\n')[0] || '';
  552. mysql = mysql.toLowerCase();
  553. if (mysql.indexOf(',') > -1) {
  554. mysql = (mysql.split(',')[0] || '').trim();
  555. const parts = mysql.split(' ');
  556. appsObj.versions.mysql = (parts[parts.length - 1] || '').trim();
  557. } else {
  558. if (mysql.indexOf(' ver ') > -1) {
  559. mysql = mysql.split(' ver ')[1];
  560. appsObj.versions.mysql = mysql.split(' ')[0];
  561. }
  562. }
  563. }
  564. functionProcessed();
  565. });
  566. }
  567. if ({}.hasOwnProperty.call(appsObj.versions, 'php')) {
  568. exec('php -v', function (error, stdout) {
  569. if (!error) {
  570. const php = stdout.toString().split('\n')[0] || '';
  571. let parts = php.split('(');
  572. if (parts[0].indexOf('-')) {
  573. parts = parts[0].split('-');
  574. }
  575. appsObj.versions.php = parts[0].replace(/[^0-9.]/g, '');
  576. }
  577. functionProcessed();
  578. });
  579. }
  580. if ({}.hasOwnProperty.call(appsObj.versions, 'redis')) {
  581. exec('redis-server --version', function (error, stdout) {
  582. if (!error) {
  583. const redis = stdout.toString().split('\n')[0] || '';
  584. const parts = redis.split(' ');
  585. appsObj.versions.redis = util.getValue(parts, 'v', '=', true);
  586. }
  587. functionProcessed();
  588. });
  589. }
  590. if ({}.hasOwnProperty.call(appsObj.versions, 'docker')) {
  591. exec('docker --version', function (error, stdout) {
  592. if (!error) {
  593. const docker = stdout.toString().split('\n')[0] || '';
  594. const parts = docker.split(' ');
  595. appsObj.versions.docker = parts.length > 2 && parts[2].endsWith(',') ? parts[2].slice(0, -1) : '';
  596. }
  597. functionProcessed();
  598. });
  599. }
  600. if ({}.hasOwnProperty.call(appsObj.versions, 'postfix')) {
  601. exec('postconf -d | grep mail_version', function (error, stdout) {
  602. if (!error) {
  603. const postfix = stdout.toString().split('\n') || [];
  604. appsObj.versions.postfix = util.getValue(postfix, 'mail_version', '=', true);
  605. }
  606. functionProcessed();
  607. });
  608. }
  609. if ({}.hasOwnProperty.call(appsObj.versions, 'mongodb')) {
  610. exec('mongod --version', function (error, stdout) {
  611. if (!error) {
  612. const mongodb = stdout.toString().split('\n')[0] || '';
  613. appsObj.versions.mongodb = (mongodb.toLowerCase().split(',')[0] || '').replace(/[^0-9.]/g, '');
  614. }
  615. functionProcessed();
  616. });
  617. }
  618. if ({}.hasOwnProperty.call(appsObj.versions, 'postgresql')) {
  619. if (_linux) {
  620. exec('locate bin/postgres', function (error, stdout) {
  621. if (!error) {
  622. const postgresqlBin = stdout.toString().split('\n').sort();
  623. if (postgresqlBin.length) {
  624. exec(postgresqlBin[postgresqlBin.length - 1] + ' -V', function (error, stdout) {
  625. if (!error) {
  626. const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
  627. appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
  628. }
  629. functionProcessed();
  630. });
  631. } else {
  632. functionProcessed();
  633. }
  634. } else {
  635. exec('psql -V', function (error, stdout) {
  636. if (!error) {
  637. const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
  638. appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
  639. appsObj.versions.postgresql = appsObj.versions.postgresql.split('-')[0];
  640. }
  641. functionProcessed();
  642. });
  643. functionProcessed();
  644. }
  645. });
  646. } else {
  647. if (_windows) {
  648. util.wmic('service get /value').then((stdout) => {
  649. let serviceSections = stdout.split(/\n\s*\n/);
  650. for (let i = 0; i < serviceSections.length; i++) {
  651. if (serviceSections[i].trim() !== '') {
  652. let lines = serviceSections[i].trim().split('\r\n');
  653. let srvCaption = util.getValue(lines, 'caption', '=', true).toLowerCase();
  654. if (srvCaption.indexOf('postgresql') > -1) {
  655. const parts = srvCaption.split(' server ');
  656. if (parts.length > 1) {
  657. appsObj.versions.postgresql = parts[1];
  658. }
  659. }
  660. }
  661. }
  662. functionProcessed();
  663. });
  664. } else {
  665. exec('postgres -V', function (error, stdout) {
  666. if (!error) {
  667. const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
  668. appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
  669. }
  670. functionProcessed();
  671. });
  672. }
  673. }
  674. }
  675. if ({}.hasOwnProperty.call(appsObj.versions, 'perl')) {
  676. exec('perl -v', function (error, stdout) {
  677. if (!error) {
  678. const perl = stdout.toString().split('\n') || '';
  679. while (perl.length > 0 && perl[0].trim() === '') {
  680. perl.shift();
  681. }
  682. if (perl.length > 0) {
  683. appsObj.versions.perl = perl[0].split('(').pop().split(')')[0].replace('v', '');
  684. }
  685. }
  686. functionProcessed();
  687. });
  688. }
  689. if ({}.hasOwnProperty.call(appsObj.versions, 'python')) {
  690. exec('python -V 2>&1', function (error, stdout) {
  691. if (!error) {
  692. const python = stdout.toString().split('\n')[0] || '';
  693. appsObj.versions.python = python.toLowerCase().replace('python', '').trim();
  694. }
  695. functionProcessed();
  696. });
  697. }
  698. if ({}.hasOwnProperty.call(appsObj.versions, 'python3')) {
  699. exec('python3 -V 2>&1', function (error, stdout) {
  700. if (!error) {
  701. const python = stdout.toString().split('\n')[0] || '';
  702. appsObj.versions.python3 = python.toLowerCase().replace('python', '').trim();
  703. }
  704. functionProcessed();
  705. });
  706. }
  707. if ({}.hasOwnProperty.call(appsObj.versions, 'pip')) {
  708. exec('pip -V 2>&1', function (error, stdout) {
  709. if (!error) {
  710. const pip = stdout.toString().split('\n')[0] || '';
  711. const parts = pip.split(' ');
  712. appsObj.versions.pip = parts.length >= 2 ? parts[1] : '';
  713. }
  714. functionProcessed();
  715. });
  716. }
  717. if ({}.hasOwnProperty.call(appsObj.versions, 'pip3')) {
  718. exec('pip3 -V 2>&1', function (error, stdout) {
  719. if (!error) {
  720. const pip = stdout.toString().split('\n')[0] || '';
  721. const parts = pip.split(' ');
  722. appsObj.versions.pip3 = parts.length >= 2 ? parts[1] : '';
  723. }
  724. functionProcessed();
  725. });
  726. }
  727. if ({}.hasOwnProperty.call(appsObj.versions, 'java')) {
  728. if (_darwin) {
  729. // check if any JVM is installed but avoid dialog box that Java needs to be installed
  730. exec('/usr/libexec/java_home -V 2>&1', function (error, stdout) {
  731. if (!error && stdout.toString().toLowerCase().indexOf('no java runtime') === -1) {
  732. // now this can be done savely
  733. exec('java -version 2>&1', function (error, stdout) {
  734. if (!error) {
  735. const java = stdout.toString().split('\n')[0] || '';
  736. const parts = java.split('"');
  737. appsObj.versions.java = parts.length === 3 ? parts[1].trim() : '';
  738. }
  739. functionProcessed();
  740. });
  741. } else {
  742. functionProcessed();
  743. }
  744. });
  745. } else {
  746. exec('java -version 2>&1', function (error, stdout) {
  747. if (!error) {
  748. const java = stdout.toString().split('\n')[0] || '';
  749. const parts = java.split('"');
  750. appsObj.versions.java = parts.length === 3 ? parts[1].trim() : '';
  751. }
  752. functionProcessed();
  753. });
  754. }
  755. }
  756. if ({}.hasOwnProperty.call(appsObj.versions, 'gcc')) {
  757. if ((_darwin && util.darwinXcodeExists()) || !_darwin) {
  758. exec('gcc -dumpversion', function (error, stdout) {
  759. if (!error) {
  760. appsObj.versions.gcc = stdout.toString().split('\n')[0].trim() || '';
  761. }
  762. if (appsObj.versions.gcc.indexOf('.') > -1) {
  763. functionProcessed();
  764. } else {
  765. exec('gcc --version', function (error, stdout) {
  766. if (!error) {
  767. const gcc = stdout.toString().split('\n')[0].trim();
  768. if (gcc.indexOf('gcc') > -1 && gcc.indexOf(')') > -1) {
  769. const parts = gcc.split(')');
  770. appsObj.versions.gcc = parts[1].trim() || appsObj.versions.gcc;
  771. }
  772. }
  773. functionProcessed();
  774. });
  775. }
  776. });
  777. } else {
  778. functionProcessed();
  779. }
  780. }
  781. if ({}.hasOwnProperty.call(appsObj.versions, 'virtualbox')) {
  782. exec(util.getVboxmanage() + ' -v 2>&1', function (error, stdout) {
  783. if (!error) {
  784. const vbox = stdout.toString().split('\n')[0] || '';
  785. const parts = vbox.split('r');
  786. appsObj.versions.virtualbox = parts[0];
  787. }
  788. functionProcessed();
  789. });
  790. }
  791. if ({}.hasOwnProperty.call(appsObj.versions, 'dotnet')) {
  792. exec('dotnet --version 2>&1', function (error, stdout) {
  793. if (!error) {
  794. const dotnet = stdout.toString().split('\n')[0] || '';
  795. appsObj.versions.dotnet = dotnet.trim();
  796. }
  797. functionProcessed();
  798. });
  799. }
  800. } catch (e) {
  801. if (callback) { callback(appsObj.versions); }
  802. resolve(appsObj.versions);
  803. }
  804. });
  805. });
  806. }
  807. exports.versions = versions;
  808. function shell(callback) {
  809. return new Promise((resolve, reject) => {
  810. process.nextTick(() => {
  811. if (_windows) {
  812. let error = new Error(NOT_SUPPORTED);
  813. if (callback) {
  814. callback(NOT_SUPPORTED);
  815. }
  816. reject(error);
  817. }
  818. let result = '';
  819. exec('echo $SHELL', function (error, stdout) {
  820. if (!error) {
  821. result = stdout.toString().split('\n')[0];
  822. }
  823. if (callback) {
  824. callback(result);
  825. }
  826. resolve(result);
  827. });
  828. });
  829. });
  830. }
  831. exports.shell = shell;
  832. function uuid(callback) {
  833. return new Promise((resolve) => {
  834. process.nextTick(() => {
  835. let result = {
  836. os: ''
  837. };
  838. let parts;
  839. if (_darwin) {
  840. exec('ioreg -rd1 -c IOPlatformExpertDevice | grep IOPlatformUUID', function (error, stdout) {
  841. if (!error) {
  842. parts = stdout.toString().split('\n')[0].replace(/"/g, '').split('=');
  843. result.os = parts.length > 1 ? parts[1].trim().toLowerCase() : '';
  844. }
  845. if (callback) {
  846. callback(result);
  847. }
  848. resolve(result);
  849. });
  850. }
  851. if (_linux) {
  852. exec('( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :', function (error, stdout) {
  853. if (!error) {
  854. result.os = stdout.toString().split('\n')[0].trim().toLowerCase();
  855. }
  856. if (callback) {
  857. callback(result);
  858. }
  859. resolve(result);
  860. });
  861. }
  862. if (_freebsd || _openbsd || _netbsd) {
  863. exec('kenv -q smbios.system.uuid', function (error, stdout) {
  864. if (!error) {
  865. result.os = stdout.toString().split('\n')[0].trim().toLowerCase();
  866. }
  867. if (callback) {
  868. callback(result);
  869. }
  870. resolve(result);
  871. });
  872. }
  873. if (_windows) {
  874. exec('%windir%\\System32\\reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid', util.execOptsWin, function (error, stdout) {
  875. if (!error) {
  876. parts = stdout.toString().split('\n\r')[0].split('REG_SZ');
  877. result.os = parts.length > 1 ? parts[1].replace(/\r+|\n+|\s+/ig, '').toLowerCase() : '';
  878. }
  879. if (callback) {
  880. callback(result);
  881. }
  882. resolve(result);
  883. });
  884. }
  885. });
  886. });
  887. }
  888. exports.uuid = uuid;