Added stable/latest self-upgrade.

This commit is contained in:
Ylian Saint-Hilaire 2020-04-17 23:17:45 -07:00
parent eef250e124
commit 9ed9257707
5 changed files with 1662 additions and 1607 deletions

View File

@ -416,6 +416,7 @@ function CreateMeshCentralServer(config, args) {
else if (data.indexOf('Server Ctrl-C exit...') >= 0) { childProcess.xrestart = 2; } else if (data.indexOf('Server Ctrl-C exit...') >= 0) { childProcess.xrestart = 2; }
else if (data.indexOf('Starting self upgrade...') >= 0) { childProcess.xrestart = 3; } else if (data.indexOf('Starting self upgrade...') >= 0) { childProcess.xrestart = 3; }
else if (data.indexOf('Server restart...') >= 0) { childProcess.xrestart = 1; } else if (data.indexOf('Server restart...') >= 0) { childProcess.xrestart = 1; }
else if (data.indexOf('Starting self upgrade to: ') >= 0) { obj.args.selfupdate = data.substring(26).split('\r')[0].split('\n')[0]; childProcess.xrestart = 3; }
var datastr = data; var datastr = data;
while (datastr.endsWith('\r') || datastr.endsWith('\n')) { datastr = datastr.substring(0, datastr.length - 1); } while (datastr.endsWith('\r') || datastr.endsWith('\n')) { datastr = datastr.substring(0, datastr.length - 1); }
console.log(datastr); console.log(datastr);
@ -457,10 +458,39 @@ function CreateMeshCentralServer(config, args) {
} catch (ex) { callback(getCurrentVerion(), null, ex); } // If the system is running out of memory, an exception here can easily happen. } catch (ex) { callback(getCurrentVerion(), null, ex); } // If the system is running out of memory, an exception here can easily happen.
}; };
// Get current version and all MeshCentral server tags using NPM
obj.getServerTags = function (callback) {
if (callback == null) return;
try {
if (typeof obj.args.selfupdate == 'string') { callback(getCurrentVerion(), obj.args.selfupdate); return; } // If we are targetting a specific version, return that one as current.
var child_process = require('child_process');
var npmpath = ((typeof obj.args.npmpath == 'string') ? obj.args.npmpath : 'npm');
var npmproxy = ((typeof obj.args.npmproxy == 'string') ? (' --proxy ' + obj.args.npmproxy) : '');
var env = Object.assign({}, process.env); // Shallow clone
if (typeof obj.args.npmproxy == 'string') { env['HTTP_PROXY'] = env['HTTPS_PROXY'] = env['http_proxy'] = env['https_proxy'] = obj.args.npmproxy; }
var xxprocess = child_process.exec(npmpath + npmproxy + ' dist-tag ls meshcentral', { maxBuffer: 512000, cwd: obj.parentpath, env: env }, function (error, stdout, stderr) { });
xxprocess.data = '';
xxprocess.stdout.on('data', function (data) { xxprocess.data += data; });
xxprocess.stderr.on('data', function (data) { });
xxprocess.on('close', function (code) {
var tags = { current: getCurrentVerion() };
if (code == 0) {
try {
var lines = xxprocess.data.split('\r\n').join('\n').split('\n');
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]; } }
} catch (e) { }
}
callback(tags);
});
} catch (ex) { callback({ current: getCurrentVerion() }, ex); } // If the system is running out of memory, an exception here can easily happen.
};
// Initiate server self-update // Initiate server self-update
obj.performServerUpdate = function () { obj.performServerUpdate = function (version) {
if (obj.serverSelfWriteAllowed == true) { console.log('Starting self upgrade...'); process.exit(200); return true; } if (obj.serverSelfWriteAllowed != true) return false;
return false; if ((version == null) || (version == '') || (typeof version != 'string')) { console.log('Starting self upgrade...'); } else { console.log('Starting self upgrade to: ' + version); }
process.exit(200);
return true;
}; };
// Initiate server self-update // Initiate server self-update

View File

@ -876,10 +876,10 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
break; break;
} }
case 'updatecheck': { case 'updatecheck': {
parent.parent.getLatestServerVersion(function (currentVer, newVer, error) { parent.parent.getServerTags(function (tags, error) {
var r2 = 'Current Version: ' + currentVer + '\r\n'; var r2 = '';
if (newVer != null) { r2 += 'Available Version: ' + newVer + '\r\n'; }
if (error != null) { r2 += 'Exception: ' + error + '\r\n'; } if (error != null) { r2 += 'Exception: ' + error + '\r\n'; }
else { for (var i in tags) { r2 += i + ': ' + tags[i] + '\r\n'; } }
try { ws.send(JSON.stringify({ action: 'serverconsole', value: r2, tag: command.tag })); } catch (ex) { } try { ws.send(JSON.stringify({ action: 'serverconsole', value: r2, tag: command.tag })); } catch (ex) { }
}); });
r = "Checking server update..."; r = "Checking server update...";
@ -2198,14 +2198,16 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
{ {
// Check the server version // Check the server version
if ((user.siteadmin & 16) == 0) break; if ((user.siteadmin & 16) == 0) break;
parent.parent.getLatestServerVersion(function (currentVersion, latestVersion) { try { ws.send(JSON.stringify({ action: 'serverversion', current: currentVersion, latest: latestVersion })); } catch (ex) { } }); //parent.parent.getLatestServerVersion(function (currentVersion, latestVersion) { try { ws.send(JSON.stringify({ action: 'serverversion', current: currentVersion, latest: latestVersion })); } catch (ex) { } });
parent.parent.getServerTags(function (tags, err) { try { ws.send(JSON.stringify({ action: 'serverversion', tags: tags })); } catch (ex) { } });
break; break;
} }
case 'serverupdate': case 'serverupdate':
{ {
// Perform server update // Perform server update
if ((user.siteadmin & 16) == 0) break; if ((user.siteadmin & 16) == 0) break;
parent.parent.performServerUpdate(); if ((command.version != null) && (typeof command.version != 'string')) break;
parent.parent.performServerUpdate(command.version);
break; break;
} }
case 'servererrors': case 'servererrors':

View File

@ -1,6 +1,6 @@
{ {
"name": "meshcentral", "name": "meshcentral",
"version": "0.5.4", "version": "0.5.5",
"keywords": [ "keywords": [
"Remote Management", "Remote Management",
"Intel AMT", "Intel AMT",

File diff suppressed because it is too large Load Diff

View File

@ -1985,15 +1985,19 @@
case 'serverversion': { case 'serverversion': {
if ((xxdialogMode == 2) && (xxdialogTag == 'MeshCentralServerUpdate')) { if ((xxdialogMode == 2) && (xxdialogTag == 'MeshCentralServerUpdate')) {
var x = '<div class=dialogText>'; var x = '<div class=dialogText>';
if (!message.current) { message.current = "Unknown"; } if (!message.tags.current) { message.tags.current = "Unknown"; }
if (!message.latest) { message.latest = "Unknown"; } if (!message.tags.stable) { message.tags.stable = "Unknown"; }
x += addHtmlValue2("Current Version", '<b>' + EscapeHtml(message.current) + '</b>'); if (!message.tags.latest) { message.tags.latest = "Unknown"; }
x += addHtmlValue2("Latest Version", '<b>' + EscapeHtml(message.latest) + '</b>'); x += addHtmlValue2("Current Version", '<b>' + EscapeHtml(message.tags.current) + '</b>');
x += '<hr />';
x += addHtmlValue2('<label><input id=d2updateCheck1 type=checkbox onclick=server_showVersionDlgUpdate()' + (((message.tags.stable == "Unknown") || (message.tags.current == message.tags.stable))?' disabled':'') + ' /> ' + "Stable Version" + '</label>', '<b>' + EscapeHtml(message.tags.stable) + '</b>');
x += addHtmlValue2('<label><input id=d2updateCheck2 type=checkbox onclick=server_showVersionDlgUpdate()' + (((message.tags.latest == "Unknown") || (message.tags.current == message.tags.latest))?' disabled':'') + ' /> ' + "Latest Version" + '</label>', '<b>' + EscapeHtml(message.tags.latest) + '</b>');
x += '</div>'; x += '</div>';
if ((message.latest.indexOf('.') == -1) || (message.current == message.latest) || ((features & 2048) == 0)) { if (((message.tags.current == message.tags.latest) && (message.tags.current == message.tags.stable)) || ((features & 2048) == 0)) {
setDialogMode(2, "MeshCentral Version", 1, null, x); setDialogMode(2, "MeshCentral Version", 1, null, x);
} else { } else {
setDialogMode(2, "MeshCentral Version", 3, server_showVersionDlgEx, x + '<br /><label><input id=d2updateCheck type=checkbox onclick=server_showVersionDlgUpdate() /> ' + "Check and click OK to start server self-update." + '</label>'); x += '<hr />' + "Check and click OK to start server self-update.";
setDialogMode(2, "MeshCentral Version", 3, server_showVersionDlgEx, x, message.tags);
server_showVersionDlgUpdate(); server_showVersionDlgUpdate();
} }
} }
@ -2004,9 +2008,11 @@
if (message.data == null) { if (message.data == null) {
setDialogMode(2, "MeshCentral Server Errors", 1, null, "Server has no error log."); setDialogMode(2, "MeshCentral Server Errors", 1, null, "Server has no error log.");
} else { } else {
var x = '<div class="dialogText dialogTextLog"><pre id=d2ServerErrorsLogPre>' + message.data + '<pre></div>'; var x = '<div class="dialogText dialogTextLog"><pre id=d2ServerErrorsLogPre>' + EscapeHtml(message.data) + '</pre></div>';
setDialogMode(2, "MeshCentral Server Errors", 3, server_showErrorsDlgEx, x + '<br /><div style=float:right><img src=images/link4.png height=10 width=10 title="' + "Download error log" + '" style=cursor:pointer onclick=d2CopyServerErrorsToClip()></div><div><label><input id=d2updateCheck type=checkbox onclick=server_showVersionDlgUpdate() /> ' + "Check and click OK to clear error log." + '</label></div>'); x += '<br /><div style=float:right><img src=images/link4.png height=10 width=10 title="' + "Download error log" + '" style=cursor:pointer onclick=d2CopyServerErrorsToClip()></div>';
server_showVersionDlgUpdate(); x += '<div><label><input id=d2clearErrorsCheck type=checkbox onclick=server_showErrorsDlgUpdate() /> ' + "Check and click OK to clear error log." + '</label></div>';
setDialogMode(2, "MeshCentral Server Errors", 3, server_showErrorsDlgEx, x);
server_showErrorsDlgUpdate();
} }
} }
break; break;
@ -8239,8 +8245,16 @@
return false; return false;
} }
function server_showVersionDlgUpdate() { QE('idx_dlgOkButton', Q('d2updateCheck').checked); } function server_showVersionDlgUpdate() {
function server_showVersionDlgEx() { meshserver.send({ action: 'serverupdate' }); } var stableCheck = Q('d2updateCheck1').checked;
var latestCheck = Q('d2updateCheck2').checked;
QE('idx_dlgOkButton', ((stableCheck) && (!latestCheck)) || ((!stableCheck) && (latestCheck)));
}
function server_showVersionDlgEx(b, tags) {
if (Q('d2updateCheck1').checked) { meshserver.send({ action: 'serverupdate', tag: 'stable', version: tags.stable }); }
if (Q('d2updateCheck2').checked) { meshserver.send({ action: 'serverupdate', tag: 'latest', version: tags.latest }); }
}
function server_showErrorsDlg() { function server_showErrorsDlg() {
if (xxdialogMode) return false; if (xxdialogMode) return false;
@ -8248,7 +8262,7 @@
meshserver.send({ action: 'servererrors' }); meshserver.send({ action: 'servererrors' });
return false; return false;
} }
function server_showErrorsDlgUpdate() { QE('idx_dlgOkButton', Q('d2updateCheck').checked); } function server_showErrorsDlgUpdate() { QE('idx_dlgOkButton', Q('d2clearErrorsCheck').checked); }
function server_showErrorsDlgEx() { meshserver.send({ action: 'serverclearerrorlog' }); } function server_showErrorsDlgEx() { meshserver.send({ action: 'serverclearerrorlog' }); }
function d2CopyServerErrorsToClip() { saveAs(new Blob([Q('d2ServerErrorsLogPre').innerText], { type: 'application/octet-stream' }), "servererrors.txt"); } function d2CopyServerErrorsToClip() { saveAs(new Blob([Q('d2ServerErrorsLogPre').innerText], { type: 'application/octet-stream' }), "servererrors.txt"); }
@ -9623,7 +9637,7 @@
// Display the users using the sorted list // Display the users using the sorted list
var x = '<table class=p3usersTable cellpadding=0 cellspacing=0>', addHeader = true; var x = '<table class=p3usersTable cellpadding=0 cellspacing=0>', addHeader = true;
x += '<th>' + "Name" + '<th style=width:80px>' + "Groups" + '<th style=width:120px>' + nobreak("Last Access") + '<th style=width:120px>' + "Permissions"; x += '<th>' + "Name" + '<th style=width:80px>' + "Device Groups" + '<th style=width:120px>' + nobreak("Last Access") + '<th style=width:120px>' + "Permissions";
// Save the list of currently checked users // Save the list of currently checked users
var checkedUserids = [], elements = document.getElementsByClassName('UserCheckbox'); var checkedUserids = [], elements = document.getElementsByClassName('UserCheckbox');