systeminformation 5.9.7 → 5.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/osinfo.js CHANGED
@@ -1,1150 +1,1150 @@
1
- 'use strict';
2
- // @ts-check
3
- // ==================================================================================
4
- // osinfo.js
5
- // ----------------------------------------------------------------------------------
6
- // Description: System Information - library
7
- // for Node.js
8
- // Copyright: (c) 2014 - 2021
9
- // Author: Sebastian Hildebrandt
10
- // ----------------------------------------------------------------------------------
11
- // License: MIT
12
- // ==================================================================================
13
- // 3. Operating System
14
- // ----------------------------------------------------------------------------------
15
-
16
- const os = require('os');
17
- const fs = require('fs');
18
- const util = require('./util');
19
- const exec = require('child_process').exec;
20
- const execSync = require('child_process').execSync;
21
- // const execPromise = util.promisify(require('child_process').exec);
22
-
23
- let _platform = process.platform;
24
-
25
- const _linux = (_platform === 'linux');
26
- const _darwin = (_platform === 'darwin');
27
- const _windows = (_platform === 'win32');
28
- const _freebsd = (_platform === 'freebsd');
29
- const _openbsd = (_platform === 'openbsd');
30
- const _netbsd = (_platform === 'netbsd');
31
- const _sunos = (_platform === 'sunos');
32
-
33
- // --------------------------
34
- // Get current time and OS uptime
35
-
36
- function time() {
37
- let t = new Date().toString().split(' ');
38
-
39
- return {
40
- current: Date.now(),
41
- uptime: os.uptime(),
42
- timezone: (t.length >= 7) ? t[5] : '',
43
- timezoneName: (t.length >= 7) ? t.slice(6).join(' ').replace(/\(/g, '').replace(/\)/g, '') : ''
44
- };
45
- }
46
-
47
- exports.time = time;
48
-
49
- // --------------------------
50
- // Get logo filename of OS distribution
51
-
52
- function getLogoFile(distro) {
53
- distro = distro || '';
54
- distro = distro.toLowerCase();
55
- let result = _platform;
56
- if (_windows) {
57
- result = 'windows';
58
- }
59
- else if (distro.indexOf('mac os') !== -1) {
60
- result = 'apple';
61
- }
62
- else if (distro.indexOf('arch') !== -1) {
63
- result = 'arch';
64
- }
65
- else if (distro.indexOf('centos') !== -1) {
66
- result = 'centos';
67
- }
68
- else if (distro.indexOf('coreos') !== -1) {
69
- result = 'coreos';
70
- }
71
- else if (distro.indexOf('debian') !== -1) {
72
- result = 'debian';
73
- }
74
- else if (distro.indexOf('deepin') !== -1) {
75
- result = 'deepin';
76
- }
77
- else if (distro.indexOf('elementary') !== -1) {
78
- result = 'elementary';
79
- }
80
- else if (distro.indexOf('fedora') !== -1) {
81
- result = 'fedora';
82
- }
83
- else if (distro.indexOf('gentoo') !== -1) {
84
- result = 'gentoo';
85
- }
86
- else if (distro.indexOf('mageia') !== -1) {
87
- result = 'mageia';
88
- }
89
- else if (distro.indexOf('mandriva') !== -1) {
90
- result = 'mandriva';
91
- }
92
- else if (distro.indexOf('manjaro') !== -1) {
93
- result = 'manjaro';
94
- }
95
- else if (distro.indexOf('mint') !== -1) {
96
- result = 'mint';
97
- }
98
- else if (distro.indexOf('mx') !== -1) {
99
- result = 'mx';
100
- }
101
- else if (distro.indexOf('openbsd') !== -1) {
102
- result = 'openbsd';
103
- }
104
- else if (distro.indexOf('freebsd') !== -1) {
105
- result = 'freebsd';
106
- }
107
- else if (distro.indexOf('opensuse') !== -1) {
108
- result = 'opensuse';
109
- }
110
- else if (distro.indexOf('pclinuxos') !== -1) {
111
- result = 'pclinuxos';
112
- }
113
- else if (distro.indexOf('puppy') !== -1) {
114
- result = 'puppy';
115
- }
116
- else if (distro.indexOf('raspbian') !== -1) {
117
- result = 'raspbian';
118
- }
119
- else if (distro.indexOf('reactos') !== -1) {
120
- result = 'reactos';
121
- }
122
- else if (distro.indexOf('redhat') !== -1) {
123
- result = 'redhat';
124
- }
125
- else if (distro.indexOf('slackware') !== -1) {
126
- result = 'slackware';
127
- }
128
- else if (distro.indexOf('sugar') !== -1) {
129
- result = 'sugar';
130
- }
131
- else if (distro.indexOf('steam') !== -1) {
132
- result = 'steam';
133
- }
134
- else if (distro.indexOf('suse') !== -1) {
135
- result = 'suse';
136
- }
137
- else if (distro.indexOf('mate') !== -1) {
138
- result = 'ubuntu-mate';
139
- }
140
- else if (distro.indexOf('lubuntu') !== -1) {
141
- result = 'lubuntu';
142
- }
143
- else if (distro.indexOf('xubuntu') !== -1) {
144
- result = 'xubuntu';
145
- }
146
- else if (distro.indexOf('ubuntu') !== -1) {
147
- result = 'ubuntu';
148
- }
149
- else if (distro.indexOf('solaris') !== -1) {
150
- result = 'solaris';
151
- }
152
- else if (distro.indexOf('tails') !== -1) {
153
- result = 'tails';
154
- }
155
- else if (distro.indexOf('feren') !== -1) {
156
- result = 'ferenos';
157
- }
158
- else if (distro.indexOf('robolinux') !== -1) {
159
- result = 'robolinux';
160
- } else if (_linux && distro) {
161
- result = distro.toLowerCase().trim().replace(/\s+/g, '-');
162
- }
163
- return result;
164
- }
165
-
166
- // --------------------------
167
- // FQDN
168
-
169
- function getFQDN() {
170
- let fqdn = os.hostname;
171
- if (_linux || _darwin || _freebsd || _openbsd || _netbsd) {
172
- try {
173
- const stdout = execSync('hostname -f');
174
- fqdn = stdout.toString().split(os.EOL)[0];
175
- } catch (e) {
176
- util.noop();
177
- }
178
- }
179
- if (_windows) {
180
- try {
181
- const stdout = execSync('echo %COMPUTERNAME%.%USERDNSDOMAIN%', util.execOptsWin);
182
- fqdn = stdout.toString().replace('.%USERDNSDOMAIN%', '').split(os.EOL)[0];
183
- } catch (e) {
184
- util.noop();
185
- }
186
- }
187
- return fqdn;
188
- }
189
-
190
- // --------------------------
191
- // OS Information
192
-
193
- function osInfo(callback) {
194
-
195
- return new Promise((resolve) => {
196
- process.nextTick(() => {
197
- let result = {
198
-
199
- platform: (_platform === 'Windows_NT' ? 'Windows' : _platform),
200
- distro: 'unknown',
201
- release: 'unknown',
202
- codename: '',
203
- kernel: os.release(),
204
- arch: os.arch(),
205
- hostname: os.hostname(),
206
- fqdn: getFQDN(),
207
- codepage: '',
208
- logofile: '',
209
- serial: '',
210
- build: '',
211
- servicepack: '',
212
- uefi: false
213
- };
214
-
215
- if (_linux) {
216
-
217
- exec('cat /etc/*-release; cat /usr/lib/os-release; cat /etc/openwrt_release', function (error, stdout) {
218
- //if (!error) {
219
- /**
220
- * @namespace
221
- * @property {string} DISTRIB_ID
222
- * @property {string} NAME
223
- * @property {string} DISTRIB_RELEASE
224
- * @property {string} VERSION_ID
225
- * @property {string} DISTRIB_CODENAME
226
- */
227
- let release = {};
228
- let lines = stdout.toString().split('\n');
229
- lines.forEach(function (line) {
230
- if (line.indexOf('=') !== -1) {
231
- release[line.split('=')[0].trim().toUpperCase()] = line.split('=')[1].trim();
232
- }
233
- });
234
- let releaseVersion = (release.VERSION || '').replace(/"/g, '');
235
- let codename = (release.DISTRIB_CODENAME || release.VERSION_CODENAME || '').replace(/"/g, '');
236
- if (releaseVersion.indexOf('(') >= 0) {
237
- codename = releaseVersion.split('(')[1].replace(/[()]/g, '').trim();
238
- releaseVersion = releaseVersion.split('(')[0].trim();
239
- }
240
- result.distro = (release.DISTRIB_ID || release.NAME || 'unknown').replace(/"/g, '');
241
- result.logofile = getLogoFile(result.distro);
242
- result.release = (releaseVersion || release.DISTRIB_RELEASE || release.VERSION_ID || 'unknown').replace(/"/g, '');
243
- result.codename = codename;
244
- result.codepage = util.getCodepage();
245
- result.build = (release.BUILD_ID || '').replace(/"/g, '').trim();
246
- isUefiLinux().then(uefi => {
247
- result.uefi = uefi;
248
- uuid().then(data => {
249
- result.serial = data.os;
250
- if (callback) {
251
- callback(result);
252
- }
253
- resolve(result);
254
- });
255
- });
256
- //}
257
- });
258
- }
259
- if (_freebsd || _openbsd || _netbsd) {
260
-
261
- exec('sysctl kern.ostype kern.osrelease kern.osrevision kern.hostuuid machdep.bootmethod', function (error, stdout) {
262
- if (!error) {
263
- let lines = stdout.toString().split('\n');
264
- result.distro = util.getValue(lines, 'kern.ostype');
265
- result.logofile = getLogoFile(result.distro);
266
- result.release = util.getValue(lines, 'kern.osrelease').split('-')[0];
267
- result.serial = util.getValue(lines, 'kern.uuid');
268
- result.codename = '';
269
- result.codepage = util.getCodepage();
270
- result.uefi = util.getValue(lines, 'machdep.bootmethod').toLowerCase().indexOf('uefi') >= 0;
271
- }
272
- if (callback) {
273
- callback(result);
274
- }
275
- resolve(result);
276
- });
277
- }
278
- if (_darwin) {
279
- exec('sw_vers; sysctl kern.ostype kern.osrelease kern.osrevision kern.uuid', function (error, stdout) {
280
- let lines = stdout.toString().split('\n');
281
- result.serial = util.getValue(lines, 'kern.uuid');
282
- result.distro = util.getValue(lines, 'ProductName');
283
- result.release = util.getValue(lines, 'ProductVersion');
284
- result.build = util.getValue(lines, 'BuildVersion');
285
- result.logofile = getLogoFile(result.distro);
286
- result.codename = 'macOS';
287
- result.codename = (result.release.indexOf('10.4') > -1 ? 'Mac OS X Tiger' : result.codename);
288
- result.codename = (result.release.indexOf('10.4') > -1 ? 'Mac OS X Tiger' : result.codename);
289
- result.codename = (result.release.indexOf('10.4') > -1 ? 'Mac OS X Tiger' : result.codename);
290
- result.codename = (result.release.indexOf('10.5') > -1 ? 'Mac OS X Leopard' : result.codename);
291
- result.codename = (result.release.indexOf('10.6') > -1 ? 'Mac OS X Snow Leopard' : result.codename);
292
- result.codename = (result.release.indexOf('10.7') > -1 ? 'Mac OS X Lion' : result.codename);
293
- result.codename = (result.release.indexOf('10.8') > -1 ? 'OS X Mountain Lion' : result.codename);
294
- result.codename = (result.release.indexOf('10.9') > -1 ? 'OS X Mavericks' : result.codename);
295
- result.codename = (result.release.indexOf('10.10') > -1 ? 'OS X Yosemite' : result.codename);
296
- result.codename = (result.release.indexOf('10.11') > -1 ? 'OS X El Capitan' : result.codename);
297
- result.codename = (result.release.indexOf('10.12') > -1 ? 'macOS Sierra' : result.codename);
298
- result.codename = (result.release.indexOf('10.13') > -1 ? 'macOS High Sierra' : result.codename);
299
- result.codename = (result.release.indexOf('10.14') > -1 ? 'macOS Mojave' : result.codename);
300
- result.codename = (result.release.indexOf('10.15') > -1 ? 'macOS Catalina' : result.codename);
301
- result.codename = (result.release.startsWith('11.') ? 'macOS Big Sur' : result.codename);
302
- result.uefi = true;
303
- result.codepage = util.getCodepage();
304
- if (callback) {
305
- callback(result);
306
- }
307
- resolve(result);
308
- });
309
- }
310
- if (_sunos) {
311
- result.release = result.kernel;
312
- exec('uname -o', function (error, stdout) {
313
- let lines = stdout.toString().split('\n');
314
- result.distro = lines[0];
315
- result.logofile = getLogoFile(result.distro);
316
- if (callback) { callback(result); }
317
- resolve(result);
318
- });
319
- }
320
- if (_windows) {
321
- result.logofile = getLogoFile();
322
- result.release = result.kernel;
323
- try {
324
- const workload = [];
325
- workload.push(util.wmic('os get /value'));
326
- // workload.push(execPromise('systeminfo', util.execOptsWin));
327
- // workload.push(util.powerShell('Get-ComputerInfo -property "HyperV*"'));
328
- workload.push(util.powerShell('(Get-CimInstance Win32_ComputerSystem).HypervisorPresent'));
329
- workload.push(util.powerShell('Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SystemInformation]::TerminalServerSession'));
330
- util.promiseAll(
331
- workload
332
- ).then(data => {
333
- let lines = data.results[0] ? data.results[0].toString().split('\r\n') : [''];
334
- result.distro = util.getValue(lines, 'Caption', '=').trim();
335
- result.serial = util.getValue(lines, 'SerialNumber', '=').trim();
336
- result.build = util.getValue(lines, 'BuildNumber', '=').trim();
337
- result.servicepack = util.getValue(lines, 'ServicePackMajorVersion', '=').trim() + '.' + util.getValue(lines, 'ServicePackMinorVersion', '=').trim();
338
- result.codepage = util.getCodepage();
339
- // const systeminfo = data.results[1] ? data.results[1].toString() : '';
340
- // result.hypervisor = (systeminfo.indexOf('hypervisor has been detected') !== -1) || (systeminfo.indexOf('ein Hypervisor erkannt') !== -1) || (systeminfo.indexOf('Un hyperviseur a ') !== -1);
341
- // const hyperv = data.results[1] ? data.results[1].toString().split('\r\n') : [];
342
- // result.hypervisor = (util.getValue(hyperv, 'HyperVisorPresent').toLowerCase() === 'true');
343
- const hyperv = data.results[1] ? data.results[1].toString().toLowerCase() : '';
344
- result.hypervisor = hyperv.indexOf('true') !== -1;
345
- const term = data.results[2] ? data.results[2].toString() : '';
346
- result.remoteSession = (term.toString().toLowerCase().indexOf('true') >= 0);
347
- isUefiWindows().then(uefi => {
348
- result.uefi = uefi;
349
- if (callback) {
350
- callback(result);
351
- }
352
- resolve(result);
353
- });
354
- });
355
- } catch (e) {
356
- if (callback) { callback(result); }
357
- resolve(result);
358
- }
359
- }
360
- });
361
- });
362
- }
363
-
364
- exports.osInfo = osInfo;
365
-
366
- function isUefiLinux() {
367
- return new Promise((resolve) => {
368
- process.nextTick(() => {
369
- fs.stat('/sys/firmware/efi', function (err) {
370
- if (!err) {
371
- return resolve(true);
372
- } else {
373
- exec('dmesg | grep -E "EFI v"', function (error, stdout) {
374
- if (!error) {
375
- const lines = stdout.toString().split('\n');
376
- return resolve(lines.length > 0);
377
- }
378
- return resolve(false);
379
- });
380
- }
381
- });
382
- });
383
- });
384
- }
385
-
386
- function isUefiWindows() {
387
- return new Promise((resolve) => {
388
- process.nextTick(() => {
389
- try {
390
- exec('findstr /C:"Detected boot environment" "%windir%\\Panther\\setupact.log"', util.execOptsWin, function (error, stdout) {
391
- if (!error) {
392
- const line = stdout.toString().split('\n\r')[0];
393
- return resolve(line.toLowerCase().indexOf('efi') >= 0);
394
- } else {
395
- exec('echo %firmware_type%', util.execOptsWin, function (error, stdout) {
396
- if (!error) {
397
- const line = stdout.toString() || '';
398
- return resolve(line.toLowerCase().indexOf('efi') >= 0);
399
- } else {
400
- return resolve(false);
401
- }
402
- });
403
- }
404
- });
405
- } catch (e) {
406
- return resolve(false);
407
- }
408
- });
409
- });
410
- }
411
-
412
- function versions(apps, callback) {
413
- let versionObject = {
414
- kernel: os.release(),
415
- openssl: '',
416
- systemOpenssl: '',
417
- systemOpensslLib: '',
418
- node: process.versions.node,
419
- v8: process.versions.v8,
420
- npm: '',
421
- yarn: '',
422
- pm2: '',
423
- gulp: '',
424
- grunt: '',
425
- git: '',
426
- tsc: '',
427
- mysql: '',
428
- redis: '',
429
- mongodb: '',
430
- apache: '',
431
- nginx: '',
432
- php: '',
433
- docker: '',
434
- postfix: '',
435
- postgresql: '',
436
- perl: '',
437
- python: '',
438
- python3: '',
439
- pip: '',
440
- pip3: '',
441
- java: '',
442
- gcc: '',
443
- virtualbox: '',
444
- bash: '',
445
- zsh: '',
446
- fish: '',
447
- powershell: '',
448
- dotnet: ''
449
- };
450
-
451
- function checkVersionParam(apps) {
452
- if (apps === '*') {
453
- return {
454
- versions: versionObject,
455
- counter: 30
456
- };
457
- }
458
- if (!Array.isArray(apps)) {
459
- apps = apps.trim().toLowerCase().replace(/,+/g, '|').replace(/ /g, '|');
460
- apps = apps.split('|');
461
- const result = {
462
- versions: {},
463
- counter: 0
464
- };
465
- apps.forEach(el => {
466
- if (el) {
467
- for (let key in versionObject) {
468
- if ({}.hasOwnProperty.call(versionObject, key)) {
469
- if (key.toLowerCase() === el.toLowerCase() && !{}.hasOwnProperty.call(result.versions, key)) {
470
- result.versions[key] = versionObject[key];
471
- if (key === 'openssl') {
472
- result.versions.systemOpenssl = '';
473
- result.versions.systemOpensslLib = '';
474
- }
475
-
476
- if (!result.versions[key]) { result.counter++; }
477
- }
478
- }
479
- }
480
- }
481
- });
482
- return result;
483
- }
484
- }
485
-
486
- return new Promise((resolve) => {
487
- process.nextTick(() => {
488
- if (util.isFunction(apps) && !callback) {
489
- callback = apps;
490
- apps = '*';
491
- } else {
492
- apps = apps || '*';
493
- if (typeof apps !== 'string') {
494
- if (callback) { callback({}); }
495
- return resolve({});
496
- }
497
- }
498
- const appsObj = checkVersionParam(apps);
499
- let totalFunctions = appsObj.counter;
500
-
501
- let functionProcessed = (function () {
502
- return function () {
503
- if (--totalFunctions === 0) {
504
- if (callback) {
505
- callback(appsObj.versions);
506
- }
507
- resolve(appsObj.versions);
508
- }
509
- };
510
- })();
511
-
512
- let cmd = '';
513
- try {
514
- if ({}.hasOwnProperty.call(appsObj.versions, 'openssl')) {
515
- appsObj.versions.openssl = process.versions.openssl;
516
- exec('openssl version', function (error, stdout) {
517
- if (!error) {
518
- let openssl_string = stdout.toString().split('\n')[0].trim();
519
- let openssl = openssl_string.split(' ');
520
- appsObj.versions.systemOpenssl = openssl.length > 0 ? openssl[1] : openssl[0];
521
- appsObj.versions.systemOpensslLib = openssl.length > 0 ? openssl[0] : 'openssl';
522
- }
523
- functionProcessed();
524
- });
525
- }
526
- if ({}.hasOwnProperty.call(appsObj.versions, 'npm')) {
527
- exec('npm -v', function (error, stdout) {
528
- if (!error) {
529
- appsObj.versions.npm = stdout.toString().split('\n')[0];
530
- }
531
- functionProcessed();
532
- });
533
- }
534
- if ({}.hasOwnProperty.call(appsObj.versions, 'pm2')) {
535
- cmd = 'pm2';
536
- if (_windows) {
537
- cmd += '.cmd';
538
- }
539
- exec(`${cmd} -v`, function (error, stdout) {
540
- if (!error) {
541
- let pm2 = stdout.toString().split('\n')[0].trim();
542
- if (!pm2.startsWith('[PM2]')) {
543
- appsObj.versions.pm2 = pm2;
544
- }
545
- }
546
- functionProcessed();
547
- });
548
- }
549
- if ({}.hasOwnProperty.call(appsObj.versions, 'yarn')) {
550
- exec('yarn --version', function (error, stdout) {
551
- if (!error) {
552
- appsObj.versions.yarn = stdout.toString().split('\n')[0];
553
- }
554
- functionProcessed();
555
- });
556
- }
557
- if ({}.hasOwnProperty.call(appsObj.versions, 'gulp')) {
558
- cmd = 'gulp';
559
- if (_windows) {
560
- cmd += '.cmd';
561
- }
562
- exec(`${cmd} --version`, function (error, stdout) {
563
- if (!error) {
564
- const gulp = stdout.toString().split('\n')[0] || '';
565
- appsObj.versions.gulp = (gulp.toLowerCase().split('version')[1] || '').trim();
566
- }
567
- functionProcessed();
568
- });
569
- }
570
- if ({}.hasOwnProperty.call(appsObj.versions, 'tsc')) {
571
- cmd = 'tsc';
572
- if (_windows) {
573
- cmd += '.cmd';
574
- }
575
- exec(`${cmd} --version`, function (error, stdout) {
576
- if (!error) {
577
- const tsc = stdout.toString().split('\n')[0] || '';
578
- appsObj.versions.tsc = (tsc.toLowerCase().split('version')[1] || '').trim();
579
- }
580
- functionProcessed();
581
- });
582
- }
583
- if ({}.hasOwnProperty.call(appsObj.versions, 'grunt')) {
584
- cmd = 'grunt';
585
- if (_windows) {
586
- cmd += '.cmd';
587
- }
588
- exec(`${cmd} --version`, function (error, stdout) {
589
- if (!error) {
590
- const grunt = stdout.toString().split('\n')[0] || '';
591
- appsObj.versions.grunt = (grunt.toLowerCase().split('cli v')[1] || '').trim();
592
- }
593
- functionProcessed();
594
- });
595
- }
596
- if ({}.hasOwnProperty.call(appsObj.versions, 'git')) {
597
- if (_darwin) {
598
- const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/git');
599
- if (util.darwinXcodeExists() || gitHomebrewExists) {
600
- exec('git --version', function (error, stdout) {
601
- if (!error) {
602
- let git = stdout.toString().split('\n')[0] || '';
603
- git = (git.toLowerCase().split('version')[1] || '').trim();
604
- appsObj.versions.git = (git.split(' ')[0] || '').trim();
605
- }
606
- functionProcessed();
607
- });
608
- } else {
609
- functionProcessed();
610
- }
611
- } else {
612
- exec('git --version', function (error, stdout) {
613
- if (!error) {
614
- let git = stdout.toString().split('\n')[0] || '';
615
- git = (git.toLowerCase().split('version')[1] || '').trim();
616
- appsObj.versions.git = (git.split(' ')[0] || '').trim();
617
- }
618
- functionProcessed();
619
- });
620
- }
621
- }
622
- if ({}.hasOwnProperty.call(appsObj.versions, 'apache')) {
623
- exec('apachectl -v 2>&1', function (error, stdout) {
624
- if (!error) {
625
- const apache = (stdout.toString().split('\n')[0] || '').split(':');
626
- appsObj.versions.apache = (apache.length > 1 ? apache[1].replace('Apache', '').replace('/', '').split('(')[0].trim() : '');
627
- }
628
- functionProcessed();
629
- });
630
- }
631
- if ({}.hasOwnProperty.call(appsObj.versions, 'nginx')) {
632
- exec('nginx -v 2>&1', function (error, stdout) {
633
- if (!error) {
634
- const nginx = stdout.toString().split('\n')[0] || '';
635
- appsObj.versions.nginx = (nginx.toLowerCase().split('/')[1] || '').trim();
636
- }
637
- functionProcessed();
638
- });
639
- }
640
- if ({}.hasOwnProperty.call(appsObj.versions, 'mysql')) {
641
- exec('mysql -V', function (error, stdout) {
642
- if (!error) {
643
- let mysql = stdout.toString().split('\n')[0] || '';
644
- mysql = mysql.toLowerCase();
645
- if (mysql.indexOf(',') > -1) {
646
- mysql = (mysql.split(',')[0] || '').trim();
647
- const parts = mysql.split(' ');
648
- appsObj.versions.mysql = (parts[parts.length - 1] || '').trim();
649
- } else {
650
- if (mysql.indexOf(' ver ') > -1) {
651
- mysql = mysql.split(' ver ')[1];
652
- appsObj.versions.mysql = mysql.split(' ')[0];
653
- }
654
- }
655
- }
656
- functionProcessed();
657
- });
658
- }
659
- if ({}.hasOwnProperty.call(appsObj.versions, 'php')) {
660
- exec('php -v', function (error, stdout) {
661
- if (!error) {
662
- const php = stdout.toString().split('\n')[0] || '';
663
- let parts = php.split('(');
664
- if (parts[0].indexOf('-')) {
665
- parts = parts[0].split('-');
666
- }
667
- appsObj.versions.php = parts[0].replace(/[^0-9.]/g, '');
668
- }
669
- functionProcessed();
670
- });
671
- }
672
- if ({}.hasOwnProperty.call(appsObj.versions, 'redis')) {
673
- exec('redis-server --version', function (error, stdout) {
674
- if (!error) {
675
- const redis = stdout.toString().split('\n')[0] || '';
676
- const parts = redis.split(' ');
677
- appsObj.versions.redis = util.getValue(parts, 'v', '=', true);
678
- }
679
- functionProcessed();
680
- });
681
- }
682
- if ({}.hasOwnProperty.call(appsObj.versions, 'docker')) {
683
- exec('docker --version', function (error, stdout) {
684
- if (!error) {
685
- const docker = stdout.toString().split('\n')[0] || '';
686
- const parts = docker.split(' ');
687
- appsObj.versions.docker = parts.length > 2 && parts[2].endsWith(',') ? parts[2].slice(0, -1) : '';
688
- }
689
- functionProcessed();
690
- });
691
- }
692
- if ({}.hasOwnProperty.call(appsObj.versions, 'postfix')) {
693
- exec('postconf -d | grep mail_version', function (error, stdout) {
694
- if (!error) {
695
- const postfix = stdout.toString().split('\n') || [];
696
- appsObj.versions.postfix = util.getValue(postfix, 'mail_version', '=', true);
697
- }
698
- functionProcessed();
699
- });
700
- }
701
- if ({}.hasOwnProperty.call(appsObj.versions, 'mongodb')) {
702
- exec('mongod --version', function (error, stdout) {
703
- if (!error) {
704
- const mongodb = stdout.toString().split('\n')[0] || '';
705
- appsObj.versions.mongodb = (mongodb.toLowerCase().split(',')[0] || '').replace(/[^0-9.]/g, '');
706
- }
707
- functionProcessed();
708
- });
709
- }
710
- if ({}.hasOwnProperty.call(appsObj.versions, 'postgresql')) {
711
- if (_linux) {
712
- exec('locate bin/postgres', function (error, stdout) {
713
- if (!error) {
714
- const postgresqlBin = stdout.toString().split('\n').sort();
715
- if (postgresqlBin.length) {
716
- exec(postgresqlBin[postgresqlBin.length - 1] + ' -V', function (error, stdout) {
717
- if (!error) {
718
- const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
719
- appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
720
- }
721
- functionProcessed();
722
- });
723
- } else {
724
- functionProcessed();
725
- }
726
- } else {
727
- exec('psql -V', function (error, stdout) {
728
- if (!error) {
729
- const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
730
- appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
731
- appsObj.versions.postgresql = appsObj.versions.postgresql.split('-')[0];
732
- }
733
- functionProcessed();
734
- });
735
- functionProcessed();
736
- }
737
- });
738
- } else {
739
- if (_windows) {
740
- util.wmic('service get /value').then((stdout) => {
741
- let serviceSections = stdout.split(/\n\s*\n/);
742
- for (let i = 0; i < serviceSections.length; i++) {
743
- if (serviceSections[i].trim() !== '') {
744
- let lines = serviceSections[i].trim().split('\r\n');
745
- let srvCaption = util.getValue(lines, 'caption', '=', true).toLowerCase();
746
- if (srvCaption.indexOf('postgresql') > -1) {
747
- const parts = srvCaption.split(' server ');
748
- if (parts.length > 1) {
749
- appsObj.versions.postgresql = parts[1];
750
- }
751
- }
752
- }
753
- }
754
- functionProcessed();
755
- });
756
- } else {
757
- exec('postgres -V', function (error, stdout) {
758
- if (!error) {
759
- const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
760
- appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
761
- }
762
- functionProcessed();
763
- });
764
- }
765
- }
766
- }
767
- if ({}.hasOwnProperty.call(appsObj.versions, 'perl')) {
768
- exec('perl -v', function (error, stdout) {
769
- if (!error) {
770
- const perl = stdout.toString().split('\n') || '';
771
- while (perl.length > 0 && perl[0].trim() === '') {
772
- perl.shift();
773
- }
774
- if (perl.length > 0) {
775
- appsObj.versions.perl = perl[0].split('(').pop().split(')')[0].replace('v', '');
776
- }
777
- }
778
- functionProcessed();
779
- });
780
- }
781
- if ({}.hasOwnProperty.call(appsObj.versions, 'python')) {
782
- if (_darwin) {
783
- const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/python');
784
- if (util.darwinXcodeExists() || gitHomebrewExists) {
785
- exec('python -V 2>&1', function (error, stdout) {
786
- if (!error) {
787
- const python = stdout.toString().split('\n')[0] || '';
788
- appsObj.versions.python = python.toLowerCase().replace('python', '').trim();
789
- }
790
- functionProcessed();
791
- });
792
- } else {
793
- functionProcessed();
794
- }
795
- } else {
796
- exec('python -V 2>&1', function (error, stdout) {
797
- if (!error) {
798
- const python = stdout.toString().split('\n')[0] || '';
799
- appsObj.versions.python = python.toLowerCase().replace('python', '').trim();
800
- }
801
- functionProcessed();
802
- });
803
- }
804
- }
805
- if ({}.hasOwnProperty.call(appsObj.versions, 'python3')) {
806
- if (_darwin) {
807
- const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/python3');
808
- if (util.darwinXcodeExists() || gitHomebrewExists) {
809
- exec('python3 -V 2>&1', function (error, stdout) {
810
- if (!error) {
811
- const python = stdout.toString().split('\n')[0] || '';
812
- appsObj.versions.python3 = python.toLowerCase().replace('python', '').trim();
813
- }
814
- functionProcessed();
815
- });
816
- } else {
817
- functionProcessed();
818
- }
819
- } else {
820
- exec('python3 -V 2>&1', function (error, stdout) {
821
- if (!error) {
822
- const python = stdout.toString().split('\n')[0] || '';
823
- appsObj.versions.python3 = python.toLowerCase().replace('python', '').trim();
824
- }
825
- functionProcessed();
826
- });
827
- }
828
- }
829
- if ({}.hasOwnProperty.call(appsObj.versions, 'pip')) {
830
- if (_darwin) {
831
- const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/pip');
832
- if (util.darwinXcodeExists() || gitHomebrewExists) {
833
- exec('pip -V 2>&1', function (error, stdout) {
834
- if (!error) {
835
- const pip = stdout.toString().split('\n')[0] || '';
836
- const parts = pip.split(' ');
837
- appsObj.versions.pip = parts.length >= 2 ? parts[1] : '';
838
- }
839
- functionProcessed();
840
- });
841
- } else {
842
- functionProcessed();
843
- }
844
- } else {
845
- exec('pip -V 2>&1', function (error, stdout) {
846
- if (!error) {
847
- const pip = stdout.toString().split('\n')[0] || '';
848
- const parts = pip.split(' ');
849
- appsObj.versions.pip = parts.length >= 2 ? parts[1] : '';
850
- }
851
- functionProcessed();
852
- });
853
- }
854
- }
855
- if ({}.hasOwnProperty.call(appsObj.versions, 'pip3')) {
856
- if (_darwin) {
857
- const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/pip3');
858
- if (util.darwinXcodeExists() || gitHomebrewExists) {
859
- exec('pip3 -V 2>&1', function (error, stdout) {
860
- if (!error) {
861
- const pip = stdout.toString().split('\n')[0] || '';
862
- const parts = pip.split(' ');
863
- appsObj.versions.pip3 = parts.length >= 2 ? parts[1] : '';
864
- }
865
- functionProcessed();
866
- });
867
- } else {
868
- functionProcessed();
869
- }
870
- } else {
871
- exec('pip3 -V 2>&1', function (error, stdout) {
872
- if (!error) {
873
- const pip = stdout.toString().split('\n')[0] || '';
874
- const parts = pip.split(' ');
875
- appsObj.versions.pip3 = parts.length >= 2 ? parts[1] : '';
876
- }
877
- functionProcessed();
878
- });
879
- }
880
- }
881
- if ({}.hasOwnProperty.call(appsObj.versions, 'java')) {
882
- if (_darwin) {
883
- // check if any JVM is installed but avoid dialog box that Java needs to be installed
884
- exec('/usr/libexec/java_home -V 2>&1', function (error, stdout) {
885
- if (!error && stdout.toString().toLowerCase().indexOf('no java runtime') === -1) {
886
- // now this can be done savely
887
- exec('java -version 2>&1', function (error, stdout) {
888
- if (!error) {
889
- const java = stdout.toString().split('\n')[0] || '';
890
- const parts = java.split('"');
891
- appsObj.versions.java = parts.length === 3 ? parts[1].trim() : '';
892
- }
893
- functionProcessed();
894
- });
895
- } else {
896
- functionProcessed();
897
- }
898
- });
899
- } else {
900
- exec('java -version 2>&1', function (error, stdout) {
901
- if (!error) {
902
- const java = stdout.toString().split('\n')[0] || '';
903
- const parts = java.split('"');
904
- appsObj.versions.java = parts.length === 3 ? parts[1].trim() : '';
905
- }
906
- functionProcessed();
907
- });
908
- }
909
- }
910
- if ({}.hasOwnProperty.call(appsObj.versions, 'gcc')) {
911
- if ((_darwin && util.darwinXcodeExists()) || !_darwin) {
912
- exec('gcc -dumpversion', function (error, stdout) {
913
- if (!error) {
914
- appsObj.versions.gcc = stdout.toString().split('\n')[0].trim() || '';
915
- }
916
- if (appsObj.versions.gcc.indexOf('.') > -1) {
917
- functionProcessed();
918
- } else {
919
- exec('gcc --version', function (error, stdout) {
920
- if (!error) {
921
- const gcc = stdout.toString().split('\n')[0].trim();
922
- if (gcc.indexOf('gcc') > -1 && gcc.indexOf(')') > -1) {
923
- const parts = gcc.split(')');
924
- appsObj.versions.gcc = parts[1].trim() || appsObj.versions.gcc;
925
- }
926
- }
927
- functionProcessed();
928
- });
929
- }
930
- });
931
- } else {
932
- functionProcessed();
933
- }
934
- }
935
- if ({}.hasOwnProperty.call(appsObj.versions, 'virtualbox')) {
936
- exec(util.getVboxmanage() + ' -v 2>&1', function (error, stdout) {
937
- if (!error) {
938
- const vbox = stdout.toString().split('\n')[0] || '';
939
- const parts = vbox.split('r');
940
- appsObj.versions.virtualbox = parts[0];
941
- }
942
- functionProcessed();
943
- });
944
- }
945
- if ({}.hasOwnProperty.call(appsObj.versions, 'bash')) {
946
- exec('bash --version', function (error, stdout) {
947
- if (!error) {
948
- const line = stdout.toString().split('\n')[0];
949
- const parts = line.split(' version ');
950
- if (parts.length > 1) {
951
- appsObj.versions.bash = parts[1].split(' ')[0].split('(')[0];
952
- }
953
- }
954
- functionProcessed();
955
- });
956
- }
957
- if ({}.hasOwnProperty.call(appsObj.versions, 'zsh')) {
958
- exec('zsh --version', function (error, stdout) {
959
- if (!error) {
960
- const line = stdout.toString().split('\n')[0];
961
- const parts = line.split('zsh ');
962
- if (parts.length > 1) {
963
- appsObj.versions.zsh = parts[1].split(' ')[0];
964
- }
965
- }
966
- functionProcessed();
967
- });
968
- }
969
- if ({}.hasOwnProperty.call(appsObj.versions, 'fish')) {
970
- exec('fish --version', function (error, stdout) {
971
- if (!error) {
972
- const line = stdout.toString().split('\n')[0];
973
- const parts = line.split(' version ');
974
- if (parts.length > 1) {
975
- appsObj.versions.fish = parts[1].split(' ')[0];
976
- }
977
- }
978
- functionProcessed();
979
- });
980
- }
981
- if ({}.hasOwnProperty.call(appsObj.versions, 'powershell')) {
982
- if (_windows) {
983
- util.powerShell('$PSVersionTable').then(stdout => {
984
- const lines = stdout.toString().split('\n').map(line => line.replace(/ +/g, ' ').replace(/ +/g, ':'));
985
- appsObj.versions.powershell = util.getValue(lines, 'psversion');
986
- functionProcessed();
987
- });
988
- } else {
989
- functionProcessed();
990
- }
991
- }
992
- if ({}.hasOwnProperty.call(appsObj.versions, 'dotnet')) {
993
- 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 => {
994
- const lines = stdout.toString().split('\r\n');
995
- let dotnet = '';
996
- lines.forEach(line => {
997
- line = line.replace(/ +/g, ' ');
998
- const parts = line.split(' ');
999
- dotnet = dotnet || ((parts[0].toLowerCase().startsWith('client') && parts.length > 2 ? parts[1].trim() : (parts[0].toLowerCase().startsWith('full') && parts.length > 2 ? parts[1].trim() : '')));
1000
- });
1001
- appsObj.versions.dotnet = dotnet.trim();
1002
- functionProcessed();
1003
- });
1004
- }
1005
- } catch (e) {
1006
- if (callback) { callback(appsObj.versions); }
1007
- resolve(appsObj.versions);
1008
- }
1009
- });
1010
- });
1011
- }
1012
-
1013
- exports.versions = versions;
1014
-
1015
- function shell(callback) {
1016
- return new Promise((resolve) => {
1017
- process.nextTick(() => {
1018
- if (_windows) {
1019
- resolve('cmd');
1020
- } else {
1021
- let result = '';
1022
- exec('echo $SHELL', function (error, stdout) {
1023
- if (!error) {
1024
- result = stdout.toString().split('\n')[0];
1025
- }
1026
- if (callback) {
1027
- callback(result);
1028
- }
1029
- resolve(result);
1030
- });
1031
- }
1032
- });
1033
- });
1034
- }
1035
-
1036
- exports.shell = shell;
1037
-
1038
- function getUniqueMacAdresses() {
1039
- const ifaces = os.networkInterfaces();
1040
- let macs = [];
1041
- for (let dev in ifaces) {
1042
- if ({}.hasOwnProperty.call(ifaces, dev)) {
1043
- ifaces[dev].forEach(function (details) {
1044
- if (details && details.mac && details.mac !== '00:00:00:00:00:00') {
1045
- const mac = details.mac.toLowerCase();
1046
- if (macs.indexOf(mac) === -1) {
1047
- macs.push(mac);
1048
- }
1049
- }
1050
- });
1051
- }
1052
- }
1053
- macs = macs.sort(function (a, b) {
1054
- if (a < b) { return -1; }
1055
- if (a > b) { return 1; }
1056
- return 0;
1057
- });
1058
- return macs;
1059
- }
1060
-
1061
- function uuid(callback) {
1062
- return new Promise((resolve) => {
1063
- process.nextTick(() => {
1064
-
1065
- let result = {
1066
- os: '',
1067
- hardware: '',
1068
- macs: getUniqueMacAdresses()
1069
- };
1070
- let parts;
1071
-
1072
- if (_darwin) {
1073
- exec('system_profiler SPHardwareDataType -json', function (error, stdout) {
1074
- if (!error) {
1075
- try {
1076
- const jsonObj = JSON.parse(stdout.toString());
1077
- if (jsonObj.SPHardwareDataType && jsonObj.SPHardwareDataType.length > 0) {
1078
- const spHardware = jsonObj.SPHardwareDataType[0];
1079
- // result.os = parts.length > 1 ? parts[1].trim().toLowerCase() : '';
1080
- result.os = spHardware.platform_UUID.toLowerCase();
1081
- result.hardware = spHardware.serial_number;
1082
- }
1083
- } catch (e) {
1084
- util.noop();
1085
- }
1086
- }
1087
- if (callback) {
1088
- callback(result);
1089
- }
1090
- resolve(result);
1091
- });
1092
- }
1093
- if (_linux) {
1094
- const cmd = `echo -n "os: "; cat /var/lib/dbus/machine-id 2> /dev/null; echo;
1095
- echo -n "os: "; cat /etc/machine-id 2> /dev/null; echo;
1096
- echo -n "hardware: "; cat /sys/class/dmi/id/product_uuid 2> /dev/null; echo;`;
1097
- exec(cmd, function (error, stdout) {
1098
- const lines = stdout.toString().split('\n');
1099
- result.os = util.getValue(lines, 'os').toLowerCase();
1100
- result.hardware = util.getValue(lines, 'hardware').toLowerCase();
1101
- if (!result.hardware) {
1102
- const lines = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
1103
- const serial = util.getValue(lines, 'serial');
1104
- result.hardware = serial || '';
1105
- }
1106
- if (callback) {
1107
- callback(result);
1108
- }
1109
- resolve(result);
1110
- });
1111
- }
1112
- if (_freebsd || _openbsd || _netbsd) {
1113
- const cmd = `echo -n "os: "; sysctl -n kern.hostid; echo;
1114
- echo -n "hardware: "; sysctl -n kern.hostuuid; echo;`;
1115
- exec(cmd, function (error, stdout) {
1116
- const lines = stdout.toString().split('\n');
1117
- result.os = util.getValue(lines, 'os').toLowerCase();
1118
- result.hardware = util.getValue(lines, 'hardware').toLowerCase();
1119
- if (result.os.indexOf('unknown') >= 0) { result.os = ''; }
1120
- if (result.hardware.indexOf('unknown') >= 0) { result.hardware = ''; }
1121
- if (callback) {
1122
- callback(result);
1123
- }
1124
- resolve(result);
1125
- });
1126
- }
1127
- if (_windows) {
1128
- let sysdir = '%windir%\\System32';
1129
- if (process.arch === 'ia32' && Object.prototype.hasOwnProperty.call(process.env, 'PROCESSOR_ARCHITEW6432')) {
1130
- sysdir = '%windir%\\sysnative\\cmd.exe /c %windir%\\System32';
1131
- }
1132
- exec(`${sysdir}\\reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid`, util.execOptsWin, function (error, stdout) {
1133
- parts = stdout.toString().split('\n\r')[0].split('REG_SZ');
1134
- result.os = parts.length > 1 ? parts[1].replace(/\r+|\n+|\s+/ig, '').toLowerCase() : '';
1135
- util.wmic('csproduct get /value').then((stdout) => {
1136
- // let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0)[0].trim().split(/\s\s+/);
1137
- let lines = stdout.split('\r\n');
1138
- result.hardware = util.getValue(lines, 'uuid', '=').toLowerCase();
1139
- if (callback) {
1140
- callback(result);
1141
- }
1142
- resolve(result);
1143
- });
1144
- });
1145
- }
1146
- });
1147
- });
1148
- }
1149
-
1150
- exports.uuid = uuid;
1
+ 'use strict';
2
+ // @ts-check
3
+ // ==================================================================================
4
+ // osinfo.js
5
+ // ----------------------------------------------------------------------------------
6
+ // Description: System Information - library
7
+ // for Node.js
8
+ // Copyright: (c) 2014 - 2021
9
+ // Author: Sebastian Hildebrandt
10
+ // ----------------------------------------------------------------------------------
11
+ // License: MIT
12
+ // ==================================================================================
13
+ // 3. Operating System
14
+ // ----------------------------------------------------------------------------------
15
+
16
+ const os = require('os');
17
+ const fs = require('fs');
18
+ const util = require('./util');
19
+ const exec = require('child_process').exec;
20
+ const execSync = require('child_process').execSync;
21
+ // const execPromise = util.promisify(require('child_process').exec);
22
+
23
+ let _platform = process.platform;
24
+
25
+ const _linux = (_platform === 'linux');
26
+ const _darwin = (_platform === 'darwin');
27
+ const _windows = (_platform === 'win32');
28
+ const _freebsd = (_platform === 'freebsd');
29
+ const _openbsd = (_platform === 'openbsd');
30
+ const _netbsd = (_platform === 'netbsd');
31
+ const _sunos = (_platform === 'sunos');
32
+
33
+ // --------------------------
34
+ // Get current time and OS uptime
35
+
36
+ function time() {
37
+ let t = new Date().toString().split(' ');
38
+
39
+ return {
40
+ current: Date.now(),
41
+ uptime: os.uptime(),
42
+ timezone: (t.length >= 7) ? t[5] : '',
43
+ timezoneName: (t.length >= 7) ? t.slice(6).join(' ').replace(/\(/g, '').replace(/\)/g, '') : ''
44
+ };
45
+ }
46
+
47
+ exports.time = time;
48
+
49
+ // --------------------------
50
+ // Get logo filename of OS distribution
51
+
52
+ function getLogoFile(distro) {
53
+ distro = distro || '';
54
+ distro = distro.toLowerCase();
55
+ let result = _platform;
56
+ if (_windows) {
57
+ result = 'windows';
58
+ }
59
+ else if (distro.indexOf('mac os') !== -1) {
60
+ result = 'apple';
61
+ }
62
+ else if (distro.indexOf('arch') !== -1) {
63
+ result = 'arch';
64
+ }
65
+ else if (distro.indexOf('centos') !== -1) {
66
+ result = 'centos';
67
+ }
68
+ else if (distro.indexOf('coreos') !== -1) {
69
+ result = 'coreos';
70
+ }
71
+ else if (distro.indexOf('debian') !== -1) {
72
+ result = 'debian';
73
+ }
74
+ else if (distro.indexOf('deepin') !== -1) {
75
+ result = 'deepin';
76
+ }
77
+ else if (distro.indexOf('elementary') !== -1) {
78
+ result = 'elementary';
79
+ }
80
+ else if (distro.indexOf('fedora') !== -1) {
81
+ result = 'fedora';
82
+ }
83
+ else if (distro.indexOf('gentoo') !== -1) {
84
+ result = 'gentoo';
85
+ }
86
+ else if (distro.indexOf('mageia') !== -1) {
87
+ result = 'mageia';
88
+ }
89
+ else if (distro.indexOf('mandriva') !== -1) {
90
+ result = 'mandriva';
91
+ }
92
+ else if (distro.indexOf('manjaro') !== -1) {
93
+ result = 'manjaro';
94
+ }
95
+ else if (distro.indexOf('mint') !== -1) {
96
+ result = 'mint';
97
+ }
98
+ else if (distro.indexOf('mx') !== -1) {
99
+ result = 'mx';
100
+ }
101
+ else if (distro.indexOf('openbsd') !== -1) {
102
+ result = 'openbsd';
103
+ }
104
+ else if (distro.indexOf('freebsd') !== -1) {
105
+ result = 'freebsd';
106
+ }
107
+ else if (distro.indexOf('opensuse') !== -1) {
108
+ result = 'opensuse';
109
+ }
110
+ else if (distro.indexOf('pclinuxos') !== -1) {
111
+ result = 'pclinuxos';
112
+ }
113
+ else if (distro.indexOf('puppy') !== -1) {
114
+ result = 'puppy';
115
+ }
116
+ else if (distro.indexOf('raspbian') !== -1) {
117
+ result = 'raspbian';
118
+ }
119
+ else if (distro.indexOf('reactos') !== -1) {
120
+ result = 'reactos';
121
+ }
122
+ else if (distro.indexOf('redhat') !== -1) {
123
+ result = 'redhat';
124
+ }
125
+ else if (distro.indexOf('slackware') !== -1) {
126
+ result = 'slackware';
127
+ }
128
+ else if (distro.indexOf('sugar') !== -1) {
129
+ result = 'sugar';
130
+ }
131
+ else if (distro.indexOf('steam') !== -1) {
132
+ result = 'steam';
133
+ }
134
+ else if (distro.indexOf('suse') !== -1) {
135
+ result = 'suse';
136
+ }
137
+ else if (distro.indexOf('mate') !== -1) {
138
+ result = 'ubuntu-mate';
139
+ }
140
+ else if (distro.indexOf('lubuntu') !== -1) {
141
+ result = 'lubuntu';
142
+ }
143
+ else if (distro.indexOf('xubuntu') !== -1) {
144
+ result = 'xubuntu';
145
+ }
146
+ else if (distro.indexOf('ubuntu') !== -1) {
147
+ result = 'ubuntu';
148
+ }
149
+ else if (distro.indexOf('solaris') !== -1) {
150
+ result = 'solaris';
151
+ }
152
+ else if (distro.indexOf('tails') !== -1) {
153
+ result = 'tails';
154
+ }
155
+ else if (distro.indexOf('feren') !== -1) {
156
+ result = 'ferenos';
157
+ }
158
+ else if (distro.indexOf('robolinux') !== -1) {
159
+ result = 'robolinux';
160
+ } else if (_linux && distro) {
161
+ result = distro.toLowerCase().trim().replace(/\s+/g, '-');
162
+ }
163
+ return result;
164
+ }
165
+
166
+ // --------------------------
167
+ // FQDN
168
+
169
+ function getFQDN() {
170
+ let fqdn = os.hostname;
171
+ if (_linux || _darwin || _freebsd || _openbsd || _netbsd) {
172
+ try {
173
+ const stdout = execSync('hostname -f');
174
+ fqdn = stdout.toString().split(os.EOL)[0];
175
+ } catch (e) {
176
+ util.noop();
177
+ }
178
+ }
179
+ if (_windows) {
180
+ try {
181
+ const stdout = execSync('echo %COMPUTERNAME%.%USERDNSDOMAIN%', util.execOptsWin);
182
+ fqdn = stdout.toString().replace('.%USERDNSDOMAIN%', '').split(os.EOL)[0];
183
+ } catch (e) {
184
+ util.noop();
185
+ }
186
+ }
187
+ return fqdn;
188
+ }
189
+
190
+ // --------------------------
191
+ // OS Information
192
+
193
+ function osInfo(callback) {
194
+
195
+ return new Promise((resolve) => {
196
+ process.nextTick(() => {
197
+ let result = {
198
+
199
+ platform: (_platform === 'Windows_NT' ? 'Windows' : _platform),
200
+ distro: 'unknown',
201
+ release: 'unknown',
202
+ codename: '',
203
+ kernel: os.release(),
204
+ arch: os.arch(),
205
+ hostname: os.hostname(),
206
+ fqdn: getFQDN(),
207
+ codepage: '',
208
+ logofile: '',
209
+ serial: '',
210
+ build: '',
211
+ servicepack: '',
212
+ uefi: false
213
+ };
214
+
215
+ if (_linux) {
216
+
217
+ exec('cat /etc/*-release; cat /usr/lib/os-release; cat /etc/openwrt_release', function (error, stdout) {
218
+ //if (!error) {
219
+ /**
220
+ * @namespace
221
+ * @property {string} DISTRIB_ID
222
+ * @property {string} NAME
223
+ * @property {string} DISTRIB_RELEASE
224
+ * @property {string} VERSION_ID
225
+ * @property {string} DISTRIB_CODENAME
226
+ */
227
+ let release = {};
228
+ let lines = stdout.toString().split('\n');
229
+ lines.forEach(function (line) {
230
+ if (line.indexOf('=') !== -1) {
231
+ release[line.split('=')[0].trim().toUpperCase()] = line.split('=')[1].trim();
232
+ }
233
+ });
234
+ let releaseVersion = (release.VERSION || '').replace(/"/g, '');
235
+ let codename = (release.DISTRIB_CODENAME || release.VERSION_CODENAME || '').replace(/"/g, '');
236
+ if (releaseVersion.indexOf('(') >= 0) {
237
+ codename = releaseVersion.split('(')[1].replace(/[()]/g, '').trim();
238
+ releaseVersion = releaseVersion.split('(')[0].trim();
239
+ }
240
+ result.distro = (release.DISTRIB_ID || release.NAME || 'unknown').replace(/"/g, '');
241
+ result.logofile = getLogoFile(result.distro);
242
+ result.release = (releaseVersion || release.DISTRIB_RELEASE || release.VERSION_ID || 'unknown').replace(/"/g, '');
243
+ result.codename = codename;
244
+ result.codepage = util.getCodepage();
245
+ result.build = (release.BUILD_ID || '').replace(/"/g, '').trim();
246
+ isUefiLinux().then(uefi => {
247
+ result.uefi = uefi;
248
+ uuid().then(data => {
249
+ result.serial = data.os;
250
+ if (callback) {
251
+ callback(result);
252
+ }
253
+ resolve(result);
254
+ });
255
+ });
256
+ //}
257
+ });
258
+ }
259
+ if (_freebsd || _openbsd || _netbsd) {
260
+
261
+ exec('sysctl kern.ostype kern.osrelease kern.osrevision kern.hostuuid machdep.bootmethod', function (error, stdout) {
262
+ if (!error) {
263
+ let lines = stdout.toString().split('\n');
264
+ result.distro = util.getValue(lines, 'kern.ostype');
265
+ result.logofile = getLogoFile(result.distro);
266
+ result.release = util.getValue(lines, 'kern.osrelease').split('-')[0];
267
+ result.serial = util.getValue(lines, 'kern.uuid');
268
+ result.codename = '';
269
+ result.codepage = util.getCodepage();
270
+ result.uefi = util.getValue(lines, 'machdep.bootmethod').toLowerCase().indexOf('uefi') >= 0;
271
+ }
272
+ if (callback) {
273
+ callback(result);
274
+ }
275
+ resolve(result);
276
+ });
277
+ }
278
+ if (_darwin) {
279
+ exec('sw_vers; sysctl kern.ostype kern.osrelease kern.osrevision kern.uuid', function (error, stdout) {
280
+ let lines = stdout.toString().split('\n');
281
+ result.serial = util.getValue(lines, 'kern.uuid');
282
+ result.distro = util.getValue(lines, 'ProductName');
283
+ result.release = util.getValue(lines, 'ProductVersion');
284
+ result.build = util.getValue(lines, 'BuildVersion');
285
+ result.logofile = getLogoFile(result.distro);
286
+ result.codename = 'macOS';
287
+ result.codename = (result.release.indexOf('10.4') > -1 ? 'Mac OS X Tiger' : result.codename);
288
+ result.codename = (result.release.indexOf('10.4') > -1 ? 'Mac OS X Tiger' : result.codename);
289
+ result.codename = (result.release.indexOf('10.4') > -1 ? 'Mac OS X Tiger' : result.codename);
290
+ result.codename = (result.release.indexOf('10.5') > -1 ? 'Mac OS X Leopard' : result.codename);
291
+ result.codename = (result.release.indexOf('10.6') > -1 ? 'Mac OS X Snow Leopard' : result.codename);
292
+ result.codename = (result.release.indexOf('10.7') > -1 ? 'Mac OS X Lion' : result.codename);
293
+ result.codename = (result.release.indexOf('10.8') > -1 ? 'OS X Mountain Lion' : result.codename);
294
+ result.codename = (result.release.indexOf('10.9') > -1 ? 'OS X Mavericks' : result.codename);
295
+ result.codename = (result.release.indexOf('10.10') > -1 ? 'OS X Yosemite' : result.codename);
296
+ result.codename = (result.release.indexOf('10.11') > -1 ? 'OS X El Capitan' : result.codename);
297
+ result.codename = (result.release.indexOf('10.12') > -1 ? 'macOS Sierra' : result.codename);
298
+ result.codename = (result.release.indexOf('10.13') > -1 ? 'macOS High Sierra' : result.codename);
299
+ result.codename = (result.release.indexOf('10.14') > -1 ? 'macOS Mojave' : result.codename);
300
+ result.codename = (result.release.indexOf('10.15') > -1 ? 'macOS Catalina' : result.codename);
301
+ result.codename = (result.release.startsWith('11.') ? 'macOS Big Sur' : result.codename);
302
+ result.uefi = true;
303
+ result.codepage = util.getCodepage();
304
+ if (callback) {
305
+ callback(result);
306
+ }
307
+ resolve(result);
308
+ });
309
+ }
310
+ if (_sunos) {
311
+ result.release = result.kernel;
312
+ exec('uname -o', function (error, stdout) {
313
+ let lines = stdout.toString().split('\n');
314
+ result.distro = lines[0];
315
+ result.logofile = getLogoFile(result.distro);
316
+ if (callback) { callback(result); }
317
+ resolve(result);
318
+ });
319
+ }
320
+ if (_windows) {
321
+ result.logofile = getLogoFile();
322
+ result.release = result.kernel;
323
+ try {
324
+ const workload = [];
325
+ workload.push(util.powerShell('Get-WmiObject Win32_OperatingSystem | fl *'));
326
+ // workload.push(execPromise('systeminfo', util.execOptsWin));
327
+ // workload.push(util.powerShell('Get-ComputerInfo -property "HyperV*"'));
328
+ workload.push(util.powerShell('(Get-CimInstance Win32_ComputerSystem).HypervisorPresent'));
329
+ workload.push(util.powerShell('Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SystemInformation]::TerminalServerSession'));
330
+ util.promiseAll(
331
+ workload
332
+ ).then(data => {
333
+ let lines = data.results[0] ? data.results[0].toString().split('\r\n') : [''];
334
+ result.distro = util.getValue(lines, 'Caption', ':').trim();
335
+ result.serial = util.getValue(lines, 'SerialNumber', ':').trim();
336
+ result.build = util.getValue(lines, 'BuildNumber', ':').trim();
337
+ result.servicepack = util.getValue(lines, 'ServicePackMajorVersion', ':').trim() + '.' + util.getValue(lines, 'ServicePackMinorVersion', ':').trim();
338
+ result.codepage = util.getCodepage();
339
+ // const systeminfo = data.results[1] ? data.results[1].toString() : '';
340
+ // result.hypervisor = (systeminfo.indexOf('hypervisor has been detected') !== -1) || (systeminfo.indexOf('ein Hypervisor erkannt') !== -1) || (systeminfo.indexOf('Un hyperviseur a ') !== -1);
341
+ // const hyperv = data.results[1] ? data.results[1].toString().split('\r\n') : [];
342
+ // result.hypervisor = (util.getValue(hyperv, 'HyperVisorPresent').toLowerCase() === 'true');
343
+ const hyperv = data.results[1] ? data.results[1].toString().toLowerCase() : '';
344
+ result.hypervisor = hyperv.indexOf('true') !== -1;
345
+ const term = data.results[2] ? data.results[2].toString() : '';
346
+ result.remoteSession = (term.toString().toLowerCase().indexOf('true') >= 0);
347
+ isUefiWindows().then(uefi => {
348
+ result.uefi = uefi;
349
+ if (callback) {
350
+ callback(result);
351
+ }
352
+ resolve(result);
353
+ });
354
+ });
355
+ } catch (e) {
356
+ if (callback) { callback(result); }
357
+ resolve(result);
358
+ }
359
+ }
360
+ });
361
+ });
362
+ }
363
+
364
+ exports.osInfo = osInfo;
365
+
366
+ function isUefiLinux() {
367
+ return new Promise((resolve) => {
368
+ process.nextTick(() => {
369
+ fs.stat('/sys/firmware/efi', function (err) {
370
+ if (!err) {
371
+ return resolve(true);
372
+ } else {
373
+ exec('dmesg | grep -E "EFI v"', function (error, stdout) {
374
+ if (!error) {
375
+ const lines = stdout.toString().split('\n');
376
+ return resolve(lines.length > 0);
377
+ }
378
+ return resolve(false);
379
+ });
380
+ }
381
+ });
382
+ });
383
+ });
384
+ }
385
+
386
+ function isUefiWindows() {
387
+ return new Promise((resolve) => {
388
+ process.nextTick(() => {
389
+ try {
390
+ exec('findstr /C:"Detected boot environment" "%windir%\\Panther\\setupact.log"', util.execOptsWin, function (error, stdout) {
391
+ if (!error) {
392
+ const line = stdout.toString().split('\n\r')[0];
393
+ return resolve(line.toLowerCase().indexOf('efi') >= 0);
394
+ } else {
395
+ exec('echo %firmware_type%', util.execOptsWin, function (error, stdout) {
396
+ if (!error) {
397
+ const line = stdout.toString() || '';
398
+ return resolve(line.toLowerCase().indexOf('efi') >= 0);
399
+ } else {
400
+ return resolve(false);
401
+ }
402
+ });
403
+ }
404
+ });
405
+ } catch (e) {
406
+ return resolve(false);
407
+ }
408
+ });
409
+ });
410
+ }
411
+
412
+ function versions(apps, callback) {
413
+ let versionObject = {
414
+ kernel: os.release(),
415
+ openssl: '',
416
+ systemOpenssl: '',
417
+ systemOpensslLib: '',
418
+ node: process.versions.node,
419
+ v8: process.versions.v8,
420
+ npm: '',
421
+ yarn: '',
422
+ pm2: '',
423
+ gulp: '',
424
+ grunt: '',
425
+ git: '',
426
+ tsc: '',
427
+ mysql: '',
428
+ redis: '',
429
+ mongodb: '',
430
+ apache: '',
431
+ nginx: '',
432
+ php: '',
433
+ docker: '',
434
+ postfix: '',
435
+ postgresql: '',
436
+ perl: '',
437
+ python: '',
438
+ python3: '',
439
+ pip: '',
440
+ pip3: '',
441
+ java: '',
442
+ gcc: '',
443
+ virtualbox: '',
444
+ bash: '',
445
+ zsh: '',
446
+ fish: '',
447
+ powershell: '',
448
+ dotnet: ''
449
+ };
450
+
451
+ function checkVersionParam(apps) {
452
+ if (apps === '*') {
453
+ return {
454
+ versions: versionObject,
455
+ counter: 30
456
+ };
457
+ }
458
+ if (!Array.isArray(apps)) {
459
+ apps = apps.trim().toLowerCase().replace(/,+/g, '|').replace(/ /g, '|');
460
+ apps = apps.split('|');
461
+ const result = {
462
+ versions: {},
463
+ counter: 0
464
+ };
465
+ apps.forEach(el => {
466
+ if (el) {
467
+ for (let key in versionObject) {
468
+ if ({}.hasOwnProperty.call(versionObject, key)) {
469
+ if (key.toLowerCase() === el.toLowerCase() && !{}.hasOwnProperty.call(result.versions, key)) {
470
+ result.versions[key] = versionObject[key];
471
+ if (key === 'openssl') {
472
+ result.versions.systemOpenssl = '';
473
+ result.versions.systemOpensslLib = '';
474
+ }
475
+
476
+ if (!result.versions[key]) { result.counter++; }
477
+ }
478
+ }
479
+ }
480
+ }
481
+ });
482
+ return result;
483
+ }
484
+ }
485
+
486
+ return new Promise((resolve) => {
487
+ process.nextTick(() => {
488
+ if (util.isFunction(apps) && !callback) {
489
+ callback = apps;
490
+ apps = '*';
491
+ } else {
492
+ apps = apps || '*';
493
+ if (typeof apps !== 'string') {
494
+ if (callback) { callback({}); }
495
+ return resolve({});
496
+ }
497
+ }
498
+ const appsObj = checkVersionParam(apps);
499
+ let totalFunctions = appsObj.counter;
500
+
501
+ let functionProcessed = (function () {
502
+ return function () {
503
+ if (--totalFunctions === 0) {
504
+ if (callback) {
505
+ callback(appsObj.versions);
506
+ }
507
+ resolve(appsObj.versions);
508
+ }
509
+ };
510
+ })();
511
+
512
+ let cmd = '';
513
+ try {
514
+ if ({}.hasOwnProperty.call(appsObj.versions, 'openssl')) {
515
+ appsObj.versions.openssl = process.versions.openssl;
516
+ exec('openssl version', function (error, stdout) {
517
+ if (!error) {
518
+ let openssl_string = stdout.toString().split('\n')[0].trim();
519
+ let openssl = openssl_string.split(' ');
520
+ appsObj.versions.systemOpenssl = openssl.length > 0 ? openssl[1] : openssl[0];
521
+ appsObj.versions.systemOpensslLib = openssl.length > 0 ? openssl[0] : 'openssl';
522
+ }
523
+ functionProcessed();
524
+ });
525
+ }
526
+ if ({}.hasOwnProperty.call(appsObj.versions, 'npm')) {
527
+ exec('npm -v', function (error, stdout) {
528
+ if (!error) {
529
+ appsObj.versions.npm = stdout.toString().split('\n')[0];
530
+ }
531
+ functionProcessed();
532
+ });
533
+ }
534
+ if ({}.hasOwnProperty.call(appsObj.versions, 'pm2')) {
535
+ cmd = 'pm2';
536
+ if (_windows) {
537
+ cmd += '.cmd';
538
+ }
539
+ exec(`${cmd} -v`, function (error, stdout) {
540
+ if (!error) {
541
+ let pm2 = stdout.toString().split('\n')[0].trim();
542
+ if (!pm2.startsWith('[PM2]')) {
543
+ appsObj.versions.pm2 = pm2;
544
+ }
545
+ }
546
+ functionProcessed();
547
+ });
548
+ }
549
+ if ({}.hasOwnProperty.call(appsObj.versions, 'yarn')) {
550
+ exec('yarn --version', function (error, stdout) {
551
+ if (!error) {
552
+ appsObj.versions.yarn = stdout.toString().split('\n')[0];
553
+ }
554
+ functionProcessed();
555
+ });
556
+ }
557
+ if ({}.hasOwnProperty.call(appsObj.versions, 'gulp')) {
558
+ cmd = 'gulp';
559
+ if (_windows) {
560
+ cmd += '.cmd';
561
+ }
562
+ exec(`${cmd} --version`, function (error, stdout) {
563
+ if (!error) {
564
+ const gulp = stdout.toString().split('\n')[0] || '';
565
+ appsObj.versions.gulp = (gulp.toLowerCase().split('version')[1] || '').trim();
566
+ }
567
+ functionProcessed();
568
+ });
569
+ }
570
+ if ({}.hasOwnProperty.call(appsObj.versions, 'tsc')) {
571
+ cmd = 'tsc';
572
+ if (_windows) {
573
+ cmd += '.cmd';
574
+ }
575
+ exec(`${cmd} --version`, function (error, stdout) {
576
+ if (!error) {
577
+ const tsc = stdout.toString().split('\n')[0] || '';
578
+ appsObj.versions.tsc = (tsc.toLowerCase().split('version')[1] || '').trim();
579
+ }
580
+ functionProcessed();
581
+ });
582
+ }
583
+ if ({}.hasOwnProperty.call(appsObj.versions, 'grunt')) {
584
+ cmd = 'grunt';
585
+ if (_windows) {
586
+ cmd += '.cmd';
587
+ }
588
+ exec(`${cmd} --version`, function (error, stdout) {
589
+ if (!error) {
590
+ const grunt = stdout.toString().split('\n')[0] || '';
591
+ appsObj.versions.grunt = (grunt.toLowerCase().split('cli v')[1] || '').trim();
592
+ }
593
+ functionProcessed();
594
+ });
595
+ }
596
+ if ({}.hasOwnProperty.call(appsObj.versions, 'git')) {
597
+ if (_darwin) {
598
+ const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/git');
599
+ if (util.darwinXcodeExists() || gitHomebrewExists) {
600
+ exec('git --version', function (error, stdout) {
601
+ if (!error) {
602
+ let git = stdout.toString().split('\n')[0] || '';
603
+ git = (git.toLowerCase().split('version')[1] || '').trim();
604
+ appsObj.versions.git = (git.split(' ')[0] || '').trim();
605
+ }
606
+ functionProcessed();
607
+ });
608
+ } else {
609
+ functionProcessed();
610
+ }
611
+ } else {
612
+ exec('git --version', function (error, stdout) {
613
+ if (!error) {
614
+ let git = stdout.toString().split('\n')[0] || '';
615
+ git = (git.toLowerCase().split('version')[1] || '').trim();
616
+ appsObj.versions.git = (git.split(' ')[0] || '').trim();
617
+ }
618
+ functionProcessed();
619
+ });
620
+ }
621
+ }
622
+ if ({}.hasOwnProperty.call(appsObj.versions, 'apache')) {
623
+ exec('apachectl -v 2>&1', function (error, stdout) {
624
+ if (!error) {
625
+ const apache = (stdout.toString().split('\n')[0] || '').split(':');
626
+ appsObj.versions.apache = (apache.length > 1 ? apache[1].replace('Apache', '').replace('/', '').split('(')[0].trim() : '');
627
+ }
628
+ functionProcessed();
629
+ });
630
+ }
631
+ if ({}.hasOwnProperty.call(appsObj.versions, 'nginx')) {
632
+ exec('nginx -v 2>&1', function (error, stdout) {
633
+ if (!error) {
634
+ const nginx = stdout.toString().split('\n')[0] || '';
635
+ appsObj.versions.nginx = (nginx.toLowerCase().split('/')[1] || '').trim();
636
+ }
637
+ functionProcessed();
638
+ });
639
+ }
640
+ if ({}.hasOwnProperty.call(appsObj.versions, 'mysql')) {
641
+ exec('mysql -V', function (error, stdout) {
642
+ if (!error) {
643
+ let mysql = stdout.toString().split('\n')[0] || '';
644
+ mysql = mysql.toLowerCase();
645
+ if (mysql.indexOf(',') > -1) {
646
+ mysql = (mysql.split(',')[0] || '').trim();
647
+ const parts = mysql.split(' ');
648
+ appsObj.versions.mysql = (parts[parts.length - 1] || '').trim();
649
+ } else {
650
+ if (mysql.indexOf(' ver ') > -1) {
651
+ mysql = mysql.split(' ver ')[1];
652
+ appsObj.versions.mysql = mysql.split(' ')[0];
653
+ }
654
+ }
655
+ }
656
+ functionProcessed();
657
+ });
658
+ }
659
+ if ({}.hasOwnProperty.call(appsObj.versions, 'php')) {
660
+ exec('php -v', function (error, stdout) {
661
+ if (!error) {
662
+ const php = stdout.toString().split('\n')[0] || '';
663
+ let parts = php.split('(');
664
+ if (parts[0].indexOf('-')) {
665
+ parts = parts[0].split('-');
666
+ }
667
+ appsObj.versions.php = parts[0].replace(/[^0-9.]/g, '');
668
+ }
669
+ functionProcessed();
670
+ });
671
+ }
672
+ if ({}.hasOwnProperty.call(appsObj.versions, 'redis')) {
673
+ exec('redis-server --version', function (error, stdout) {
674
+ if (!error) {
675
+ const redis = stdout.toString().split('\n')[0] || '';
676
+ const parts = redis.split(' ');
677
+ appsObj.versions.redis = util.getValue(parts, 'v', '=', true);
678
+ }
679
+ functionProcessed();
680
+ });
681
+ }
682
+ if ({}.hasOwnProperty.call(appsObj.versions, 'docker')) {
683
+ exec('docker --version', function (error, stdout) {
684
+ if (!error) {
685
+ const docker = stdout.toString().split('\n')[0] || '';
686
+ const parts = docker.split(' ');
687
+ appsObj.versions.docker = parts.length > 2 && parts[2].endsWith(',') ? parts[2].slice(0, -1) : '';
688
+ }
689
+ functionProcessed();
690
+ });
691
+ }
692
+ if ({}.hasOwnProperty.call(appsObj.versions, 'postfix')) {
693
+ exec('postconf -d | grep mail_version', function (error, stdout) {
694
+ if (!error) {
695
+ const postfix = stdout.toString().split('\n') || [];
696
+ appsObj.versions.postfix = util.getValue(postfix, 'mail_version', '=', true);
697
+ }
698
+ functionProcessed();
699
+ });
700
+ }
701
+ if ({}.hasOwnProperty.call(appsObj.versions, 'mongodb')) {
702
+ exec('mongod --version', function (error, stdout) {
703
+ if (!error) {
704
+ const mongodb = stdout.toString().split('\n')[0] || '';
705
+ appsObj.versions.mongodb = (mongodb.toLowerCase().split(',')[0] || '').replace(/[^0-9.]/g, '');
706
+ }
707
+ functionProcessed();
708
+ });
709
+ }
710
+ if ({}.hasOwnProperty.call(appsObj.versions, 'postgresql')) {
711
+ if (_linux) {
712
+ exec('locate bin/postgres', function (error, stdout) {
713
+ if (!error) {
714
+ const postgresqlBin = stdout.toString().split('\n').sort();
715
+ if (postgresqlBin.length) {
716
+ exec(postgresqlBin[postgresqlBin.length - 1] + ' -V', function (error, stdout) {
717
+ if (!error) {
718
+ const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
719
+ appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
720
+ }
721
+ functionProcessed();
722
+ });
723
+ } else {
724
+ functionProcessed();
725
+ }
726
+ } else {
727
+ exec('psql -V', function (error, stdout) {
728
+ if (!error) {
729
+ const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
730
+ appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
731
+ appsObj.versions.postgresql = appsObj.versions.postgresql.split('-')[0];
732
+ }
733
+ functionProcessed();
734
+ });
735
+ functionProcessed();
736
+ }
737
+ });
738
+ } else {
739
+ if (_windows) {
740
+ util.powerShell('Get-WmiObject Win32_Service | fl *').then((stdout) => {
741
+ let serviceSections = stdout.split(/\n\s*\n/);
742
+ for (let i = 0; i < serviceSections.length; i++) {
743
+ if (serviceSections[i].trim() !== '') {
744
+ let lines = serviceSections[i].trim().split('\r\n');
745
+ let srvCaption = util.getValue(lines, 'caption', ':', true).toLowerCase();
746
+ if (srvCaption.indexOf('postgresql') > -1) {
747
+ const parts = srvCaption.split(' server ');
748
+ if (parts.length > 1) {
749
+ appsObj.versions.postgresql = parts[1];
750
+ }
751
+ }
752
+ }
753
+ }
754
+ functionProcessed();
755
+ });
756
+ } else {
757
+ exec('postgres -V', function (error, stdout) {
758
+ if (!error) {
759
+ const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
760
+ appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
761
+ }
762
+ functionProcessed();
763
+ });
764
+ }
765
+ }
766
+ }
767
+ if ({}.hasOwnProperty.call(appsObj.versions, 'perl')) {
768
+ exec('perl -v', function (error, stdout) {
769
+ if (!error) {
770
+ const perl = stdout.toString().split('\n') || '';
771
+ while (perl.length > 0 && perl[0].trim() === '') {
772
+ perl.shift();
773
+ }
774
+ if (perl.length > 0) {
775
+ appsObj.versions.perl = perl[0].split('(').pop().split(')')[0].replace('v', '');
776
+ }
777
+ }
778
+ functionProcessed();
779
+ });
780
+ }
781
+ if ({}.hasOwnProperty.call(appsObj.versions, 'python')) {
782
+ if (_darwin) {
783
+ const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/python');
784
+ if (util.darwinXcodeExists() || gitHomebrewExists) {
785
+ exec('python -V 2>&1', function (error, stdout) {
786
+ if (!error) {
787
+ const python = stdout.toString().split('\n')[0] || '';
788
+ appsObj.versions.python = python.toLowerCase().replace('python', '').trim();
789
+ }
790
+ functionProcessed();
791
+ });
792
+ } else {
793
+ functionProcessed();
794
+ }
795
+ } else {
796
+ exec('python -V 2>&1', function (error, stdout) {
797
+ if (!error) {
798
+ const python = stdout.toString().split('\n')[0] || '';
799
+ appsObj.versions.python = python.toLowerCase().replace('python', '').trim();
800
+ }
801
+ functionProcessed();
802
+ });
803
+ }
804
+ }
805
+ if ({}.hasOwnProperty.call(appsObj.versions, 'python3')) {
806
+ if (_darwin) {
807
+ const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/python3');
808
+ if (util.darwinXcodeExists() || gitHomebrewExists) {
809
+ exec('python3 -V 2>&1', function (error, stdout) {
810
+ if (!error) {
811
+ const python = stdout.toString().split('\n')[0] || '';
812
+ appsObj.versions.python3 = python.toLowerCase().replace('python', '').trim();
813
+ }
814
+ functionProcessed();
815
+ });
816
+ } else {
817
+ functionProcessed();
818
+ }
819
+ } else {
820
+ exec('python3 -V 2>&1', function (error, stdout) {
821
+ if (!error) {
822
+ const python = stdout.toString().split('\n')[0] || '';
823
+ appsObj.versions.python3 = python.toLowerCase().replace('python', '').trim();
824
+ }
825
+ functionProcessed();
826
+ });
827
+ }
828
+ }
829
+ if ({}.hasOwnProperty.call(appsObj.versions, 'pip')) {
830
+ if (_darwin) {
831
+ const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/pip');
832
+ if (util.darwinXcodeExists() || gitHomebrewExists) {
833
+ exec('pip -V 2>&1', function (error, stdout) {
834
+ if (!error) {
835
+ const pip = stdout.toString().split('\n')[0] || '';
836
+ const parts = pip.split(' ');
837
+ appsObj.versions.pip = parts.length >= 2 ? parts[1] : '';
838
+ }
839
+ functionProcessed();
840
+ });
841
+ } else {
842
+ functionProcessed();
843
+ }
844
+ } else {
845
+ exec('pip -V 2>&1', function (error, stdout) {
846
+ if (!error) {
847
+ const pip = stdout.toString().split('\n')[0] || '';
848
+ const parts = pip.split(' ');
849
+ appsObj.versions.pip = parts.length >= 2 ? parts[1] : '';
850
+ }
851
+ functionProcessed();
852
+ });
853
+ }
854
+ }
855
+ if ({}.hasOwnProperty.call(appsObj.versions, 'pip3')) {
856
+ if (_darwin) {
857
+ const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/pip3');
858
+ if (util.darwinXcodeExists() || gitHomebrewExists) {
859
+ exec('pip3 -V 2>&1', function (error, stdout) {
860
+ if (!error) {
861
+ const pip = stdout.toString().split('\n')[0] || '';
862
+ const parts = pip.split(' ');
863
+ appsObj.versions.pip3 = parts.length >= 2 ? parts[1] : '';
864
+ }
865
+ functionProcessed();
866
+ });
867
+ } else {
868
+ functionProcessed();
869
+ }
870
+ } else {
871
+ exec('pip3 -V 2>&1', function (error, stdout) {
872
+ if (!error) {
873
+ const pip = stdout.toString().split('\n')[0] || '';
874
+ const parts = pip.split(' ');
875
+ appsObj.versions.pip3 = parts.length >= 2 ? parts[1] : '';
876
+ }
877
+ functionProcessed();
878
+ });
879
+ }
880
+ }
881
+ if ({}.hasOwnProperty.call(appsObj.versions, 'java')) {
882
+ if (_darwin) {
883
+ // check if any JVM is installed but avoid dialog box that Java needs to be installed
884
+ exec('/usr/libexec/java_home -V 2>&1', function (error, stdout) {
885
+ if (!error && stdout.toString().toLowerCase().indexOf('no java runtime') === -1) {
886
+ // now this can be done savely
887
+ exec('java -version 2>&1', function (error, stdout) {
888
+ if (!error) {
889
+ const java = stdout.toString().split('\n')[0] || '';
890
+ const parts = java.split('"');
891
+ appsObj.versions.java = parts.length === 3 ? parts[1].trim() : '';
892
+ }
893
+ functionProcessed();
894
+ });
895
+ } else {
896
+ functionProcessed();
897
+ }
898
+ });
899
+ } else {
900
+ exec('java -version 2>&1', function (error, stdout) {
901
+ if (!error) {
902
+ const java = stdout.toString().split('\n')[0] || '';
903
+ const parts = java.split('"');
904
+ appsObj.versions.java = parts.length === 3 ? parts[1].trim() : '';
905
+ }
906
+ functionProcessed();
907
+ });
908
+ }
909
+ }
910
+ if ({}.hasOwnProperty.call(appsObj.versions, 'gcc')) {
911
+ if ((_darwin && util.darwinXcodeExists()) || !_darwin) {
912
+ exec('gcc -dumpversion', function (error, stdout) {
913
+ if (!error) {
914
+ appsObj.versions.gcc = stdout.toString().split('\n')[0].trim() || '';
915
+ }
916
+ if (appsObj.versions.gcc.indexOf('.') > -1) {
917
+ functionProcessed();
918
+ } else {
919
+ exec('gcc --version', function (error, stdout) {
920
+ if (!error) {
921
+ const gcc = stdout.toString().split('\n')[0].trim();
922
+ if (gcc.indexOf('gcc') > -1 && gcc.indexOf(')') > -1) {
923
+ const parts = gcc.split(')');
924
+ appsObj.versions.gcc = parts[1].trim() || appsObj.versions.gcc;
925
+ }
926
+ }
927
+ functionProcessed();
928
+ });
929
+ }
930
+ });
931
+ } else {
932
+ functionProcessed();
933
+ }
934
+ }
935
+ if ({}.hasOwnProperty.call(appsObj.versions, 'virtualbox')) {
936
+ exec(util.getVboxmanage() + ' -v 2>&1', function (error, stdout) {
937
+ if (!error) {
938
+ const vbox = stdout.toString().split('\n')[0] || '';
939
+ const parts = vbox.split('r');
940
+ appsObj.versions.virtualbox = parts[0];
941
+ }
942
+ functionProcessed();
943
+ });
944
+ }
945
+ if ({}.hasOwnProperty.call(appsObj.versions, 'bash')) {
946
+ exec('bash --version', function (error, stdout) {
947
+ if (!error) {
948
+ const line = stdout.toString().split('\n')[0];
949
+ const parts = line.split(' version ');
950
+ if (parts.length > 1) {
951
+ appsObj.versions.bash = parts[1].split(' ')[0].split('(')[0];
952
+ }
953
+ }
954
+ functionProcessed();
955
+ });
956
+ }
957
+ if ({}.hasOwnProperty.call(appsObj.versions, 'zsh')) {
958
+ exec('zsh --version', function (error, stdout) {
959
+ if (!error) {
960
+ const line = stdout.toString().split('\n')[0];
961
+ const parts = line.split('zsh ');
962
+ if (parts.length > 1) {
963
+ appsObj.versions.zsh = parts[1].split(' ')[0];
964
+ }
965
+ }
966
+ functionProcessed();
967
+ });
968
+ }
969
+ if ({}.hasOwnProperty.call(appsObj.versions, 'fish')) {
970
+ exec('fish --version', function (error, stdout) {
971
+ if (!error) {
972
+ const line = stdout.toString().split('\n')[0];
973
+ const parts = line.split(' version ');
974
+ if (parts.length > 1) {
975
+ appsObj.versions.fish = parts[1].split(' ')[0];
976
+ }
977
+ }
978
+ functionProcessed();
979
+ });
980
+ }
981
+ if ({}.hasOwnProperty.call(appsObj.versions, 'powershell')) {
982
+ if (_windows) {
983
+ util.powerShell('$PSVersionTable').then(stdout => {
984
+ const lines = stdout.toString().split('\n').map(line => line.replace(/ +/g, ' ').replace(/ +/g, ':'));
985
+ appsObj.versions.powershell = util.getValue(lines, 'psversion');
986
+ functionProcessed();
987
+ });
988
+ } else {
989
+ functionProcessed();
990
+ }
991
+ }
992
+ if ({}.hasOwnProperty.call(appsObj.versions, 'dotnet')) {
993
+ 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 => {
994
+ const lines = stdout.toString().split('\r\n');
995
+ let dotnet = '';
996
+ lines.forEach(line => {
997
+ line = line.replace(/ +/g, ' ');
998
+ const parts = line.split(' ');
999
+ dotnet = dotnet || ((parts[0].toLowerCase().startsWith('client') && parts.length > 2 ? parts[1].trim() : (parts[0].toLowerCase().startsWith('full') && parts.length > 2 ? parts[1].trim() : '')));
1000
+ });
1001
+ appsObj.versions.dotnet = dotnet.trim();
1002
+ functionProcessed();
1003
+ });
1004
+ }
1005
+ } catch (e) {
1006
+ if (callback) { callback(appsObj.versions); }
1007
+ resolve(appsObj.versions);
1008
+ }
1009
+ });
1010
+ });
1011
+ }
1012
+
1013
+ exports.versions = versions;
1014
+
1015
+ function shell(callback) {
1016
+ return new Promise((resolve) => {
1017
+ process.nextTick(() => {
1018
+ if (_windows) {
1019
+ resolve('cmd');
1020
+ } else {
1021
+ let result = '';
1022
+ exec('echo $SHELL', function (error, stdout) {
1023
+ if (!error) {
1024
+ result = stdout.toString().split('\n')[0];
1025
+ }
1026
+ if (callback) {
1027
+ callback(result);
1028
+ }
1029
+ resolve(result);
1030
+ });
1031
+ }
1032
+ });
1033
+ });
1034
+ }
1035
+
1036
+ exports.shell = shell;
1037
+
1038
+ function getUniqueMacAdresses() {
1039
+ const ifaces = os.networkInterfaces();
1040
+ let macs = [];
1041
+ for (let dev in ifaces) {
1042
+ if ({}.hasOwnProperty.call(ifaces, dev)) {
1043
+ ifaces[dev].forEach(function (details) {
1044
+ if (details && details.mac && details.mac !== '00:00:00:00:00:00') {
1045
+ const mac = details.mac.toLowerCase();
1046
+ if (macs.indexOf(mac) === -1) {
1047
+ macs.push(mac);
1048
+ }
1049
+ }
1050
+ });
1051
+ }
1052
+ }
1053
+ macs = macs.sort(function (a, b) {
1054
+ if (a < b) { return -1; }
1055
+ if (a > b) { return 1; }
1056
+ return 0;
1057
+ });
1058
+ return macs;
1059
+ }
1060
+
1061
+ function uuid(callback) {
1062
+ return new Promise((resolve) => {
1063
+ process.nextTick(() => {
1064
+
1065
+ let result = {
1066
+ os: '',
1067
+ hardware: '',
1068
+ macs: getUniqueMacAdresses()
1069
+ };
1070
+ let parts;
1071
+
1072
+ if (_darwin) {
1073
+ exec('system_profiler SPHardwareDataType -json', function (error, stdout) {
1074
+ if (!error) {
1075
+ try {
1076
+ const jsonObj = JSON.parse(stdout.toString());
1077
+ if (jsonObj.SPHardwareDataType && jsonObj.SPHardwareDataType.length > 0) {
1078
+ const spHardware = jsonObj.SPHardwareDataType[0];
1079
+ // result.os = parts.length > 1 ? parts[1].trim().toLowerCase() : '';
1080
+ result.os = spHardware.platform_UUID.toLowerCase();
1081
+ result.hardware = spHardware.serial_number;
1082
+ }
1083
+ } catch (e) {
1084
+ util.noop();
1085
+ }
1086
+ }
1087
+ if (callback) {
1088
+ callback(result);
1089
+ }
1090
+ resolve(result);
1091
+ });
1092
+ }
1093
+ if (_linux) {
1094
+ const cmd = `echo -n "os: "; cat /var/lib/dbus/machine-id 2> /dev/null; echo;
1095
+ echo -n "os: "; cat /etc/machine-id 2> /dev/null; echo;
1096
+ echo -n "hardware: "; cat /sys/class/dmi/id/product_uuid 2> /dev/null; echo;`;
1097
+ exec(cmd, function (error, stdout) {
1098
+ const lines = stdout.toString().split('\n');
1099
+ result.os = util.getValue(lines, 'os').toLowerCase();
1100
+ result.hardware = util.getValue(lines, 'hardware').toLowerCase();
1101
+ if (!result.hardware) {
1102
+ const lines = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
1103
+ const serial = util.getValue(lines, 'serial');
1104
+ result.hardware = serial || '';
1105
+ }
1106
+ if (callback) {
1107
+ callback(result);
1108
+ }
1109
+ resolve(result);
1110
+ });
1111
+ }
1112
+ if (_freebsd || _openbsd || _netbsd) {
1113
+ const cmd = `echo -n "os: "; sysctl -n kern.hostid; echo;
1114
+ echo -n "hardware: "; sysctl -n kern.hostuuid; echo;`;
1115
+ exec(cmd, function (error, stdout) {
1116
+ const lines = stdout.toString().split('\n');
1117
+ result.os = util.getValue(lines, 'os').toLowerCase();
1118
+ result.hardware = util.getValue(lines, 'hardware').toLowerCase();
1119
+ if (result.os.indexOf('unknown') >= 0) { result.os = ''; }
1120
+ if (result.hardware.indexOf('unknown') >= 0) { result.hardware = ''; }
1121
+ if (callback) {
1122
+ callback(result);
1123
+ }
1124
+ resolve(result);
1125
+ });
1126
+ }
1127
+ if (_windows) {
1128
+ let sysdir = '%windir%\\System32';
1129
+ if (process.arch === 'ia32' && Object.prototype.hasOwnProperty.call(process.env, 'PROCESSOR_ARCHITEW6432')) {
1130
+ sysdir = '%windir%\\sysnative\\cmd.exe /c %windir%\\System32';
1131
+ }
1132
+ exec(`${sysdir}\\reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid`, util.execOptsWin, function (error, stdout) {
1133
+ parts = stdout.toString().split('\n\r')[0].split('REG_SZ');
1134
+ result.os = parts.length > 1 ? parts[1].replace(/\r+|\n+|\s+/ig, '').toLowerCase() : '';
1135
+ util.powerShell('Get-WmiObject Win32_ComputerSystemProduct | fl *').then((stdout) => {
1136
+ // let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0)[0].trim().split(/\s\s+/);
1137
+ let lines = stdout.split('\r\n');
1138
+ result.hardware = util.getValue(lines, 'uuid', ':').toLowerCase();
1139
+ if (callback) {
1140
+ callback(result);
1141
+ }
1142
+ resolve(result);
1143
+ });
1144
+ });
1145
+ }
1146
+ });
1147
+ });
1148
+ }
1149
+
1150
+ exports.uuid = uuid;