refactor: rename function getCurrentVerion => getCurrentVersion

Nicolas Duteil committed May 3, 2021 at 10:58 UTC 038d3e85d6e68965afc5aa0e8ec5a9a1773a0a0a
1 file changed +17 -17
meshcentral.js
+17 -17
@@ -77,8 +77,8 @@ function CreateMeshCentralServer(config, args) {
77
78 // Server version
79 obj.currentVer = null;
80 - function getCurrentVerion() { try { obj.currentVer = JSON.parse(obj.fs.readFileSync(obj.path.join(__dirname, 'package.json'), 'utf8')).version; } catch (e) { } return obj.currentVer; } // Fetch server version
81 - getCurrentVerion();
80 + 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
81 + getCurrentVersion();
82
83 // Setup the default configuration and files paths
84 if ((__dirname.endsWith('/node_modules/meshcentral')) || (__dirname.endsWith('\\node_modules\\meshcentral')) || (__dirname.endsWith('/node_modules/meshcentral/')) || (__dirname.endsWith('\\node_modules\\meshcentral\\'))) {
@@ -144,7 +144,7 @@ function CreateMeshCentralServer(config, args) {
144 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.
145
146 if ((obj.args.help == true) || (obj.args['?'] == true)) {
147 - console.log('MeshCentral v' + getCurrentVerion() + ', remote computer management web portal.');
147 + console.log('MeshCentral v' + getCurrentVersion() + ', remote computer management web portal.');
148 console.log('This software is open source under Apache 2.0 license.');
149 console.log('Details at: https://www.meshcommander.com/meshcentral2\r\n');
150 if ((obj.platform == 'win32') || (obj.platform == 'linux')) {
@@ -485,7 +485,7 @@ function CreateMeshCentralServer(config, args) {
485 try {
486 var errlogpath = null;
487 if (typeof obj.args.mesherrorlogpath == 'string') { errlogpath = obj.path.join(obj.args.mesherrorlogpath, 'mesherrors.txt'); } else { errlogpath = obj.getConfigFilePath('mesherrors.txt'); }
488 - obj.fs.appendFileSync(errlogpath, '-------- ' + new Date().toLocaleString() + ' ---- ' + getCurrentVerion() + ' --------\r\n\r\n' + data + '\r\n\r\n\r\n');
488 + obj.fs.appendFileSync(errlogpath, '-------- ' + new Date().toLocaleString() + ' ---- ' + getCurrentVersion() + ' --------\r\n\r\n' + data + '\r\n\r\n\r\n');
489 } catch (ex) { console.log('ERROR: Unable to write to mesherrors.txt.'); }
490 });
491 childProcess.on('close', function (code) { if ((code != 0) && (code != 123)) { /* console.log("Exited with code " + code); */ } });
@@ -495,7 +495,7 @@ function CreateMeshCentralServer(config, args) {
495 obj.getLatestServerVersion = function (callback) {
496 if (callback == null) return;
497 try {
498 - if (typeof obj.args.selfupdate == 'string') { callback(getCurrentVerion(), obj.args.selfupdate); return; } // If we are targetting a specific version, return that one as current.
498 + if (typeof obj.args.selfupdate == 'string') { callback(getCurrentVersion(), obj.args.selfupdate); return; } // If we are targetting a specific version, return that one as current.
499 var child_process = require('child_process');
500 var npmpath = ((typeof obj.args.npmpath == 'string') ? obj.args.npmpath : 'npm');
501 var npmproxy = ((typeof obj.args.npmproxy == 'string') ? (' --proxy ' + obj.args.npmproxy) : '');
@@ -508,16 +508,16 @@ function CreateMeshCentralServer(config, args) {
508 xxprocess.on('close', function (code) {
509 var latestVer = null;
510 if (code == 0) { try { latestVer = xxprocess.data.split(' ').join('').split('\r').join('').split('\n').join(''); } catch (e) { } }
511 - callback(getCurrentVerion(), latestVer);
511 + callback(getCurrentVersion(), latestVer);
512 });
513 - } catch (ex) { callback(getCurrentVerion(), null, ex); } // If the system is running out of memory, an exception here can easily happen.
513 + } catch (ex) { callback(getCurrentVersion(), null, ex); } // If the system is running out of memory, an exception here can easily happen.
514 };
515
516 // Get current version and all MeshCentral server tags using NPM
517 obj.getServerTags = function (callback) {
518 if (callback == null) return;
519 try {
520 - if (typeof obj.args.selfupdate == 'string') { callback({ current: getCurrentVerion(), latest: obj.args.selfupdate }); return; } // If we are targetting a specific version, return that one as current.
520 + if (typeof obj.args.selfupdate == 'string') { callback({ current: getCurrentVersion(), latest: obj.args.selfupdate }); return; } // If we are targetting a specific version, return that one as current.
521 var child_process = require('child_process');
522 var npmpath = ((typeof obj.args.npmpath == 'string') ? obj.args.npmpath : 'npm');
523 var npmproxy = ((typeof obj.args.npmproxy == 'string') ? (' --proxy ' + obj.args.npmproxy) : '');
@@ -528,7 +528,7 @@ function CreateMeshCentralServer(config, args) {
528 xxprocess.stdout.on('data', function (data) { xxprocess.data += data; });
529 xxprocess.stderr.on('data', function (data) { });
530 xxprocess.on('close', function (code) {
531 - var tags = { current: getCurrentVerion() };
531 + var tags = { current: getCurrentVersion() };
532 if (code == 0) {
533 try {
534 var lines = xxprocess.data.split('\r\n').join('\n').split('\n');
@@ -537,7 +537,7 @@ function CreateMeshCentralServer(config, args) {
537 }
538 callback(tags);
539 });
540 - } catch (ex) { callback({ current: getCurrentVerion() }, ex); } // If the system is running out of memory, an exception here can easily happen.
540 + } catch (ex) { callback({ current: getCurrentVersion() }, ex); } // If the system is running out of memory, an exception here can easily happen.
541 };
542
543 // Initiate server self-update
@@ -668,20 +668,20 @@ function CreateMeshCentralServer(config, args) {
668 obj.syslog = require('modern-syslog');
669 console.log('Starting ' + config.settings.syslog + ' syslog.');
670 obj.syslog.init(config.settings.syslog, obj.syslog.LOG_PID | obj.syslog.LOG_ODELAY, obj.syslog.LOG_LOCAL0);
671 - obj.syslog.log(obj.syslog.LOG_INFO, "MeshCentral v" + getCurrentVerion() + " Server Start");
671 + obj.syslog.log(obj.syslog.LOG_INFO, "MeshCentral v" + getCurrentVersion() + " Server Start");
672 }
673 if (typeof config.settings.syslogjson == 'string') {
674 obj.syslogjson = require('modern-syslog');
675 console.log('Starting ' + config.settings.syslogjson + ' JSON syslog.');
676 obj.syslogjson.init(config.settings.syslogjson, obj.syslogjson.LOG_PID | obj.syslogjson.LOG_ODELAY, obj.syslogjson.LOG_LOCAL0);
677 - obj.syslogjson.log(obj.syslogjson.LOG_INFO, "MeshCentral v" + getCurrentVerion() + " Server Start");
677 + obj.syslogjson.log(obj.syslogjson.LOG_INFO, "MeshCentral v" + getCurrentVersion() + " Server Start");
678 }
679 if (typeof config.settings.syslogauth == 'string') {
680 obj.authlog = true;
681 obj.syslogauth = require('modern-syslog');
682 console.log('Starting ' + config.settings.syslogauth + ' auth syslog.');
683 obj.syslogauth.init(config.settings.syslogauth, obj.syslogauth.LOG_PID | obj.syslogauth.LOG_ODELAY, obj.syslogauth.LOG_LOCAL0);
684 - obj.syslogauth.log(obj.syslogauth.LOG_INFO, "MeshCentral v" + getCurrentVerion() + " Server Start");
684 + obj.syslogauth.log(obj.syslogauth.LOG_INFO, "MeshCentral v" + getCurrentVersion() + " Server Start");
685 }
686 }
687
@@ -1150,7 +1150,7 @@ function CreateMeshCentralServer(config, args) {
1150 // If we are targetting a specific version, update now.
1151 if ((obj.serverSelfWriteAllowed == true) && (typeof obj.args.selfupdate == 'string')) {
1152 obj.args.selfupdate = obj.args.selfupdate.toLowerCase();
1153 - if (getCurrentVerion() !== obj.args.selfupdate) { obj.performServerUpdate(); return; } // We are targetting a specific version, run self update now.
1153 + if (getCurrentVersion() !== obj.args.selfupdate) { obj.performServerUpdate(); return; } // We are targetting a specific version, run self update now.
1154 }
1155
1156 // Write the server state
@@ -1483,7 +1483,7 @@ function CreateMeshCentralServer(config, args) {
1483 // Write server version and run mode
1484 var productionMode = (process.env.NODE_ENV && (process.env.NODE_ENV == 'production'));
1485 var runmode = (obj.args.lanonly ? 2 : (obj.args.wanonly ? 1 : 0));
1486 - console.log("MeshCentral v" + getCurrentVerion() + ', ' + (["Hybrid (LAN + WAN) mode", "WAN mode", "LAN mode"][runmode]) + (productionMode ? ", Production mode." : '.'));
1486 + console.log("MeshCentral v" + getCurrentVersion() + ', ' + (["Hybrid (LAN + WAN) mode", "WAN mode", "LAN mode"][runmode]) + (productionMode ? ", Production mode." : '.'));
1487
1488 // Check that no sub-domains have the same DNS as the parent
1489 for (i in obj.config.domains) {
@@ -1829,7 +1829,7 @@ function CreateMeshCentralServer(config, args) {
1829 });
1830
1831 // Check for self-update that targets a specific version
1832 - if ((typeof obj.args.selfupdate == 'string') && (getCurrentVerion() === obj.args.selfupdate)) { obj.args.selfupdate = false; }
1832 + if ((typeof obj.args.selfupdate == 'string') && (getCurrentVersion() === obj.args.selfupdate)) { obj.args.selfupdate = false; }
1833
1834 // Check if we need to perform server self-update
1835 if ((obj.args.selfupdate) && (obj.serverSelfWriteAllowed == true)) {
@@ -2355,7 +2355,7 @@ function CreateMeshCentralServer(config, args) {
2355 else if ((obj.args.minifycore !== false) && (obj.fs.existsSync(obj.path.join(__dirname, 'agents', 'meshcmd.min.js')))) { meshcmdPath = obj.path.join(__dirname, 'agents', 'meshcmd.min.js'); meshCmd = obj.fs.readFileSync(meshcmdPath).toString(); }
2356 else if (obj.fs.existsSync(obj.path.join(__dirname, 'agents', 'meshcmd.js'))) { meshcmdPath = obj.path.join(__dirname, 'agents', 'meshcmd.js'); meshCmd = obj.fs.readFileSync(meshcmdPath).toString(); }
2357 else { obj.defaultMeshCmd = null; if (func != null) { func(false); } return; } // meshcmd.js not found
2358 - meshCmd = meshCmd.replace("'***Mesh*Cmd*Version***'", '\'' + getCurrentVerion() + '\'');
2358 + meshCmd = meshCmd.replace("'***Mesh*Cmd*Version***'", '\'' + getCurrentVersion() + '\'');
2359
2360 // Figure out where the modules_meshcmd folder is.
2361 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.