Repository navigation
fix: Dashboard 401 after upgrade, Graph Viewer fatal, MacTrack tab script - #396
Merged
Merged
Conversation
- Dashboard returned "401 Permission Denied" after upgrading: the page was added to the Mactrack Viewer realm without a version bump, so mactrack_check_upgrade() never re-registered the realm and the file stayed unmapped (realm 0). Realm definitions now live in mactrack_realm_definitions() and mactrack_realms_are_stale() makes the upgrade check re-register them on installed plugins. - Graphs tab fataled with "Call to undefined function graph_view_has_untemplated_graphs()": Cacti 1.2.x defines it in graph_view.php but html_graph_preview_filter() calls it. Add a guarded polyfill that is a no-op where core defines it. - The MacTrack tab script rewrote the href of whichever main tab was selected; scope it to the MacTrack tab so it can never repoint Console. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Automatic realm repair can grant unintended privileges and replay disruptive database migrations.
3 open findings
What changed in this PR
Addresses post-upgrade access and rendering failures in the MacTrack plugin.
Changes:
- Centralizes realm definitions and detects stale registrations without a version bump.
- Adds a guarded Graph Viewer compatibility helper.
- Restricts tab-link rewriting to MacTrack and adds regression tests.
| File | Description |
|---|---|
| tests/Unit/MactrackRealmAndGraphViewerTest.php | Tests realm registration, graph compatibility, and tab targeting. |
| setup.php | Adds shared realm definitions and stale-registration repair. |
| lib/mactrack_functions.php | Adds the graph helper and scopes tab-link updates. |
| CHANGELOG.md | Documents the three fixes. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
xmacan
previously approved these changes
Oct 16, 2026
Same-version realm repair now only registers the realms with auto-grant disabled, so it no longer re-runs mactrack_database_upgrade() or hands a missing realm to the requesting user. Move the get_allowed_graphs() test stub into the shared bootstrap and reset its state in TestCase::setUp(). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cacti's api_plugin_valid_entrypoint() only honors the call when the calling function's name contains install, upgrade or setup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
xmacan
approved these changes
Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fixes the three problems seen after upgrading to the current
develop.1. Dashboard:
401 Permission DeniedThe Dashboard commit added
mactrack_view_dashboard.phpto the Mactrack Viewer realm inplugin_mactrack_install(), butINFOstayed at 4.9.mactrack_check_upgrade()only re-registers realms when the stored version differs, so upgraded installs never mapped the page to a realm. Cacti then resolves it to realm 0 (include/auth.php) and denies it.mactrack_realm_definitions()and the installer loops over them.mactrack_realms_are_stale()compares the files inplugin_realmswith the code.mactrack_check_upgrade()re-registers the realms when the plugin is installed (status 1 or 4) and they are stale, even without a version change. It still only runs onindex.php,plugins.phpandmactrack_devices.php.api_plugin_register_realm()updates the existing Viewer row in place, so users who already have Mactrack Viewer get the Dashboard automatically.After deploying: open the Console once (or the Plugins page) so the check runs, then reload the Dashboard. If the session still holds the old realm map, log out and back in.
2. Graphs tab:
500 Mactrack Graph ViewerLog:
Call to undefined function graph_view_has_untemplated_graphs() in lib/html_graph.php:217. In Cacti 1.2.xhtml_graph_preview_filter()calls this helper, but it is defined ingraph_view.php, which plugin pages never load.lib/mactrack_functions.phpnow defines a guarded polyfill (if (!function_exists(...))) that mirrors core's implementation, so it does nothing where core already defines it and does not affect older Cacti.3. Console not activating until a full refresh
I could not reproduce this without a live Cacti, so the explanation below comes from reading core
layout.jsand is not confirmed in a browser.top_header()/top_graph_header()include. Console admin pages usetop_header(), and the tab pages usegeneral_header()like other plugin tab pages.loadTopTab(), a failed AJAX load (the Dashboard 401 or the Graph Viewer 500) switches the selected tab but never updatespageName. InsetupResponsiveMenuAndTabs(), a Console click whilepageName == 'index.php'and#navigationexists only callshandleUserMenu(true), which toggles the menu instead of loading the console, until a full refresh. Fixing 1 and 2 removes those failures.mactrack_tabs()rewrote the href of whichever.maintabs a.selectedexisted. It now targets only the MacTrack tab (a[href*="plugins/mactrack/mactrack_view_"]), so it can never repoint Console at a MacTrack page.If Console still misbehaves after this, the remaining cause is probably in Cacti core (
loadTopTabnot resettingpageNameon failure), so please tell me which page you were on and what the browser console shows.Tests
tests/Unit/MactrackRealmAndGraphViewerTest.phpcovers the realm definitions, the installer registering every realm, the stale/current/empty detection, the polyfill (with and without a restriction) and the scoped tab script. PHPUnit 10.5 passes for the 86 class-based tests in a scratch Cacti layout; the Pest-style tests were not run locally, so CI will run them. No version bump is included, since that is a release decision.