Commit Graph
159 Commits
Author SHA1 Message Date
Jash e20a2f58eb fix: report a refused or failed event delete instead of success refs #5975 2026-11-15 12:54:58 +05:30
Isaac Connor 027dceadb6 Merge pull request #5655 from AJ0070/deep-delete-secondary-dodelete
fix: delete the secondary copy of Deep events and honour DoDelete in Event::delete
2026-11-15 00:00:42 -05:00
Isaac Connor 7a2c42e6f3 Merge pull request #5657 from AJ0070/deep-delete-stop-at-storage
fix: prune only empty date dirs below the monitor dir when deleting a Deep event
2026-11-14 23:59:47 -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 a1f1df5d2c Merge pull request #5681 from AJ0070/zm-namespace-exceptions
fix: import Exception and PDOException in namespace ZM classes
2026-11-14 23:49:02 -05:00
Isaac Connor 7c4524c2de Merge pull request #5707 from AJ0070/export-generatevideo
fix: reuse a generated event video in exports instead of re-encoding
2026-11-14 19:56:53 -05:00
Isaac Connor 93afa44757 Merge pull request #5739 from AJ0070/ms-event-remote-auth
fix: use get_auth_relay for remote event file info
2026-11-14 19:55:37 -05:00
Isaac Connor c29de5400f Merge pull request #5771 from AJ0070/thumb-zero-size
fix: don't divide by a zero event size when sizing list thumbnails
2026-11-14 18:55:15 -05:00
Jash 5646d03750 fix: delete the secondary copy of Deep events and honour DoDelete in Event::delete fixes #5654 2026-11-14 23:51:34 +05:30
Jash ed95f01161 fix: prune only empty date dirs below the monitor dir when deleting a Deep event fixes #5656 2026-11-14 23:51:25 +05:30
Jash 0e4ae0a82f fix: do not resolve or delete date-based event paths when StartDateTime is NULL refs #5682 2026-11-14 23:51:20 +05:30
Isaac Connor dbf3ab81a0 Merge pull request #5837 from AJ0070/event-delete-fixes
fix: event deletion order, archived checks and directory cleanup
2026-11-14 11:49:45 -05:00
Jash 81d2cef41a fix: let the export make a video for an event with no length instead of dividing by zero refs #5850 2026-11-14 19:09:33 +05:30
Jash 2644d77a1f fix: place frames after the last bulk frame by interpolating to the event end instead of whole seconds refs #5850 2026-11-14 19:09:33 +05:30
Jash eaa6dce4e2 fix: remove the empty date directory after deleting a Medium scheme event refs #5836 2026-11-14 18:58:30 +05:30
Jash 4359270a34 fix: re-check Archived after reloading the event row before deleting it refs #5836 2026-11-14 18:58:30 +05:30
Jash ad45b6ad3f fix: keep the storage area and monitor directory when deleting the last Deep scheme event refs #5836 2026-11-14 18:58:30 +05:30
Jash d3c1e56e12 fix: delete event rows before files and keep the files when the delete fails refs #5836 2026-11-14 18:58:30 +05:30
Jash 1c4c5e61c3 fix: delete Event_Data rows when deleting an event in the web UI refs #5836 2026-11-14 18:58:30 +05:30
Jash 87eaff2d13 fix: do not divide by a zero event width or height when sizing list thumbnails refs #5770 2026-11-14 18:12:00 +05:30
Jash 6d8d61882a fix: send the auth relay once when fetching event file info from another server refs #5738 2026-11-14 17:59:47 +05:30
Jash 19f49937e0 fix: reuse a generated event video in exports instead of re-encoding refs #5706 2026-11-13 14:14:54 +05:30
Jash 49637348a2 fix: import Exception and PDOException in namespace ZM classes fixes #5680 2026-11-13 13:13:42 +05:30
Jash 3f635686a1 fix: take a deleted event's DiskSpace off its Storage in the PHP delete refs #5605 2026-11-12 09:49:11 +05:30
Isaac ConnorandClaude Opus 5.5 9e3885e8fd refactor: remove ZM_OPT_FAST_DELETE
With fast deletes on, deleting an event in the web interface removed only
its Events row and left its Frames and Stats rows and its files for
zmaudit, and deleting a monitor left all of its events. zmaudit only runs
when ZM_RUN_AUDIT is on, and both options default to off independently,
so with fast deletes on and the audit off nothing ever removed them and
the Frames table grew without bound. In the Perl Event::delete the option
also kept zmfilter from removing the files of the events it purged.

Remove the option. ZM\Event::delete() always removes the Stats and Frames
rows and the files in one transaction with the Events row,
ZM\Monitor::destroy() always deletes the monitor's events, and the Perl
Event::delete deletes the files unless the storage area has DoDelete off.
zmupdate.pl rebuilds the Config table from ConfigData, so the option's row
goes away on upgrade without a migration. Drop the option from the docs,
from the zmaudit option help, and from the es_la, ro_ro and ru_ru
translations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 22:50:01 -05:00
Nic BoetandClaude Opus 5.5 49ab7682ea fix: keep the auth relay out of PHP warnings on failed remote requests
When the other server of a multi-server install did not answer,
file_get_contents() raised a PHP warning whose text is the call and its
URL, ?auth=<hash> or user=/pass= included, and PHP wrote it to the web
server's error log (Event.php, Filter.php). The same happened with the
image proxy's digest retry (camera user:password@) and the X-Frame
check of a website monitor (get_headers()), which also took the false
it returns on failure for an array.

Fetch with @ and log lastErrorForLog(), the reason without the call
and its URL, next to urlForLog() of the URL. Server::SendToApi()
already used @ and now logs the reason too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:27:39 -05:00
Nic BoetandClaude Opus 5.5 b9e20c84a4 fix: stop logging the auth relay in multi-server request URLs
Event.php, Server.php and Filter.php call the API or index.php of
another server with the auth relay appended (?auth=<hash>, or with
ZM_AUTH_RELAY=plain the user's username and password) and logged that
URL, at debug level before the call and at Error level when the other
server did not answer. Error reaches the Logs table at the default
database log level. Log it through urlForLog(), without the query.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:27:39 -05:00
Nic Boet 184d33cd36 fix: refuse canView and canEdit for an Event with no Id
ZM\Event::canView() and canEdit() asked the event's Monitor, and an
Event with no MonitorId (built from an empty or failed lookup) gets an
empty Monitor, whose canView() falls back to the user's global Monitors
permission. So an Event with no Id passed both checks for any user with
Events access, whatever monitors they were denied. A caller that built
an Event from a lookup that could come back empty and trusted canView()
without checking Id() first failed open; the API's events/view did.

Return false from both when the Event has no Id. Every caller in the
web UI, ajax and API either checks Id() first or builds the Event from
a database row, so none relied on the empty Event passing; callers that
did not check (the frame view, export and download lists) now refuse a
missing event id instead of working on an empty one.

Test: tests/php/test_event_can_view_no_id.php drives the real ZM\Event
with a stub Monitor (8 of 13 checks fail before this change).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 054d4f0fa6)
2026-10-31 19:08:08 -04:00
Nic Boet bf745f2b8c fix: let a Snapshots grant view the events held in a snapshot
Event::canView() looked an event up in Snapshot_Events, a table that
doesn't exist (it is Snapshots_Events), and passed the event id as
dbFetchOne()'s column argument, so the id was never bound. The query
failed every time and a user allowed only through Snapshots could not
view the events in a snapshot. Check the role's Snapshots level as well
as the user's own, like the Events check above it.

The monitor check before it is unchanged.

refs #5189
2026-10-21 19:06:25 -05:00
Nic Boet 1a8964d066 fix: count the user's role in Event::canView() and canEdit()
Event::canView() and canEdit() compared the user's own Events field, so a
user whose own Events was None but whose role granted Events=View or Edit
could not view or edit any event, while the global canView('Events') and
canEdit('Events') let them through to the page. Use ZM\User::canView() and
canEdit(), which read the role as well. The monitor check is unchanged.

refs #5189
2026-10-21 19:06:25 -05:00
Isaac ConnorandClaude Opus 5.5 8d6c18db7e fix: only dispatch set()/changes() keys to field accessors refs GHSA-vvx7-ghpv-jq98
ZM_Object::set() called any method whose name matched a key in its data,
and changes() called it as a getter. That data is usually a request array
(filter[...], newMonitor[...], user[...]), so a request could invoke
save(), delete(), execute() and the like. filterdebug with fid=0 did
exactly that before its authorization check: filter[save][...] stored an
AutoExecute filter with a chosen command and filter[execute] ran
zmfilter.pl on it, giving command execution to any logged-in user. The
filter and events views pass filter[...] to set() the same way.

set() and changes() now dispatch a key to a method only when the key is
a field in $defaults or is listed in the class's new static $setters, the
accessors outside $defaults that take a value (Filter's query accessors,
Monitor::Model/Manufacturer/Groups, User::Role, and so on). Other method
names are refused with a warning.

filterdebug also requires Events view before it builds a filter from the
request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 19:32:25 -04:00
Isaac ConnorandClaude Opus 5.5 1d5fb76b04 fix: quote each ffmpeg argument in the PHP event video generator
Event::GenerateVideo() built the ffmpeg command as one string and ran it
through escapeshellcmd(), which leaves spaces alone. Any value in the string
could therefore add ffmpeg arguments. The event Name is already reduced to a
safe filename, but DefaultVideo and the transforms were not.

The command is now a list with every argument passed through escapeshellarg(),
the same approach as the Perl GenerateVideo. The configured input and output
option strings are split on whitespace, as the Perl side does. ffmpeg output
goes to ffmpeg.log through proc_open descriptors: escapeshellcmd() was escaping
the old '> ffmpeg.log 2>&1' redirect, so it was passed to ffmpeg as arguments.
An empty transforms string no longer adds a bare -vf.

Checked with a stub ffmpeg that records its argv: a Name and a DefaultVideo
carrying shell and option payloads arrive as single literal arguments and
nothing runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 07:56:03 -04:00
Isaac Connor 844ef61e07 fix: keep event DefaultVideo and Name from escaping the event directory in the web UI
DefaultVideo can be set by any user with Events=Edit through the API
(EventsController add/edit), and readers join it onto the event path:
view_video.php streams it, image.php extracts frames from it,
findVideoEventFile, Event::getStreamSrc/FileSize and the API fileExists
check all use Path().'/'.DefaultVideo. A value such as ../../x pointed
those reads at arbitrary files readable by the web account.

Reject DefaultVideo values on save in the API model unless they are a
bare filename (no / or \, no NUL, not . or ..). Make the PHP Event
DefaultVideo() accessor return basename() so every web reader only ever
looks inside the event directory, even for rows written before this
check, and apply basename() to the raw array read in the API model's
fileExists.

Event::GenerateVideo built its output filename from Name with only
whitespace replaced; Name is editable through the event rename and
eventdetail actions. Replace anything outside [-A-Za-z0-9_.] and a
leading dot so the output stays inside the event directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f3f679b644db28b4b1bff79d5dd98eca24395fc4)
2026-09-24 23:16:11 -04:00
Isaac ConnorandClaude Opus 5 9c06eb6ba2 refactor: connect to the database on first use, not on include
database.php called dbConnect() at file scope, so including it opened a socket,
and on failure rendered views/no_database_connection.php and exit()ed from
inside a library include. Every model in web/includes requires this file, so
merely loading a class did both.

Connect on first use instead. $dbConn becomes tri-state - false for "not
attempted", null for "attempt failed", a PDO for connected - and two accessors
sit on top of it:

  zmDbConn()        opens if needed; on failure renders the error view and
                    stops, which is what the include used to do, just at the
                    point a query is actually attempted.
  zmDbConnOrNull()  opens if needed but returns null instead of ending the
                    request, for callers with a fallback.

dbQuery() is the funnel every fetch helper goes through, so routing it plus
dbEscape(), dbError() and dbInsertId() through the accessors covers the library.
The five callers that reached for the raw global are updated: config.php.in,
Event.php and ajax/console.php need a connection and take zmDbConn(); logger.php
takes zmDbConnOrNull() and falls through to its error_log target, so a logging
call can no longer end the request or open a connection by itself.

ZMSessionHandler captured $dbConn in its constructor. It is constructed while
session.php is being included, before anything has needed the database, so with
a lazy connection that captured false. It now resolves per call and its methods
return "no session" rather than dereferencing a bool.

Two smaller fixes fall out. The error view was included by a relative path that
only resolved when the cwd was web/, so it never worked for requests served out
of web/api/; it is now anchored with __DIR__. And dbDisconnect() set $dbConn to
null, which in the new tri-state means "connecting failed" and would send the
next query to the error page; it sets false so a later query can reconnect.
Nothing calls dbDisconnect() today.

This does NOT make database.php includable without a database. It requires
logger.php, which requires config.php, which reads ZoneMinder's configuration
out of the Config table at include time. Until that cycle is broken the
connection still happens during bootstrap, just from config.php rather than from
here.

Tests: tests/php/test_database_lazy_connect.php, 7 assertions, all pass. It
tokenises database.php and asserts nothing runs at include time, that dbQuery()
goes through the accessor, and that only the connection plumbing touches the
global. Verified it reports the pre-refactor file's `if ( !dbConnect() )` - an
earlier version of the check skipped tokens inside parentheses and so passed on
exactly the code it exists to reject.

Not covered by tests: behaviour when the database is genuinely unreachable, and
the session handler against a live database. Needs manual testing on an
installed tree, including stopping mysql to confirm the error view still renders
for both a web request and an API request.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01477mR97vfnK6zczbHgzq6T
2026-08-17 20:52:10 -04:00
SteveGilvarryandClaude Opus 4.8 cd6aeb2c74 fix: correct thumbnail aspect ratio for high-resolution monitors
Event::ThumbnailWidth()/ThumbnailHeight() derived the secondary dimension
through an integer SCALE_BASE scale:

  $scale = intval((SCALE_BASE * THUMB_WIDTH) / Width);
  ThumbnailHeight = reScale(Height, $scale);

For a high-resolution monitor the scale factor is small and intval()
truncates it. e.g. a 2688x1520 monitor with WEB_LIST_THUMB_WIDTH=48 gives
scale = intval(100*48/2688) = intval(1.78) = 1, so the height becomes 15
instead of 27 — a 3.2:1 thumbnail instead of 16:9. The events-list hover
overlay sizes its container from that thumbnail and object-fit:cover-crops
the real (correct-aspect) video into the squashed box, which shows as a
"long narrow" popout.

Compute the secondary dimension directly from the aspect ratio
(round(Height * THUMB_WIDTH / Width)) so no precision is lost.

refs #3443

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-13 22:47:13 +10:00
IgorA100 f3ac936605 Deleted the unnecessary line (Event.php) 2026-06-04 14:47:51 +03:00
IgorA100 a233fc1224 - Correct HLS playback on the Watch page
- When executing Event->Length() , get the duration of the recorded event file if the duration in the database table is 0
- If native HLS playback fails in Safari, we first try playing MP4, and only if MP4 playback fails do we switch to MJPEG playback
2026-05-31 16:25:51 +03:00
IgorA100 964ea784fc - Do not check the M3u8 file if currentView === 'frames'
- When executing Length() and Duration() , do not write the result to the database.
- When assigning a value to the "data-video-duration-secs" attribute, first check the Length in $row['Length'] and, if it is 0, only then check the file's Duration.
- If the M3u8 file is missing or invalid, do not cache the server response.
2026-05-26 19:23:59 +03:00
IgorA100andCopilot Autofix powered by AI 0ff920ec07 Apply suggestions from code review
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-05-26 16:58:19 +03:00
IgorA100 be29253b12 Added comment (Event.php) 2026-05-24 11:03:19 +03:00
IgorA100 5cdeca1529 Duration is only saved to the database if it's greater than zero. (Event.php) 2026-05-24 10:51:28 +03:00
IgorA100 3c7410bf09 Added a private Duration() method as a synonym for the Length() method. (Event.php)
Added retrieval of the Duration from a video file and saving it to the database if it wasn't already present.
2026-05-24 00:54:06 +03:00
IgorA100 16f350c4da Fixed the value assignment for "$args['view']" (Event.php) 2026-05-21 13:17:15 +03:00
IgorA100 1678c13993 Option to generate 'view=view_hls' (Event.php) 2026-05-17 01:27:19 +03:00
Isaac ConnorandClaude Opus 4.6 5561829450 fix: include username in auth relay and fix stale auth in stream restart
- Add user= parameter to get_auth_relay() so zms can use the indexed
  Username column instead of iterating all users to validate the hash
- Apply the same fix to Event.php getStreamSrc() and getThumbnailSrc()
- Tighten Monitor.php from isset() to !empty() for consistency
- In MonitorStream.js start(), check if the auth hash in the img src
  matches the current auth_hash before resuming via CMD_PLAY. If stale,
  fall through to rebuild the URL with fresh auth_relay. This prevents
  long-running montage pages from spawning zms with expired credentials.
- Downgrade zms auth failure from Error to Warning

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 10:01:47 -04:00
Isaac ConnorandClaude Opus 4.6 ffe6362dc3 fix: harden web interface against injection and SSRF vulnerabilities
FilterTerm.php:
- Replace eval() with safe compare() method for SystemLoad, DiskPercent,
  and DiskBlocks filter conditions (RCE via crafted op/val)
- Validate operator against allowlist in constructor
- Sanitize collate field to alphanumeric/underscore only (SQLi)

onvifprobe.php:
- Use escapeshellarg() on interface, device_ep, soapversion, username,
  and password arguments passed to execONVIF() (command injection)

Event.php:
- Use escapeshellarg() on all arguments to zmvideo.pl instead of
  escapeshellcmd() on the whole command (command injection via format)
- Anchor scale regex with ^ and $ to prevent partial matches

image.php:
- Restrict proxy URL scheme to http/https only (SSRF via file:// etc)

filterdebug.php:
- Use already-sanitized $fid instead of raw $_REQUEST['fid'] (XSS)

MonitorsController.php:
- Use escapeshellarg() on token, username, password, and monitor id
  in zmu shell command instead of escapeshellcmd() on whole command

HostController.php:
- Use escapeshellarg() on path in du command (command injection via mid)
- Remove space from daemon name allowlist (argument injection)

EventsController.php:
- Remove single quotes from interval expression regex (SQLi)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:30:49 -04:00
Isaac ConnorandClaude Opus 4.6 b036408a5b Fix RCE vulnerability via API config edit privilege escalation
Add RBAC checks to ConfigsController edit() and delete() requiring
System=Edit permission, matching the pattern used by other controllers.
Harden System/Readonly column checks with !empty() to handle missing
columns gracefully. Fix command injection in Event.php by using
ZM_PATH_FFMPEG constant with escapeshellarg() instead of hardcoded
unsanitized ffmpeg call. Add is_executable() validation at all exec()
sites using ZM_PATH_FFMPEG as defense-in-depth against poisoned config
values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 13:51:30 -05:00
Isaac Connor aeff647f90 Apply intval to scale calculations 2025-10-10 13:26:30 -04:00
Isaac Connor 2ba42345a7 Don't commit updated DiskSpace to the db. If we want to do that, we can call Save. This prevents UI from hanging waiting for this update to happen 2025-08-07 11:29:46 -04:00
IgorA100 f2aed5fc21 Chore: Adjust spaces, tabs, newlines 2024-04-03 22:58:21 +03:00