Skip to content

mactrack: restore device-level rescan, fix endless interface rescan spinner, reorder tabs - #406

Merged
TheWitness merged 4 commits into
developfrom
fix/mactrack-rescan-tabs
Nov 5, 2026
Merged

TheWitness merged 4 commits into
developfrom
fix/mactrack-rescan-tabs

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Description

Three MacTrack fixes around the device/site Rescan action, plus a tab reorder:

  • Restore the device-level Rescan glyph. The Device report view
    (mactrack_view_devices.php) builds its rows inline and the rescan glyph had
    been decontented from that path (the shared mactrack_format_device_row()
    still had it). The row actions now render the rescan glyph for enabled devices
    (class='mactrackRescanDevice', id='r_<device_id>', data-device-id), and
    the view gains the shared #response results dialog. It reuses the existing
    delegated, CSP-safe click handler.

  • Fix the endless interface/device rescan spinner. The three scan JS
    functions now run through one mactrackRunScan() helper that POSTs with the
    CSRF token, bounds the request with a timeout, and always clears the
    spinner on done/fail/timeout, so a stalled subprocess can no longer leave the
    icon spinning forever. The backend mactrack_rescan()/mactrack_site_scan()
    now always emit UTF-8-safe JSON (JSON_INVALID_UTF8_SUBSTITUTE), which also
    prevents an empty response when a device reports non-UTF-8 SNMP output.

  • Report completion with a toast. Each scan returns a short
    "<device|site> ... completed in N.NN seconds" message that the AJAX caller
    surfaces as an auto-fading Cacti toast via the 1.2.x session-message mechanism
    (sessionMessage + displayMessages(), what raise_message_javascript()
    emits), while the detailed scan output stays in the results dialog.

  • Reorder the tabs to Dashboard, Sites, Devices, Interfaces, IP Ranges,
    IP Addresses, MAC Addresses, Dot1x, Graphs, and pluralize the IP/MAC Address
    tab labels to match the rest of the UI.

Permissions are unchanged and validated on both layers: the glyph is gated by
api_user_realm_auth('mactrack_sites.php') (Mactrack Administrator realm) and
hidden for disabled devices, and mactrack_ajax_admin.php is registered to the
same realm so include/auth.php enforces it server-side. All four admin actions
remain POST-only via mactrack_require_post().

Related Issue

N/A — reported directly: the device-level Rescan action was missing from the
Device report view and the interface-level rescan spun indefinitely without
reporting a result.

Motivation and Context

Prior releases exposed a Rescan action at the device and site level that forces
an immediate rescan (ports and interface updates) and reported the scan result
and timing. The device-level action had gone missing from the Device report
view, and the interface-level rescan spun forever and never surfaced a result.
This restores the action, makes the request self-limiting, and brings back the
completion/timing feedback using Cacti's native toast.

How Has This Been Tested?

  • Pest suite (Cacti develop checkout, plugin at plugins/mactrack):
    include/vendor/bin/pest --configuration=plugins/mactrack/phpunit.xml →
    262 passed (2045 assertions).
  • php tests/bin/validate-manifest.php → OK.
  • php tests/bin/check-i18n-pot.php origin/develop → OK (regenerated
    locales/po/cacti.pot only; .po/.mo left to Weblate).
  • php -l on changed PHP and node --check js/mactrack.js → clean.
  • AdminActionsRequirePostTest updated to assert the new helper structure
    (POST + CSRF token + timeout + always-clears-spinner + failure reporting).

Screenshots (if appropriate):

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation repository accordingly.

…pinner, reorder tabs

Restore the Rescan action to the Device report view (mactrack_view_devices.php),
which had been decontented: the row actions now render the rescan glyph
(class mactrackRescanDevice, id r_<device_id>, data-device-id) for enabled
devices and the view gains the shared #response results dialog. The glyph
reuses the existing delegated, CSP-safe click handler.

Stop the interface/device rescan icon from spinning forever: the three scan
JS functions now run through a shared mactrackRunScan() helper that POSTs with
the CSRF token, bounds the request with a timeout, and always clears the
spinner on done/fail/timeout. The backend mactrack_rescan()/mactrack_site_scan()
now always return UTF-8-safe JSON (JSON_INVALID_UTF8_SUBSTITUTE).

On completion each scan returns a short "<device|site> ... completed in N.NN
seconds" message that the AJAX caller surfaces as an auto-fading Cacti toast
via the 1.2.x session-message mechanism (sessionMessage + displayMessages(),
what raise_message_javascript() emits), while the detailed scan output stays in
the results dialog.

Reorder the MacTrack tabs to Dashboard, Sites, Devices, Interfaces, IP Ranges,
IP Addresses, MAC Addresses, Dot1x, Graphs and pluralize the IP/MAC Address
tab labels to match the rest of the UI.

Update AdminActionsRequirePostTest JS assertions for the new helper structure
and regenerate locales/po/cacti.pot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 5, 2026 16:54
TheWitness and others added 2 commits November 5, 2026 12:11
Drive mactrack_rescan() and mactrack_site_scan() through the full scan block with a no-op subprocess (/bin/false) so the new timing/message/content lines are exercised, satisfying the 100%% patch-coverage gate. Add cacti_escapeshellarg()/cacti_escapeshellcmd() stubs the path needs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mirror Cactis variadic __() in the test stub (func_get_args) so static analysis no longer reads the parameterized __() calls as passing too many arguments (php:S930), and assign the shared toast message through window.sessionMessage so the global is explicit (javascript:S2703).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

Scan failures can trigger misleading success notifications, while requests that time out without a response leave users with no failure feedback.

2 open issues

Review effort: Balanced

Comment thread js/mactrack.js Resolved
Comment thread js/mactrack.js Resolved
xmacan
xmacan previously approved these changes Nov 5, 2026
Do not toast a failed scan as a success: a nonzero subprocess exit returns HTTP 200 with an error flag, so suppress the completion toast when data.error is set (the error detail is already shown in the results dialog). Report request timeouts explicitly: getPresentHTTPError() renders nothing when the failure has no response body, so show an error-level toast instead of silently clearing the spinner.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

@TheWitness
TheWitness merged commit 7ecc749 into develop Nov 5, 2026
7 checks passed
@TheWitness
TheWitness deleted the fix/mactrack-rescan-tabs branch November 5, 2026 19:14
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