Repository navigation
Add third-party panel registration API - #468
Conversation
Allow other Cacti plugins to publish their own Intropage dashboard panels at runtime, without copying a file into Intropage's panellib/ directory. Plugins call intropage_register_panel() (guarded by function_exists) plus the companion update/enable/disable/unregister calls. Registrations are stored in the new plugin_intropage_panel_registration table (owning plugin, callback functions, declared request variables and their types, and the full panel attribute set), merged into the live panel library by initialize_panel_library(), and seeded into the definition/data tables so they poll and render like native panels. intropage_prune_stale_registrations() runs on every poller cycle and every dashboard view to remove registrations whose owning plugin is no longer installed, stripping the panel from all dashboards, data, definitions and permissions. The panel schema and every API call are documented in README.md; a focused unit test covers the validation and mapping helpers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical flaws allow registration to bypass panel permissions and overwrite or delete built-in panels.
10 open issues
Reject built-in IDs and registration ownership conflicts · New Check panel permissions against the configured administrator · New Align the live panel schema with accepted callback lengths · New Expose the registration API before foreign plugin hooks run · New Reject numeric panel IDs that collide with row IDs · New Register fallback metadata for custom panel categories · New Enforce plugin dependencies when dispatching panel callbacks · New Use the declared default for invalid boolean values · New Reject non-scalar input for string variables · New Invalidate the panel library cache after registration changes · New
What changed in this PR
Adds an API for other Cacti plugins to register Intropage dashboard panels without copying files into panellib/.
Changes:
- Introduces persistent panel registration, lifecycle APIs, callback loading and request-variable validation.
- Integrates registered panels into the library and adds stale-registration cleanup during polling and dashboard views.
- Adds API documentation and unit tests, with a registration-table migration and version bump to 4.1.0.
| File | Description |
|---|---|
tests/Unit/IntropagePanelRegistrationTest.php |
Tests registration validation, defaults, path guards and definition mapping. |
README.md |
Documents the API, schema, lifecycle and integration example. |
poller_intropage.php |
Prunes stale registrations before polling. |
panellib/README.md |
Points third-party plugins to the registration API. |
INFO |
Bumps the plugin version to 4.1.0. |
includes/registration.php |
Implements registration, publication, cleanup and validation helpers. |
includes/functions.php |
Loads the API and merges registered panels into the library. |
includes/database.php |
Adds registration-table installation, migration and removal. |
display.php |
Prunes stale registrations before dashboard rendering. |
CHANGELOG.md |
Records the third-party panel registration feature. |
Review effort: Balanced
The uninstall contract test counted DROP TABLE statements and expected 7; the new plugin_intropage_panel_registration table makes it 8, so update the expectation. Also fix a pre-existing typo in initialize_panel_library()'s auto-unregister cleanup, which deleted from the non-existent plugin_intropage_definition table instead of plugin_intropage_panel_definition, leaving a stale definition row and raising a SQL error whenever a panel's required plugin was uninstalled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The patch-coverage gate requires every changed production line to be exercised. Cover the database-backed registration functions (register/update/enable/ disable/unregister, prune, load, request-variable validation, admin grant and permission cleanup) with in-process unit tests driven by the bootstrap stubs. To make the two hard-to-reach blocks of initialize_panel_library() testable in isolation, extract them into intropage_unregister_missing_panels() (which now also owns the intropage_unregister guard, so the call site is unconditional and always exercised) and intropage_merge_registered_panels(). Make the unit bootstrap's db_table_exists() stub configurable via $GLOBALS['__test_tables'] (defaulting to false, so existing tests are unaffected) so the registration-table-guarded paths can run. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Act on the code-review findings on the registration API: - Reject numeric, over-length, built-in, and cross-plugin panel ids before persisting; only the owning plugin may re-register or withdraw its panels (intropage_registration_conflict()). - Resolve the permission-grant target from the configured admin user instead of the current session visitor, so registering on an ordinary user's page load cannot grant that user panels. - Expose the API from setup.php (loaded for every enabled plugin at start-up) so a foreign plugin's config_arrays hook sees it regardless of plugin order. - Enforce the requires gate in intropage_reload_panel()/intropage_detail_panel() so a panel stops executing callbacks once its plugin is disabled. - Register a fallback $registry category for loaded registrations so the permission editors render their category heading. - Use FILTER_NULL_ON_FAILURE for boolean request vars and reject non-scalar request-variable input instead of coercing it to 'Array'. - Invalidate initialize_panel_library()'s static cache (not just the session snapshot) on every registration mutation. - Validate registration string lengths against the live panel_definition column widths so a published registration never overflows or truncates. Extend the unit tests to cover every new path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…stration-api # Conflicts: # CHANGELOG.md
Advice re: rendering third-party cards (card + chart scope)Following up on the intent here — Intropage presenting any card from any plugin — with a concrete analysis of what a registered panel can actually render. What the registration delivers today: a panel supplies PHP only ( The charting pieces the dashboard plugins use (gauges, bullets, usage/stacked bars) are currently pinned per-plugin — So: a third-party card using those primitives renders correctly in Intropage only incidentally — if the owning plugin happens to load its content CSS on every page. A plugin that scopes its CSS to its own pages would have its Intropage card render unstyled. Fix (done in core): Cacti/cacti#8680 now ships a shared, themeable Remaining gap for this PR to consider (so the promise fully holds beyond the shared primitives):
Suggestion: keep #468's PHP-callback model, lean on the shared |
…stration-api # Conflicts: # CHANGELOG.md
…urce prefixes
Make the registration table the single catalog of every panel (core and
third-party) and read from it instead of rebuilding the library from disk on
every request:
- Poller sync: intropage_sync_core_registrations() stats each panellib/*.php
file's mtime and, when a file changes (or is added/removed), re-runs its
register_<basename>() and upserts its panels as Intropage-owned ('intropage')
core registrations. Runs each poller cycle (cheap when nothing changed) and
at install/upgrade. A panel's enabled flag is preserved across syncs.
- Enable/Disable: the registration enabled flag now governs the whole library.
initialize_panel_library() drops disabled panels (core or third-party) so the
poller, panel picker and is_panel_enabled() skip them and the dashboard render
loop hides them, all non-destructively (data and placements are retained).
- Management page: Console > Intropage > Panel Library (intropage_panels.php,
guarded by the new Intropage Panel Library realm) lists every registered panel
in a filterable, sortable table with a free-text search, a Source (plugin)
dropdown and Enable/Disable bulk actions. Columns: Panel Name, Source,
Category, Level, Requires, Refresh, Update Function, Status.
- Source prefixes: panel titles are prefixed by origin wherever the definition
name is rendered (cards, detail dialog): 'Core - ' for Intropage's own panels
and the title-cased plugin name for third-party panels.
- The built-in-id conflict guard now lets the reserved 'intropage' owner adopt
its own built-ins while still blocking foreign plugins from shadowing them.
Covers the new logic with unit tests (source prefixing, disabled filtering,
enable/disable, the mtime sync and withdraw paths, the menu/navigation wiring)
and allowlists the new web entry point for patch coverage.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…into feature/panel-registration-api # Conflicts: # CHANGELOG.md
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
SonarCloud flagged the search, source and rows filter controls as inputs without an associated label (Web:InputWithoutLabelCheck). Wrap each filter caption in a <label for=...> tied to its control. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Bump the INFO `compat` floor from 1.2.17 to 1.2.29 and update the matching references in the README requirements, the PHP compatibility test note, the database upgrade comment and the repository instructions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|





Summary
Adds a third-party panel registration API so other Cacti plugins can publish their own Intropage dashboard panels at runtime — without copying a file into Intropage's
panellib/directory.A foreign plugin guards each call with
function_exists()and callsintropage_register_panel()(typically from itsconfig_arrays/install hook). Registered panels behave exactly like the built-inpanellibpanels: Intropage polls them, users can be granted them and add them to dashboards, and they are automatically removed everywhere when the owning plugin is uninstalled.What's included
plugin_intropage_panel_registrationstoring the owning plugin name, the callback functions (update_func/details_func/trends_func+include_file), the declared request variables and their types (request_varsJSON), and the full panel attribute set. Created on install and via a4.1.0upgrade step; dropped on uninstall.includes/registration.php— the public API:intropage_register_panel($panel)— register / fully replace (validates, persists, and immediately publishes an enabled panel into the definition/data tables)intropage_update_panel_registration($panel_id, $fields)— patch selected attributesintropage_enable_panel_registration($panel_id)/intropage_disable_panel_registration($panel_id)intropage_unregister_panel($panel_id)(delete) andintropage_unregister_plugin_panels($plugin)intropage_get_panel_registration(s)(),intropage_validate_request_vars(),intropage_prune_stale_registrations()initialize_panel_library()merges enabled registrations (whose plugin is installed), including their callback file, without clobbering built-in panels.intropage_prune_stale_registrations()runs on every poller cycle and every dashboard view; when a plugin is uninstalled its panels are stripped from all dashboards, data, definitions and permissions. A merely disabled plugin keeps its registration (its panels simply stop rendering via therequiresgate).include_filepaths are constrained to existing.phpfiles beneathplugins/(no traversal / arbitrary include); all writes use prepared statements.README.mdgains a "Registering panels from another plugin" section documenting the full schema (every attribute, type, default and options), therequest_varssub-schema and types, every API call, the lifecycle/pruning behavior, and a complete worked example.panellib/README.mdcross-references it.tests/Unit/IntropagePanelRegistrationTest.phpcovers validation, the request-var spec, defaults, the include-file guard and the row→library mapping.Version
Bumps
INFOto4.1.0with a matchingCHANGELOG.mdentry and an idempotent upgrade migration.Validation
php -lclean on every changed PHP file.Review notes
plugingoverns installed/uninstalled pruning;requires(defaulting to the owning plugin) governs enabled/disabled runtime gating — mirroring how built-in panels already work.panel_idis idempotent, so plugins can safely register on every page load to keep definitions in sync.