systeminformation 5.9.9 → 5.9.13

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