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

Ryan Blenis committed Nov 22, 2019 at 21:17 UTC d7b94639b2e7c6785d279f3346426e35b6e49cfd
3 files changed +23 -6
meshuser.js
+7 -1
@@ -3137,6 +3137,12 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3137 }
3138 break;
3139 }
3140 + case 'distributeCore': {
3141 + for (var i in command.nodes) {
3142 + parent.sendMeshAgentCore(user, domain, command.nodes[i]._id, 'default');
3143 + }
3144 + break;
3145 + }
3146 case 'plugins': {
3147 // Since plugin actions generally require a server restart, use the Full admin permission
3148 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
3178 }
3179 case 'installplugin': {
3180 if ((user.siteadmin & 0xFFFFFFFF) == 0 || parent.parent.pluginHandler == null) break; // must be full admin, plugins enabled
3175 - parent.parent.pluginHandler.installPlugin(command.id, command.version_only, function(){
3181 + parent.parent.pluginHandler.installPlugin(command.id, command.version_only, null, function(){
3182 parent.db.getPlugins(function(err, docs) {
3183 try { ws.send(JSON.stringify({ action: 'updatePluginList', list: docs, result: err })); } catch (ex) { }
3184 });
pluginHandler.js
+8 -4
@@ -317,7 +317,7 @@ module.exports.pluginHandler = function (parent) {
317 });
318 };
319
320 - obj.installPlugin = function(id, version_only, func) {
320 + obj.installPlugin = function(id, version_only, force_url, func) {
321 parent.db.getPlugin(id, function(err, docs){
322 // the "id" would probably suffice, but is probably an sanitary issue, generate a random instead
323 var randId = Math.random().toString(32).replace('0.', '');
@@ -327,6 +327,7 @@ module.exports.pluginHandler = function (parent) {
327 const file = obj.fs.createWriteStream(fileName);
328 var dl_url = plugin.downloadUrl;
329 if (version_only != null && version_only != false) dl_url = version_only.url;
330 + if (force_url != null) dl_url = force_url;
331 var url = require('url');
332 var q = url.parse(dl_url, true);
333 var http = (q.protocol == "http") ? require('http') : require('https');
@@ -342,7 +343,7 @@ module.exports.pluginHandler = function (parent) {
343 };
344 var request = http.get(opts, function(response) {
345 // handle redirections with grace
345 - if (response.headers.location) return obj.installPlugin(id, { name: version_only.name, url: response.headers.location }, func);
346 + if (response.headers.location) return obj.installPlugin(id, version_only, response.headers.location, func);
347 response.pipe(file);
348 file.on('finish', function() {
349 file.close(function(){
@@ -377,13 +378,16 @@ module.exports.pluginHandler = function (parent) {
378 zipfile.on("end", function () { setTimeout(function () {
379 obj.fs.unlinkSync(fileName);
380 if (version_only == null || version_only === false) {
380 - parent.db.setPluginStatus(id, 1, func);
381 + parent.db.setPluginStatus(id, 1, func);
382 } else {
382 - parent.db.updatePlugin(id, { status: 1, version: version_only.name }, func);
383 + parent.db.updatePlugin(id, { status: 1, version: version_only.name }, func);
384 }
385 obj.plugins[plugin.shortName] = require(obj.pluginPath + '/' + plugin.shortName + '/' + plugin.shortName + '.js')[plugin.shortName](obj);
386 obj.exports[plugin.shortName] = obj.plugins[plugin.shortName].exports;
387 if (typeof obj.plugins[plugin.shortName].server_startup == 'function') obj.plugins[plugin.shortName].server_startup();
388 + var plugin_config = obj.fs.readFileSync(obj.pluginPath + '/' + plugin.shortName + '/config.json');
389 + plugin_config = JSON.parse(plugin_config);
390 + parent.db.updatePlugin(plugin._id, plugin_config);
391 parent.updateMeshCore();
392 }); });
393 });
views/default.handlebars
+8 -1
@@ -423,7 +423,9 @@
423 <table id="p7tbl">
424 <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>
425 </table>
426 - <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>
426 + <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 />
427 + Click <a href="#" onclick="distributeCore(); return false;">here</a> to update all Mesh Agent cores.
428 + </div>
429 </div>
430 <div id=p10 style="display:none">
431 <table style="width:100%" cellpadding="0" cellspacing="0">
@@ -9564,6 +9566,11 @@
9566 meshserver.send({ action: 'pluginLatestCheck' });
9567 }
9568
9569 + function distributeCore() {
9570 + meshserver.send({ action: 'distributeCore', nodes: nodes }); // all nodes the user has access to
9571 + QV('pluginRestartNotice', false);
9572 + }
9573 +
9574 function pluginActionEx() {
9575 var act = Q('lastPluginAct').value, id = Q('lastPluginId').value, pVersUrl = Q('lastPluginVersion').value;
9576