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
Collaborator

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, so ip must be the host only, port the ONVIF port, and onvif_ctrl the device service path.

Keep a custom ONVIF port when credentials change (1e3eb8a)

lib/controller/doCameraOperation.php, CMD 4 (change IP / credentials):

  • Port kept: an address without :port used to set port=NULL. The camera editor showed the IP without the port, so changing only the credentials moved a camera on 8080 back to port 80. Now ip:port sets the port, and a plain ip keeps the stored one.
  • No double port: a port kept inside onvif_ctrl (:8080/onvif/device_service, cameras added by discovery) is moved to port. Once port was also set, la_mojo built http://ip:8080:8080/....

doCameraOperation.php, CMD 3 (add camera / check credentials):

  • Existing camera: the port may also come from onvif_ctrl. The credential check used to go to port 80 and fail.
  • Direct address: ip:port or 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_ctrl used to be the full media service URL and ip was ip:port.
  • PHP 8 crash: count() of a string threw an uncaught TypeError that killed the request when the snapshot URI was read.

lib/controller/getCameraEditor.php:

  • Address field: shows ip:port when the camera has a port, so Apply keeps it.

XML-escape the values in ONVIF requests (1f0b081)

lib/php/onvif/toto.php:

  • Problem: all 19 request builders put the user name, profile / preset / node tokens, preset name, stream and protocol into the SOAP XML unescaped. A user name like a&b, or a token containing & or <, made the request malformed, and the UI reported "Provided Credentials are Wrong!".
  • Fix: _xesc() / _xescAll() escape string values. Numbers and booleans are unchanged.
  • Password: not affected, because only its digest is sent.

Testing

Tested with PHP 8.3, a SQLite cameras / media_streams table, and a fake ONVIF camera on a custom port.

Case Before After
Credentials changed, address without port (camera on 8080) port dropped, http://ip/... port kept, http://ip:8080/...
Credentials changed, port inside onvif_ctrl http://ip:8080:8080/... http://ip:8080/onvif/device_service
Add camera 127.0.0.1:<port> without discovery PHP 8 fatal error, ip=ip:port, onvif_ctrl=media URL ip, port and path stored, stream stored, status 1
Credential check of a discovered camera on a custom port "Credentials are Wrong" (port 80) check passes, login stored
User us&er<1>, token main&0 malformed XML, "Credentials are Wrong" camera, login and stream stored
  • PTZ requests (presets, moves, Stop) use the same escaping, but were not run in this test.
  • Existing records: records stored with ip:port or a full URL in onvif_ctrl are not converted automatically. One Apply in the editor, which now shows ip:port, or re-adding the camera, corrects them.

Generated with Claude Code

https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16

## 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`, so `ip` must be the host only, `port` the ONVIF port, and `onvif_ctrl` the device service path. ### Keep a custom ONVIF port when credentials change (1e3eb8a) `lib/controller/doCameraOperation.php`, CMD 4 (change IP / credentials): - **Port kept:** an address without `:port` used to set `port=NULL`. The camera editor showed the IP without the port, so changing only the credentials moved a camera on 8080 back to port 80. Now `ip:port` sets the port, and a plain `ip` keeps the stored one. - **No double port:** a port kept inside `onvif_ctrl` (`:8080/onvif/device_service`, cameras added by discovery) is moved to `port`. Once `port` was also set, la_mojo built `http://ip:8080:8080/...`. `doCameraOperation.php`, CMD 3 (add camera / check credentials): - **Existing camera:** the port may also come from `onvif_ctrl`. The credential check used to go to port 80 and fail. - **Direct address:** `ip:port` or 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_ctrl` used to be the full media service URL and `ip` was `ip:port`. - **PHP 8 crash:** `count()` of a string threw an uncaught TypeError that killed the request when the snapshot URI was read. `lib/controller/getCameraEditor.php`: - **Address field:** shows `ip:port` when the camera has a port, so Apply keeps it. ### XML-escape the values in ONVIF requests (1f0b081) `lib/php/onvif/toto.php`: - **Problem:** all 19 request builders put the user name, profile / preset / node tokens, preset name, stream and protocol into the SOAP XML unescaped. A user name like `a&b`, or a token containing `&` or `<`, made the request malformed, and the UI reported "Provided Credentials are Wrong!". - **Fix:** `_xesc()` / `_xescAll()` escape string values. Numbers and booleans are unchanged. - **Password:** not affected, because only its digest is sent. ## Testing Tested with PHP 8.3, a SQLite `cameras` / `media_streams` table, and a fake ONVIF camera on a custom port. | Case | Before | After | |---|---|---| | Credentials changed, address without port (camera on 8080) | port dropped, `http://ip/...` | port kept, `http://ip:8080/...` | | Credentials changed, port inside `onvif_ctrl` | `http://ip:8080:8080/...` | `http://ip:8080/onvif/device_service` | | Add camera `127.0.0.1:<port>` without discovery | PHP 8 fatal error, `ip`=`ip:port`, `onvif_ctrl`=media URL | ip, port and path stored, stream stored, status 1 | | Credential check of a discovered camera on a custom port | "Credentials are Wrong" (port 80) | check passes, login stored | | User `us&er<1>`, token `main&0` | malformed XML, "Credentials are Wrong" | camera, login and stream stored | - **PTZ requests** (presets, moves, Stop) use the same escaping, but were not run in this test. - **Existing records:** records stored with `ip:port` or a full URL in `onvif_ctrl` are not converted automatically. One Apply in the editor, which now shows `ip:port`, or re-adding the camera, corrects them. Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
ClaudeAI added 2 commits 10 hours ago
1e3eb8a892
Cameras: keep a custom ONVIF port (e.g. 8080) when credentials change
1f0b0812ff
toto.php: XML-escape the values put into ONVIF requests
ClaudeAI added 1 commit 2 hours ago
d66bde56dd
toto.php: no PHP Error past try/catch in initialize()
ClaudeAI added 1 commit 2 hours ago
8b061ae862
doCameraOperation: CMD 3 without PR parameter = ONVIF, no undefined key warning
ClaudeAI added 1 commit 2 hours ago
b43f159cc7
doCameraOperation: a failed credential check returns status "error"
ClaudeAI added 1 commit 2 hours ago
536e0ddefb
ONVIF behind NAT: use the reachable address for the camera's services and URIs
ClaudeAI merged commit 1be265c515 into master 35 minutes ago
The pull request has been merged as 1be265c515.
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This pull request currently doesn't have any dependencies.

Loading…
There is no content yet.