Added --dumpcores options to MeshCentral, used to dump packed meshcores.

Ylian Saint-Hilaire committed Feb 3, 2022 at 19:11 UTC 8b150628803e0e1efc9b429c5435c45bb5514671
1 file changed +49 -41
meshcentral.js
+49 -41
@@ -17,7 +17,7 @@
17 const common = require('./common.js');
18
19 // If app metrics is available
20 -if (process.argv[2] == '--launch') { try { require('appmetrics-dash').monitor({ url: '/', title: 'MeshCentral', port: 88, host: '127.0.0.1' }); } catch (e) { } }
20 +if (process.argv[2] == '--launch') { try { require('appmetrics-dash').monitor({ url: '/', title: 'MeshCentral', port: 88, host: '127.0.0.1' }); } catch (ex) { } }
21
22 function CreateMeshCentralServer(config, args) {
23 var obj = {};
@@ -76,7 +76,7 @@ function CreateMeshCentralServer(config, args) {
76
77 // Server version
78 obj.currentVer = null;
79 - function getCurrentVersion() { try { obj.currentVer = JSON.parse(obj.fs.readFileSync(obj.path.join(__dirname, 'package.json'), 'utf8')).version; } catch (e) { } return obj.currentVer; } // Fetch server version
79 + function getCurrentVersion() { try { obj.currentVer = JSON.parse(obj.fs.readFileSync(obj.path.join(__dirname, 'package.json'), 'utf8')).version; } catch (ex) { } return obj.currentVer; } // Fetch server version
80 getCurrentVersion();
81
82 // Setup the default configuration and files paths
@@ -118,8 +118,8 @@ function CreateMeshCentralServer(config, args) {
118 if (obj.config.settings && (typeof obj.config.settings.filespath == 'string')) { obj.filespath = obj.config.settings.filespath; }
119
120 // Create data and files folders if needed
121 - try { obj.fs.mkdirSync(obj.datapath); } catch (e) { }
122 - try { obj.fs.mkdirSync(obj.filespath); } catch (e) { }
121 + try { obj.fs.mkdirSync(obj.datapath); } catch (ex) { }
122 + try { obj.fs.mkdirSync(obj.filespath); } catch (ex) { }
123
124 // Windows Specific Code, setup service and event log
125 obj.service = null;
@@ -134,10 +134,10 @@ function CreateMeshCentralServer(config, args) {
134 // Start the Meshcentral server
135 obj.Start = function () {
136 var i;
137 - try { require('./pass').hash('test', function () { }, 0); } catch (e) { console.log('Old version of node, must upgrade.'); return; } // TODO: Not sure if this test works or not.
137 + try { require('./pass').hash('test', function () { }, 0); } catch (ex) { console.log('Old version of node, must upgrade.'); return; } // TODO: Not sure if this test works or not.
138
139 // Check for invalid arguments
140 - var validArguments = ['_', 'user', 'port', 'aliasport', 'mpsport', 'mpsaliasport', 'redirport', 'rediraliasport', 'cert', 'mpscert', 'deletedomain', 'deletedefaultdomain', 'showall', 'showusers', 'showitem', 'listuserids', 'showusergroups', 'shownodes', 'showallmeshes', 'showmeshes', 'showevents', 'showsmbios', 'showpower', 'clearpower', 'showiplocations', 'help', 'exactports', 'xinstall', 'xuninstall', 'install', 'uninstall', 'start', 'stop', 'restart', 'debug', 'filespath', 'datapath', 'noagentupdate', 'launch', 'noserverbackup', 'mongodb', 'mongodbcol', 'wanonly', 'lanonly', 'nousers', 'mpspass', 'ciralocalfqdn', 'dbexport', 'dbexportmin', 'dbimport', 'dbmerge', 'dbfix', 'dbencryptkey', 'selfupdate', 'tlsoffload', 'userallowedip', 'userblockedip', 'swarmallowedip', 'agentallowedip', 'agentblockedip', 'fastcert', 'swarmport', 'logintoken', 'logintokenkey', 'logintokengen', 'mailtokengen', 'admin', 'unadmin', 'sessionkey', 'sessiontime', 'minify', 'minifycore', 'dblistconfigfiles', 'dbshowconfigfile', 'dbpushconfigfiles', 'dbpullconfigfiles', 'dbdeleteconfigfiles', 'vaultpushconfigfiles', 'vaultpullconfigfiles', 'vaultdeleteconfigfiles', 'configkey', 'loadconfigfromdb', 'npmpath', 'serverid', 'recordencryptionrecode', 'vault', 'token', 'unsealkey', 'name', 'log', 'dbstats', 'translate', 'createaccount', 'resetaccount', 'pass', 'removesubdomain', 'adminaccount', 'domain', 'email', 'configfile', 'maintenancemode', 'nedbtodb', 'removetestagents', 'agentupdatetest', 'hashpassword', 'hashpass', 'indexmcrec', 'mpsdebug'];
140 + var validArguments = ['_', 'user', 'port', 'aliasport', 'mpsport', 'mpsaliasport', 'redirport', 'rediraliasport', 'cert', 'mpscert', 'deletedomain', 'deletedefaultdomain', 'showall', 'showusers', 'showitem', 'listuserids', 'showusergroups', 'shownodes', 'showallmeshes', 'showmeshes', 'showevents', 'showsmbios', 'showpower', 'clearpower', 'showiplocations', 'help', 'exactports', 'xinstall', 'xuninstall', 'install', 'uninstall', 'start', 'stop', 'restart', 'debug', 'filespath', 'datapath', 'noagentupdate', 'launch', 'noserverbackup', 'mongodb', 'mongodbcol', 'wanonly', 'lanonly', 'nousers', 'mpspass', 'ciralocalfqdn', 'dbexport', 'dbexportmin', 'dbimport', 'dbmerge', 'dbfix', 'dbencryptkey', 'selfupdate', 'tlsoffload', 'userallowedip', 'userblockedip', 'swarmallowedip', 'agentallowedip', 'agentblockedip', 'fastcert', 'swarmport', 'logintoken', 'logintokenkey', 'logintokengen', 'mailtokengen', 'admin', 'unadmin', 'sessionkey', 'sessiontime', 'minify', 'minifycore', 'dblistconfigfiles', 'dbshowconfigfile', 'dbpushconfigfiles', 'dbpullconfigfiles', 'dbdeleteconfigfiles', 'vaultpushconfigfiles', 'vaultpullconfigfiles', 'vaultdeleteconfigfiles', 'configkey', 'loadconfigfromdb', 'npmpath', 'serverid', 'recordencryptionrecode', 'vault', 'token', 'unsealkey', 'name', 'log', 'dbstats', 'translate', 'createaccount', 'resetaccount', 'pass', 'removesubdomain', 'adminaccount', 'domain', 'email', 'configfile', 'maintenancemode', 'nedbtodb', 'removetestagents', 'agentupdatetest', 'hashpassword', 'hashpass', 'indexmcrec', 'mpsdebug', 'dumpcores'];
141 for (var arg in obj.args) { obj.args[arg.toLocaleLowerCase()] = obj.args[arg]; if (validArguments.indexOf(arg.toLocaleLowerCase()) == -1) { console.log('Invalid argument "' + arg + '", use --help.'); return; } }
142 if (obj.args.mongodb == true) { console.log('Must specify: --mongodb [connectionstring] \r\nSee https://docs.mongodb.com/manual/reference/connection-string/ for MongoDB connection string.'); return; }
143 for (i in obj.config.settings) { obj.args[i] = obj.config.settings[i]; } // Place all settings into arguments, arguments have already been placed into settings so arguments take precedence.
@@ -173,7 +173,7 @@ function CreateMeshCentralServer(config, args) {
173 // Fix a NeDB database
174 if (obj.args.dbfix) {
175 var lines = null, badJsonCount = 0, feildNames = [], fixedDb = [];
176 - try { lines = obj.fs.readFileSync(obj.getConfigFilePath(obj.args.dbfix), { encoding: 'utf8' }).split('\n'); } catch (e) { console.log('Invalid file: ' + obj.args.dbfix + ': ' + e); process.exit(); }
176 + try { lines = obj.fs.readFileSync(obj.getConfigFilePath(obj.args.dbfix), { encoding: 'utf8' }).split('\n'); } catch (ex) { console.log('Invalid file: ' + obj.args.dbfix + ': ' + ex); process.exit(); }
177 for (var i = 0; i < lines.length; i++) {
178 var x = null;
179 try { x = JSON.parse(lines[i]); } catch (ex) { badJsonCount++; }
@@ -190,6 +190,9 @@ function CreateMeshCentralServer(config, args) {
190 // Perform a password hash
191 if (obj.args.hashpassword) { require('./pass').hash(obj.args.hashpassword, function (err, salt, hash, tag) { console.log(salt + ',' + hash); process.exit(); }); return; }
192
193 + // Dump to mesh cores
194 + if (obj.args.dumpcores) { obj.updateMeshCore(function () { console.log('Done.'); }, true); return; }
195 +
196 // Perform web site translations into different languages
197 if (obj.args.translate) {
198 // Check NodeJS version
@@ -381,10 +384,10 @@ function CreateMeshCentralServer(config, args) {
384 svc.on('alreadyinstalled', function () { console.log('MeshCentral service already installed.'); process.exit(); });
385 svc.on('invalidinstallation', function () { console.log('Invalid MeshCentral service installation.'); process.exit(); });
386
384 - if (obj.args.xinstall == true) { try { svc.install(); } catch (e) { logException(e); } }
385 - if (obj.args.stop == true || obj.args.restart == true) { try { svc.stop(); } catch (e) { logException(e); } }
386 - if (obj.args.start == true) { try { svc.start(); } catch (e) { logException(e); } }
387 - if (obj.args.xuninstall == true) { try { svc.uninstall(); } catch (e) { logException(e); } }
387 + if (obj.args.xinstall == true) { try { svc.install(); } catch (ex) { logException(ex); } }
388 + if (obj.args.stop == true || obj.args.restart == true) { try { svc.stop(); } catch (ex) { logException(ex); } }
389 + if (obj.args.start == true) { try { svc.start(); } catch (ex) { logException(ex); } }
390 + if (obj.args.xuninstall == true) { try { svc.uninstall(); } catch (ex) { logException(ex); } }
391 return;
392 }
393
@@ -534,7 +537,7 @@ function CreateMeshCentralServer(config, args) {
537 xxprocess.stderr.on('data', function (data) { });
538 xxprocess.on('close', function (code) {
539 var latestVer = null;
537 - if (code == 0) { try { latestVer = xxprocess.data.split(' ').join('').split('\r').join('').split('\n').join(''); } catch (e) { } }
540 + if (code == 0) { try { latestVer = xxprocess.data.split(' ').join('').split('\r').join('').split('\n').join(''); } catch (ex) { } }
541 callback(getCurrentVersion(), latestVer);
542 });
543 } catch (ex) { callback(getCurrentVersion(), null, ex); } // If the system is running out of memory, an exception here can easily happen.
@@ -560,7 +563,7 @@ function CreateMeshCentralServer(config, args) {
563 try {
564 var lines = xxprocess.data.split('\r\n').join('\n').split('\n');
565 for (var i in lines) { var s = lines[i].split(': '); if ((s.length == 2) && (obj.args.npmtag == null) || (obj.args.npmtag == s[0])) { tags[s[0]] = s[1]; } }
563 - } catch (e) { }
566 + } catch (ex) { }
567 }
568 callback(tags);
569 });
@@ -1045,10 +1048,10 @@ function CreateMeshCentralServer(config, args) {
1048 // Import the entire database from a JSON file
1049 if (obj.args.dbimport == true) { obj.args.dbimport = obj.getConfigFilePath('meshcentral.db.json'); }
1050 var json = null, json2 = '', badCharCount = 0;
1048 - try { json = obj.fs.readFileSync(obj.args.dbimport, { encoding: 'utf8' }); } catch (e) { console.log('Invalid JSON file: ' + obj.args.dbimport + ': ' + e); process.exit(); }
1051 + try { json = obj.fs.readFileSync(obj.args.dbimport, { encoding: 'utf8' }); } catch (ex) { console.log('Invalid JSON file: ' + obj.args.dbimport + ': ' + ex); process.exit(); }
1052 for (i = 0; i < json.length; i++) { if (json.charCodeAt(i) >= 32) { json2 += json[i]; } else { var tt = json.charCodeAt(i); if (tt != 10 && tt != 13) { badCharCount++; } } } // Remove all bad chars
1053 if (badCharCount > 0) { console.log(badCharCount + ' invalid character(s) where removed.'); }
1051 - try { json = JSON.parse(json2); } catch (e) { console.log('Invalid JSON format: ' + obj.args.dbimport + ': ' + e); process.exit(); }
1054 + try { json = JSON.parse(json2); } catch (ex) { console.log('Invalid JSON format: ' + obj.args.dbimport + ': ' + e); process.exit(); }
1055 if ((json == null) || (typeof json.length != 'number') || (json.length < 1)) { console.log('Invalid JSON format: ' + obj.args.dbimport + '.'); }
1056 // Escape MongoDB invalid field chars
1057 for (i in json) {
@@ -1086,10 +1089,10 @@ function CreateMeshCentralServer(config, args) {
1089 // Import the entire database from a JSON file
1090 if (obj.args.dbmerge == true) { obj.args.dbmerge = obj.getConfigFilePath('meshcentral.db.json'); }
1091 var json = null, json2 = "", badCharCount = 0;
1089 - try { json = obj.fs.readFileSync(obj.args.dbmerge, { encoding: 'utf8' }); } catch (e) { console.log('Invalid JSON file: ' + obj.args.dbmerge + ': ' + e); process.exit(); }
1092 + try { json = obj.fs.readFileSync(obj.args.dbmerge, { encoding: 'utf8' }); } catch (ex) { console.log('Invalid JSON file: ' + obj.args.dbmerge + ': ' + ex); process.exit(); }
1093 for (i = 0; i < json.length; i++) { if (json.charCodeAt(i) >= 32) { json2 += json[i]; } else { var tt = json.charCodeAt(i); if (tt != 10 && tt != 13) { badCharCount++; } } } // Remove all bad chars
1094 if (badCharCount > 0) { console.log(badCharCount + ' invalid character(s) where removed.'); }
1092 - try { json = JSON.parse(json2); } catch (e) { console.log('Invalid JSON format: ' + obj.args.dbmerge + ': ' + e); process.exit(); }
1095 + try { json = JSON.parse(json2); } catch (ex) { console.log('Invalid JSON format: ' + obj.args.dbmerge + ': ' + ex); process.exit(); }
1096 if ((json == null) || (typeof json.length != 'number') || (json.length < 1)) { console.log('Invalid JSON format: ' + obj.args.dbimport + '.'); }
1097
1098 // Get all users from current database
@@ -2428,7 +2431,7 @@ function CreateMeshCentralServer(config, args) {
2431 }
2432
2433 // Update the default mesh core
2431 - obj.updateMeshCore = function (func) {
2434 + obj.updateMeshCore = function (func, dumpToFile) {
2435 // Figure out where meshcore.js is
2436 var meshcorePath = obj.datapath;
2437 if (obj.fs.existsSync(obj.path.join(meshcorePath, 'meshcore.js')) == false) {
@@ -2476,12 +2479,12 @@ function CreateMeshCentralServer(config, args) {
2479 }
2480 }
2481
2479 - if (obj.args.minifycore !== false) { try { meshCore = obj.fs.readFileSync(obj.path.join(meshcorePath, 'meshcore.min.js')).toString(); } catch (e) { } } // Favor minified meshcore if present.
2480 - if (meshCore == null) { try { meshCore = obj.fs.readFileSync(obj.path.join(meshcorePath, 'meshcore.js')).toString(); } catch (e) { } } // Use non-minified meshcore.
2482 + if (obj.args.minifycore !== false) { try { meshCore = obj.fs.readFileSync(obj.path.join(meshcorePath, 'meshcore.min.js')).toString(); } catch (ex) { } } // Favor minified meshcore if present.
2483 + if (meshCore == null) { try { meshCore = obj.fs.readFileSync(obj.path.join(meshcorePath, 'meshcore.js')).toString(); } catch (ex) { } } // Use non-minified meshcore.
2484 if (meshCore != null) {
2485 var moduleDirPath = null;
2483 - if (obj.args.minifycore !== false) { try { moduleDirPath = obj.path.join(meshcorePath, 'modules_meshcore_min'); modulesDir = obj.fs.readdirSync(moduleDirPath); } catch (e) { } } // Favor minified modules if present.
2484 - if (modulesDir == null) { try { moduleDirPath = obj.path.join(meshcorePath, 'modules_meshcore'); modulesDir = obj.fs.readdirSync(moduleDirPath); } catch (e) { } } // Use non-minified mofules.
2486 + if (obj.args.minifycore !== false) { try { moduleDirPath = obj.path.join(meshcorePath, 'modules_meshcore_min'); modulesDir = obj.fs.readdirSync(moduleDirPath); } catch (ex) { } } // Favor minified modules if present.
2487 + if (modulesDir == null) { try { moduleDirPath = obj.path.join(meshcorePath, 'modules_meshcore'); modulesDir = obj.fs.readdirSync(moduleDirPath); } catch (ex) { } } // Use non-minified mofules.
2488 if (modulesDir != null) {
2489 for (var i in modulesDir) {
2490 if (modulesDir[i].toLowerCase().endsWith('.json')) {
@@ -2500,7 +2503,7 @@ function CreateMeshCentralServer(config, args) {
2503 // We are adding a JS file to the meshcores
2504 var moduleName = modulesDir[i].substring(0, modulesDir[i].length - 3);
2505 if (moduleName.endsWith('.min')) { moduleName = moduleName.substring(0, moduleName.length - 4); } // Remove the ".min" for ".min.js" files.
2503 - const moduleData = [ 'try { addModule("', moduleName, '", "', obj.escapeCodeString(obj.fs.readFileSync(obj.path.join(moduleDirPath, modulesDir[i])).toString('binary')), '"); addedModules.push("', moduleName, '"); } catch (e) { }\r\n' ];
2506 + const moduleData = [ 'try { addModule("', moduleName, '", "', obj.escapeCodeString(obj.fs.readFileSync(obj.path.join(moduleDirPath, modulesDir[i])).toString('binary')), '"); addedModules.push("', moduleName, '"); } catch (ex) { }\r\n' ];
2507
2508 // Merge this module
2509 // NOTE: "smbios" module makes some non-AI Linux segfault, only include for IA platforms.
@@ -2542,6 +2545,9 @@ function CreateMeshCentralServer(config, args) {
2545 // Add plugins to cores
2546 if (obj.pluginHandler) { obj.pluginHandler.addMeshCoreModules(modulesAdd); }
2547
2548 + // If we need to dump modules to file, create a meshcores folder
2549 + if (dumpToFile) { try { obj.fs.mkdirSync('meshcores'); } catch (ex) { } }
2550 +
2551 // Merge the cores and compute the hashes
2552 for (var i in modulesAdd) {
2553 if ((i == 'windows-recovery') || (i == 'linux-recovery')) {
@@ -2557,9 +2563,11 @@ function CreateMeshCentralServer(config, args) {
2563 obj.defaultMeshCoresHash[i] = obj.crypto.createHash('sha384').update(obj.defaultMeshCores[i]).digest('binary');
2564 obj.debug('main', 'Core module ' + i + ' is ' + obj.defaultMeshCores[i].length + ' bytes.');
2565
2560 - // These lines will write all modules to files. Great for debugging.
2561 - //console.log('Core module ' + i + ' is ' + obj.defaultMeshCores[i].length + ' bytes.'); // DEBUG, Print the core size
2562 - //obj.fs.writeFile("C:\\temp\\" + i + ".js", obj.defaultMeshCores[i].slice(4), function () { }); // DEBUG, Write the core to file
2566 + // Write all modules to files. Great for debugging.
2567 + if (dumpToFile) {
2568 + console.log('Core module ' + i + ' is ' + obj.defaultMeshCores[i].length + ' bytes, saving to meshcores/' + i + '.js.'); // Print the core size and filename
2569 + obj.fs.writeFile('meshcores/' + i + '.js', obj.defaultMeshCores[i].slice(4), function () { }); // Write the core to file
2570 + }
2571
2572 // Compress the mesh cores with DEFLATE
2573 const callback = function MeshCoreDeflateCb(err, buffer) { if (err == null) { obj.defaultMeshCoresDeflate[MeshCoreDeflateCb.i] = buffer; } }
@@ -2585,10 +2593,10 @@ function CreateMeshCentralServer(config, args) {
2593 meshCmd = meshCmd.replace("'***Mesh*Cmd*Version***'", '\'' + getCurrentVersion() + '\'');
2594
2595 // Figure out where the modules_meshcmd folder is.
2588 - if (obj.args.minifycore !== false) { try { moduleDirPath = obj.path.join(meshcmdPath, 'modules_meshcmd_min'); modulesDir = obj.fs.readdirSync(moduleDirPath); } catch (e) { } } // Favor minified modules if present.
2589 - if (modulesDir == null) { try { moduleDirPath = obj.path.join(meshcmdPath, 'modules_meshcmd'); modulesDir = obj.fs.readdirSync(moduleDirPath); } catch (e) { } } // Use non-minified mofules.
2590 - if (obj.args.minifycore !== false) { if (modulesDir == null) { try { moduleDirPath = obj.path.join(__dirname, 'agents', 'modules_meshcmd_min'); modulesDir = obj.fs.readdirSync(moduleDirPath); } catch (e) { } } } // Favor minified modules if present.
2591 - if (modulesDir == null) { try { moduleDirPath = obj.path.join(__dirname, 'agents', 'modules_meshcmd'); modulesDir = obj.fs.readdirSync(moduleDirPath); } catch (e) { } } // Use non-minified mofules.
2596 + if (obj.args.minifycore !== false) { try { moduleDirPath = obj.path.join(meshcmdPath, 'modules_meshcmd_min'); modulesDir = obj.fs.readdirSync(moduleDirPath); } catch (ex) { } } // Favor minified modules if present.
2597 + if (modulesDir == null) { try { moduleDirPath = obj.path.join(meshcmdPath, 'modules_meshcmd'); modulesDir = obj.fs.readdirSync(moduleDirPath); } catch (ex) { } } // Use non-minified mofules.
2598 + if (obj.args.minifycore !== false) { if (modulesDir == null) { try { moduleDirPath = obj.path.join(__dirname, 'agents', 'modules_meshcmd_min'); modulesDir = obj.fs.readdirSync(moduleDirPath); } catch (ex) { } } } // Favor minified modules if present.
2599 + if (modulesDir == null) { try { moduleDirPath = obj.path.join(__dirname, 'agents', 'modules_meshcmd'); modulesDir = obj.fs.readdirSync(moduleDirPath); } catch (ex) { } } // Use non-minified mofules.
2600
2601 // Read all .js files in the meshcmd modules folder.
2602 if (modulesDir != null) {
@@ -2597,7 +2605,7 @@ function CreateMeshCentralServer(config, args) {
2605 // Merge this module
2606 var moduleName = modulesDir[i].substring(0, modulesDir[i].length - 3);
2607 if (moduleName.endsWith('.min')) { moduleName = moduleName.substring(0, moduleName.length - 4); } // Remove the ".min" for ".min.js" files.
2600 - moduleAdditions.push('try { addModule("', moduleName, '", "', obj.escapeCodeString(obj.fs.readFileSync(obj.path.join(moduleDirPath, modulesDir[i])).toString('binary')), '"); addedModules.push("', moduleName, '"); } catch (e) { }\r\n');
2608 + moduleAdditions.push('try { addModule("', moduleName, '", "', obj.escapeCodeString(obj.fs.readFileSync(obj.path.join(moduleDirPath, modulesDir[i])).toString('binary')), '"); addedModules.push("', moduleName, '"); } catch (ex) { }\r\n');
2609 }
2610 }
2611 }
@@ -2643,7 +2651,7 @@ function CreateMeshCentralServer(config, args) {
2651 obj.meshToolsBinaries[this.toolname] = { hash: data.toString('hex'), hashx: this.hashx, path: this.toolpath, dlname: this.dlname, url: this.url };
2652 obj.meshToolsBinaries[this.toolname].url = 'https://' + obj.certificates.CommonName + ':' + ((typeof obj.args.aliasport == 'number') ? obj.args.aliasport : obj.args.port) + '/meshagents?meshaction=' + this.dlname;
2653 var stats = null;
2646 - try { stats = obj.fs.statSync(this.toolpath); } catch (e) { }
2654 + try { stats = obj.fs.statSync(this.toolpath); } catch (ex) { }
2655 if (stats != null) { obj.meshToolsBinaries[this.toolname].size = stats.size; }
2656 });
2657 var options = { sourcePath: toolpath, targetStream: hashStream };
@@ -2670,7 +2678,7 @@ function CreateMeshCentralServer(config, args) {
2678 obj.meshToolsBinaries[this.toolname].dlname = this.dlname;
2679 obj.meshToolsBinaries[this.toolname].url = 'https://' + obj.certificates.CommonName + ':' + ((typeof obj.args.aliasport == 'number') ? obj.args.aliasport : obj.args.port) + '/meshagents?meshaction=' + this.dlname;
2680 var stats = null;
2673 - try { stats = obj.fs.statSync(this.agentpath); } catch (e) { }
2681 + try { stats = obj.fs.statSync(this.agentpath); } catch (ex) { }
2682 if (stats != null) { obj.meshToolsBinaries[this.toolname].size = stats.size; }
2683 });
2684 stream.toolname = toolname;
@@ -2678,7 +2686,7 @@ function CreateMeshCentralServer(config, args) {
2686 stream.dlname = meshToolsList[toolname].dlname;
2687 stream.hash = obj.crypto.createHash('sha384', stream);
2688 stream.hashx = 0;
2681 - } catch (e) { }
2689 + } catch (ex) { }
2690 }
2691 }
2692 };
@@ -2712,7 +2720,7 @@ function CreateMeshCentralServer(config, args) {
2720 obj.meshAgentInstallScripts[this.info.id].data = this.xdata;
2721 obj.meshAgentInstallScripts[this.info.id].url = 'https://' + obj.certificates.CommonName + ':' + ((typeof obj.args.aliasport == 'number') ? obj.args.aliasport : obj.args.port) + '/meshagents?script=' + this.info.id;
2722 var stats = null;
2715 - try { stats = obj.fs.statSync(this.agentpath); } catch (e) { }
2723 + try { stats = obj.fs.statSync(this.agentpath); } catch (ex) { }
2724 if (stats != null) { obj.meshAgentInstallScripts[this.info.id].size = stats.size; }
2725
2726 // Place Unit line breaks on Linux scripts if not already present.
@@ -2721,7 +2729,7 @@ function CreateMeshCentralServer(config, args) {
2729 stream.info = meshAgentsInstallScriptList[scriptid];
2730 stream.agentpath = scriptpath;
2731 stream.hash = obj.crypto.createHash('sha384', stream);
2724 - } catch (e) { }
2732 + } catch (ex) { }
2733 }
2734 };
2735
@@ -2786,7 +2794,7 @@ function CreateMeshCentralServer(config, args) {
2794
2795 // Fetch all the agent binary information
2796 var stats = null;
2789 - try { stats = obj.fs.statSync(agentpath); } catch (e) { }
2797 + try { stats = obj.fs.statSync(agentpath); } catch (ex) { }
2798 if ((stats != null)) {
2799 // If file exists
2800 archcount++;
@@ -2798,7 +2806,7 @@ function CreateMeshCentralServer(config, args) {
2806
2807 // If this is a windows binary, pull binary information
2808 if (obj.meshAgentsArchitectureNumbers[archid].platform == 'win32') {
2801 - try { obj.meshAgentBinaries[archid].pe = obj.exeHandler.parseWindowsExecutable(agentpath); } catch (e) { }
2809 + try { obj.meshAgentBinaries[archid].pe = obj.exeHandler.parseWindowsExecutable(agentpath); } catch (ex) { }
2810 }
2811
2812 // If agents must be stored in RAM or if this is a Windows 32/64 agent, load the agent in RAM.
@@ -3235,7 +3243,7 @@ function getConfig(createSampleConfig) {
3243 datapath = path.join(__dirname, '../meshcentral-data');
3244 }
3245 if (args.datapath) { datapath = args.datapath; }
3238 - try { fs.mkdirSync(datapath); } catch (e) { }
3246 + try { fs.mkdirSync(datapath); } catch (ex) { }
3247
3248 // Read configuration file if present and change arguments.
3249 var config = {}, configFilePath = path.join(datapath, 'config.json');
@@ -3244,7 +3252,7 @@ function getConfig(createSampleConfig) {
3252 }
3253 if (fs.existsSync(configFilePath)) {
3254 // Load and validate the configuration file
3247 - try { config = require(configFilePath); } catch (e) { console.log('ERROR: Unable to parse ' + configFilePath + '.'); return null; }
3255 + try { config = require(configFilePath); } catch (ex) { console.log('ERROR: Unable to parse ' + configFilePath + '.'); return null; }
3256 if (config.domains == null) { config.domains = {}; }
3257 for (i in config.domains) { if ((i.split('/').length > 1) || (i.split(' ').length > 1)) { console.log("ERROR: Error in config.json, domain names can't have spaces or /."); return null; } }
3258 } else {
@@ -3292,7 +3300,7 @@ function InstallModules(modules, func) {
3300 if (typeof dependencies[moduleName] != undefined) { moduleVersion = dependencies[moduleName]; }
3301 require(moduleName);
3302 }
3295 - } catch (e) {
3303 + } catch (ex) {
3304 if (previouslyInstalledModules[modules[i]] !== true) { missingModules.push(moduleNameAndVersion); }
3305 }
3306 }