systeminformation 5.9.9 → 5.9.10

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,1149 @@
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
+
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
+ exec('sysctl -i kern.hostid kern.hostuuid', function (error, stdout) {
1115
+ const lines = stdout.toString().split('\n');
1116
+ result.os = util.getValue(lines, 'kern.hostid', ':').toLowerCase();
1117
+ result.hardware = util.getValue(lines, 'kern.hostuuid', ':').toLowerCase();
1118
+ if (result.os.indexOf('unknown') >= 0) { result.os = ''; }
1119
+ if (result.hardware.indexOf('unknown') >= 0) { result.hardware = ''; }
1120
+ if (callback) {
1121
+ callback(result);
1122
+ }
1123
+ resolve(result);
1124
+ });
1125
+ }
1126
+ if (_windows) {
1127
+ let sysdir = '%windir%\\System32';
1128
+ if (process.arch === 'ia32' && Object.prototype.hasOwnProperty.call(process.env, 'PROCESSOR_ARCHITEW6432')) {
1129
+ sysdir = '%windir%\\sysnative\\cmd.exe /c %windir%\\System32';
1130
+ }
1131
+ exec(`${sysdir}\\reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid`, util.execOptsWin, function (error, stdout) {
1132
+ parts = stdout.toString().split('\n\r')[0].split('REG_SZ');
1133
+ result.os = parts.length > 1 ? parts[1].replace(/\r+|\n+|\s+/ig, '').toLowerCase() : '';
1134
+ util.powerShell('Get-WmiObject Win32_ComputerSystemProduct | fl *').then((stdout) => {
1135
+ // let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0)[0].trim().split(/\s\s+/);
1136
+ let lines = stdout.split('\r\n');
1137
+ result.hardware = util.getValue(lines, 'uuid', ':').toLowerCase();
1138
+ if (callback) {
1139
+ callback(result);
1140
+ }
1141
+ resolve(result);
1142
+ });
1143
+ });
1144
+ }
1145
+ });
1146
+ });
1147
+ }
1148
+
1149
+ exports.uuid = uuid;