Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
39 changes: 37 additions & 2 deletions devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
39 changes: 38 additions & 1 deletion views/admin.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
}
Expand Down Expand Up @@ -57,8 +76,23 @@
sel += '</select>';
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 = '<select id="dtEnablePlugin">'
parent.installedPluginList.forEach((plugin) => {
if (plugin.status) { return; }
sel += `<option${plugin._devtools_previousStatus ? ' style="font-weight: bold;"' : ''} value="${plugin._id}">${plugin.name}</option>`;
});
sel += '</select>';
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) {
Expand All @@ -84,6 +118,9 @@
<a href="#" onclick="deletePluginConfig(); return false;">Delete a plugin config from the database</a><br /><br />
<a href="#" onclick="refreshHandler(); return false;">Refresh PluginHandler</a><br /><br />
<a href="#" onclick="editPluginConfig(); return false;">Edit a plugin config</a><br /><br />
<a href="#" onclick="disableAllPlugins(); return false;">Disable all plugins</a> except the Dev Tools<br /><br />
<a href="#" onclick="enablePlugin(); return false;">Enable a plugin</a><br /><br />
<a href="#" onclick="enablePreviouslyDisabledPlugins(); return false;">Enable previously disabled plugins</a><br /><br />
<a href="#" onclick="restartServer(); return false;">Restart Server</a><br /><br />
</div>
</body>
Expand Down