 Cameras: keep a custom ONVIF port (e.g. 8080) when credentials change
The camera address is ip + port + onvif_ctrl (la_mojo builds
http://ip[:port]onvif_ctrl). The web UI broke it for cameras whose ONVIF
interface isn't on port 80.
doCameraOperation.php, CMD 4 (change IP / credentials)
- An address without ":port" 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 "ip" keeps the
stored one.
- A port kept inside onvif_ctrl (":8080/onvif/device_service", cameras
added by discovery) is moved to `port`. Once port was set too, la_mojo
built http://ip:8080:8080/onvif/device_service.
doCameraOperation.php, CMD 3 (add camera / check credentials)
- Camera from the DB: the port may also come from onvif_ctrl (it was read
from `port` only, so the check went to port 80 and failed).
- Direct address: "ip:port" or the dialog's Port field (PO) is the ONVIF
port. Discovery stores ip, port and the device service path separately.
Without discovery, onvif_ctrl was the full MEDIA service URL and ip
was "ip:port"; now it is /onvif/device_service, ip and port.
- count() of a string (PHP 8 TypeError, not caught) killed the request
when the snapshot URI was read.
getCameraEditor.php
- The address field shows "ip:port" when the camera has a port.
Tested with PHP 8.3, a SQLite cameras table and a fake ONVIF camera on a
custom port. The old code dropped the port, built ip:8080:8080, stored
"ip:port" + the media URL, and crashed. Now the record and the
credential check are correct.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago  ONVIF behind NAT: use the reachable address for the camera's services and URIs
Tested with the real camera reached as 2.54.237.28:8080 (port forward). It
reports its services and URIs at its LAN address 192.168.200.118:
GetCapabilities XAddrs http://192.168.200.118:8080/onvif/..., stream URIs
rtsp://192.168.200.118:554/...
toto.php
- initialize(): a service URL (media, device, ptz) on another host than
the one the device service was reached at is moved to that address,
keeping its path (_reachableUri). GetVideoSources went to
192.168.200.118 and failed with "Couldn't connect", and the UI said
"Credentials are Wrong!". A service on the same host is unchanged.
doCameraOperation.php
- Stream / snapshot URIs are split with parse_url (camMediaUri):
protocol, port (scheme default if none) and path + query, whatever the
host is. Before, only "proto://<ip of the record>" was removed, so with
the LAN host the whole URL was stored as the path. The two copies of
that code are replaced by the helper.
Real camera, request of the camera editor (CID=5, AU=7, CMD=3) through
the real login (users table / session): before, status "error" (LAN
address unreachable). Now status "ok", credentials, auth mode and PTZ
token stored, 3 profiles: mainStream 1920x1080
/Streaming/Channels/101?..., subStream, thirdStream; snapshot http:8080
/onvif-http/snapshot?Profile_n.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
2 hours ago  Cameras: keep a custom ONVIF port (e.g. 8080) when credentials change
The camera address is ip + port + onvif_ctrl (la_mojo builds
http://ip[:port]onvif_ctrl). The web UI broke it for cameras whose ONVIF
interface isn't on port 80.
doCameraOperation.php, CMD 4 (change IP / credentials)
- An address without ":port" 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 "ip" keeps the
stored one.
- A port kept inside onvif_ctrl (":8080/onvif/device_service", cameras
added by discovery) is moved to `port`. Once port was set too, la_mojo
built http://ip:8080:8080/onvif/device_service.
doCameraOperation.php, CMD 3 (add camera / check credentials)
- Camera from the DB: the port may also come from onvif_ctrl (it was read
from `port` only, so the check went to port 80 and failed).
- Direct address: "ip:port" or the dialog's Port field (PO) is the ONVIF
port. Discovery stores ip, port and the device service path separately.
Without discovery, onvif_ctrl was the full MEDIA service URL and ip
was "ip:port"; now it is /onvif/device_service, ip and port.
- count() of a string (PHP 8 TypeError, not caught) killed the request
when the snapshot URI was read.
getCameraEditor.php
- The address field shows "ip:port" when the camera has a port.
Tested with PHP 8.3, a SQLite cameras table and a fake ONVIF camera on a
custom port. The old code dropped the port, built ip:8080:8080, stored
"ip:port" + the media URL, and crashed. Now the record and the
credential check are correct.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago  Cameras: keep a custom ONVIF port (e.g. 8080) when credentials change
The camera address is ip + port + onvif_ctrl (la_mojo builds
http://ip[:port]onvif_ctrl). The web UI broke it for cameras whose ONVIF
interface isn't on port 80.
doCameraOperation.php, CMD 4 (change IP / credentials)
- An address without ":port" 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 "ip" keeps the
stored one.
- A port kept inside onvif_ctrl (":8080/onvif/device_service", cameras
added by discovery) is moved to `port`. Once port was set too, la_mojo
built http://ip:8080:8080/onvif/device_service.
doCameraOperation.php, CMD 3 (add camera / check credentials)
- Camera from the DB: the port may also come from onvif_ctrl (it was read
from `port` only, so the check went to port 80 and failed).
- Direct address: "ip:port" or the dialog's Port field (PO) is the ONVIF
port. Discovery stores ip, port and the device service path separately.
Without discovery, onvif_ctrl was the full MEDIA service URL and ip
was "ip:port"; now it is /onvif/device_service, ip and port.
- count() of a string (PHP 8 TypeError, not caught) killed the request
when the snapshot URI was read.
getCameraEditor.php
- The address field shows "ip:port" when the camera has a port.
Tested with PHP 8.3, a SQLite cameras table and a fake ONVIF camera on a
custom port. The old code dropped the port, built ip:8080:8080, stored
"ip:port" + the media URL, and crashed. Now the record and the
credential check are correct.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago  Cameras: keep a custom ONVIF port (e.g. 8080) when credentials change
The camera address is ip + port + onvif_ctrl (la_mojo builds
http://ip[:port]onvif_ctrl). The web UI broke it for cameras whose ONVIF
interface isn't on port 80.
doCameraOperation.php, CMD 4 (change IP / credentials)
- An address without ":port" 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 "ip" keeps the
stored one.
- A port kept inside onvif_ctrl (":8080/onvif/device_service", cameras
added by discovery) is moved to `port`. Once port was set too, la_mojo
built http://ip:8080:8080/onvif/device_service.
doCameraOperation.php, CMD 3 (add camera / check credentials)
- Camera from the DB: the port may also come from onvif_ctrl (it was read
from `port` only, so the check went to port 80 and failed).
- Direct address: "ip:port" or the dialog's Port field (PO) is the ONVIF
port. Discovery stores ip, port and the device service path separately.
Without discovery, onvif_ctrl was the full MEDIA service URL and ip
was "ip:port"; now it is /onvif/device_service, ip and port.
- count() of a string (PHP 8 TypeError, not caught) killed the request
when the snapshot URI was read.
getCameraEditor.php
- The address field shows "ip:port" when the camera has a port.
Tested with PHP 8.3, a SQLite cameras table and a fake ONVIF camera on a
custom port. The old code dropped the port, built ip:8080:8080, stored
"ip:port" + the media URL, and crashed. Now the record and the
credential check are correct.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago  Cameras: keep a custom ONVIF port (e.g. 8080) when credentials change
The camera address is ip + port + onvif_ctrl (la_mojo builds
http://ip[:port]onvif_ctrl). The web UI broke it for cameras whose ONVIF
interface isn't on port 80.
doCameraOperation.php, CMD 4 (change IP / credentials)
- An address without ":port" 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 "ip" keeps the
stored one.
- A port kept inside onvif_ctrl (":8080/onvif/device_service", cameras
added by discovery) is moved to `port`. Once port was set too, la_mojo
built http://ip:8080:8080/onvif/device_service.
doCameraOperation.php, CMD 3 (add camera / check credentials)
- Camera from the DB: the port may also come from onvif_ctrl (it was read
from `port` only, so the check went to port 80 and failed).
- Direct address: "ip:port" or the dialog's Port field (PO) is the ONVIF
port. Discovery stores ip, port and the device service path separately.
Without discovery, onvif_ctrl was the full MEDIA service URL and ip
was "ip:port"; now it is /onvif/device_service, ip and port.
- count() of a string (PHP 8 TypeError, not caught) killed the request
when the snapshot URI was read.
getCameraEditor.php
- The address field shows "ip:port" when the camera has a port.
Tested with PHP 8.3, a SQLite cameras table and a fake ONVIF camera on a
custom port. The old code dropped the port, built ip:8080:8080, stored
"ip:port" + the media URL, and crashed. Now the record and the
credential check are correct.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago  Cameras: keep a custom ONVIF port (e.g. 8080) when credentials change
The camera address is ip + port + onvif_ctrl (la_mojo builds
http://ip[:port]onvif_ctrl). The web UI broke it for cameras whose ONVIF
interface isn't on port 80.
doCameraOperation.php, CMD 4 (change IP / credentials)
- An address without ":port" 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 "ip" keeps the
stored one.
- A port kept inside onvif_ctrl (":8080/onvif/device_service", cameras
added by discovery) is moved to `port`. Once port was set too, la_mojo
built http://ip:8080:8080/onvif/device_service.
doCameraOperation.php, CMD 3 (add camera / check credentials)
- Camera from the DB: the port may also come from onvif_ctrl (it was read
from `port` only, so the check went to port 80 and failed).
- Direct address: "ip:port" or the dialog's Port field (PO) is the ONVIF
port. Discovery stores ip, port and the device service path separately.
Without discovery, onvif_ctrl was the full MEDIA service URL and ip
was "ip:port"; now it is /onvif/device_service, ip and port.
- count() of a string (PHP 8 TypeError, not caught) killed the request
when the snapshot URI was read.
getCameraEditor.php
- The address field shows "ip:port" when the camera has a port.
Tested with PHP 8.3, a SQLite cameras table and a fake ONVIF camera on a
custom port. The old code dropped the port, built ip:8080:8080, stored
"ip:port" + the media URL, and crashed. Now the record and the
credential check are correct.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago  Cameras: keep a custom ONVIF port (e.g. 8080) when credentials change
The camera address is ip + port + onvif_ctrl (la_mojo builds
http://ip[:port]onvif_ctrl). The web UI broke it for cameras whose ONVIF
interface isn't on port 80.
doCameraOperation.php, CMD 4 (change IP / credentials)
- An address without ":port" 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 "ip" keeps the
stored one.
- A port kept inside onvif_ctrl (":8080/onvif/device_service", cameras
added by discovery) is moved to `port`. Once port was set too, la_mojo
built http://ip:8080:8080/onvif/device_service.
doCameraOperation.php, CMD 3 (add camera / check credentials)
- Camera from the DB: the port may also come from onvif_ctrl (it was read
from `port` only, so the check went to port 80 and failed).
- Direct address: "ip:port" or the dialog's Port field (PO) is the ONVIF
port. Discovery stores ip, port and the device service path separately.
Without discovery, onvif_ctrl was the full MEDIA service URL and ip
was "ip:port"; now it is /onvif/device_service, ip and port.
- count() of a string (PHP 8 TypeError, not caught) killed the request
when the snapshot URI was read.
getCameraEditor.php
- The address field shows "ip:port" when the camera has a port.
Tested with PHP 8.3, a SQLite cameras table and a fake ONVIF camera on a
custom port. The old code dropped the port, built ip:8080:8080, stored
"ip:port" + the media URL, and crashed. Now the record and the
credential check are correct.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago  Cameras: keep a custom ONVIF port (e.g. 8080) when credentials change
The camera address is ip + port + onvif_ctrl (la_mojo builds
http://ip[:port]onvif_ctrl). The web UI broke it for cameras whose ONVIF
interface isn't on port 80.
doCameraOperation.php, CMD 4 (change IP / credentials)
- An address without ":port" 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 "ip" keeps the
stored one.
- A port kept inside onvif_ctrl (":8080/onvif/device_service", cameras
added by discovery) is moved to `port`. Once port was set too, la_mojo
built http://ip:8080:8080/onvif/device_service.
doCameraOperation.php, CMD 3 (add camera / check credentials)
- Camera from the DB: the port may also come from onvif_ctrl (it was read
from `port` only, so the check went to port 80 and failed).
- Direct address: "ip:port" or the dialog's Port field (PO) is the ONVIF
port. Discovery stores ip, port and the device service path separately.
Without discovery, onvif_ctrl was the full MEDIA service URL and ip
was "ip:port"; now it is /onvif/device_service, ip and port.
- count() of a string (PHP 8 TypeError, not caught) killed the request
when the snapshot URI was read.
getCameraEditor.php
- The address field shows "ip:port" when the camera has a port.
Tested with PHP 8.3, a SQLite cameras table and a fake ONVIF camera on a
custom port. The old code dropped the port, built ip:8080:8080, stored
"ip:port" + the media URL, and crashed. Now the record and the
credential check are correct.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago  Cameras: keep a custom ONVIF port (e.g. 8080) when credentials change
The camera address is ip + port + onvif_ctrl (la_mojo builds
http://ip[:port]onvif_ctrl). The web UI broke it for cameras whose ONVIF
interface isn't on port 80.
doCameraOperation.php, CMD 4 (change IP / credentials)
- An address without ":port" 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 "ip" keeps the
stored one.
- A port kept inside onvif_ctrl (":8080/onvif/device_service", cameras
added by discovery) is moved to `port`. Once port was set too, la_mojo
built http://ip:8080:8080/onvif/device_service.
doCameraOperation.php, CMD 3 (add camera / check credentials)
- Camera from the DB: the port may also come from onvif_ctrl (it was read
from `port` only, so the check went to port 80 and failed).
- Direct address: "ip:port" or the dialog's Port field (PO) is the ONVIF
port. Discovery stores ip, port and the device service path separately.
Without discovery, onvif_ctrl was the full MEDIA service URL and ip
was "ip:port"; now it is /onvif/device_service, ip and port.
- count() of a string (PHP 8 TypeError, not caught) killed the request
when the snapshot URI was read.
getCameraEditor.php
- The address field shows "ip:port" when the camera has a port.
Tested with PHP 8.3, a SQLite cameras table and a fake ONVIF camera on a
custom port. The old code dropped the port, built ip:8080:8080, stored
"ip:port" + the media URL, and crashed. Now the record and the
credential check are correct.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago  Cameras: keep a custom ONVIF port (e.g. 8080) when credentials change
The camera address is ip + port + onvif_ctrl (la_mojo builds
http://ip[:port]onvif_ctrl). The web UI broke it for cameras whose ONVIF
interface isn't on port 80.
doCameraOperation.php, CMD 4 (change IP / credentials)
- An address without ":port" 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 "ip" keeps the
stored one.
- A port kept inside onvif_ctrl (":8080/onvif/device_service", cameras
added by discovery) is moved to `port`. Once port was set too, la_mojo
built http://ip:8080:8080/onvif/device_service.
doCameraOperation.php, CMD 3 (add camera / check credentials)
- Camera from the DB: the port may also come from onvif_ctrl (it was read
from `port` only, so the check went to port 80 and failed).
- Direct address: "ip:port" or the dialog's Port field (PO) is the ONVIF
port. Discovery stores ip, port and the device service path separately.
Without discovery, onvif_ctrl was the full MEDIA service URL and ip
was "ip:port"; now it is /onvif/device_service, ip and port.
- count() of a string (PHP 8 TypeError, not caught) killed the request
when the snapshot URI was read.
getCameraEditor.php
- The address field shows "ip:port" when the camera has a port.
Tested with PHP 8.3, a SQLite cameras table and a fake ONVIF camera on a
custom port. The old code dropped the port, built ip:8080:8080, stored
"ip:port" + the media URL, and crashed. Now the record and the
credential check are correct.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago  ONVIF behind NAT: use the reachable address for the camera's services and URIs
Tested with the real camera reached as 2.54.237.28:8080 (port forward). It
reports its services and URIs at its LAN address 192.168.200.118:
GetCapabilities XAddrs http://192.168.200.118:8080/onvif/..., stream URIs
rtsp://192.168.200.118:554/...
toto.php
- initialize(): a service URL (media, device, ptz) on another host than
the one the device service was reached at is moved to that address,
keeping its path (_reachableUri). GetVideoSources went to
192.168.200.118 and failed with "Couldn't connect", and the UI said
"Credentials are Wrong!". A service on the same host is unchanged.
doCameraOperation.php
- Stream / snapshot URIs are split with parse_url (camMediaUri):
protocol, port (scheme default if none) and path + query, whatever the
host is. Before, only "proto://<ip of the record>" was removed, so with
the LAN host the whole URL was stored as the path. The two copies of
that code are replaced by the helper.
Real camera, request of the camera editor (CID=5, AU=7, CMD=3) through
the real login (users table / session): before, status "error" (LAN
address unreachable). Now status "ok", credentials, auth mode and PTZ
token stored, 3 profiles: mainStream 1920x1080
/Streaming/Channels/101?..., subStream, thirdStream; snapshot http:8080
/onvif-http/snapshot?Profile_n.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
2 hours ago  toto.php: no PHP Error past try/catch in initialize()
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_0139veDo3XyavMuVhdnHcN16
2 hours ago  Cameras: keep a custom ONVIF port (e.g. 8080) when credentials change
The camera address is ip + port + onvif_ctrl (la_mojo builds
http://ip[:port]onvif_ctrl). The web UI broke it for cameras whose ONVIF
interface isn't on port 80.
doCameraOperation.php, CMD 4 (change IP / credentials)
- An address without ":port" 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 "ip" keeps the
stored one.
- A port kept inside onvif_ctrl (":8080/onvif/device_service", cameras
added by discovery) is moved to `port`. Once port was set too, la_mojo
built http://ip:8080:8080/onvif/device_service.
doCameraOperation.php, CMD 3 (add camera / check credentials)
- Camera from the DB: the port may also come from onvif_ctrl (it was read
from `port` only, so the check went to port 80 and failed).
- Direct address: "ip:port" or the dialog's Port field (PO) is the ONVIF
port. Discovery stores ip, port and the device service path separately.
Without discovery, onvif_ctrl was the full MEDIA service URL and ip
was "ip:port"; now it is /onvif/device_service, ip and port.
- count() of a string (PHP 8 TypeError, not caught) killed the request
when the snapshot URI was read.
getCameraEditor.php
- The address field shows "ip:port" when the camera has a port.
Tested with PHP 8.3, a SQLite cameras table and a fake ONVIF camera on a
custom port. The old code dropped the port, built ip:8080:8080, stored
"ip:port" + the media URL, and crashed. Now the record and the
credential check are correct.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago  ONVIF behind NAT: use the reachable address for the camera's services and URIs
Tested with the real camera reached as 2.54.237.28:8080 (port forward). It
reports its services and URIs at its LAN address 192.168.200.118:
GetCapabilities XAddrs http://192.168.200.118:8080/onvif/..., stream URIs
rtsp://192.168.200.118:554/...
toto.php
- initialize(): a service URL (media, device, ptz) on another host than
the one the device service was reached at is moved to that address,
keeping its path (_reachableUri). GetVideoSources went to
192.168.200.118 and failed with "Couldn't connect", and the UI said
"Credentials are Wrong!". A service on the same host is unchanged.
doCameraOperation.php
- Stream / snapshot URIs are split with parse_url (camMediaUri):
protocol, port (scheme default if none) and path + query, whatever the
host is. Before, only "proto://<ip of the record>" was removed, so with
the LAN host the whole URL was stored as the path. The two copies of
that code are replaced by the helper.
Real camera, request of the camera editor (CID=5, AU=7, CMD=3) through
the real login (users table / session): before, status "error" (LAN
address unreachable). Now status "ok", credentials, auth mode and PTZ
token stored, 3 profiles: mainStream 1920x1080
/Streaming/Channels/101?..., subStream, thirdStream; snapshot http:8080
/onvif-http/snapshot?Profile_n.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
2 hours ago doCameraOperation: a failed credential check returns status "error"
CMD 3 for a camera (the editor's "Set credentials" button) set
status "ok" before the ONVIF check. When the check failed (wrong
credentials, unreachable camera, unusable reply), the page saw "ok",
reloaded the list and never showed the message. The two failure
branches now set status "error", so the reason is shown.
Tested through the real ajax_asm.php / web.php login (users table and
session id) with the editor's request (UID, SID, CID=5, UU, PP, AU,
CMD=3):
- camera unreachable: error, "GetCapabilities: Communication error
(Failed to connect to ... port 8080 ...)"
- fake camera, good: ok, credentials and stream stored
- fake camera, HTML 401 page: error, "GetVideoSources: Communication
error (HTTP 401: reply is not a SOAP envelope)"
- wrong SID: redirected (302)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
2 hours ago  toto.php: no PHP Error past try/catch in initialize()
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_0139veDo3XyavMuVhdnHcN16
2 hours ago doCameraOperation: a failed credential check returns status "error"
CMD 3 for a camera (the editor's "Set credentials" button) set
status "ok" before the ONVIF check. When the check failed (wrong
credentials, unreachable camera, unusable reply), the page saw "ok",
reloaded the list and never showed the message. The two failure
branches now set status "error", so the reason is shown.
Tested through the real ajax_asm.php / web.php login (users table and
session id) with the editor's request (UID, SID, CID=5, UU, PP, AU,
CMD=3):
- camera unreachable: error, "GetCapabilities: Communication error
(Failed to connect to ... port 8080 ...)"
- fake camera, good: ok, credentials and stream stored
- fake camera, HTML 401 page: error, "GetVideoSources: Communication
error (HTTP 401: reply is not a SOAP envelope)"
- wrong SID: redirected (302)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
2 hours ago  toto.php: no PHP Error past try/catch in initialize()
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_0139veDo3XyavMuVhdnHcN16
2 hours ago  Cameras: keep a custom ONVIF port (e.g. 8080) when credentials change
The camera address is ip + port + onvif_ctrl (la_mojo builds
http://ip[:port]onvif_ctrl). The web UI broke it for cameras whose ONVIF
interface isn't on port 80.
doCameraOperation.php, CMD 4 (change IP / credentials)
- An address without ":port" 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 "ip" keeps the
stored one.
- A port kept inside onvif_ctrl (":8080/onvif/device_service", cameras
added by discovery) is moved to `port`. Once port was set too, la_mojo
built http://ip:8080:8080/onvif/device_service.
doCameraOperation.php, CMD 3 (add camera / check credentials)
- Camera from the DB: the port may also come from onvif_ctrl (it was read
from `port` only, so the check went to port 80 and failed).
- Direct address: "ip:port" or the dialog's Port field (PO) is the ONVIF
port. Discovery stores ip, port and the device service path separately.
Without discovery, onvif_ctrl was the full MEDIA service URL and ip
was "ip:port"; now it is /onvif/device_service, ip and port.
- count() of a string (PHP 8 TypeError, not caught) killed the request
when the snapshot URI was read.
getCameraEditor.php
- The address field shows "ip:port" when the camera has a port.
Tested with PHP 8.3, a SQLite cameras table and a fake ONVIF camera on a
custom port. The old code dropped the port, built ip:8080:8080, stored
"ip:port" + the media URL, and crashed. Now the record and the
credential check are correct.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago  toto.php: no PHP Error past try/catch in initialize()
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_0139veDo3XyavMuVhdnHcN16
2 hours ago  toto.php: no PHP Error past try/catch in initialize()
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_0139veDo3XyavMuVhdnHcN16
2 hours ago  toto.php: no PHP Error past try/catch in initialize()
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_0139veDo3XyavMuVhdnHcN16
2 hours ago  toto.php: no PHP Error past try/catch in initialize()
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_0139veDo3XyavMuVhdnHcN16
2 hours ago  toto.php: no PHP Error past try/catch in initialize()
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_0139veDo3XyavMuVhdnHcN16
2 hours ago |
|
<?php require_once('../ajax_asm.php');
/* Camera address model (as la_mojo reads it): `ip` = host only, `port` = ONVIF/HTTP port (NULL = 80), `onvif_ctrl` = path of the ONVIF device service. la_mojo builds http://ip[:port]onvif_ctrl. */ // "1.2.3.4" / "1.2.3.4:8080" -> array( host, port ) - port 0 when not given
function camSplitHostPort( $S ){ $S = trim( $S ); $P = 0; if( preg_match( '/^(.*):(\d{1,5})$/', $S, $M ) ){ $S = $M[1]; $P = intval( $M[2] ); if( $P > 65535 ) $P = 0; }; return array( $S, $P ); }; // ONVIF service URL or stored onvif_ctrl -> array( path, port ):
// "http://1.2.3.4:8080/onvif/device_service" and ":8080/onvif/device_service" -> ( "/onvif/device_service", 8080 )
function camOnvifPath( $U ){ $U = trim( $U ); $P = 0; if( preg_match( '#^[a-z]+://#i', $U ) ){ $H = parse_url( $U ); $P = isset( $H['port'] ) ? intval( $H['port'] ) : 0; $U = isset( $H['path'] ) ? $H['path'] : '/'; } elseif( preg_match( '#^:(\d{1,5})(/.*)?$#', $U, $M ) ){ $P = intval( $M[1] ); $U = isset( $M[2] ) ? $M[2] : '/'; }; return array( $U, $P ); }; // Stream / snapshot URI of the camera -> array( proto, port, path ): the camera may report its LAN address
// (192.168.x.y behind NAT / port forwarding) - the path is taken whatever the host is. Before, only
// "proto://<ip of the record>" was cut off, so with another host the whole URL was stored as the path.
function camMediaUri( $U ){ if( !is_string( $U ) || $U == '' ) return array( '', 0, '' ); $H = parse_url( $U ); if( $H === false || !isset( $H['scheme'] ) ) return array( '', 0, $U ); $Proto = strtolower( $H['scheme'] ); $Port = isset( $H['port'] ) ? intval( $H['port'] ) : 0; if( $Port == 0 ){ switch( $Proto ){ case 'rtsp': $Port = 554; break; case 'http': $Port = 80; break; case 'https': $Port = 443; break; }; }; $Path = ( isset( $H['path'] ) ? $H['path'] : '/' ) . ( isset( $H['query'] ) ? '?' . $H['query'] : '' ); return array( $Proto, $Port, $Path ); }; if( $CUser->Data['id'] > 1 ){ $Data = array(); $Data['status'] = 'na'; if( isset( $_POST['CMD'] ) ){ $CMD = intval( $_POST['CMD'] ); } else $CMD = 0; if( isset( $_POST['CID'] ) ) { $CameraID = intval($_POST['CID']); } else $CameraID = 0; switch( $CMD ){ case 0:{ echo "CMD is 0"; // List Discovered Cameras
break; }; case 1:{ break; }; case 2:{ //Assign Camera to the system
$QS ="SELECT * FROM `cameras` WHERE `id`={$CameraID}"; $JJ = $DATABASE->Query( $QS ); if( count( $JJ ) ){ $CC = $JJ[0]; $S_Stream = intval( $CC['stream_id'] ); $S_PTZ = intval( $CC['protocol'] ); if( $S_PTZ != 6 ){ // Real Camera
if( $S_Stream == 0 ){ $QS = "SELECT `id`,`source_type` FROM `media_streams` WHERE `source_id`={$CameraID} LIMIT 1"; } else { $QS = "SELECT `id`,`source_type` FROM `media_streams` WHERE `id`={$S_Stream}"; }; $SJ = $DATABASE->Query( $QS ); if( count( $SJ ) ){ $S_Stream = intval( $SJ[0]['id'] ); $CT = $SJ[0]['source_type']; if( $CT == 'D' ){ if( $S_PTZ ) $S_Type = 13; else $S_Type = 12; } else { if( $S_PTZ ) $S_Type = 11; else $S_Type = 10; }; $S_Name = $CC['name'].'_'.$CameraID; $QS = "INSERT INTO `nodes`(`type`,`aux_id`,`aux_parameter`,`enable`,`name`) VALUES({$S_Type},{$CameraID},{$S_Stream}, 1,'{$S_Name}')"; $DATABASE->Query( $QS ); $QS = "UPDATE `cameras` SET `status`=3,`type`={$S_Type} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok'; }; } else { $S_Name = $CC['name'].'_'.$CameraID; $QS = "INSERT INTO `nodes`(`type`,`aux_id`,`aux_parameter`,`enable`,`name`) VALUES(13,{$CameraID},0, 1,'{$S_Name}')"; $DATABASE->Query( $QS ); $QS = "UPDATE `cameras` SET `status`=3 WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok'; }; }; break; }; case 3:{ if( intval( isset( $_POST['PR'] ) ? $_POST['PR'] : 0 ) == 0 ){ // PR missing = ONVIF (an undefined key warning broke the JSON)
// Checkup Onvif Camera Credentials
require_once('../php/onvif/toto.php'); $EUser = $DATABASE->escape( $_POST['UU'] ); $EPass = $DATABASE->escape( $_POST['PP'] ); $AUTH = intval( $_POST['AU'] ); $onvif = new Ponvif(); $IP = ''; $PORT = 0; if( $CameraID ){ // Cam From DB
$QS ="SELECT `ip`,`port`,`onvif_ctrl` FROM `cameras` WHERE `id`={$CameraID}"; $JJ = $DATABASE->Query( $QS ); if( count( $JJ ) ){ $IP = $JJ[0]['ip']; $PORT = intval($JJ[0]['port']); if( !$PORT ){ // Older records keep the port in onvif_ctrl (":8080/onvif/device_service")
list( $CTRL, $PORT ) = camOnvifPath( $JJ[0]['onvif_ctrl'] ); }; if( $PORT ){ $onvif->setIPAddress( $IP.':'.$PORT ); } else { $onvif->setIPAddress( $IP ); }; } else $CameraID = 0; } else { // Direct IP
$Data['ss']='DirectIP'; // "1.2.3.4:8080" or the Port field of the dialog (PO): a camera whose ONVIF interface is not on port 80
list( $IP, $PORT ) = camSplitHostPort( $_POST['IP'] ); $IP = $DATABASE->escape( $IP ); if( !$PORT && isset( $_POST['PO'] ) ){ $PORT = intval( $_POST['PO'] ); if( $PORT < 1 || $PORT > 65535 ) $PORT = 0; }; $onvif->setIPAddress( $IP ); // WS-Discovery probe goes to the host
$RR = $onvif->discover(); if( count( $RR ) ){ $Data['ss']='Discover Have'; $R= $RR[0]; if(isset($R['EndpointReference'])){ if(isset($R['EndpointReference']['Address'])){ $TArr = explode( ':', $R['EndpointReference']['Address'] ); $CA = $DATABASE->escape( $TArr[1] ); $TArr = explode( ' ', $R['Scopes']); $CM = ''; $CI = $DATABASE->escape($R['IPAddr']); $Frr = explode( ' ', $R['XAddrs']); // Path and port of the device service: the port was left inside onvif_ctrl (":8080/onvif/...")
list( $CTRL, $XPORT ) = camOnvifPath( $Frr[0] ); $CP = $DATABASE->escape( $CTRL ); if( !$PORT ) $PORT = $XPORT; // a port typed by the user wins (NAT / port forwarding)
$SPORT = $PORT ? $PORT : 'NULL'; $CN = ''; $CH = ''; $CC = 0; foreach( $TArr as $T ){ $TT = str_ireplace('onvif://www.onvif.org/','', $T ); $TBrr = explode( '/', $TT ); if( stripos($TBrr[0],'type') !== false ){ if( stripos($TBrr[1],'video') !== false ) $CC |= 0x1; if( stripos($TBrr[1],'audio') !== false ) $CC |= 0x2; if( stripos($TBrr[1],'ptz') !== false ) $CC |= 0x4; }; if( stripos($TBrr[0],'name') !== false ) $CN = $DATABASE->escape(urldecode($TBrr[1])); if( stripos($TBrr[0],'hardware') !== false ) $CH = $DATABASE->escape(urldecode($TBrr[1])); if( stripos($TBrr[0],'mac') !== false ) $CM = $DATABASE->escape(urldecode($TBrr[1])); }; $QS = "INSERT INTO `cameras`(hardware,type,name,uuid,mac,ip,port,status,onvif_ctrl,online,manual) VALUES('{$CH}',13,'{$CN}','{$CA}','{$CM}','{$CI}',{$SPORT},0,'{$CP}',1,1) ON CONFLICT( uuid ) DO UPDATE SET ip='{$CI}', port={$SPORT}, onvif_ctrl='{$CP}', online=1"; $DATABASE->Query($QS,false); $CameraID = $DATABASE->getLastInsertID(); if( $CameraID == 0 ){ $QS = "SELECT `id` FROM `cameras` WHERE `uuid`='{$CA}'"; $RV = $DATABASE->Query( $QS ); if( count( $RV ) ) $CameraID = intval( $RV[0]['id']); }; }; }; } else { $Data['ss'] .='No Discover'; $onvif->setIPAddress( $PORT ? $IP.':'.$PORT : $IP ); $onvif->setUsername( $EUser ); $onvif->setPassword( $EPass ); $onvif->setAuthMethod( $AUTH ); $CI = $IP; $SPORT = $PORT ? $PORT : 'NULL'; $CameraID = 0; try { $onvif->initialize(); if ( !$onvif->isFault($info=$onvif->core_GetDeviceInformation())){ //Adding Camera
$CH = $info['Manufacturer'].'_'.$info['Model']; $CN = $info['Manufacturer'].'_CAM'.$info['HardwareId']; $CA = $info['SerialNumber']; $CM = $info['SerialNumber']; // getDeviceUri() returns the MEDIA service URL (full URL): la_mojo needs the device service path
$CP = '/onvif/device_service'; $QS = "INSERT INTO `cameras`(hardware,type,name,uuid,mac,ip,port,status,onvif_ctrl,online,manual) VALUES('{$CH}',13,'{$CN}','{$CA}','{$CM}','{$CI}',{$SPORT},0,'{$CP}',1,1) ON CONFLICT( uuid ) DO UPDATE SET ip='{$CI}', port={$SPORT}, onvif_ctrl='{$CP}', online=1"; $DATABASE->Query($QS,false); $CameraID = $DATABASE->getLastInsertID(); }; if( $CameraID ){ if ( !$onvif->isFault($devices=$onvif->getSources()) ){ $Data['ss'] .='No Fault'; foreach( $devices[0] as $source ) if( is_array( $source ) ){ //print_r( $source );
$Ename = $DATABASE->escape( $source['profilename']); $Etoken = $DATABASE->escape( $source['profiletoken']); $Eencode = $DATABASE->escape( $source['encoding']); $Ewidth = intval($source['width']); $Eheight = intval($source['height']); $Efps = intval($source['fps']); $Ebitrate = intval($source['bitrate']); if( isset( $source['ptz'] ) ){ $Eptz = $DATABASE->escape( $source['ptz']['nodetoken'] ); } else { $Eptz=''; }; $mrl = $onvif->media_GetStreamUri($source['profiletoken']); $pic = $onvif->media_GetSnapshotUri($source['profiletoken']); list( $mrl_proto, $mrl_port, $Emrl ) = camMediaUri( $mrl ); $Emrl = $DATABASE->escape( $Emrl ); list( $pic_proto, $pic_port, $Epic ) = camMediaUri( $pic ); $Epic = $DATABASE->escape( $Epic ); $QS = "INSERT INTO `media_streams`(`source_id`,`source_type`,`valid`,`name`,`token`,`img_width`,`img_height`,`compression_type`,`bitrate`,`fps`,`mrl`,`mrl_proto`,`mrl_port`,`picture_proto`,`picture_port`,`picture`) VALUES({$CameraID},'D',1,'{$Ename}','{$Etoken}',{$Ewidth},{$Eheight},'{$Eencode}',{$Ebitrate},{$Efps},'{$Emrl}','{$mrl_proto}','{$mrl_port}','{$pic_proto}','{$pic_port}','{$Epic}') ON CONFLICT(`source_id`,`token`) DO UPDATE SET `source_type`='D', `valid`=1, `mrl`='{$Emrl}', `mrl_proto`='{$mrl_proto}', `mrl_port`='{$mrl_port}', `picture_proto`='{$pic_proto}', `picture_port`='{$pic_port}', `picture`='{$Epic}'"; $Data['ss'] .='Added'; $Data['QS'] = $QS; $DATABASE->Query( $QS, false ); $Data['ss'] .='After DBQ'; }; $QS = "UPDATE cameras SET access_login='$EUser', access_pass='$EPass', auth_mode={$AUTH}, ptz_token='{$Eptz}', `status`=1 WHERE id={$CameraID}"; $DATABASE->Query( $QS, false ); $Data['status'] = 'ok'; } else { $Data['msg'] = 'Camera was added.<br/>However provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']'; }; } else { $Data['msg'] = 'No Camera was added.<br/>'; }; } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
$Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() ); }; break; }; }; if( $CameraID ){ $Data['status'] = 'ok'; if( $EUser!= '' ){ if( $PORT ) $onvif->setIPAddress( $IP.':'.$PORT ); // not port 80
$onvif->setUsername( $EUser ); $onvif->setPassword( $EPass ); $onvif->setAuthMethod( $AUTH ); try { $onvif->initialize(); if ( !$onvif->isFault($devices=$onvif->getSources())){ foreach( $devices[0] as $source ) if( is_array( $source ) ){ //print_r( $source );
$Ename = $DATABASE->escape( $source['profilename']); $Etoken = $DATABASE->escape( $source['profiletoken']); $Eencode = $DATABASE->escape( $source['encoding']); $Ewidth = intval($source['width']); $Eheight = intval($source['height']); $Efps = intval($source['fps']); $Ebitrate = intval($source['bitrate']); if( isset( $source['ptz'] ) ){ $Eptz = $DATABASE->escape( $source['ptz']['nodetoken'] ); } else { $Eptz=''; }; $mrl = $onvif->media_GetStreamUri($source['profiletoken']); $pic = $onvif->media_GetSnapshotUri($source['profiletoken']); list( $mrl_proto, $mrl_port, $Emrl ) = camMediaUri( $mrl ); $Emrl = $DATABASE->escape( $Emrl ); list( $pic_proto, $pic_port, $Epic ) = camMediaUri( $pic ); $Epic = $DATABASE->escape( $Epic ); $QS = "INSERT INTO `media_streams`(`source_id`,`source_type`,`valid`,`name`,`token`,`img_width`,`img_height`,`compression_type`,`bitrate`,`fps`,`mrl`,`mrl_proto`,`mrl_port`,`picture_proto`,`picture_port`,`picture`) VALUES({$CameraID},'D',1,'{$Ename}','{$Etoken}',{$Ewidth},{$Eheight},'{$Eencode}',{$Ebitrate},{$Efps},'{$Emrl}','{$mrl_proto}','{$mrl_port}','{$pic_proto}','{$pic_port}','{$Epic}') ON CONFLICT(`source_id`,`token`) DO UPDATE SET `source_type`='D', `valid`=1, `mrl`='{$Emrl}', `mrl_proto`='{$mrl_proto}', `mrl_port`='{$mrl_port}', `picture_proto`='{$pic_proto}', `picture_port`='{$pic_port}', `picture`='{$Epic}'"; $DATABASE->Query( $QS, false ); }; $QS = "UPDATE cameras SET access_login='$EUser', access_pass='$EPass', auth_mode={$AUTH}, ptz_token='{$Eptz}', `status`=1 WHERE id={$CameraID}"; $DATABASE->Query( $QS, false ); } else { $Data['status'] = 'error'; // the page shows msg only when status is not 'ok' (a failed check was silent)
$Data['msg'] = 'Camera was added.<br/>However provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']'; }; } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
$Data['status'] = 'error'; $Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() ); }; } else { $Data['msg'] = 'Camera Sucessfully Added<br/>Please Provide Access Credentials and Other Camera Settings'; }; } else { $Data['status'] = 'error'; $Data['msg'] = '<p align="center">Camera IP Address is Wrong!</p><p align="center">Please consider run network discovery.</p><p align="center">To refresh all aveable cameras addreses.</p>'; }; } else { //Bosch
$EUser = $DATABASE->escape( $_POST['UU'] ); $EPass = $DATABASE->escape( $_POST['PP'] ); $IP = $DATABASE->escape( $_POST['IP'] ); $AUTH = intval( $_POST['AU'] ); $PORT = intval($_POST['PO']); $CN = 'CAMERA_' . $IP; $CP = '/rcp.xml'; $UUID = md5( $CN ); $QS = "INSERT INTO `cameras`(type,hardware,name,uuid,ip,port,status,protocol,access_login,access_pass,onvif_access,onvif_ctrl,online,manual) VALUES(13,'BOSCH-RCP+','{$CN}','{$UUID}','{$IP}',{$PORT},1,6,'{$EUser}','{$EPass}','http','{$CP}',1,1) ON CONFLICT( uuid ) DO UPDATE SET ip='{$IP}', online=1"; $DATABASE->Query($QS,false); $CameraID = $DATABASE->getLastInsertID(); $Data['status'] = 'ok'; }; break; }; case 4:{ // change IP/Credentials
if( $CameraID ){ $QS ="SELECT * FROM `cameras` WHERE `id`={$CameraID}"; $JJ = $DATABASE->Query( $QS ); if( count( $JJ ) ){ $CC = $JJ[0]; //$PA = explode( '/', $CC['onvif_ctrl'] );
$EUser = $DATABASE->escape( $_POST['UU'] ); $EPass = $DATABASE->escape( $_POST['PP'] ); $EIP = $DATABASE->escape( $_POST['UI'] ); //$PA[2] = $EIP;
//$OVC = implode('/',$PA);
$AUTH = intval( $_POST['AU'] ); /* Before: an address without ":port" set port=NULL. The 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, "ip" keeps the stored one. A port kept inside onvif_ctrl (":8080/onvif/...", cameras added by discovery) is moved to `port`: with both, la_mojo built http://ip:8080:8080/onvif/... */ list( $EIP, $POR ) = camSplitHostPort( $_POST['UI'] ); $EIP = $DATABASE->escape( $EIP ); list( $CTRL, $CTRL_PORT ) = camOnvifPath( $CC['onvif_ctrl'] ); if( !$POR ) $POR = intval( $CC['port'] ); if( !$POR ) $POR = $CTRL_PORT; $SPOR = $POR ? $POR : 'NULL'; $ECTRL = $DATABASE->escape( $CTRL ); $QS = "UPDATE cameras SET access_login='$EUser', access_pass='$EPass', auth_mode={$AUTH},`ip`='{$EIP}', port={$SPOR}, onvif_ctrl='{$ECTRL}' WHERE id={$CameraID}"; $DATABASE->Query( $QS, false ); $Data['status'] = 'ok'; } else { $Data['msg'] = '<p align="center">Wrong Camera</p><p align="center">Please consider run network discovery.</p><p align="center">To refresh all aveable cameras.</p>'; }; } else { $Data['msg'] = '<p align="center">Wrong Camera</p><p align="center">Please consider run network discovery.</p><p align="center">To refresh all aveable cameras.</p>'; }; break; }; case 5:{ // Add Analog Video Stream Camera Manully
}; case 6:{ // Register the Camera
break; }; case 7:{ //Remove Camera
$QS ="SELECT * FROM `cameras` WHERE `id`={$CameraID}"; $RR = $DATABASE->Query( $QS ); if( count ( $RR ) ){ $CCD = $RR[0]; $QS ="DELETE FROM `nodes` WHERE `type` IN (10,11,12,13,14,15) AND `aux_id`={$CameraID}"; $DATABASE->Query( $QS ); if( $CCD['type'] < 12 ){//Analog
$QS="UPDATE `cameras` SET `status`=0 WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); } else { // IP
$QS ="DELETE FROM `media_streams` WHERE `source_id`={$CameraID}"; $DATABASE->Query( $QS ); $QS ="DELETE FROM `cameras` WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); }; $QS="DELETE FROM `cameras_preset_sets` WHERE `camera_id`={$CameraID}"; $DATABASE->Query( $QS ); $QS="DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok'; }; break; }; case 8:{ // Direct PTZ Controll
//$QS = "SELECT `aux_id` FROM `nodes` WHERE `id`={$CameraID}";
//$RR = $DATABASE->Query( $QS );
//$CameraID = intval( $RR[0]['aux_id'] );
if( $CameraID && isset( $_POST['MOV'] ) ){ $CCC = intval( $_POST['MOV'] ); switch( $CCC ){ case 0: $ACMD = 0x01; break; //Stop
case 10: $ACMD = 0x21; break; //Zoom In
case 11: $ACMD = 0x41; break; //Zoom Out
case 27: $ACMD = 0x03; break; // Right
case 28: $ACMD = 0x13; break; // RD
case 29: $ACMD = 0x11; break; // Down
case 30: $ACMD = 0x15; break; // LD
case 31: $ACMD = 0x05; break; // Left
case 32: $ACMD = 0x0d; break; // LU
case 33: $ACMD = 0x09; break; // Up
case 34: $ACMD = 0x0B; break; // RU
case 35: $ACMD = 0x82; break; // IR Off
case 36: $ACMD = 0x81; break; // IR On
case 37: $ACMD = 0x84; break; // Wiper
case 38: $ACMD = 0x83; break; // IR Auto
case 39: $ACMD = 0x85; break; // Set Home Preset Via Comntrol
}; echo $CameraID . " -> " .$ACMD; if( $ACMD ){ $QS = "INSERT INTO `nodes_qcq`(`cmd`,`node_id`,`status`) VALUES ({$ACMD},{$CameraID},0)"; @$MEMDB = new SQLite_DB( '/dev/shm/argus/mem_db.db'); $MEMDB->Query( $QS ); }; }; break; }; case 9:{ // Set Camera Home Preset
require_once('../php/onvif/toto.php'); $onvif = new Ponvif(); $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}"; $JJ = $DATABASE->Query( $QS ); if( count( $JJ ) ){ $IP = $JJ[0]['ip']; $PORT = intval($JJ[0]['port']); $EUser = $JJ[0]['access_login']; $EPass = $JJ[0]['access_pass']; $AUTH = intval($JJ[0]['auth_mode']); try { $Data['status'] = 'try'; if( $PORT ){ $onvif->setIPAddress( $IP.':'.$PORT ); } else { $onvif->setIPAddress( $IP ); }; $onvif->setUsername( $EUser ); $onvif->setPassword( $EPass ); $onvif->setAuthMethod( $AUTH ); $onvif->initialize(); if ( !$onvif->isFault( $devices = $onvif->getSources())){ $TK = ''; $Data['status'] = 'notoken'; foreach( $devices[0] as $source ) if( is_array( $source ) ){ $TK = $source['profiletoken']; break; }; if( $TK == '' ) break; $Data['token'] = $TK; $HTK = $JJ[0]['home_token']; if( $HTK!='' ){ $onvif->ptz_RemovePreset( $TK, $HTK ); }; $HTK = '1'; $onvif->ptz_SetPreset( $TK, $HTK ); //Old Method (LA Metro)
$QS = "UPDATE `cameras` SET `home_token` = '{$HTK}' WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); //New Presets mode
$QS="DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=2"; $DATABASE->Query( $QS ); $QS = "INSERT INTO `cameras_presets`(`preset_id`,`role`,`token`,`column`,`row`) VALUES({$CameraID},2,'{$HTK}',0,0)"; $DATABASE->Query( $QS ); $Data['status'] = 'ok'; } else { $Data['msg'] = 'OnVif Query Device Fault!'; } } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
$Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() ); }; } else { $Data['status'] = 'nocam'; }; break; }; case 11:{ // Direct PTZ Controll
$QS = "SELECT `id` FROM `nodes` WHERE `type` IN (10,11,12,13,14,15) AND `aux_id`={$CameraID}"; $RR = $DATABASE->Query( $QS ); $NID = intval( $RR[0]['id'] ); if( $NID && isset( $_POST['MOV'] ) ){ $CCC = intval( $_POST['MOV'] ); switch( $CCC ){ case 0: $ACMD = 0x01; break; //Stop
case 10: $ACMD = 0x21; break; //Zoom In
case 11: $ACMD = 0x41; break; //Zoom Out
case 27: $ACMD = 0x03; break; // Right
case 28: $ACMD = 0x13; break; // RD
case 29: $ACMD = 0x11; break; // Down
case 30: $ACMD = 0x15; break; // LD
case 31: $ACMD = 0x05; break; // Left
case 32: $ACMD = 0x0d; break; // LU
case 33: $ACMD = 0x09; break; // Up
case 34: $ACMD = 0x0B; break; // RU
case 35: $ACMD = 0x82; break; // IR Off
case 36: $ACMD = 0x81; break; // IR On
case 37: $ACMD = 0x84; break; // Wiper
case 38: $ACMD = 0x83; break; // IR Auto
case 39: $ACMD = 0x85; break; // Set Home Preset Via Comntrol
}; echo $NID . " -> " .$ACMD; if( $ACMD ){ $QS = "INSERT INTO `nodes_qcq`(`cmd`,`node_id`,`status`) VALUES ({$ACMD},{$NID},0)"; @$MEMDB = new SQLite_DB( '/dev/shm/argus/mem_db.db'); $MEMDB->Query( $QS ); }; }; break; }; case 10:{ //Additionall commands
$OP = intval( $_POST['OPID'] ); switch( $OP ){ case 1:{ //Bind Stream to Camera
$Param = intval( $_POST['OPCODE'] ); $QS = "SELECT * FROM `cameras` WHERE `id`={$CameraID}"; $JJ = $DATABASE->Query( $QS ); if( count( $JJ ) ){ $CC = $JJ[0]; if( $CC['status'] == 3 ){ $QS = "UPDATE `nodes` SET `aux_parameter`={$Param} WHERE `aux_id`={$CameraID} AND `type` IN(10,11,12,13,14,15)"; $DATABASE->Query( $QS ); }; $QS = "UPDATE `cameras` SET `stream_id`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-1'; }; break; }; case 2:{ //Set Lens Parameter
$Param = intval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `imager_type`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-2'; break; }; case 3:{ //Set Lens Parameter
$Param = intval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `lens_f`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-3'; break; }; case 4:{ //Set Lens Parameter
$Param = floatval( $_POST['OPCODE'] ); if( $Param > 0 ){ $ZM = 1; } else { $ZM = 0; }; $QS = "UPDATE `cameras` SET `zoom`={$Param}, `zoom_model`={$ZM} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-4'; break; }; case 5:{ // Set Protocol
$Param = intval( $_POST['OPCODE'] ); $QS = "SELECT `id`, `type` FROM `nodes` WHERE `aux_id`={$CameraID} AND `type` IN (10,11,12,13,14,15)"; $NR = $DATABASE->Query( $QS ); $NODE = $NR[0]; $Param = intval( $_POST['OPCODE'] ); $NMODE = 0; if( $Param ){ switch( $NODE['type'] ){ case 10: $NMODE = 11; break; case 12: $NMODE = 13; break; }; } else { switch( $NODE['type'] ){ case 11: $NMODE = 10; break; case 13: $NMODE = 12; break; case 14: $NMODE = 12; break; case 15: $NMODE = 12; break; }; }; if( $NMODE ){ $QS = "UPDATE `nodes` SET `type`={$NMODE} WHERE `id`={$NODE['id']}"; $DATABASE->Query( $QS ); $QS = "UPDATE `cameras` SET `type`={$NMODE} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); }; $QS = "UPDATE `cameras` SET `protocol`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-5'; break; }; case 6:{ //Set Uart Parameter
$QS = "SELECT `id` FROM `uart_settings` ORDER BY `id`"; $JUJA = $DATABASE->Query( $QS ); $Param = intval( $_POST['OPCODE'] ); $RID = intval($JUJA[$Param]['id']); $QS = "UPDATE `cameras` SET `uart_id`={$RID} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-6'; break; }; case 7:{ //Set Protocol Parameter
$Param = intval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `protocol_aux`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-7'; break; }; case 8:{ $Param = intval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `pan_model`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-8'; break; }; case 9:{ $Param = intval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `pan_angles`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-9'; break; }; case 10:{ $Param = intval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `tilt_model`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-10'; break; }; case 11:{ $Param = intval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `tilt_angles`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-11'; break; }; case 12:{ $Param = intval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `trigger_mode`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-12'; break; }; case 13:{ $Param = intval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `ptz_axel`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-13'; break; }; case 14:{ $Param = floatval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `x_rot`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-14'; break; }; case 15:{ $Param = floatval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `y_rot`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-15'; break; }; case 16:{ $Param = floatval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `z_rot`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-16'; break; }; case 17:{ $Param = floatval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `x`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-17'; break; }; case 18:{ $Param = floatval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `y`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-18'; break; }; case 19:{ $Param = floatval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `z`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-19'; break; }; case 20:{ //Set Camera Name
$Param = $DATABASE->escape( $_POST['OPCODE'] ); $QS = "UPDATE `nodes` SET `name`='{$Param}' WHERE `type` IN (10,11,12,13,14,15) AND `aux_id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-20'; break; }; case 21:{ // Set Cam Zoom Model
$Param = intval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `zoom_model`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-21'; break; }; case 22:{ // Set Cam Max Range in ZM=2
$Param = floatval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `zoom_model`=2, `max_range`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-22'; break; }; case 23:{ // Set Cam Zoom PERC in ZM=2
$Param = floatval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `zoom_model`=2, `zoom`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-23'; break; }; case 24:{ $Param = intval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `manual`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-24'; break; }; case 25:{ $Param = intval( $_POST['OPCODE'] ); if( $Param ){ $QS = "UPDATE `cameras` SET `homing_enable`=1 WHERE `id`={$CameraID}"; } else { $QS = "UPDATE `cameras` SET `homing_enable`=0 WHERE `id`={$CameraID}"; }; $DATABASE->Query( $QS ); $Data['status'] = 'ok-25'; break; }; case 26:{ $Param = intval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `homing_to`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-26'; break; }; case 27:{ // Set Camera Presets Mode
$QS = "SELECT `id`, `type` FROM `nodes` WHERE `aux_id`={$CameraID} AND `type` IN (10,11,12,13,14,15)"; $NR = $DATABASE->Query( $QS ); $NODE = $NR[0]; $Param = intval( $_POST['OPCODE'] ); $NMODE = 0; if( $Param ){ switch( $NODE['type'] ){ case 11: $NMODE = 15; break; case 13: $NMODE = 14; break; }; } else { switch( $NODE['type'] ){ case 14: $NMODE = 13; break; case 15: $NMODE = 11; break; }; }; if( $NMODE ){ $QS = "UPDATE `nodes` SET `type`={$NMODE} WHERE `id`={$NODE['id']}"; $DATABASE->Query( $QS ); $QS = "UPDATE `cameras` SET `type`={$NMODE} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); }; $Data['status'] = 'ok-27'; break; }; case 28:{ $TArr = explode ( '_', $_POST['OPCODE'] ); $CCOL = intval( $TArr[0] ); $CROW = intval( $TArr[1] ); $QS = "SELECT * FROM `cameras_preset_sets` WHERE `camera_id`={$CameraID}"; $RV = $DATABASE->Query( $QS ); if( count( $RV ) == 0 ){ $QS = "INSERT INTO `cameras_preset_sets`(`camera_id`,`maxCount`,`p_segs`,`z_segs`) VALUES( {$CameraID},8,5,3"; $DATABASE->Query( $QS ); $QS = "SELECT * FROM `cameras_preset_sets` WHERE `camera_id`={$CameraID}"; $RV = $DATABASE->Query( $QS ); }; $PSS = $RV[0]; $QS = "SELECT `id`,`token` FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=1 AND `row`={$CROW} AND `column`={$CCOL}"; $RV = $DATABASE->Query( $QS ); $OID = 0; $TOKEN = ''; if( count( $RV ) ){ $OID = intval( $RV[0]['id'] ); $TOKEN = $RV[0]['token']; } else { $QS = "SELECT `token` FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=1 ORDER BY `token`"; $RV = $DATABASE->Query( $QS ); }; if( $OID || ( count( $RV ) < $PSS['maxCount'] ) ){ if( $TOKEN == '' ){ if( count( $RV ) ){ $TOKEN = ( intval( $RV[count( $RV )-1]['token'] ) + 1 ).''; } else { $TOKEN = '2'; }; }; // Set Camera Position Preset
require_once('../php/onvif/toto.php'); $onvif = new Ponvif(); $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}"; $JJ = $DATABASE->Query( $QS ); if( count( $JJ ) ){ $IP = $JJ[0]['ip']; $PORT = intval($JJ[0]['port']); $EUser = $JJ[0]['access_login']; $EPass = $JJ[0]['access_pass']; $AUTH = intval($JJ[0]['auth_mode']); try { $Data['status'] = 'try'; if( $PORT ){ $onvif->setIPAddress( $IP.':'.$PORT ); } else { $onvif->setIPAddress( $IP ); }; $onvif->setUsername( $EUser ); $onvif->setPassword( $EPass ); $onvif->setAuthMethod( $AUTH ); $onvif->initialize(); if ( !$onvif->isFault( $devices = $onvif->getSources())){ $TK = ''; $Data['status'] = 'notoken'; foreach( $devices[0] as $source ) if( is_array( $source ) ){ $TK = $source['profiletoken']; break; }; if( $TK == '' ) break; $Data['token'] = $TK; //$HTK = $JJ[0]['home_token'];
if( $OID ){ $onvif->ptz_RemovePreset( $TK, $TOKEN ); }; $onvif->ptz_SetPreset( $TK, $TOKEN ); if( $OID ){ $QS = "UPDATE `cameras_presets` SET `column`={$CCOL},`row`={$CROW} WHERE `id`={$OID}"; } else { $QS = "INSERT INTO `cameras_presets`(`preset_id`,`role`,`token`,`column`,`row`) VALUES({$CameraID},1,'{$TOKEN}',{$CCOL},{$CROW})"; }; $DATABASE->Query( $QS ); $Data['status'] = 'ok'; } else { $Data['msg'] = 'OnVif Query Device Fault!'; } } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
$Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() ); }; } else $Data['status'] = 'nocam'; } else $Data['status'] = 'nopresetspace'; break; }; case 29:{ $PID = intval( $_POST['OPCODE'] ); if( $PID ){ $QS = "SELECT `token` FROM `cameras_presets` WHERE `id`={$PID}"; $RR = $DATABASE->Query( $QS ); if( count( $RR ) ){ $TOKEN = $RR[0]['token']; // remove Camera Position Preset
require_once('../php/onvif/toto.php'); $onvif = new Ponvif(); $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}"; $JJ = $DATABASE->Query( $QS ); if( count( $JJ ) ){ $IP = $JJ[0]['ip']; $PORT = intval($JJ[0]['port']); $EUser = $JJ[0]['access_login']; $EPass = $JJ[0]['access_pass']; $AUTH = intval($JJ[0]['auth_mode']); try { $Data['status'] = 'try'; if( $PORT ){ $onvif->setIPAddress( $IP.':'.$PORT ); } else { $onvif->setIPAddress( $IP ); }; $onvif->setUsername( $EUser ); $onvif->setPassword( $EPass ); $onvif->setAuthMethod( $AUTH ); $onvif->initialize(); if ( !$onvif->isFault( $devices = $onvif->getSources())){ $TK = ''; $Data['status'] = 'notoken'; foreach( $devices[0] as $source ) if( is_array( $source ) ){ $TK = $source['profiletoken']; break; }; if( $TK == '' ) break; $Data['token'] = $TK; $onvif->ptz_RemovePreset( $TK, $TOKEN ); $QS = "DELETE FROM `cameras_presets` WHERE `id`={$PID}"; $RR = $DATABASE->Query( $QS ); $Data['status'] = 'ok'; } else { $Data['msg'] = 'OnVif Query Device Fault!'; } } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
$Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() ); }; } else $Data['status'] = 'nocam'; } else $Data['status'] = 'nopreset'; } else $Data['status'] = 'nocam'; break; }; case 30:{ $PID = intval( $_POST['OPCODE'] ); if( $PID ){ $QS = "SELECT `token` FROM `cameras_presets` WHERE `id`={$PID}"; $RR = $DATABASE->Query( $QS ); if( count( $RR ) ){ $TOKEN = $RR[0]['token']; // Set Camera Position Preset
require_once('../php/onvif/toto.php'); $onvif = new Ponvif(); $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}"; $JJ = $DATABASE->Query( $QS ); if( count( $JJ ) ){ $IP = $JJ[0]['ip']; $PORT = intval($JJ[0]['port']); $EUser = $JJ[0]['access_login']; $EPass = $JJ[0]['access_pass']; $AUTH = intval($JJ[0]['auth_mode']); try { $Data['status'] = 'try'; if( $PORT ){ $onvif->setIPAddress( $IP.':'.$PORT ); } else { $onvif->setIPAddress( $IP ); }; $onvif->setUsername( $EUser ); $onvif->setPassword( $EPass ); $onvif->setAuthMethod( $AUTH ); $onvif->initialize(); if ( !$onvif->isFault( $devices = $onvif->getSources())){ $TK = ''; $Data['status'] = 'notoken'; foreach( $devices[0] as $source ) if( is_array( $source ) ){ $TK = $source['profiletoken']; break; }; if( $TK == '' ) break; $Data['token'] = $TK; $Data['p_token'] = $TOKEN; $onvif->ptz_GotoPreset( $TK, $TOKEN, 1.0, 1.0, 1.0 ); $Data['status'] = 'ok'; } else { $Data['msg'] = 'OnVif Query Device Fault!'; } } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
$Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() ); }; } else $Data['status'] = 'nocam'; } else $Data['status'] = 'nopreset'; } else $Data['status'] = 'nocam'; break; }; case 31:{ //Set MaxPreset Count
$NCT = intval( $_POST['OPCODE'] ); if( $NCT ){ $QS = "UPDATE `cameras_preset_sets` SET `maxCount`={$NCT} WHERE `camera_id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok31'; }; break; }; case 32:{ //Set MaxColumnt Count
$NCT = intval( $_POST['OPCODE'] ); if( $NCT ){ $QS = "UPDATE `cameras_preset_sets` SET `p_segs`={$NCT} WHERE `camera_id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok32'; }; break; }; case 33:{ //Set MaxRow Count
$NCT = intval( $_POST['OPCODE'] ); if( $NCT ){ $QS = "UPDATE `cameras_preset_sets` SET `z_segs`={$NCT} WHERE `camera_id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok33'; }; break; }; case 34:{ //Delete all presets
$QS = "SELECT `id`,`token` FROM `cameras_presets` WHERE `role`=1 AND `preset_id`={$CameraID}"; $RR = $DATABASE->Query( $QS ); if( count( $RR ) ){ foreach( $RR as $R ){ $QS = "DELETE FROM `cameras_presets` WHERE `id`={$R['id']}"; $DATABASE->Query( $QS ); }; }; // Set Camera Position Preset
require_once('../php/onvif/toto.php'); $onvif = new Ponvif(); $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}"; $JJ = $DATABASE->Query( $QS ); if( count( $JJ ) ){ $IP = $JJ[0]['ip']; $PORT = intval($JJ[0]['port']); $EUser = $JJ[0]['access_login']; $EPass = $JJ[0]['access_pass']; $AUTH = intval($JJ[0]['auth_mode']); try { $Data['status'] = 'try'; if( $PORT ){ $onvif->setIPAddress( $IP.':'.$PORT ); } else { $onvif->setIPAddress( $IP ); }; $onvif->setUsername( $EUser ); $onvif->setPassword( $EPass ); $onvif->setAuthMethod( $AUTH ); $onvif->initialize(); if ( !$onvif->isFault( $devices = $onvif->getSources())){ $TK = ''; $Data['status'] = 'notoken'; foreach( $devices[0] as $source ) if( is_array( $source ) ){ $TK = $source['profiletoken']; break; }; if( $TK == '' ) break; $Data['token'] = $TK; for( $i=2; $i<32; $i++ ){ // '1' = token for home position
$CTT = $i.''; $onvif->ptz_RemovePreset( $TK, $CTT ); }; $Data['status'] = 'ok'; } else { $Data['msg'] = 'OnVif Query Device Fault!'; } } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
$Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() ); }; } else $Data['status'] = 'nocam'; break; }; case 35:{ //Set IR Off
$NCT = intval( $_POST['OPCODE'] ); $QS = "DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=5"; $DATABASE->Query( $QS ); if( $NCT ){ $QS = "REPLACE INTO `cameras_presets`( `preset_id`,`role`,`token`) VALUES ({$CameraID},5,'{$NCT}')"; $DATABASE->Query( $QS ); }; $Data['status'] = 'ok35'; break; }; case 36:{ //Set IR On
$NCT = intval( $_POST['OPCODE'] ); $QS = "DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=4"; $DATABASE->Query( $QS ); if( $NCT ){ $QS = "REPLACE INTO `cameras_presets`( `preset_id`,`role`,`token`) VALUES ({$CameraID},4,'{$NCT}')"; $DATABASE->Query( $QS ); }; $Data['status'] = 'ok36'; break; }; case 37:{ //Set IR Auto
$NCT = intval( $_POST['OPCODE'] ); $QS = "DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=3"; $DATABASE->Query( $QS ); if( $NCT ){ $QS = "REPLACE INTO `cameras_presets`( `preset_id`,`role`,`token`) VALUES ({$CameraID},3,'{$NCT}')"; $DATABASE->Query( $QS ); }; $Data['status'] = 'ok37'; break; }; case 38:{ //Set Wiper
$NCT = intval( $_POST['OPCODE'] ); $QS = "DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=6"; $DATABASE->Query( $QS ); if( $NCT ){ $QS = "REPLACE INTO `cameras_presets`( `preset_id`,`role`,`token`) VALUES ({$CameraID},6,'{$NCT}')"; $DATABASE->Query( $QS ); }; $Data['status'] = 'ok38'; break; }; case 39:{ //IR ECO Mode
$Param = intval( $_POST['OPCODE'] ); if( $Param ){ $QS = "UPDATE `cameras` SET `eco_ir`=1 WHERE `id`={$CameraID}"; } else { $QS = "UPDATE `cameras` SET `eco_ir`=0 WHERE `id`={$CameraID}"; }; $DATABASE->Query( $QS ); $Data['status'] = 'ok-39'; break; }; case 40:{ //Prefered Only Targets
$Param = intval( $_POST['OPCODE'] ); if( $Param ){ $QS = "UPDATE `cameras` SET `prefered_events_only`=1 WHERE `id`={$CameraID}"; } else { $QS = "UPDATE `cameras` SET `prefered_events_only`=0 WHERE `id`={$CameraID}"; }; $DATABASE->Query( $QS ); $Data['status'] = 'ok-39'; break; }; case 41:{ //Set Enable - Disable
// CamID == Node ID
$Param = intval( $_POST['OPCODE'] ); $QS = "UPDATE `nodes` SET `enable`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-41'; break; }; case 42:{ // Set Cam Zoom Model / Upgrade DB
$QS = "SELECT * FROM `cameras` WHERE `id`={$CameraID}"; $J = $DATABASE->Query( $QS ); if( count( $J ) ) if( !isset( $J[0]['flip_mode'] ) ){ $QS = "ALTER TABLE `cameras` ADD `flip_mode` INTEGER DEFAULT 0"; $DATABASE->Query( $QS ); }; $Param = intval( $_POST['OPCODE'] ); $QS = "UPDATE `cameras` SET `flip_mode`={$Param} WHERE `id`={$CameraID}"; $DATABASE->Query( $QS ); $Data['status'] = 'ok-42'; break; }; }; break; }; }; echo json_encode( $Data ); } else { header('location: /'); };?>
|