Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 3.04 KB

File metadata and controls

59 lines (42 loc) · 3.04 KB

pluginHandler.js

Manages the MeshCentral plugin lifecycle — loading, initializing, and exposing plugins to both the server-side Node.js environment and the browser-side Web UI.

Key Components

Export / Function Description
pluginHandler(parent) Factory function that returns the plugin handler object
obj.plugins Map of loaded plugin instances keyed by short name
obj.exports Map of each plugin's exported function names
obj.callHook(hookName, ...args) Invokes a named hook across all loaded plugins (server-side)
obj.prepExports() Serializes plugin exports into a self-executing JS string for browser injection
obj.refreshJS(req, res) HTTP handler that streams the rebuilt pluginHandler to the browser without a server restart
obj.addMeshCoreModules(modulesAdd) Injects plugin modules_meshcore JS files into the appropriate agent core bundles (Windows/Linux/AMT)
obj.deviceViewPanel() Collects device tab header + page HTML from every plugin that implements on_device_header / on_device_page
obj.isValidConfig(conf, url) Validates a plugin config.json against required fields before installation

Client-side helpers (serialized into the browser bundle via prepExports):

  • callHook — fan-out hook invocation in the browser
  • registerPluginTab — injects a tab into the device panel (#p19headers / #p19pages)
  • callPluginPage — tab switching logic
  • addPluginDlg / addPluginEx — UI dialog for installing plugins by URL
  • refreshPluginHandler — hot-reloads the plugin JS bundle without a page refresh

Usage Example

// Instantiated internally by MeshCentral during startup
const pluginHandler = require('./pluginHandler.js').pluginHandler(parent);

// Server-side: fire a hook on all loaded plugins
pluginHandler.callHook('onWebUIStartupEnd');

// Server-side: inject plugin modules into agent cores
pluginHandler.addMeshCoreModules(modulesAdd);

// HTTP route: serve live-updated plugin bundle to the browser
// GET /pluginHandler.js
app.get('/pluginHandler.js', (req, res) => pluginHandler.refreshJS(req, res));

Plugin Loading Strategy

Plugins are loaded from <datapath>/plugins/<shortName>/ at startup via one of two paths:

  • Database-driven — queries db.getPlugins() for enabled (status == 1) records, then calls updateMeshCore() once all async loads complete.
  • Config-driven — reads settings.plugins.list (an array of short names) for local development or manual installs; loaded synchronously.

Each plugin module must export a factory function named after its shortName that receives the handler object.

⚠️ The addPluginDlg UI warns users that installing plugins from untrusted URLs may compromise server security.

See Also