Improved web socket error handling, Selfupdate can now be set to specific version.
This commit is contained in:
parent
25ccec1d81
commit
e6b05f2b4a
2
db.js
2
db.js
|
@ -48,7 +48,7 @@ module.exports.CreateDB = function (parent) {
|
||||||
var datastoreOptions = { filename: obj.parent.getConfigFilePath('meshcentral.db'), autoload: true };
|
var datastoreOptions = { filename: obj.parent.getConfigFilePath('meshcentral.db'), autoload: true };
|
||||||
|
|
||||||
// If a DB encryption key is provided, perform database encryption
|
// If a DB encryption key is provided, perform database encryption
|
||||||
if (typeof obj.parent.args.dbencryptkey == 'string') {
|
if ((typeof obj.parent.args.dbencryptkey == 'string') && (obj.parent.args.dbencryptkey.length != 0)) {
|
||||||
// Hash the database password into a AES256 key and setup encryption and decryption.
|
// Hash the database password into a AES256 key and setup encryption and decryption.
|
||||||
obj.dbKey = obj.parent.crypto.createHash('sha384').update(obj.parent.args.dbencryptkey).digest("raw").slice(0, 32);
|
obj.dbKey = obj.parent.crypto.createHash('sha384').update(obj.parent.args.dbencryptkey).digest("raw").slice(0, 32);
|
||||||
datastoreOptions.afterSerialization = function (plaintext) {
|
datastoreOptions.afterSerialization = function (plaintext) {
|
||||||
|
|
|
@ -94,7 +94,7 @@ function CreateMeshCentralServer(config, args) {
|
||||||
try { require('./pass').hash('test', function () { }); } catch (e) { console.log('Old version of node, must upgrade.'); return; } // TODO: Not sure if this test works or not.
|
try { require('./pass').hash('test', function () { }); } catch (e) { console.log('Old version of node, must upgrade.'); return; } // TODO: Not sure if this test works or not.
|
||||||
|
|
||||||
// Check for invalid arguments
|
// Check for invalid arguments
|
||||||
var validArguments = ['_', 'notls', 'user', 'port', 'aliasport', 'mpsport', 'mpsaliasport', 'redirport', 'cert', 'mpscert', 'deletedomain', 'deletedefaultdomain', 'showall', 'showusers', 'shownodes', 'showmeshes', 'showevents', 'showpower', 'clearpower', 'showiplocations', 'help', 'exactports', 'install', 'uninstall', 'start', 'stop', 'restart', 'debug', 'filespath', 'datapath', 'noagentupdate', 'launch', 'noserverbackup', 'mongodb', 'mongodbcol', 'wanonly', 'lanonly', 'nousers', 'mpsdebug', 'mpspass', 'ciralocalfqdn', 'dbexport', 'dbexportmin', 'dbimport', 'selfupdate', 'tlsoffload', 'userallowedip', 'swarmallowedip', 'fastcert', 'swarmport', 'swarmdebug', 'logintoken', 'logintokenkey', 'logintokengen', 'logintokengen', 'mailtokengen', 'admin', 'unadmin', 'sessionkey', 'sessiontime', 'minify', 'minifycore'];
|
var validArguments = ['_', 'notls', 'user', 'port', 'aliasport', 'mpsport', 'mpsaliasport', 'redirport', 'cert', 'mpscert', 'deletedomain', 'deletedefaultdomain', 'showall', 'showusers', 'shownodes', 'showmeshes', 'showevents', 'showpower', 'clearpower', 'showiplocations', 'help', 'exactports', 'install', 'uninstall', 'start', 'stop', 'restart', 'debug', 'filespath', 'datapath', 'noagentupdate', 'launch', 'noserverbackup', 'mongodb', 'mongodbcol', 'wanonly', 'lanonly', 'nousers', 'mpsdebug', 'mpspass', 'ciralocalfqdn', 'dbexport', 'dbexportmin', 'dbimport', 'dbencryptkey', 'selfupdate', 'tlsoffload', 'userallowedip', 'swarmallowedip', 'fastcert', 'swarmport', 'swarmdebug', 'logintoken', 'logintokenkey', 'logintokengen', 'logintokengen', 'mailtokengen', 'admin', 'unadmin', 'sessionkey', 'sessiontime', 'minify', 'minifycore'];
|
||||||
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; } }
|
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; } }
|
||||||
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; }
|
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; }
|
||||||
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.
|
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.
|
||||||
|
@ -168,12 +168,15 @@ function CreateMeshCentralServer(config, args) {
|
||||||
process.exit(); // User CTRL-C exit.
|
process.exit(); // User CTRL-C exit.
|
||||||
} else if (xprocess.xrestart == 3) {
|
} else if (xprocess.xrestart == 3) {
|
||||||
// Server self-update exit
|
// Server self-update exit
|
||||||
|
var version = '';
|
||||||
|
if (typeof obj.args.selfupdate == 'string') { version = '@' + obj.args.selfupdate; }
|
||||||
var child_process = require('child_process');
|
var child_process = require('child_process');
|
||||||
var xxprocess = child_process.exec('npm install meshcentral', { maxBuffer: Infinity, cwd: obj.path.join(__dirname, '../..') }, function (error, stdout, stderr) { });
|
console.log('npm install meshcentral' + version);
|
||||||
xxprocess.data = '';
|
//var xxprocess = child_process.exec('npm install meshcentral' + version, { maxBuffer: Infinity, cwd: obj.path.join(__dirname, '../..') }, function (error, stdout, stderr) { });
|
||||||
xxprocess.stdout.on('data', function (data) { xxprocess.data += data; });
|
//xxprocess.data = '';
|
||||||
xxprocess.stderr.on('data', function (data) { xxprocess.data += data; });
|
//xxprocess.stdout.on('data', function (data) { xxprocess.data += data; });
|
||||||
xxprocess.on('close', function (code) { console.log('Update completed...'); setTimeout(function () { obj.launchChildServer(startLine); }, 1000); });
|
//xxprocess.stderr.on('data', function (data) { xxprocess.data += data; });
|
||||||
|
//xxprocess.on('close', function (code) { console.log('Update completed...'); setTimeout(function () { obj.launchChildServer(startLine); }, 1000); });
|
||||||
} else {
|
} else {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
// This is an un-expected restart
|
// This is an un-expected restart
|
||||||
|
@ -195,6 +198,7 @@ function CreateMeshCentralServer(config, args) {
|
||||||
// Get current and latest MeshCentral server versions using NPM
|
// Get current and latest MeshCentral server versions using NPM
|
||||||
obj.getLatestServerVersion = function (callback) {
|
obj.getLatestServerVersion = function (callback) {
|
||||||
if (callback == null) return;
|
if (callback == null) return;
|
||||||
|
if (typeof obj.args.selfupdate == 'string') { callback(obj.currentVer, obj.args.selfupdate); return; } // If we are targetting a specific version, return that one as current.
|
||||||
var child_process = require('child_process');
|
var child_process = require('child_process');
|
||||||
var xprocess = child_process.exec('npm view meshcentral dist-tags.latest', { maxBuffer: 512000 }, function (error, stdout, stderr) { });
|
var xprocess = child_process.exec('npm view meshcentral dist-tags.latest', { maxBuffer: 512000 }, function (error, stdout, stderr) { });
|
||||||
xprocess.data = '';
|
xprocess.data = '';
|
||||||
|
@ -218,6 +222,12 @@ function CreateMeshCentralServer(config, args) {
|
||||||
//var wincmd = require('node-windows');
|
//var wincmd = require('node-windows');
|
||||||
//wincmd.list(function (svc) { console.log(svc); }, true);
|
//wincmd.list(function (svc) { console.log(svc); }, true);
|
||||||
|
|
||||||
|
// If we are targetting a specific version, update now.
|
||||||
|
if (typeof obj.args.selfupdate == 'string') {
|
||||||
|
obj.args.selfupdate = obj.args.selfupdate.toLowerCase();
|
||||||
|
if (obj.currentVer !== obj.args.selfupdate) { obj.performServerUpdate(); return; } // We are targetting a specific version, run self update now.
|
||||||
|
}
|
||||||
|
|
||||||
// Write the server state
|
// Write the server state
|
||||||
obj.updateServerState('state', 'starting');
|
obj.updateServerState('state', 'starting');
|
||||||
|
|
||||||
|
@ -561,8 +571,11 @@ function CreateMeshCentralServer(config, args) {
|
||||||
|
|
||||||
// Perform maintenance operations (called every hour)
|
// Perform maintenance operations (called every hour)
|
||||||
obj.maintenanceActions = function () {
|
obj.maintenanceActions = function () {
|
||||||
|
// Check for self-update that targets a specific version
|
||||||
|
if ((typeof obj.args.selfupdate == 'string') && (obj.currentVer === obj.args.selfupdate)) { obj.args.selfupdate = false; }
|
||||||
|
|
||||||
// Check if we need to perform server self-update
|
// Check if we need to perform server self-update
|
||||||
if ((obj.args.selfupdate == true) && (obj.serverSelfWriteAllowed == true)) {
|
if ((obj.args.selfupdate) && (obj.serverSelfWriteAllowed == true)) {
|
||||||
obj.db.getValueOfTheDay('performSelfUpdate', 1, function (performSelfUpdate) {
|
obj.db.getValueOfTheDay('performSelfUpdate', 1, function (performSelfUpdate) {
|
||||||
if (performSelfUpdate.value > 0) {
|
if (performSelfUpdate.value > 0) {
|
||||||
performSelfUpdate.value--;
|
performSelfUpdate.value--;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "meshcentral",
|
"name": "meshcentral",
|
||||||
"version": "0.2.6-x",
|
"version": "0.2.6-y",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Remote Management",
|
"Remote Management",
|
||||||
"Intel AMT",
|
"Intel AMT",
|
||||||
|
|
|
@ -10,35 +10,38 @@ var MeshServerCreateControl = function (domain) {
|
||||||
obj.connectstate = 0;
|
obj.connectstate = 0;
|
||||||
obj.pingTimer = null;
|
obj.pingTimer = null;
|
||||||
|
|
||||||
obj.xxStateChange = function (newstate) {
|
obj.xxStateChange = function (newstate, errCode) {
|
||||||
if (obj.State == newstate) return;
|
if (obj.State == newstate) return;
|
||||||
|
var previousState = obj.State;
|
||||||
obj.State = newstate;
|
obj.State = newstate;
|
||||||
if (obj.onStateChanged) obj.onStateChanged(obj, obj.State);
|
if (obj.onStateChanged) obj.onStateChanged(obj, obj.State, previousState, errCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.Start = function () {
|
obj.Start = function () {
|
||||||
|
if (obj.connectstate != 0) return;
|
||||||
obj.connectstate = 0;
|
obj.connectstate = 0;
|
||||||
obj.socket = new WebSocket(window.location.protocol.replace("http", "ws") + "//" + window.location.host + domain + "control.ashx");
|
obj.socket = new WebSocket(window.location.protocol.replace("http", "ws") + "//" + window.location.host + domain + "control.ashx");
|
||||||
obj.socket.onopen = function () { obj.connectstate = 1; obj.xxStateChange(2); }
|
obj.socket.onopen = function (e) { obj.connectstate = 1; }
|
||||||
obj.socket.onmessage = obj.xxOnMessage;
|
obj.socket.onmessage = obj.xxOnMessage;
|
||||||
obj.socket.onclose = function () { obj.Stop(); }
|
obj.socket.onclose = function(e) { obj.Stop(e.code); }
|
||||||
obj.xxStateChange(1);
|
obj.xxStateChange(1, 0);
|
||||||
if (obj.pingTimer != null) { clearInterval(obj.pingTimer); }
|
if (obj.pingTimer != null) { clearInterval(obj.pingTimer); }
|
||||||
obj.pingTimer = setInterval(function () { obj.send({ action: 'ping' }); }, 29000); // Ping the server every 29 seconds, stops corporate proxies from disconnecting.
|
obj.pingTimer = setInterval(function () { obj.send({ action: 'ping' }); }, 29000); // Ping the server every 29 seconds, stops corporate proxies from disconnecting.
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.Stop = function () {
|
obj.Stop = function (errCode) {
|
||||||
obj.connectstate = 0;
|
obj.connectstate = 0;
|
||||||
if (obj.socket) { obj.socket.close(); delete obj.socket; }
|
if (obj.socket) { obj.socket.close(); delete obj.socket; }
|
||||||
if (obj.pingTimer != null) { clearInterval(obj.pingTimer); obj.pingTimer = null; }
|
if (obj.pingTimer != null) { clearInterval(obj.pingTimer); obj.pingTimer = null; }
|
||||||
obj.xxStateChange(0);
|
obj.xxStateChange(0, errCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.xxOnMessage = function (e) {
|
obj.xxOnMessage = function (e) {
|
||||||
// console.log('xxOnMessage', e.data);
|
if (obj.State == 1) { obj.xxStateChange(2); }
|
||||||
|
//console.log('xxOnMessage', e.data);
|
||||||
var message;
|
var message;
|
||||||
try { message = JSON.parse(e.data); } catch (e) { return; }
|
try { message = JSON.parse(e.data); } catch (e) { return; }
|
||||||
if (message.action == 'pong') { return; }
|
if ((typeof message != 'object') || (message.action == 'pong')) { return; }
|
||||||
if (obj.onMessage) obj.onMessage(obj, message);
|
if (obj.onMessage) obj.onMessage(obj, message);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -195,13 +195,13 @@
|
||||||
<strong><font style="font-size:12px;font-family:Arial,Helvetica,sans-serif">{{{title2}}}</font></strong>
|
<strong><font style="font-size:12px;font-family:Arial,Helvetica,sans-serif">{{{title2}}}</font></strong>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<img class=noselect style="position:absolute;right:0;top:10px;bottom:50px;color:#c8c8c8;font-size:44px;margin-right:8px;cursor:pointer" onclick=topMenu() src="/images/3bars-30.png" width=30 height=30 />
|
<img id="topMenuIcon" class=noselect style="position:absolute;right:0;top:10px;bottom:50px;color:#c8c8c8;font-size:44px;margin-right:8px;cursor:pointer;display:none" onclick=topMenu() src="/images/3bars-30.png" width=30 height=30 />
|
||||||
</div>
|
</div>
|
||||||
<div id=page_content style="overflow-y:scroll;position:absolute;bottom:32px;top:50px;width:100%">
|
<div id=page_content style="overflow-y:scroll;position:absolute;bottom:32px;top:50px;width:100%">
|
||||||
<div id=column_l style="width:100%;padding:0;position:absolute;bottom:0px;top:0px">
|
<div id=column_l style="width:100%;padding:0;position:absolute;bottom:0px;top:0px">
|
||||||
<div id=p0 style=display:none;width:100%;height:100%>
|
<div id=p0 style=display:none;width:100%;height:100%>
|
||||||
<div style="display:flex;align-items:center;width:100%;height:100%">
|
<div style="display:flex;align-items:center;width:100%;height:100%">
|
||||||
<div id=p0message style=text-align:center;width:100%>Server disconnected, <href onclick=reload() style=cursor:pointer><u>click to reconnect</u></href>.</div>
|
<div id=p0message style=text-align:center;width:100%><span id="p0span">Server disconnected</span>, <href onclick=reload() style=cursor:pointer><u>click to reconnect</u></href>.</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id=p1 style=display:none;width:100%;height:100%>
|
<div id=p1 style=display:none;width:100%;height:100%>
|
||||||
|
@ -617,13 +617,12 @@
|
||||||
applyDesktopSettings();
|
applyDesktopSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onStateChanged(server, state) {
|
function onStateChanged(server, state, prevState, errorCode) {
|
||||||
if (state == 0) {
|
if (state == 0) {
|
||||||
// Control web socket disconnected
|
// Control web socket disconnected
|
||||||
setDialogMode(0); // Close any dialog boxes if present
|
setDialogMode(0); // Close any dialog boxes if present
|
||||||
go(0); // Go to disconnection panel
|
go(0); // Go to disconnection panel
|
||||||
setTimeout(serverPoll, 5000); // Start polling for the server
|
if (prevState == 2) { setTimeout(serverPoll, 5000); } else { QH('p0span', 'Unable to connect web socket'); }
|
||||||
|
|
||||||
// Clean up here
|
// Clean up here
|
||||||
|
|
||||||
} else if (state == 2) {
|
} else if (state == 2) {
|
||||||
|
@ -633,6 +632,7 @@
|
||||||
meshserver.send({ action: 'files' });
|
meshserver.send({ action: 'files' });
|
||||||
if (xxcurrentView < 2) { go(2); }
|
if (xxcurrentView < 2) { go(2); }
|
||||||
}
|
}
|
||||||
|
QV('topMenuIcon', state == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Poll the server, if it responds, refresh the page.
|
// Poll the server, if it responds, refresh the page.
|
||||||
|
|
|
@ -147,7 +147,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="column_l">
|
<div id="column_l">
|
||||||
<div id=p0 style=display:none>
|
<div id=p0 style=display:none>
|
||||||
<div id=p0message style=margin:50px;text-align:center>Server disconnected, <href onclick=reload() style=cursor:pointer><u>click to reconnect</u></href>.</div>
|
<div id=p0message style=margin:50px;text-align:center><span id=p0span>Server disconnected</span>, <href onclick=reload() style=cursor:pointer><u>click to reconnect</u></href>.</div>
|
||||||
</div>
|
</div>
|
||||||
<div id=p1 style=display:none>
|
<div id=p1 style=display:none>
|
||||||
<div style="float:right;display:none" id="devListToolbarViewIcons">
|
<div style="float:right;display:none" id="devListToolbarViewIcons">
|
||||||
|
@ -1025,7 +1025,7 @@
|
||||||
function getNodeFromId(id) { for (var i in nodes) { if (nodes[i]._id == id) return nodes[i]; } return null; }
|
function getNodeFromId(id) { for (var i in nodes) { if (nodes[i]._id == id) return nodes[i]; } return null; }
|
||||||
function reload() { window.location.href = window.location.href; }
|
function reload() { window.location.href = window.location.href; }
|
||||||
|
|
||||||
function onStateChanged(server, state) {
|
function onStateChanged(server, state, prevState, errorCode) {
|
||||||
if (state == 0) {
|
if (state == 0) {
|
||||||
// Control web socket disconnected
|
// Control web socket disconnected
|
||||||
setDialogMode(0); // Close any dialog boxes if present
|
setDialogMode(0); // Close any dialog boxes if present
|
||||||
|
@ -1040,12 +1040,13 @@
|
||||||
hideContextMenu(); // Hide the context menu if present
|
hideContextMenu(); // Hide the context menu if present
|
||||||
QV('verifyEmailId2', false);
|
QV('verifyEmailId2', false);
|
||||||
QV('logoutControl', false);
|
QV('logoutControl', false);
|
||||||
setTimeout(serverPoll, 5000);
|
if (prevState == 2) { setTimeout(serverPoll, 5000); } else { QH('p0span', 'Unable to connect web socket'); }
|
||||||
} else if (state == 2) {
|
} else if (state == 2) {
|
||||||
// Fetch list of meshes, nodes, files
|
// Fetch list of meshes, nodes, files
|
||||||
meshserver.send({ action: 'meshes' });
|
meshserver.send({ action: 'meshes' });
|
||||||
meshserver.send({ action: 'nodes' });
|
meshserver.send({ action: 'nodes' });
|
||||||
meshserver.send({ action: 'files' });
|
meshserver.send({ action: 'files' });
|
||||||
|
go(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6493,7 +6494,7 @@
|
||||||
var xxdialogFunc;
|
var xxdialogFunc;
|
||||||
var xxdialogButtons;
|
var xxdialogButtons;
|
||||||
var xxdialogTag;
|
var xxdialogTag;
|
||||||
var xxcurrentView = 0;
|
var xxcurrentView = -1;
|
||||||
|
|
||||||
// Display a dialog box
|
// Display a dialog box
|
||||||
// Parameters: Dialog Mode (0 = none), Dialog Title, Buttons (1 = OK, 2 = Cancel, 3 = OK & Cancel), Call back function(0 = Cancel, 1 = OK), Dialog Content (Mode 2 only)
|
// Parameters: Dialog Mode (0 = none), Dialog Title, Buttons (1 = OK, 2 = Cancel, 3 = OK & Cancel), Call back function(0 = Cancel, 1 = OK), Dialog Content (Mode 2 only)
|
||||||
|
|
Loading…
Reference in New Issue