Cameras: custom ONVIF port and XML-escaped ONVIF requests #2
Merged
ClaudeAI
merged 6 commits from fix/camera-custom-onvif-port into master 35 minutes ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'fix/camera-custom-onvif-port'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Summary
Fixes cameras whose ONVIF interface is not on port 80 (for example 8080), and ONVIF requests that broke on special characters.
la_mojo builds the camera address as
http://ip[:port]+onvif_ctrl, soipmust be the host only,portthe ONVIF port, andonvif_ctrlthe device service path.Keep a custom ONVIF port when credentials change (
1e3eb8a)lib/controller/doCameraOperation.php, CMD 4 (change IP / credentials)::portused to setport=NULL. The camera editor showed the IP without the port, so changing only the credentials moved a camera on 8080 back to port 80. Nowip:portsets the port, and a plainipkeeps the stored one.onvif_ctrl(:8080/onvif/device_service, cameras added by discovery) is moved toport. Onceportwas also set, la_mojo builthttp://ip:8080:8080/....doCameraOperation.php, CMD 3 (add camera / check credentials):onvif_ctrl. The credential check used to go to port 80 and fail.ip:portor the dialog's Port field (PO) is used as the ONVIF port. Discovery stores ip, port and the device service path separately. Without discovery,onvif_ctrlused to be the full media service URL andipwasip:port.count()of a string threw an uncaught TypeError that killed the request when the snapshot URI was read.lib/controller/getCameraEditor.php:ip:portwhen the camera has a port, so Apply keeps it.XML-escape the values in ONVIF requests (
1f0b081)lib/php/onvif/toto.php:a&b, or a token containing&or<, made the request malformed, and the UI reported "Provided Credentials are Wrong!"._xesc()/_xescAll()escape string values. Numbers and booleans are unchanged.Testing
Tested with PHP 8.3, a SQLite
cameras/media_streamstable, and a fake ONVIF camera on a custom port.http://ip/...http://ip:8080/...onvif_ctrlhttp://ip:8080:8080/...http://ip:8080/onvif/device_service127.0.0.1:<port>without discoveryip=ip:port,onvif_ctrl=media URLus&er<1>, tokenmain&0ip:portor a full URL inonvif_ctrlare not converted automatically. One Apply in the editor, which now showsip:port, or re-adding the camera, corrects them.Generated with Claude Code
https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
Ponvif::initialize() -> media_GetVideoSources() ended the whole request on PHP 8, past the callers' try { } catch (Exception $e): - a camera answering with an HTML page (e.g. HTTP 401): _xml2array() found no <Envelope>, simplexml_load_string() returned false, and $xml->getName() threw an Error; - a reply without <VideoSources>: _getActiveSources() called count(null), which throws a TypeError. toto.php - _xml2array() never throws: an empty, HTML or non-SOAP reply becomes a Fault ("reply is not a SOAP envelope", "empty reply", ...). The HTTP status is added in _send_request() ("HTTP 401: ..."). - initialize() throws an Exception when there is no media service, no video source or no profile. Any other PHP Error inside is re-thrown as an Exception. The time query catches Throwable. - The "Communication error" exceptions (19) give the reason: the HTTP fault above, or the SOAP Fault text of the camera. - A camera with ONE profile or video source works: a single XML element decodes to an associative array, so count() counted its fields and no source was found. - _getOnvifVersion(), GetVideoSources and the profile fields (RateControl is optional in ONVIF) are read with isset(). Warnings displayed by PHP would otherwise end up in the AJAX JSON reply. doCameraOperation.php - The 7 try blocks catch Throwable, and "Provided Credentials are Wrong!" now shows the reason, e.g. "GetVideoSources: Communication error (HTTP 401: reply is not a SOAP envelope)". Tested with PHP 8.3 and a fake ONVIF camera. HTML 401 page and empty <VideoSources>: before, a fatal Error/TypeError ended the script; now an Exception with the reason, and a JSON reply from doCameraOperation. An empty 401 body and a good camera behave as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN161be265c515.