Skip to content

fix: Dashboard 401 after upgrade, Graph Viewer fatal, MacTrack tab script - #396

Merged
TheWitness merged 3 commits into
developfrom
fix/dashboard-realm-graph-viewer
Oct 16, 2026
Merged

TheWitness merged 3 commits into
developfrom
fix/dashboard-realm-graph-viewer

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Fixes the three problems seen after upgrading to the current develop.

1. Dashboard: 401 Permission Denied

The Dashboard commit added mactrack_view_dashboard.php to the Mactrack Viewer realm in plugin_mactrack_install(), but INFO stayed 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.

  • Realm definitions now live in mactrack_realm_definitions() and the installer loops over them.
  • mactrack_realms_are_stale() compares the files in plugin_realms with 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 on index.php, plugins.php and mactrack_devices.php.
  • Cacti's 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 Viewer

Log: Call to undefined function graph_view_has_untemplated_graphs() in lib/html_graph.php:217. In Cacti 1.2.x html_graph_preview_filter() calls this helper, but it is defined in graph_view.php, which plugin pages never load. lib/mactrack_functions.php now 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.js and is not confirmed in a browser.

  • No legacy header found. The plugin has no stray legacy top_header()/top_graph_header() include. Console admin pages use top_header(), and the tab pages use general_header() like other plugin tab pages.
  • Likely trigger. In loadTopTab(), a failed AJAX load (the Dashboard 401 or the Graph Viewer 500) switches the selected tab but never updates pageName. In setupResponsiveMenuAndTabs(), a Console click while pageName == 'index.php' and #navigation exists only calls handleUserMenu(true), which toggles the menu instead of loading the console, until a full refresh. Fixing 1 and 2 removes those failures.
  • Hardening. The tab script in mactrack_tabs() rewrote the href of whichever .maintabs a.selected existed. 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 (loadTopTab not resetting pageName on failure), so please tell me which page you were on and what the browser console shows.

Tests

tests/Unit/MactrackRealmAndGraphViewerTest.php covers 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.

- 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>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 15:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment thread setup.php Outdated
Comment thread setup.php Outdated
Comment thread tests/Unit/MactrackRealmAndGraphViewerTest.php Outdated
xmacan
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>
@TheWitness
TheWitness merged commit 0a83eda into develop Oct 16, 2026
5 checks passed
@TheWitness
TheWitness deleted the fix/dashboard-realm-graph-viewer branch October 20, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants