Redirect download fixes, option to redistribute the meshcore to all nodes after plugin installation

This commit is contained in:
Ryan Blenis 2019-11-22 21:17:07 -05:00
parent a5007c995a
commit d7b94639b2
3 changed files with 23 additions and 6 deletions

View File

@ -3137,6 +3137,12 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
}
break;
}
case 'distributeCore': {
for (var i in command.nodes) {
parent.sendMeshAgentCore(user, domain, command.nodes[i]._id, 'default');
}
break;
}
case 'plugins': {
// Since plugin actions generally require a server restart, use the Full admin permission
if ((user.siteadmin & 0xFFFFFFFF) == 0 || parent.parent.pluginHandler == null) break; // must be full admin with plugins enabled
@ -3172,7 +3178,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
}
case 'installplugin': {
if ((user.siteadmin & 0xFFFFFFFF) == 0 || parent.parent.pluginHandler == null) break; // must be full admin, plugins enabled
parent.parent.pluginHandler.installPlugin(command.id, command.version_only, function(){
parent.parent.pluginHandler.installPlugin(command.id, command.version_only, null, function(){
parent.db.getPlugins(function(err, docs) {
try { ws.send(JSON.stringify({ action: 'updatePluginList', list: docs, result: err })); } catch (ex) { }
});

View File

@ -317,7 +317,7 @@ module.exports.pluginHandler = function (parent) {
});
};
obj.installPlugin = function(id, version_only, func) {
obj.installPlugin = function(id, version_only, force_url, func) {
parent.db.getPlugin(id, function(err, docs){
// the "id" would probably suffice, but is probably an sanitary issue, generate a random instead
var randId = Math.random().toString(32).replace('0.', '');
@ -327,6 +327,7 @@ module.exports.pluginHandler = function (parent) {
const file = obj.fs.createWriteStream(fileName);
var dl_url = plugin.downloadUrl;
if (version_only != null && version_only != false) dl_url = version_only.url;
if (force_url != null) dl_url = force_url;
var url = require('url');
var q = url.parse(dl_url, true);
var http = (q.protocol == "http") ? require('http') : require('https');
@ -342,7 +343,7 @@ module.exports.pluginHandler = function (parent) {
};
var request = http.get(opts, function(response) {
// handle redirections with grace
if (response.headers.location) return obj.installPlugin(id, { name: version_only.name, url: response.headers.location }, func);
if (response.headers.location) return obj.installPlugin(id, version_only, response.headers.location, func);
response.pipe(file);
file.on('finish', function() {
file.close(function(){
@ -377,13 +378,16 @@ module.exports.pluginHandler = function (parent) {
zipfile.on("end", function () { setTimeout(function () {
obj.fs.unlinkSync(fileName);
if (version_only == null || version_only === false) {
parent.db.setPluginStatus(id, 1, func);
parent.db.setPluginStatus(id, 1, func);
} else {
parent.db.updatePlugin(id, { status: 1, version: version_only.name }, func);
parent.db.updatePlugin(id, { status: 1, version: version_only.name }, func);
}
obj.plugins[plugin.shortName] = require(obj.pluginPath + '/' + plugin.shortName + '/' + plugin.shortName + '.js')[plugin.shortName](obj);
obj.exports[plugin.shortName] = obj.plugins[plugin.shortName].exports;
if (typeof obj.plugins[plugin.shortName].server_startup == 'function') obj.plugins[plugin.shortName].server_startup();
var plugin_config = obj.fs.readFileSync(obj.pluginPath + '/' + plugin.shortName + '/config.json');
plugin_config = JSON.parse(plugin_config);
parent.db.updatePlugin(plugin._id, plugin_config);
parent.updateMeshCore();
}); });
});

View File

@ -423,7 +423,9 @@
<table id="p7tbl">
<tr><th class="chName">Name</th><th class="chDescription">Description</th><th class="chSite">Link</th><th class="chVersion">Version</th><th class="chUpgradeAvail">Latest Available</th><th class="chStatus">Status</th><th class="chAction">Action</th></tr>
</table>
<div id="pluginRestartNotice" style="display:none;"><div>Notice:</div> MeshCentral plugins have been altered. Agent cores require may require an update before full features are available.</div>
<div id="pluginRestartNotice" style="display:none;"><div>Notice:</div> MeshCentral plugins have been altered. Agent cores require may require an update before full features are available.<br />
Click <a href="#" onclick="distributeCore(); return false;">here</a> to update all Mesh Agent cores.
</div>
</div>
<div id=p10 style="display:none">
<table style="width:100%" cellpadding="0" cellspacing="0">
@ -9564,6 +9566,11 @@
meshserver.send({ action: 'pluginLatestCheck' });
}
function distributeCore() {
meshserver.send({ action: 'distributeCore', nodes: nodes }); // all nodes the user has access to
QV('pluginRestartNotice', false);
}
function pluginActionEx() {
var act = Q('lastPluginAct').value, id = Q('lastPluginId').value, pVersUrl = Q('lastPluginVersion').value;