diff --git a/changelog.md b/changelog.md index 7d7a49a..2e4ff90 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Known Issues] - None. Please feel free to submit an issue via [GitHub](https://github.com/ryanblenis/MeshCentral-DevTools) if you find anything. +## [0.0.3] - 2025-03-16 +### Added +- Actions to disable and enable plugins (PR #1) + ## [0.0.2] - 2020-03-07 ### Fixed - Prevent race condition with conflicting plugins changing the app views directory by using absolute paths diff --git a/config.json b/config.json index 6d12c50..6b1127b 100644 --- a/config.json +++ b/config.json @@ -1,7 +1,7 @@ { "name": "Dev Tools", "shortName": "devtools", - "version": "0.0.2", + "version": "0.0.3", "author": "Ryan Blenis", "description": "Tools for plugin developers to make testing easier.", "hasAdminPanel": true, diff --git a/devtools.js b/devtools.js index c953367..3bb1b3a 100644 --- a/devtools.js +++ b/devtools.js @@ -11,12 +11,12 @@ module.exports.devtools = function (parent) { var obj = {}; obj.parent = parent; obj.meshServer = parent.parent; - obj.VIEWS = __dirname + '/views/'; + obj.VIEWS = __dirname + '/views/'; obj.handleAdminReq = function(req, res, user) { if ((user.siteadmin & 0xFFFFFFFF) == 0) { res.sendStatus(401); return; } var vars = {}; - res.render(obj.VIEWS + 'admin', vars); + res.render(obj.VIEWS + 'admin', vars); }; obj.serveraction = function(command, myparent, grandparent) { @@ -54,6 +54,41 @@ module.exports.devtools = function (parent) { }); }); break; + case 'disableAllPlugins': { + obj.meshServer.db.getPlugins(function(err, docs) { + if (err) { console.log('PLUGIN: devtools:', err); return; } + let pendingUpdates = 0; + for (const doc of docs) { + if (doc.shortName === 'devtools' || doc.status === 0) { continue; } + ++pendingUpdates; + console.log('PLUGIN: devtools: disabling plugin:', doc.shortName); + doc._devtools_previousStatus = doc.status; + doc.status = 0; + obj.meshServer.db.updatePlugin(doc._id, doc, function() { + if (--pendingUpdates == 0 ) { console.log('PLUGIN: devtools:', command.pluginaction, 'DONE'); } + }) + } + }); + break; + } + case 'enablePreviouslyDisabledPlugins': { + obj.meshServer.db.getPlugins(function(err, docs) { + if (err) { console.log('PLUGIN: devtools:', err); return; } + let pendingUpdates = 0; + for (const doc of docs) { + const previousStatus = (+doc._devtools_previousStatus) ?? 0; + if (isNaN(previousStatus) || previousStatus === 0) { continue; } + ++pendingUpdates; + console.log('PLUGIN: devtools: enabling plugin:', doc.shortName); + doc.status = previousStatus; + delete doc._devtools_previousStatus; + obj.meshServer.db.updatePlugin(doc._id, doc, function() { + if (--pendingUpdates == 0 ) { console.log('PLUGIN: devtools:', command.pluginaction, 'DONE'); } + }) + } + }); + break; + } case 'restartServer': process.exit(123); default: diff --git a/readme.md b/readme.md index 699e290..c1b091c 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MeshCentral-DevTools -*Released: 2020-03-07* +*Released: 2025-03-16* Tools to aid plugin developers for the [MeshCentral2](https://github.com/Ylianst/MeshCentral) Project. @@ -20,4 +20,6 @@ Restart your MeshCentral server after making this change. - Force Refresh the PluginHandler - Edit a plugin config directly - Remove a plugin config from the database +- Disable all plugins at once +- Enable a single plugin or all previously disabled plugins - Restart the server \ No newline at end of file diff --git a/views/admin.handlebars b/views/admin.handlebars index aa31f81..1c264f8 100644 --- a/views/admin.handlebars +++ b/views/admin.handlebars @@ -22,6 +22,25 @@ var deletePluginConfigEx = function() { parent.meshserver.send({ action: 'plugin', plugin: 'devtools', pluginaction: 'deletePluginConfig', id: parent.Q('dtDeletePluginConf').value }); }; + var disableAllPluginsEx = function() { + parent.meshserver.send({ action: 'plugin', plugin: 'devtools', pluginaction: 'disableAllPlugins' }); + } + var enablePluginEx = function() { + const id = parent.Q('dtEnablePlugin').value; + let conf; + parent.installedPluginList.some((doc) => (doc._id === id && ((conf = doc), true))); + if (conf._devtools_previousStatus) { + conf.status = conf._devtools_previousStatus; + delete conf._devtools_previousStatus; + } else { + conf.status = 1; + } + console.log(conf); + parent.meshserver.send({ action: 'plugin', plugin: 'devtools', pluginaction: 'savePluginConfig', id, conf }); + }; + var enablePreviouslyDisabledPluginsEx = function() { + parent.meshserver.send({ action: 'plugin', plugin: 'devtools', pluginaction: 'enablePreviouslyDisabledPlugins' }); + } var restartServerEx = function() { parent.meshserver.send({ action: 'plugin', plugin: 'devtools', pluginaction: 'restartServer' }); } @@ -57,8 +76,23 @@ sel += ''; parent.setDialogMode(2, "Delete which Plugin?", 3, deletePluginConfigEx, sel); } + function disableAllPlugins() { + parent.setDialogMode(2, "Disable all plugins?", 3, disableAllPluginsEx, 'Are you sure you want to disable all plugins except the Dev Tools?'); + } + function enablePreviouslyDisabledPlugins() { + parent.setDialogMode(2, "Enable previously disabled plugins?", 3, enablePreviouslyDisabledPluginsEx, 'Are you sure you want to enable all previously disabled plugins?'); + } + function enablePlugin() { + var sel = ''; + parent.setDialogMode(2, "Enable which Plugin?", 3, enablePluginEx, sel); + } function restartServer() { - parent.setDialogMode(2, "Restart Server?", 3, restartServerEx, 'Are you sure?'); + parent.setDialogMode(2, "Restart Server?", 3, restartServerEx, 'Are you sure you want to restart the server?'); } function initPtools() { parent.pluginHandler.devtools.loadEditPluginConfig = function(args, msg) { @@ -84,6 +118,9 @@ Delete a plugin config from the database

Refresh PluginHandler

Edit a plugin config

+ Disable all plugins except the Dev Tools

+ Enable a plugin

+ Enable previously disabled plugins

Restart Server