code-poltergeist-system-monitor 1.0.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of code-poltergeist-system-monitor might be problematic. Click here for more details.

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