Commit Graph
212 Commits
Author SHA1 Message Date
Isaac Connor 09bcfe872f Merge pull request #6891 from AJ0070/fix-zmaudit-unlink-result
fix: zmaudit only re-scans after a broken event link was actually deleted
2026-11-19 22:42:36 -05:00
Isaac Connor 15d6809ea8 Merge pull request #6889 from AJ0070/fix-zmaudit-single-sleep
fix: zmaudit continuous mode waits one check interval per pass, not two
2026-11-19 19:34:32 -05:00
Jash ddf41bb539 fix: zmaudit only re-scans after a broken event link was actually deleted refs #6890 2026-11-19 20:27:40 +05:30
Jash b0888d0d56 fix: zmaudit continuous mode waits one check interval per pass, not two refs #6888 2026-11-19 20:01:12 +05:30
singhharsh1708 8fac4b5104 fix: treat every number <= 0 as no log limit and trim the log limits 2026-11-19 16:45:59 +05:30
singhharsh1708 c9859b35fb fix: treat a negative ZM_LOG_DATABASE_LIMIT as no limit in zmstats and zmaudit 2026-11-18 23:34:52 +05:30
Jash 1edbc8fbab fix: zmaudit closes open events with Event::Close and fixes their DefaultVideo refs #4354 2026-11-18 12:27:33 +05:30
Isaac Connor 9566320838 Merge pull request #6621 from singhharsh1708/fix/r3-zmaudit-confirm-answers
fix: zmaudit --interactive treats end of input as quit, not yes
2026-11-17 21:19:22 -05:00
singhharsh1708 0499d9852c fix: zmaudit --interactive treats end of input as quit, not yes 2026-11-18 00:08:10 +05:30
singhharsh1708 a67f5d68e6 fix: zmaudit audits the monitors after an unreadable directory 2026-11-18 00:07:44 +05:30
Jash 70e3fa98f0 fix: zmaudit -s and --level options, read-only report mode, endless restart and new monitor directories refs #6350 2026-11-16 12:17:04 +05:30
Isaac Connor 555a918ed3 Merge pull request #5980 from AJ0070/zmaudit-event-data-orphans
fix: remove orphaned Event_Data rows in zmaudit
2026-11-15 11:26:50 -05:00
Isaac Connor 6f0dcf3c78 Merge pull request #5943 from AJ0070/zmaudit-fixes
fix: zmaudit unreadable storage, report mode, swap cleanup and stale pid file
2026-11-15 10:43:51 -05:00
Jash ff75bfea90 fix: remove orphaned Event_Data rows in zmaudit refs #5979 2026-11-15 12:58:11 +05:30
Isaac Connor 9dba70f0ea Merge pull request #5659 from AJ0070/zmaudit-deep-years
fix: do not treat Deep scheme year directories as Shallow events in zmaudit
2026-11-15 00:00:08 -05:00
Isaac Connor a170abe59f Merge pull request #5683 from AJ0070/event-null-start
fix: handle events with no StartDateTime in the web delete and zmaudit
2026-11-14 23:51:08 -05:00
Isaac Connor 9fc5abfaea Merge pull request #5741 from AJ0070/ms-zmaudit-server-storage
fix: zmaudit only audits this server's storage in multi-server setups
2026-11-14 19:26:50 -05:00
Jash 05b0ce4b55 fix: zmaudit ignores a pid file left by a process that is no longer running refs #5942 2026-11-15 00:00:17 +05:30
Jash 17acb19c63 fix: zmaudit deletes old swap images instead of skipping every file refs #5942 2026-11-15 00:00:17 +05:30
Jash 1c9b4c5723 fix: zmaudit -r no longer deletes old images, prunes logs or resyncs counters refs #5942 2026-11-15 00:00:17 +05:30
Jash 01dc97d2f0 fix: zmaudit leaves events alone on a storage area it cannot read refs #5942 2026-11-15 00:00:17 +05:30
Jash 93b6118eb1 fix: zmaudit skips the other-storage search for events with no path refs #5682 2026-11-14 23:51:20 +05:30
Jash 5ac1818593 fix: select Archived in the zmaudit empty event query so archived events are kept refs #5836 2026-11-14 18:58:30 +05:30
Jash 1727417c5a fix: audit only this server's storage areas in multi-server setups refs #5740 2026-11-14 17:59:53 +05:30
Jash ce4db4eeda fix: do not treat Deep scheme year directories as Shallow events in zmaudit fixes #5658 2026-11-13 11:21:07 +05:30
Isaac Connor 4d474ded4e Merge pull request #5567 from AJ0070/5563-zmaudit-batch-event-rows
perf: load the events zmaudit checks in batches of 1000 instead of one query each
2026-11-12 08:36:25 -05:00
Isaac Connor 06c093c44b Merge pull request #5572 from AJ0070/5568-zmaudit-lazy-start-time
perf: work out a filesystem event's start time in zmaudit only when it is needed
2026-11-11 19:14:48 -05:00
Jash e6597da6be perf: work out a filesystem event's start time in zmaudit only when it is needed fixes #5568 2026-11-12 02:18:34 +05:30
Jash 7266e2717b perf: load the events zmaudit checks in batches of 1000 instead of one query each fixes #5563 2026-11-12 02:02:24 +05:30
Jash 7efeaf6809 fix: clear the object cache on every zmaudit pass so looked up events are freed fixes #5558 2026-11-12 01:35:01 +05:30
Isaac ConnorandClaude Opus 4.8 2e7fd06d95 fix: remove dangling monitor links with unlink() instead of a shell rm
zmaudit removes a filesystem monitor link that no longer points to a valid
monitor directory with executeShellCommand("$ZM_PATH_RM \"$link\""). The link
name is the monitor name. The web layer names the link from the raw request
(basename($_REQUEST['newMonitor']['Name'])) rather than the filtered name
stored in the database, so it can contain shell metacharacters that the stored
name cannot. Inside the double-quoted rm argument, $(...) and backticks in the
name are still expanded, so a user with Monitors create/edit can have zmaudit
run arbitrary shell commands when it later cleans up the dangling link.

Use Perl unlink() on the de-tainted link name: it removes the symlink itself
with no shell, so nothing in the name is interpreted.

Addresses GHSA-746p-4622-p3fr.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-23 22:32:04 -04:00
Steve GilvarryandClaude Opus 5 ba49bbb33c fix: make the Perl scripts' taint-safe PATH configurable
The scripts run under -T, so they cannot trust the caller's PATH and set
their own. Sixteen of them hardcoded /bin:/usr/bin:/usr/local/bin, which
assumes everything they shell out to lives under /usr or /usr/local.

ZoneMinder::General::findDbCommand looks for a database client on that
PATH, and zmupdate.pl and zmcamtool.pl run what it finds. So an install
whose client sits anywhere else cannot apply schema changes:

  sh: mysql: command not found
  Command 'mysql -u'zmuser' ... ' exited with status: 127

even with the client on the caller's PATH. Homebrew on Apple Silicon is
the case that surfaced it - the client is in /opt/homebrew/bin - but a
--prefix=/opt install on Linux has the same shape, as does anything that
keeps its database client outside the FHS locations.

Replaced the literal with @ZM_SCRIPT_PATH@, defaulting to the same three
directories plus wherever cmake actually found a client, and overridable
for packagers who want to pin it. Warn at configure time when no client
is found at all, since that failure otherwise appears much later and
says something unrelated.

Nothing changes for an install whose client is already under /usr/bin:
the directory is only appended when it is not in the list, so the
default stays exactly as it was.

Memory.pm is deliberately left alone. It has a narrower PATH of
/bin:/usr/bin, and the only command it runs is uname through an absolute
path from ZM_PATH_UNAME, so it does not need widening.

Verified on macOS across the three cases: with the client in
/opt/homebrew/bin the directory is appended; -DZM_SCRIPT_PATH= is
respected verbatim; and pointing detection at /usr/bin/mariadb leaves
the default untouched. Build clean, suite 146 cases.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B5KL9Xbi7K5aGsauLtd8tG
2026-09-13 13:04:59 +10:00
Isaac Connor 8a58971bef fix: string-compare BIGINT counters in zmaudit CAS skip checks
Perl's != / == coerces both sides to NV (double-precision float).
BIGINT DiskSpace columns can exceed 2^53 (~9 PB), at which point distinct
integers collapse to the same double. The "already correct, skip"
checks for both the Event_Summaries CAS loop and the Storage CAS loop
were comparing scalars with numeric operators, so two distinct
DiskSpace values above 2^53 could be treated as equal and the resync
skipped — and skipped again on every subsequent pass because the
collapse is deterministic, so drift would persist indefinitely.

Switch both checks to string equality. DBI binds these scalars as
strings anyway, so this matches what the database will compare against
when the WHERE clause runs.
2026-05-21 07:20:36 -04:00
Isaac Connor 25da6cce9e fix: CAS-guard Event_Summaries UPDATE in zmaudit to preserve concurrent writes
zmaudit's per-monitor UPDATE writes absolute snapshot values across all
12 counter columns. Without a CAS guard, a concurrent writer touching ES
between our snapshot and our UPDATE gets clobbered. The TotalEvents /
ArchivedEvents columns are particularly exposed because zmstats doesn't
maintain them (it only touches Hour/Day/Week/Month), so any drift
introduced by zmaudit racing event_delete_trigger or the zmc insert
path persists until the next zmaudit cycle.

Read the current ES row alongside the aggregates, skip monitors whose
snapshot matches the current row (no X-lock for no-op writes), and
guard each UPDATE with null-safe equality (MariaDB <=>) on every
column we're writing. Track CAS-deferred and skipped counts separately
from failures in the audit log.

zmstats does not need the same treatment: its UPDATE runs inside a TX
that already holds the bucket X-locks that gate the trigger writers
updating its column set.
2026-05-20 08:50:32 -04:00
Isaac Connor 07d50a8fed fix: CAS-style Storage DiskSpace update in zmaudit to preserve concurrent adjustments
Unlike Event_Summaries, Storage.DiskSpace has no trigger-based
incremental maintenance — Event::delete and the event-finalize paths do
their own +/- adjustments in application code. The previous absolute
snapshot+overwrite could undo a concurrent Event::delete adjustment
that committed between our Events SUM SELECT and our Storage UPDATE,
making accounting transiently wrong under normal load until the next
zmaudit pass.

Read the current Storage.DiskSpace alongside the aggregate, skip rows
that are already correct, and UPDATE with a null-safe equality guard
(MariaDB <=>) so a concurrent writer's newer value blocks the
overwrite. Track CAS-deferred rows separately from failures and
surface both counts in the audit log.
2026-05-18 20:04:54 -04:00
Isaac Connor d098a055b8 fix: track Event_Summaries enumerate failure as partial resync in zmaudit
Without this, an enumerate failure (SELECT MonitorId FROM Event_Summaries)
left @skipped empty and the per-monitor UPDATE loop ran for whatever rows
the bucket aggregates returned — but monitors that exist only in
Event_Summaries (no current bucket rows) never got zeroed, while the
audit log claimed a full resync. Track enumerate success and report
partial resync when it fails.
2026-05-17 08:50:38 -04:00
Isaac Connor ccc0bcf82b fix: track per-row UPDATE failures in zmaudit ES and Storage resync
Previously zmaudit logged "Finished resyncing Event_Summaries" /
"Finished updating Storage DiskSpace" unconditionally as long as the
aggregate SELECTs succeeded, masking per-row UPDATE failures (e.g.
zmDbDo exhausting its deadlock retries) and skipped aggregate column
groups. Track which aggregates were skipped and which per-monitor /
per-storage UPDATEs failed (zmDbDo returns undef on failure), and
surface that in the audit log instead of claiming the resync is
complete.
2026-05-16 23:14:38 -04:00
Isaac Connor 7b4617b1ad docs: document atomicity tradeoff in zmstats/zmaudit ES resync
A concurrent trigger writer can adjust Event_Summaries between our
snapshot SELECTs and the per-monitor UPDATE; the UPDATE then overwrites
that adjustment with the older snapshot. Drift is bounded by the
zmstats/zmaudit interval and corrected on the next pass, because the
incremental triggers continue to maintain ES correctly between resyncs.
Locking ES before reading aggregates would invert the canonical lock
order and re-introduce the deadlock cycle the resync rewrite eliminated.
2026-05-16 22:44:14 -04:00
Isaac ConnorandClaude Opus 4.7 943114da99 fix: don't zero Event_Summaries counters on aggregate SELECT failure in zmaudit
Previously, if any of the five aggregate SELECTs (Events, Events_Hour/Day/
Week/Month) failed transiently, the per-monitor UPDATE phase still ran and
wrote `// 0` for every column from those failed groups, destroying valid
counters across all monitors.

Track per-aggregate success and build the UPDATE SET clause from only the
column groups whose SELECT succeeded. zmaudit re-runs on its normal
interval, so a missed group is corrected on the next pass instead of being
overwritten with zeros now.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 09:39:08 -04:00
Isaac ConnorandClaude Opus 4.7 830a92542d perf: snapshot bucket aggregates instead of joining in Event_Summaries resync
The previous resync code in zmstats and zmaudit used multi-table
UPDATEs against Event_Summaries that joined the bucket tables:

  UPDATE Event_Summaries es
  LEFT JOIN (SELECT ... FROM Events_Hour ...) h ON ...
  LEFT JOIN (SELECT ... FROM Events_Day  ...) d ON ...
  ... SET es.HourEvents = h.c, ...

zmaudit additionally used scalar correlated subqueries against Events
for the Total/Archived columns and against Events for Storage.DiskSpace.

MariaDB takes S-locks on the joined and sub-queried rows for the
duration of any multi-table UPDATE statement, regardless of isolation
level. event_update_trigger and event_delete_trigger hold X-locks on
those same bucket rows while they walk the trigger body, so the resync
deadlocks against active event lifecycle traffic. Captured a textbook
example in SHOW ENGINE INNODB STATUS:

  TX(1) zma:    HOLDS X Events_Hour[42229643]
                WAITS X Event_Summaries[28]
  TX(2) zmstats: HOLDS X Event_Summaries[2,4,5,...,28,...,73]
                 WAITS S Events_Hour[42229643]

Replace the JOIN/subquery pattern in both scripts with a snapshot phase
followed by per-monitor UPDATEs:

  1. SELECT MonitorId, COUNT(*), SUM(DiskSpace) FROM each bucket
     (and the equivalent Total/Archived aggregate from Events).
     Plain SELECTs do consistent reads and take no row locks.
  2. SELECT MonitorId FROM Event_Summaries to widen the universe so
     monitors with empty buckets still get zeroed out.
  3. For each monitor, UPDATE Event_Summaries SET ... WHERE MonitorId=?.
     Each UPDATE only X-locks one ES row and reads no other table.

zmaudit's five separate UPDATEs collapse to one snapshot phase plus
one UPDATE per monitor. Storage DiskSpace gets the same treatment.

zmstats keeps the same outer transaction (BEGIN ... COMMIT, RC
isolation, retry on 1213) so the bucket DELETEs and the resync stay
atomic, but the resync no longer reads the bucket tables under lock.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 15:22:51 -04:00
Isaac ConnorandClaude Opus 4.6 e6ace6fcf4 feat: add AUDIT logging level for tracking administrative changes
Add a new AUDIT logging level (-5) between PANIC (-4) and NOLOG (shifted
to -6) across C++, PHP, and Perl loggers. AUDIT entries use code 'AUD'
and syslog priority LOG_NOTICE. They record who changed what, from where,
for monitors, filters, users, config, roles, groups, zones, states,
servers, storage, events, snapshots, control caps, and login/logout.

AUDIT entries have their own retention period (ZM_LOG_AUDIT_DATABASE_LIMIT,
default 1 year) separate from regular log pruning. The log pruning in
zmstats.pl and zmaudit.pl now excludes AUDIT rows from regular pruning
and prunes them independently.

Critical safety: the C++ termination logic is changed from
'if (level <= FATAL)' to 'if (level == FATAL || level == PANIC)' to
prevent AUDIT-level log calls from killing the process.

Includes db migration zm_update-1.39.1.sql to shift any stored NOLOG
config values from -5 to -6.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 18:19:20 -05:00
Isaac Connor 988bab6dcb Handle when there are no frame records 2025-12-02 13:58:00 -05:00
Isaac Connor 10901eb08f Remove extra line, use // to collapse lines 2025-11-06 21:25:40 -05:00
Isaac Connor 4c9f6d3091 Put swap file File::find into an eval because it can die. 2024-07-16 10:11:52 -04:00
Isaac Connor 178eacc06b Use Term instead of exit when q is hit so that we clean up the pid file 2024-04-12 14:07:20 -04:00
Isaac Connor 243edcc82f Use new ZM_PATH_RM instead of hard coding path to rm 2023-09-28 12:59:08 -04:00
Alejandro Criado-Pérez 871bf1772f fix: messages 2023-07-05 01:03:48 +02:00
Isaac Connor c7f6cdd6ce Always check for Shallow events 2023-03-24 14:19:54 -04:00
Isaac Connor 0ec9a9f732 Don't delete archived empty events. 2022-12-09 10:14:59 -05:00
Isaac Connor 7e4f9f49e8 Fix not handling Shallow storage areas 2022-10-14 09:25:58 -04:00