Skip to content

fix: finish the cleanup left in #241, #276, #306, #351 and #399 - #481

Merged
TheWitness merged 6 commits into
developfrom
chore/cleanup-open-issues
Dec 3, 2026
Merged

TheWitness merged 6 commits into
developfrom
chore/cleanup-open-issues

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

This finishes the cleanup that was still open in five issues. The rest of each issue had already landed on develop (see the comments on each issue). With this change, nothing is left in any of them.

Fixes #241
Fixes #276
Fixes #306
Fixes #351
Fixes #399

Changes

#276: editing a MacAuth address created a duplicate row

mac_track_macauth is keyed on mac_address, and sql_save() was called with that key. Changing an entry's address therefore inserted a new row with the same mac_id instead of updating the old one. sql_save() also returned the MAC string rather than the id on updates, so the post-save redirect was wrong.

  • New mactrack_maca_store() updates an existing entry by mac_id, or inserts a new one, using prepared statements.
  • An address that another entry already authorizes is rejected with a clear message.
  • When an address changes, the old address's ports lose authorized unless another entry still covers them.
  • form_save() no longer raises the save message twice and now redirects with mac_id= (the edit page ignored id=).

#399 item 7: ArpWatch correlation never matched

The lookup keys were built with mt_mac_delim, but scanned MACs are stored as 12 hex digits with no separator. mactrack_parse_arpwatch_line() now always returns the stored form. Every other #399 item was already fixed by #400, #411, #421, #433 and #434. I rechecked them on develop.

#351: PHP 8 leftovers

  • Removed the top_header_tabs hook registration. No Cacti release calls api_plugin_hook('top_header_tabs'), and top_graph_header_tabs already draws the tab. Upgrades delete the stale plugin_hooks row.
  • errors_disable() / errors_restore() no longer save and restore track_errors, which PHP 8.0 removed. They still install and restore the MacTrack error handler.
  • Removed the $host_template_hashes / $graph_template_hashes globals from mactrack_view_graphs(). Neither is defined in Cacti or the plugin.

#306: housekeeping

  • Deleted the empty mactrack_ajax.php. It is added to the manifest.json tombstones, removed from the realm definitions, and stripped from existing plugin_realms file lists on upgrade.
  • Fixed "aggergated" ? "aggregated" in the two Utilities strings, and regenerated locales/po/cacti.pot. The .po/.mo catalogs are left to Weblate's msgmerge.
  • locales/build_gettext.sh reads the version from INFO instead of include/cacti_version, which does not exist in a plugin. It also uses portable basename file .po and writes sed output through a temp file instead of GNU-only sed -i.
  • The doubled >> in the .pot bugs address was already fixed on develop.

#241: wiki link

The README now points to Plugin-Mactrack in the Cacti documentation instead of the repository wiki. Disabling the GitHub wiki is a repository setting, so it is left to a maintainer.

Not included

#465: the catalog side is already fixed on develop (39919fc / #470, plus the lv-LV and uk-UA catalogs), and every .po passes msgfmt --check --check-format. What remains is the duplicate weblate.autotranslate.autotranslate addon (id 6, mode: translate) on the Weblate component. That needs a Weblate admin, not a code change.

Testing

  • Full Pest suite against Cacti 1.2.x: 1178 passed, 13 skipped (database recovery tests that need MACTRACK_TEST_DSN), 0 failed.
  • New tests/Unit/MacAuthStoreTest.php covers:
    • an in-place address change
    • a description-only edit
    • a duplicate address being rejected
    • a new insert
    • editing an entry that has since been removed
  • MactrackUpgradeTest asserts the hook and realm cleanup on upgrade. ArpwatchParseTest was updated for the new signature.
  • tests/bin/patch-coverage.php: 100% of measured changed lines.
  • tests/bin/check-i18n-pot.php: OK.
  • php -l on all changed PHP files.
  • locales/build_gettext.sh ran end to end in a scratch copy.

- MacAuth (#276): update an entry in place when its address is edited
  instead of adding a second row that reuses its mac_id; reject an address
  another entry already authorizes, clear the old address's authorization,
  and return to the saved entry after saving.
- ArpWatch (#399 item 7): build lookup keys in the stored MAC form so they
  match scanned MACs when mt_mac_delim is set.
- PHP 8 cleanup (#351): drop the never-fired top_header_tabs hook (and its
  row on upgrade), the removed track_errors ini handling, and the undefined
  graph template hash globals.
- Housekeeping (#306): remove the empty mactrack_ajax.php (tombstoned, and
  stripped from existing realm lists on upgrade), fix the "aggregated"
  spelling, and make build_gettext.sh read the version from INFO and work
  with BSD basename/sed.
- Docs (#241): point the README at the Cacti documentation instead of the
  repository wiki.

Fixes #241
Fixes #276
Fixes #306
Fixes #351
Fixes #399

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 05:13

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

Authorization updates can fail on duplicate IDs yet report success, while address changes leave stale authorization flags in aggregate and staging data.

3 open issues
What changed in this PR

Addresses remaining MacTrack cleanup from #241, #276, #306, #351, and #399 across authorization saving, ArpWatch matching, plugin registration, and documentation.

Changes:

  • Updates MacAuth entries by ID and normalizes ArpWatch lookup keys.
  • Removes obsolete hooks, PHP settings, globals, and the empty AJAX endpoint.
  • Updates documentation, gettext generation, and regression coverage.
File Description
tests/​Unit/​PartitionRebuildTest.php Updates the save-guard assertion.
tests/​Unit/​MactrackUpgradeTest.php Checks hook and realm cleanup.
tests/​Unit/​MacAuthStoreTest.php Adds authorization-save coverage.
tests/​Unit/​DeviceTypeSqlSafetyTest.php Removes deleted-endpoint checks.
tests/​Unit/​ArpwatchParseTest.php Updates parser calls.
tests/​Unit/​AggregatedPortsKeyTest.php Updates realm fixtures.
tests/​Security/​SqlSafetyAndOutputEscapingTest.php Removes deleted-endpoint checks.
tests/​bin/​patch-coverage.php Removes the deleted endpoint exclusion.
setup.php Removes obsolete registrations and cleans upgrades.
README.md Links maintained documentation.
poller_mactrack.php Fixes ArpWatch keys and removes track_errors handling.
manifest.json Tombstones the removed endpoint.
mactrack_view_graphs.php Removes unused globals.
mactrack_utilities.php Corrects user-facing spelling.
mactrack_macauth.php Adds ID-based saving and fixes redirects.
mactrack_ajax.php Deletes the empty endpoint.
locales/​po/​cacti.pot Refreshes translation strings and metadata.
locales/​build_gettext.sh Reads plugin version and improves portability.
CHANGELOG.md Records fixes and cleanup.
.github/​copilot-instructions.md Updates endpoint and hook documentation.

Review effort: Balanced

Comment thread mactrack_macauth.php Resolved
Comment thread mactrack_macauth.php Resolved
Comment thread mactrack_macauth.php Resolved
…ables

Address review on #481:

- Upgrade gives every MAC authorization row that shares a mac_id (left by
  #276) its own id, oldest row keeping the original, then makes the mac_id
  key unique; new installs create it unique. Edits also match on the old
  address so they cannot collide before the upgrade runs.
- mactrack_maca_store() runs in one transaction, checks every write, and
  rolls back and returns 0 when any statement or the commit fails, before
  any port flag is left changed.
- mactrack_maca_set_authorized() sets the flag on mac_track_ports,
  mac_track_temp_ports and mac_track_aggregated_ports. Revocation skips
  rows another entry still covers. Aggregated rows whose flipped twin
  already exists (authorized is in the unique key) are merged into it, and
  date_last is preserved.

Verified against MariaDB 10.5 with a scratch schema in addition to the unit
suite.

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.

🟡 Changes recommended

MacAuth saves can silently roll back on supported MySQL installations, while index repairs may be skipped or marked complete despite failure, leaving shared IDs that can cause unintended bulk deletions.

2 open issues
3 resolved since last review

Review effort: Balanced

Comment thread includes/database.php Resolved
Comment thread mactrack_macauth.php Resolved
…pair

Address the second review round on #481:

- Cacti 1.2.29's db_commit_transaction() only commits when the
  MariaDB-only @@in_transaction is set, so on MySQL every MacAuth save
  rolled back. Use explicit START TRANSACTION / COMMIT / ROLLBACK, as
  mactrack_update_aggregated_ports() already does.
- Report a missing or non-unique mac_id key as pending upgrade work, so
  installs already at this version get the repair.
- Run the repair before plugin_mactrack_install() (Cacti 1.2.x applies the
  table definition to existing tables, which would try to add the unique
  key over duplicate rows), and leave the version unrecorded when it fails
  so the upgrade retries.

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.

🟡 Changes recommended

The upgrade’s ID repair can race with live MacAuth saves and falsely report success, while same-version upgrades skip required housekeeping.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

High severity Protect ID repair from concurrent MacAuth saves

setup.php:450

The ID repair can renumber a row between a live MacAuth save's lookup and UPDATE: upgrades hold the scan lock, but saves hold partitions. That UPDATE can match no rows yet report success, committing authorization flags for an unsaved address and returning the obsolete ID. Hold the partition lock around the entire repair, including its reads and index change, and release it in finally.

2 resolved since last review

Review effort: Balanced

Comment thread setup.php Resolved
Installs already recorded at 5.1 are relaunched by the mac_id key check without a version change, so the idempotent top_header_tabs and mactrack_ajax.php realm cleanup now runs on every upgrade instead of only when the version changes. The tombstone prune stays version-gated because it also removes the dev-only tests/ tree.

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.

🔵 Needs a closer look

Human judgment is needed to weigh an unpublished localization-header nit that can recur during regeneration.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

TheWitness and others added 2 commits December 3, 2026 06:41
Entries added after the v5.0 tag (4c9aba9) were listed under 5.0. Move them, unchanged and in order, to a new --- develop --- section so the 5.0 section matches what shipped.

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

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

@TheWitness
TheWitness merged commit b9e3fe6 into develop Dec 3, 2026
10 checks passed
@TheWitness
TheWitness deleted the chore/cleanup-open-issues branch December 3, 2026 12:01
TheWitness added a commit that referenced this pull request Dec 3, 2026
… 5.1 (#465) (#482)

* fix(i18n): ASCII percent signs, restore fuzzied translations, prepare 5.1

- zh-TW, zh-CN and ja-JP used the full-width percent sign (U+FF05) in the
  interface InBound/OutBound % labels and in the MAC authorization
  wildcard help, which tells users to type a character the plugin does
  not accept. Use the ASCII form the source string uses.
- Correcting "aggergated" in #481 made Weblate mark the two Utilities
  messages fuzzy in all 42 catalogs, so they showed in English. The
  existing translations are still correct; clear the flag.
- Rebuild every compiled catalog. The committed .mo files also still
  carried the two retired misspelled messages.
- Release prep: rename the pending CHANGELOG section to --- 5.1 ---, fold
  the unreleased documentation note into it, and update the README and
  contributor instructions to 5.1 (INFO is already 5.1).

Fixes #465

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

* fix(i18n): single percent in zh labels, correct mistranslated aggregated-table messages

Address review on #482:

- Cacti unescapes %% once, so "InBound %%%" renders as "InBound %%". Use a single % in the zh-TW and zh-CN labels.
- The restored Utilities messages were machine-translated from the misspelled "aggergated" and read as "intensified", "aggravated", "aggressive" or "approaching" table in some catalogs. Use each catalog's own term for aggregated in de-DE, pt-BR, pt-PT, pl-PL, he-IL, zh-CN, tr-TR and hi-IN, and rebuild their compiled catalogs.

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

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants