Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1186 lines
47 KiB

​
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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
5 months ago
​
​
​
4 years ago
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
5 months ago
4 years ago
5 months ago
4 years ago
5 months ago
4 years ago
​
​
​
​
​
5 months 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
5 months 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
5 months 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
​
​
​
5 months 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
​
​
​
​
​
​
​
5 months 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
​
​
​
​
5 months 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
5 months ago
​
​
​
​
​
​
5 months 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
5 months 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
5 months 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
​
​
5 months ago
​
5 months 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
5 months 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
​
5 months ago
5 months 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
5 months ago
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
2 years ago
​
​
​
​
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years 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
3 years ago
5 months ago
​
​
5 months ago
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
5 months ago
2 years ago
​
​
5 months ago
​
2 years 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years 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
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
​
​
​
3 years ago
3 years ago
3 years 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. require_once('../ajax_asm.php');
  3. /*
  4. Camera address model (as la_mojo reads it): `ip` = host only, `port` = ONVIF/HTTP port (NULL = 80),
  5. `onvif_ctrl` = path of the ONVIF device service. la_mojo builds http://ip[:port]onvif_ctrl.
  6. */
  7. // "1.2.3.4" / "1.2.3.4:8080" -> array( host, port ) - port 0 when not given
  8. function camSplitHostPort( $S ){
  9. $S = trim( $S );
  10. $P = 0;
  11. if( preg_match( '/^(.*):(\d{1,5})$/', $S, $M ) ){
  12. $S = $M[1];
  13. $P = intval( $M[2] );
  14. if( $P > 65535 ) $P = 0;
  15. };
  16. return array( $S, $P );
  17. };
  18. // ONVIF service URL or stored onvif_ctrl -> array( path, port ):
  19. // "http://1.2.3.4:8080/onvif/device_service" and ":8080/onvif/device_service" -> ( "/onvif/device_service", 8080 )
  20. function camOnvifPath( $U ){
  21. $U = trim( $U );
  22. $P = 0;
  23. if( preg_match( '#^[a-z]+://#i', $U ) ){
  24. $H = parse_url( $U );
  25. $P = isset( $H['port'] ) ? intval( $H['port'] ) : 0;
  26. $U = isset( $H['path'] ) ? $H['path'] : '/';
  27. } elseif( preg_match( '#^:(\d{1,5})(/.*)?$#', $U, $M ) ){
  28. $P = intval( $M[1] );
  29. $U = isset( $M[2] ) ? $M[2] : '/';
  30. };
  31. return array( $U, $P );
  32. };
  33. if( $CUser->Data['id'] > 1 ){
  34. $Data = array();
  35. $Data['status'] = 'na';
  36. if( isset( $_POST['CMD'] ) ){
  37. $CMD = intval( $_POST['CMD'] );
  38. } else $CMD = 0;
  39. if( isset( $_POST['CID'] ) ) {
  40. $CameraID = intval($_POST['CID']);
  41. } else $CameraID = 0;
  42. switch( $CMD ){
  43. case 0:{
  44. echo "CMD is 0";
  45. // List Discovered Cameras
  46. break;
  47. };
  48. case 1:{
  49. break;
  50. };
  51. case 2:{
  52. //Assign Camera to the system
  53. $QS ="SELECT * FROM `cameras` WHERE `id`={$CameraID}";
  54. $JJ = $DATABASE->Query( $QS );
  55. if( count( $JJ ) ){
  56. $CC = $JJ[0];
  57. $S_Stream = intval( $CC['stream_id'] );
  58. $S_PTZ = intval( $CC['protocol'] );
  59. if( $S_PTZ != 6 ){
  60. // Real Camera
  61. if( $S_Stream == 0 ){
  62. $QS = "SELECT `id`,`source_type` FROM `media_streams` WHERE `source_id`={$CameraID} LIMIT 1";
  63. } else {
  64. $QS = "SELECT `id`,`source_type` FROM `media_streams` WHERE `id`={$S_Stream}";
  65. };
  66. $SJ = $DATABASE->Query( $QS );
  67. if( count( $SJ ) ){
  68. $S_Stream = intval( $SJ[0]['id'] );
  69. $CT = $SJ[0]['source_type'];
  70. if( $CT == 'D' ){
  71. if( $S_PTZ ) $S_Type = 13; else $S_Type = 12;
  72. } else {
  73. if( $S_PTZ ) $S_Type = 11; else $S_Type = 10;
  74. };
  75. $S_Name = $CC['name'].'_'.$CameraID;
  76. $QS = "INSERT INTO `nodes`(`type`,`aux_id`,`aux_parameter`,`enable`,`name`) VALUES({$S_Type},{$CameraID},{$S_Stream}, 1,'{$S_Name}')";
  77. $DATABASE->Query( $QS );
  78. $QS = "UPDATE `cameras` SET `status`=3,`type`={$S_Type} WHERE `id`={$CameraID}";
  79. $DATABASE->Query( $QS );
  80. $Data['status'] = 'ok';
  81. };
  82. } else {
  83. $S_Name = $CC['name'].'_'.$CameraID;
  84. $QS = "INSERT INTO `nodes`(`type`,`aux_id`,`aux_parameter`,`enable`,`name`) VALUES(13,{$CameraID},0, 1,'{$S_Name}')";
  85. $DATABASE->Query( $QS );
  86. $QS = "UPDATE `cameras` SET `status`=3 WHERE `id`={$CameraID}";
  87. $DATABASE->Query( $QS );
  88. $Data['status'] = 'ok';
  89. };
  90. };
  91. break;
  92. };
  93. case 3:{
  94. if( intval( isset( $_POST['PR'] ) ? $_POST['PR'] : 0 ) == 0 ){ // PR missing = ONVIF (an undefined key warning broke the JSON)
  95. // Checkup Onvif Camera Credentials
  96. require_once('../php/onvif/toto.php');
  97. $EUser = $DATABASE->escape( $_POST['UU'] );
  98. $EPass = $DATABASE->escape( $_POST['PP'] );
  99. $AUTH = intval( $_POST['AU'] );
  100. $onvif = new Ponvif();
  101. $IP = '';
  102. $PORT = 0;
  103. if( $CameraID ){ // Cam From DB
  104. $QS ="SELECT `ip`,`port`,`onvif_ctrl` FROM `cameras` WHERE `id`={$CameraID}";
  105. $JJ = $DATABASE->Query( $QS );
  106. if( count( $JJ ) ){
  107. $IP = $JJ[0]['ip'];
  108. $PORT = intval($JJ[0]['port']);
  109. if( !$PORT ){
  110. // Older records keep the port in onvif_ctrl (":8080/onvif/device_service")
  111. list( $CTRL, $PORT ) = camOnvifPath( $JJ[0]['onvif_ctrl'] );
  112. };
  113. if( $PORT ){
  114. $onvif->setIPAddress( $IP.':'.$PORT );
  115. } else {
  116. $onvif->setIPAddress( $IP );
  117. };
  118. } else $CameraID = 0;
  119. } else { // Direct IP
  120. $Data['ss']='DirectIP';
  121. // "1.2.3.4:8080" or the Port field of the dialog (PO): a camera whose ONVIF interface is not on port 80
  122. list( $IP, $PORT ) = camSplitHostPort( $_POST['IP'] );
  123. $IP = $DATABASE->escape( $IP );
  124. if( !$PORT && isset( $_POST['PO'] ) ){
  125. $PORT = intval( $_POST['PO'] );
  126. if( $PORT < 1 || $PORT > 65535 ) $PORT = 0;
  127. };
  128. $onvif->setIPAddress( $IP ); // WS-Discovery probe goes to the host
  129. $RR = $onvif->discover();
  130. if( count( $RR ) ){
  131. $Data['ss']='Discover Have';
  132. $R= $RR[0];
  133. if(isset($R['EndpointReference'])){
  134. if(isset($R['EndpointReference']['Address'])){
  135. $TArr = explode( ':', $R['EndpointReference']['Address'] );
  136. $CA = $DATABASE->escape( $TArr[1] );
  137. $TArr = explode( ' ', $R['Scopes']);
  138. $CM = '';
  139. $CI = $DATABASE->escape($R['IPAddr']);
  140. $Frr = explode( ' ', $R['XAddrs']);
  141. // Path and port of the device service: the port was left inside onvif_ctrl (":8080/onvif/...")
  142. list( $CTRL, $XPORT ) = camOnvifPath( $Frr[0] );
  143. $CP = $DATABASE->escape( $CTRL );
  144. if( !$PORT ) $PORT = $XPORT; // a port typed by the user wins (NAT / port forwarding)
  145. $SPORT = $PORT ? $PORT : 'NULL';
  146. $CN = '';
  147. $CH = '';
  148. $CC = 0;
  149. foreach( $TArr as $T ){
  150. $TT = str_ireplace('onvif://www.onvif.org/','', $T );
  151. $TBrr = explode( '/', $TT );
  152. if( stripos($TBrr[0],'type') !== false ){
  153. if( stripos($TBrr[1],'video') !== false ) $CC |= 0x1;
  154. if( stripos($TBrr[1],'audio') !== false ) $CC |= 0x2;
  155. if( stripos($TBrr[1],'ptz') !== false ) $CC |= 0x4;
  156. };
  157. if( stripos($TBrr[0],'name') !== false ) $CN = $DATABASE->escape(urldecode($TBrr[1]));
  158. if( stripos($TBrr[0],'hardware') !== false ) $CH = $DATABASE->escape(urldecode($TBrr[1]));
  159. if( stripos($TBrr[0],'mac') !== false ) $CM = $DATABASE->escape(urldecode($TBrr[1]));
  160. };
  161. $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";
  162. $DATABASE->Query($QS,false);
  163. $CameraID = $DATABASE->getLastInsertID();
  164. if( $CameraID == 0 ){
  165. $QS = "SELECT `id` FROM `cameras` WHERE `uuid`='{$CA}'";
  166. $RV = $DATABASE->Query( $QS );
  167. if( count( $RV ) ) $CameraID = intval( $RV[0]['id']);
  168. };
  169. };
  170. };
  171. } else {
  172. $Data['ss'] .='No Discover';
  173. $onvif->setIPAddress( $PORT ? $IP.':'.$PORT : $IP );
  174. $onvif->setUsername( $EUser );
  175. $onvif->setPassword( $EPass );
  176. $onvif->setAuthMethod( $AUTH );
  177. $CI = $IP;
  178. $SPORT = $PORT ? $PORT : 'NULL';
  179. $CameraID = 0;
  180. try {
  181. $onvif->initialize();
  182. if ( !$onvif->isFault($info=$onvif->core_GetDeviceInformation())){
  183. //Adding Camera
  184. $CH = $info['Manufacturer'].'_'.$info['Model'];
  185. $CN = $info['Manufacturer'].'_CAM'.$info['HardwareId'];
  186. $CA = $info['SerialNumber'];
  187. $CM = $info['SerialNumber'];
  188. // getDeviceUri() returns the MEDIA service URL (full URL): la_mojo needs the device service path
  189. $CP = '/onvif/device_service';
  190. $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";
  191. $DATABASE->Query($QS,false);
  192. $CameraID = $DATABASE->getLastInsertID();
  193. };
  194. if( $CameraID ){
  195. if ( !$onvif->isFault($devices=$onvif->getSources()) ){
  196. $Data['ss'] .='No Fault';
  197. foreach( $devices[0] as $source ) if( is_array( $source ) ){
  198. //print_r( $source );
  199. $Ename = $DATABASE->escape( $source['profilename']);
  200. $Etoken = $DATABASE->escape( $source['profiletoken']);
  201. $Eencode = $DATABASE->escape( $source['encoding']);
  202. $Ewidth = intval($source['width']);
  203. $Eheight = intval($source['height']);
  204. $Efps = intval($source['fps']);
  205. $Ebitrate = intval($source['bitrate']);
  206. if( isset( $source['ptz'] ) ){
  207. $Eptz = $DATABASE->escape( $source['ptz']['nodetoken'] );
  208. } else {
  209. $Eptz='';
  210. };
  211. $mrl = $onvif->media_GetStreamUri($source['profiletoken']);
  212. $pic = $onvif->media_GetSnapshotUri($source['profiletoken']);
  213. $TPArr = explode(':',$mrl);
  214. $mrl_proto = $TPArr[0];
  215. $mrl_port = intval( $TPArr[2] );
  216. if( $mrl_port == 0 ) {
  217. switch( $mrl_proto ){
  218. case 'rtsp': $mrl_port = 554; break;
  219. case 'http': $mrl_port = 80; break;
  220. case 'https': $mrl_port = 443; break;
  221. };
  222. };
  223. $Emrl = $DATABASE->escape( $mrl );
  224. $Emrl = str_replace( $mrl_proto . '://' . $IP . ':' . $mrl_port, '', $Emrl );
  225. $Emrl = str_replace( $mrl_proto . '://' . $IP, '', $Emrl );
  226. $TPArr = explode(':',$pic );
  227. $pic_proto = $TPArr[0];
  228. if( count( $TPArr ) > 2 ){
  229. $pic_port = intval( $TPArr[2] );
  230. if($pic_port == 0 ) $pic_port = 80;
  231. } else $pic_port = 80;
  232. $Epic = $DATABASE->escape( $pic );
  233. $Epic = str_replace( $pic_proto . '://' . $IP . ':' . $pic_port, '', $Epic );
  234. $Epic = str_replace( $pic_proto . '://' . $IP , '', $Epic );
  235. $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}'";
  236. $Data['ss'] .='Added';
  237. $Data['QS'] = $QS;
  238. $DATABASE->Query( $QS, false );
  239. $Data['ss'] .='After DBQ';
  240. };
  241. $QS = "UPDATE cameras SET access_login='$EUser', access_pass='$EPass', auth_mode={$AUTH}, ptz_token='{$Eptz}', `status`=1 WHERE id={$CameraID}";
  242. $DATABASE->Query( $QS, false );
  243. $Data['status'] = 'ok';
  244. } else {
  245. $Data['msg'] = 'Camera was added.<br/>However provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']';
  246. };
  247. } else {
  248. $Data['msg'] = 'No Camera was added.<br/>';
  249. };
  250. } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
  251. $Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() );
  252. };
  253. break;
  254. };
  255. };
  256. if( $CameraID ){
  257. $Data['status'] = 'ok';
  258. if( $EUser!= '' ){
  259. if( $PORT ) $onvif->setIPAddress( $IP.':'.$PORT ); // not port 80
  260. $onvif->setUsername( $EUser );
  261. $onvif->setPassword( $EPass );
  262. $onvif->setAuthMethod( $AUTH );
  263. try {
  264. $onvif->initialize();
  265. if ( !$onvif->isFault($devices=$onvif->getSources())){
  266. foreach( $devices[0] as $source ) if( is_array( $source ) ){
  267. //print_r( $source );
  268. $Ename = $DATABASE->escape( $source['profilename']);
  269. $Etoken = $DATABASE->escape( $source['profiletoken']);
  270. $Eencode = $DATABASE->escape( $source['encoding']);
  271. $Ewidth = intval($source['width']);
  272. $Eheight = intval($source['height']);
  273. $Efps = intval($source['fps']);
  274. $Ebitrate = intval($source['bitrate']);
  275. if( isset( $source['ptz'] ) ){
  276. $Eptz = $DATABASE->escape( $source['ptz']['nodetoken'] );
  277. } else {
  278. $Eptz='';
  279. };
  280. $mrl = $onvif->media_GetStreamUri($source['profiletoken']);
  281. $pic = $onvif->media_GetSnapshotUri($source['profiletoken']);
  282. $TPArr = explode(':',$mrl);
  283. $mrl_proto = $TPArr[0];
  284. $mrl_port = intval( $TPArr[2] );
  285. if( $mrl_port == 0 ) {
  286. switch( $mrl_proto ){
  287. case 'rtsp': $mrl_port = 554; break;
  288. case 'http': $mrl_port = 80; break;
  289. case 'https': $mrl_port = 443; break;
  290. };
  291. };
  292. $Emrl = $DATABASE->escape( $mrl );
  293. $Emrl = str_replace( $mrl_proto . '://' . $IP . ':' . $mrl_port, '', $Emrl );
  294. $Emrl = str_replace( $mrl_proto . '://' . $IP, '', $Emrl );
  295. $TPArr = explode(':',$pic );
  296. $pic_proto = $TPArr[0];
  297. $pic_port = intval( $TPArr[2] );
  298. if($pic_port == 0 ) $pic_port = 80;
  299. $Epic = $DATABASE->escape( $pic );
  300. $Epic = str_replace( $pic_proto . '://' . $IP . ':' . $pic_port, '', $Epic );
  301. $Epic = str_replace( $pic_proto . '://' . $IP , '', $Epic );
  302. $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}'";
  303. $DATABASE->Query( $QS, false );
  304. };
  305. $QS = "UPDATE cameras SET access_login='$EUser', access_pass='$EPass', auth_mode={$AUTH}, ptz_token='{$Eptz}', `status`=1 WHERE id={$CameraID}";
  306. $DATABASE->Query( $QS, false );
  307. } else {
  308. $Data['status'] = 'error'; // the page shows msg only when status is not 'ok' (a failed check was silent)
  309. $Data['msg'] = 'Camera was added.<br/>However provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']';
  310. };
  311. } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
  312. $Data['status'] = 'error';
  313. $Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() );
  314. };
  315. } else {
  316. $Data['msg'] = 'Camera Sucessfully Added<br/>Please Provide Access Credentials and Other Camera Settings';
  317. };
  318. } else {
  319. $Data['status'] = 'error';
  320. $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>';
  321. };
  322. } else {
  323. //Bosch
  324. $EUser = $DATABASE->escape( $_POST['UU'] );
  325. $EPass = $DATABASE->escape( $_POST['PP'] );
  326. $IP = $DATABASE->escape( $_POST['IP'] );
  327. $AUTH = intval( $_POST['AU'] );
  328. $PORT = intval($_POST['PO']);
  329. $CN = 'CAMERA_' . $IP;
  330. $CP = '/rcp.xml';
  331. $UUID = md5( $CN );
  332. $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";
  333. $DATABASE->Query($QS,false);
  334. $CameraID = $DATABASE->getLastInsertID();
  335. $Data['status'] = 'ok';
  336. };
  337. break;
  338. };
  339. case 4:{
  340. // change IP/Credentials
  341. if( $CameraID ){
  342. $QS ="SELECT * FROM `cameras` WHERE `id`={$CameraID}";
  343. $JJ = $DATABASE->Query( $QS );
  344. if( count( $JJ ) ){
  345. $CC = $JJ[0];
  346. //$PA = explode( '/', $CC['onvif_ctrl'] );
  347. $EUser = $DATABASE->escape( $_POST['UU'] );
  348. $EPass = $DATABASE->escape( $_POST['PP'] );
  349. $EIP = $DATABASE->escape( $_POST['UI'] );
  350. //$PA[2] = $EIP;
  351. //$OVC = implode('/',$PA);
  352. $AUTH = intval( $_POST['AU'] );
  353. /*
  354. Before: an address without ":port" set port=NULL. The editor showed the IP without the
  355. port, so changing only the credentials moved a camera on 8080 back to port 80.
  356. Now: "ip:port" sets the port, "ip" keeps the stored one. A port kept inside onvif_ctrl
  357. (":8080/onvif/...", cameras added by discovery) is moved to `port`: with both, la_mojo
  358. built http://ip:8080:8080/onvif/...
  359. */
  360. list( $EIP, $POR ) = camSplitHostPort( $_POST['UI'] );
  361. $EIP = $DATABASE->escape( $EIP );
  362. list( $CTRL, $CTRL_PORT ) = camOnvifPath( $CC['onvif_ctrl'] );
  363. if( !$POR ) $POR = intval( $CC['port'] );
  364. if( !$POR ) $POR = $CTRL_PORT;
  365. $SPOR = $POR ? $POR : 'NULL';
  366. $ECTRL = $DATABASE->escape( $CTRL );
  367. $QS = "UPDATE cameras SET access_login='$EUser', access_pass='$EPass', auth_mode={$AUTH},`ip`='{$EIP}', port={$SPOR}, onvif_ctrl='{$ECTRL}' WHERE id={$CameraID}";
  368. $DATABASE->Query( $QS, false );
  369. $Data['status'] = 'ok';
  370. } else {
  371. $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>';
  372. };
  373. } else {
  374. $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>';
  375. };
  376. break;
  377. };
  378. case 5:{
  379. // Add Analog Video Stream Camera Manully
  380. };
  381. case 6:{
  382. // Register the Camera
  383. break;
  384. };
  385. case 7:{
  386. //Remove Camera
  387. $QS ="SELECT * FROM `cameras` WHERE `id`={$CameraID}";
  388. $RR = $DATABASE->Query( $QS );
  389. if( count ( $RR ) ){
  390. $CCD = $RR[0];
  391. $QS ="DELETE FROM `nodes` WHERE `type` IN (10,11,12,13,14,15) AND `aux_id`={$CameraID}";
  392. $DATABASE->Query( $QS );
  393. if( $CCD['type'] < 12 ){//Analog
  394. $QS="UPDATE `cameras` SET `status`=0 WHERE `id`={$CameraID}";
  395. $DATABASE->Query( $QS );
  396. } else { // IP
  397. $QS ="DELETE FROM `media_streams` WHERE `source_id`={$CameraID}";
  398. $DATABASE->Query( $QS );
  399. $QS ="DELETE FROM `cameras` WHERE `id`={$CameraID}";
  400. $DATABASE->Query( $QS );
  401. };
  402. $QS="DELETE FROM `cameras_preset_sets` WHERE `camera_id`={$CameraID}";
  403. $DATABASE->Query( $QS );
  404. $QS="DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID}";
  405. $DATABASE->Query( $QS );
  406. $Data['status'] = 'ok';
  407. };
  408. break;
  409. };
  410. case 8:{
  411. // Direct PTZ Controll
  412. //$QS = "SELECT `aux_id` FROM `nodes` WHERE `id`={$CameraID}";
  413. //$RR = $DATABASE->Query( $QS );
  414. //$CameraID = intval( $RR[0]['aux_id'] );
  415. if( $CameraID && isset( $_POST['MOV'] ) ){
  416. $CCC = intval( $_POST['MOV'] );
  417. switch( $CCC ){
  418. case 0: $ACMD = 0x01; break; //Stop
  419. case 10: $ACMD = 0x21; break; //Zoom In
  420. case 11: $ACMD = 0x41; break; //Zoom Out
  421. case 27: $ACMD = 0x03; break; // Right
  422. case 28: $ACMD = 0x13; break; // RD
  423. case 29: $ACMD = 0x11; break; // Down
  424. case 30: $ACMD = 0x15; break; // LD
  425. case 31: $ACMD = 0x05; break; // Left
  426. case 32: $ACMD = 0x0d; break; // LU
  427. case 33: $ACMD = 0x09; break; // Up
  428. case 34: $ACMD = 0x0B; break; // RU
  429. case 35: $ACMD = 0x82; break; // IR Off
  430. case 36: $ACMD = 0x81; break; // IR On
  431. case 37: $ACMD = 0x84; break; // Wiper
  432. case 38: $ACMD = 0x83; break; // IR Auto
  433. case 39: $ACMD = 0x85; break; // Set Home Preset Via Comntrol
  434. };
  435. echo $CameraID . " -> " .$ACMD;
  436. if( $ACMD ){
  437. $QS = "INSERT INTO `nodes_qcq`(`cmd`,`node_id`,`status`) VALUES ({$ACMD},{$CameraID},0)";
  438. @$MEMDB = new SQLite_DB( '/dev/shm/argus/mem_db.db');
  439. $MEMDB->Query( $QS );
  440. };
  441. };
  442. break;
  443. };
  444. case 9:{
  445. // Set Camera Home Preset
  446. require_once('../php/onvif/toto.php');
  447. $onvif = new Ponvif();
  448. $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}";
  449. $JJ = $DATABASE->Query( $QS );
  450. if( count( $JJ ) ){
  451. $IP = $JJ[0]['ip'];
  452. $PORT = intval($JJ[0]['port']);
  453. $EUser = $JJ[0]['access_login'];
  454. $EPass = $JJ[0]['access_pass'];
  455. $AUTH = intval($JJ[0]['auth_mode']);
  456. try {
  457. $Data['status'] = 'try';
  458. if( $PORT ){
  459. $onvif->setIPAddress( $IP.':'.$PORT );
  460. } else {
  461. $onvif->setIPAddress( $IP );
  462. };
  463. $onvif->setUsername( $EUser );
  464. $onvif->setPassword( $EPass );
  465. $onvif->setAuthMethod( $AUTH );
  466. $onvif->initialize();
  467. if ( !$onvif->isFault( $devices = $onvif->getSources())){
  468. $TK = '';
  469. $Data['status'] = 'notoken';
  470. foreach( $devices[0] as $source ) if( is_array( $source ) ){
  471. $TK = $source['profiletoken'];
  472. break;
  473. };
  474. if( $TK == '' ) break;
  475. $Data['token'] = $TK;
  476. $HTK = $JJ[0]['home_token'];
  477. if( $HTK!='' ){
  478. $onvif->ptz_RemovePreset( $TK, $HTK );
  479. };
  480. $HTK = '1';
  481. $onvif->ptz_SetPreset( $TK, $HTK );
  482. //Old Method (LA Metro)
  483. $QS = "UPDATE `cameras` SET `home_token` = '{$HTK}' WHERE `id`={$CameraID}";
  484. $DATABASE->Query( $QS );
  485. //New Presets mode
  486. $QS="DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=2";
  487. $DATABASE->Query( $QS );
  488. $QS = "INSERT INTO `cameras_presets`(`preset_id`,`role`,`token`,`column`,`row`) VALUES({$CameraID},2,'{$HTK}',0,0)";
  489. $DATABASE->Query( $QS );
  490. $Data['status'] = 'ok';
  491. } else {
  492. $Data['msg'] = 'OnVif Query Device Fault!';
  493. }
  494. } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
  495. $Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() );
  496. };
  497. } else {
  498. $Data['status'] = 'nocam';
  499. };
  500. break;
  501. };
  502. case 11:{
  503. // Direct PTZ Controll
  504. $QS = "SELECT `id` FROM `nodes` WHERE `type` IN (10,11,12,13,14,15) AND `aux_id`={$CameraID}";
  505. $RR = $DATABASE->Query( $QS );
  506. $NID = intval( $RR[0]['id'] );
  507. if( $NID && isset( $_POST['MOV'] ) ){
  508. $CCC = intval( $_POST['MOV'] );
  509. switch( $CCC ){
  510. case 0: $ACMD = 0x01; break; //Stop
  511. case 10: $ACMD = 0x21; break; //Zoom In
  512. case 11: $ACMD = 0x41; break; //Zoom Out
  513. case 27: $ACMD = 0x03; break; // Right
  514. case 28: $ACMD = 0x13; break; // RD
  515. case 29: $ACMD = 0x11; break; // Down
  516. case 30: $ACMD = 0x15; break; // LD
  517. case 31: $ACMD = 0x05; break; // Left
  518. case 32: $ACMD = 0x0d; break; // LU
  519. case 33: $ACMD = 0x09; break; // Up
  520. case 34: $ACMD = 0x0B; break; // RU
  521. case 35: $ACMD = 0x82; break; // IR Off
  522. case 36: $ACMD = 0x81; break; // IR On
  523. case 37: $ACMD = 0x84; break; // Wiper
  524. case 38: $ACMD = 0x83; break; // IR Auto
  525. case 39: $ACMD = 0x85; break; // Set Home Preset Via Comntrol
  526. };
  527. echo $NID . " -> " .$ACMD;
  528. if( $ACMD ){
  529. $QS = "INSERT INTO `nodes_qcq`(`cmd`,`node_id`,`status`) VALUES ({$ACMD},{$NID},0)";
  530. @$MEMDB = new SQLite_DB( '/dev/shm/argus/mem_db.db');
  531. $MEMDB->Query( $QS );
  532. };
  533. };
  534. break;
  535. };
  536. case 10:{
  537. //Additionall commands
  538. $OP = intval( $_POST['OPID'] );
  539. switch( $OP ){
  540. case 1:{
  541. //Bind Stream to Camera
  542. $Param = intval( $_POST['OPCODE'] );
  543. $QS = "SELECT * FROM `cameras` WHERE `id`={$CameraID}";
  544. $JJ = $DATABASE->Query( $QS );
  545. if( count( $JJ ) ){
  546. $CC = $JJ[0];
  547. if( $CC['status'] == 3 ){
  548. $QS = "UPDATE `nodes` SET `aux_parameter`={$Param} WHERE `aux_id`={$CameraID} AND `type` IN(10,11,12,13,14,15)";
  549. $DATABASE->Query( $QS );
  550. };
  551. $QS = "UPDATE `cameras` SET `stream_id`={$Param} WHERE `id`={$CameraID}";
  552. $DATABASE->Query( $QS );
  553. $Data['status'] = 'ok-1';
  554. };
  555. break;
  556. };
  557. case 2:{
  558. //Set Lens Parameter
  559. $Param = intval( $_POST['OPCODE'] );
  560. $QS = "UPDATE `cameras` SET `imager_type`={$Param} WHERE `id`={$CameraID}";
  561. $DATABASE->Query( $QS );
  562. $Data['status'] = 'ok-2';
  563. break;
  564. };
  565. case 3:{
  566. //Set Lens Parameter
  567. $Param = intval( $_POST['OPCODE'] );
  568. $QS = "UPDATE `cameras` SET `lens_f`={$Param} WHERE `id`={$CameraID}";
  569. $DATABASE->Query( $QS );
  570. $Data['status'] = 'ok-3';
  571. break;
  572. };
  573. case 4:{
  574. //Set Lens Parameter
  575. $Param = floatval( $_POST['OPCODE'] );
  576. if( $Param > 0 ){
  577. $ZM = 1;
  578. } else {
  579. $ZM = 0;
  580. };
  581. $QS = "UPDATE `cameras` SET `zoom`={$Param}, `zoom_model`={$ZM} WHERE `id`={$CameraID}";
  582. $DATABASE->Query( $QS );
  583. $Data['status'] = 'ok-4';
  584. break;
  585. };
  586. case 5:{
  587. // Set Protocol
  588. $Param = intval( $_POST['OPCODE'] );
  589. $QS = "SELECT `id`, `type` FROM `nodes` WHERE `aux_id`={$CameraID} AND `type` IN (10,11,12,13,14,15)";
  590. $NR = $DATABASE->Query( $QS );
  591. $NODE = $NR[0];
  592. $Param = intval( $_POST['OPCODE'] );
  593. $NMODE = 0;
  594. if( $Param ){
  595. switch( $NODE['type'] ){
  596. case 10: $NMODE = 11; break;
  597. case 12: $NMODE = 13; break;
  598. };
  599. } else {
  600. switch( $NODE['type'] ){
  601. case 11: $NMODE = 10; break;
  602. case 13: $NMODE = 12; break;
  603. case 14: $NMODE = 12; break;
  604. case 15: $NMODE = 12; break;
  605. };
  606. };
  607. if( $NMODE ){
  608. $QS = "UPDATE `nodes` SET `type`={$NMODE} WHERE `id`={$NODE['id']}";
  609. $DATABASE->Query( $QS );
  610. $QS = "UPDATE `cameras` SET `type`={$NMODE} WHERE `id`={$CameraID}";
  611. $DATABASE->Query( $QS );
  612. };
  613. $QS = "UPDATE `cameras` SET `protocol`={$Param} WHERE `id`={$CameraID}";
  614. $DATABASE->Query( $QS );
  615. $Data['status'] = 'ok-5';
  616. break;
  617. };
  618. case 6:{
  619. //Set Uart Parameter
  620. $QS = "SELECT `id` FROM `uart_settings` ORDER BY `id`";
  621. $JUJA = $DATABASE->Query( $QS );
  622. $Param = intval( $_POST['OPCODE'] );
  623. $RID = intval($JUJA[$Param]['id']);
  624. $QS = "UPDATE `cameras` SET `uart_id`={$RID} WHERE `id`={$CameraID}";
  625. $DATABASE->Query( $QS );
  626. $Data['status'] = 'ok-6';
  627. break;
  628. };
  629. case 7:{
  630. //Set Protocol Parameter
  631. $Param = intval( $_POST['OPCODE'] );
  632. $QS = "UPDATE `cameras` SET `protocol_aux`={$Param} WHERE `id`={$CameraID}";
  633. $DATABASE->Query( $QS );
  634. $Data['status'] = 'ok-7';
  635. break;
  636. };
  637. case 8:{
  638. $Param = intval( $_POST['OPCODE'] );
  639. $QS = "UPDATE `cameras` SET `pan_model`={$Param} WHERE `id`={$CameraID}";
  640. $DATABASE->Query( $QS );
  641. $Data['status'] = 'ok-8';
  642. break;
  643. };
  644. case 9:{
  645. $Param = intval( $_POST['OPCODE'] );
  646. $QS = "UPDATE `cameras` SET `pan_angles`={$Param} WHERE `id`={$CameraID}";
  647. $DATABASE->Query( $QS );
  648. $Data['status'] = 'ok-9';
  649. break;
  650. };
  651. case 10:{
  652. $Param = intval( $_POST['OPCODE'] );
  653. $QS = "UPDATE `cameras` SET `tilt_model`={$Param} WHERE `id`={$CameraID}";
  654. $DATABASE->Query( $QS );
  655. $Data['status'] = 'ok-10';
  656. break;
  657. };
  658. case 11:{
  659. $Param = intval( $_POST['OPCODE'] );
  660. $QS = "UPDATE `cameras` SET `tilt_angles`={$Param} WHERE `id`={$CameraID}";
  661. $DATABASE->Query( $QS );
  662. $Data['status'] = 'ok-11';
  663. break;
  664. };
  665. case 12:{
  666. $Param = intval( $_POST['OPCODE'] );
  667. $QS = "UPDATE `cameras` SET `trigger_mode`={$Param} WHERE `id`={$CameraID}";
  668. $DATABASE->Query( $QS );
  669. $Data['status'] = 'ok-12';
  670. break;
  671. };
  672. case 13:{
  673. $Param = intval( $_POST['OPCODE'] );
  674. $QS = "UPDATE `cameras` SET `ptz_axel`={$Param} WHERE `id`={$CameraID}";
  675. $DATABASE->Query( $QS );
  676. $Data['status'] = 'ok-13';
  677. break;
  678. };
  679. case 14:{
  680. $Param = floatval( $_POST['OPCODE'] );
  681. $QS = "UPDATE `cameras` SET `x_rot`={$Param} WHERE `id`={$CameraID}";
  682. $DATABASE->Query( $QS );
  683. $Data['status'] = 'ok-14';
  684. break;
  685. };
  686. case 15:{
  687. $Param = floatval( $_POST['OPCODE'] );
  688. $QS = "UPDATE `cameras` SET `y_rot`={$Param} WHERE `id`={$CameraID}";
  689. $DATABASE->Query( $QS );
  690. $Data['status'] = 'ok-15';
  691. break;
  692. };
  693. case 16:{
  694. $Param = floatval( $_POST['OPCODE'] );
  695. $QS = "UPDATE `cameras` SET `z_rot`={$Param} WHERE `id`={$CameraID}";
  696. $DATABASE->Query( $QS );
  697. $Data['status'] = 'ok-16';
  698. break;
  699. };
  700. case 17:{
  701. $Param = floatval( $_POST['OPCODE'] );
  702. $QS = "UPDATE `cameras` SET `x`={$Param} WHERE `id`={$CameraID}";
  703. $DATABASE->Query( $QS );
  704. $Data['status'] = 'ok-17';
  705. break;
  706. };
  707. case 18:{
  708. $Param = floatval( $_POST['OPCODE'] );
  709. $QS = "UPDATE `cameras` SET `y`={$Param} WHERE `id`={$CameraID}";
  710. $DATABASE->Query( $QS );
  711. $Data['status'] = 'ok-18';
  712. break;
  713. };
  714. case 19:{
  715. $Param = floatval( $_POST['OPCODE'] );
  716. $QS = "UPDATE `cameras` SET `z`={$Param} WHERE `id`={$CameraID}";
  717. $DATABASE->Query( $QS );
  718. $Data['status'] = 'ok-19';
  719. break;
  720. };
  721. case 20:{
  722. //Set Camera Name
  723. $Param = $DATABASE->escape( $_POST['OPCODE'] );
  724. $QS = "UPDATE `nodes` SET `name`='{$Param}' WHERE `type` IN (10,11,12,13,14,15) AND `aux_id`={$CameraID}";
  725. $DATABASE->Query( $QS );
  726. $Data['status'] = 'ok-20';
  727. break;
  728. };
  729. case 21:{
  730. // Set Cam Zoom Model
  731. $Param = intval( $_POST['OPCODE'] );
  732. $QS = "UPDATE `cameras` SET `zoom_model`={$Param} WHERE `id`={$CameraID}";
  733. $DATABASE->Query( $QS );
  734. $Data['status'] = 'ok-21';
  735. break;
  736. };
  737. case 22:{
  738. // Set Cam Max Range in ZM=2
  739. $Param = floatval( $_POST['OPCODE'] );
  740. $QS = "UPDATE `cameras` SET `zoom_model`=2, `max_range`={$Param} WHERE `id`={$CameraID}";
  741. $DATABASE->Query( $QS );
  742. $Data['status'] = 'ok-22';
  743. break;
  744. };
  745. case 23:{
  746. // Set Cam Zoom PERC in ZM=2
  747. $Param = floatval( $_POST['OPCODE'] );
  748. $QS = "UPDATE `cameras` SET `zoom_model`=2, `zoom`={$Param} WHERE `id`={$CameraID}";
  749. $DATABASE->Query( $QS );
  750. $Data['status'] = 'ok-23';
  751. break;
  752. };
  753. case 24:{
  754. $Param = intval( $_POST['OPCODE'] );
  755. $QS = "UPDATE `cameras` SET `manual`={$Param} WHERE `id`={$CameraID}";
  756. $DATABASE->Query( $QS );
  757. $Data['status'] = 'ok-24';
  758. break;
  759. };
  760. case 25:{
  761. $Param = intval( $_POST['OPCODE'] );
  762. if( $Param ){
  763. $QS = "UPDATE `cameras` SET `homing_enable`=1 WHERE `id`={$CameraID}";
  764. } else {
  765. $QS = "UPDATE `cameras` SET `homing_enable`=0 WHERE `id`={$CameraID}";
  766. };
  767. $DATABASE->Query( $QS );
  768. $Data['status'] = 'ok-25';
  769. break;
  770. };
  771. case 26:{
  772. $Param = intval( $_POST['OPCODE'] );
  773. $QS = "UPDATE `cameras` SET `homing_to`={$Param} WHERE `id`={$CameraID}";
  774. $DATABASE->Query( $QS );
  775. $Data['status'] = 'ok-26';
  776. break;
  777. };
  778. case 27:{
  779. // Set Camera Presets Mode
  780. $QS = "SELECT `id`, `type` FROM `nodes` WHERE `aux_id`={$CameraID} AND `type` IN (10,11,12,13,14,15)";
  781. $NR = $DATABASE->Query( $QS );
  782. $NODE = $NR[0];
  783. $Param = intval( $_POST['OPCODE'] );
  784. $NMODE = 0;
  785. if( $Param ){
  786. switch( $NODE['type'] ){
  787. case 11: $NMODE = 15; break;
  788. case 13: $NMODE = 14; break;
  789. };
  790. } else {
  791. switch( $NODE['type'] ){
  792. case 14: $NMODE = 13; break;
  793. case 15: $NMODE = 11; break;
  794. };
  795. };
  796. if( $NMODE ){
  797. $QS = "UPDATE `nodes` SET `type`={$NMODE} WHERE `id`={$NODE['id']}";
  798. $DATABASE->Query( $QS );
  799. $QS = "UPDATE `cameras` SET `type`={$NMODE} WHERE `id`={$CameraID}";
  800. $DATABASE->Query( $QS );
  801. };
  802. $Data['status'] = 'ok-27';
  803. break;
  804. };
  805. case 28:{
  806. $TArr = explode ( '_', $_POST['OPCODE'] );
  807. $CCOL = intval( $TArr[0] );
  808. $CROW = intval( $TArr[1] );
  809. $QS = "SELECT * FROM `cameras_preset_sets` WHERE `camera_id`={$CameraID}";
  810. $RV = $DATABASE->Query( $QS );
  811. if( count( $RV ) == 0 ){
  812. $QS = "INSERT INTO `cameras_preset_sets`(`camera_id`,`maxCount`,`p_segs`,`z_segs`) VALUES( {$CameraID},8,5,3";
  813. $DATABASE->Query( $QS );
  814. $QS = "SELECT * FROM `cameras_preset_sets` WHERE `camera_id`={$CameraID}";
  815. $RV = $DATABASE->Query( $QS );
  816. };
  817. $PSS = $RV[0];
  818. $QS = "SELECT `id`,`token` FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=1 AND `row`={$CROW} AND `column`={$CCOL}";
  819. $RV = $DATABASE->Query( $QS );
  820. $OID = 0;
  821. $TOKEN = '';
  822. if( count( $RV ) ){
  823. $OID = intval( $RV[0]['id'] );
  824. $TOKEN = $RV[0]['token'];
  825. } else {
  826. $QS = "SELECT `token` FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=1 ORDER BY `token`";
  827. $RV = $DATABASE->Query( $QS );
  828. };
  829. if( $OID || ( count( $RV ) < $PSS['maxCount'] ) ){
  830. if( $TOKEN == '' ){
  831. if( count( $RV ) ){
  832. $TOKEN = ( intval( $RV[count( $RV )-1]['token'] ) + 1 ).'';
  833. } else {
  834. $TOKEN = '2';
  835. };
  836. };
  837. // Set Camera Position Preset
  838. require_once('../php/onvif/toto.php');
  839. $onvif = new Ponvif();
  840. $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}";
  841. $JJ = $DATABASE->Query( $QS );
  842. if( count( $JJ ) ){
  843. $IP = $JJ[0]['ip'];
  844. $PORT = intval($JJ[0]['port']);
  845. $EUser = $JJ[0]['access_login'];
  846. $EPass = $JJ[0]['access_pass'];
  847. $AUTH = intval($JJ[0]['auth_mode']);
  848. try {
  849. $Data['status'] = 'try';
  850. if( $PORT ){
  851. $onvif->setIPAddress( $IP.':'.$PORT );
  852. } else {
  853. $onvif->setIPAddress( $IP );
  854. };
  855. $onvif->setUsername( $EUser );
  856. $onvif->setPassword( $EPass );
  857. $onvif->setAuthMethod( $AUTH );
  858. $onvif->initialize();
  859. if ( !$onvif->isFault( $devices = $onvif->getSources())){
  860. $TK = '';
  861. $Data['status'] = 'notoken';
  862. foreach( $devices[0] as $source ) if( is_array( $source ) ){
  863. $TK = $source['profiletoken'];
  864. break;
  865. };
  866. if( $TK == '' ) break;
  867. $Data['token'] = $TK;
  868. //$HTK = $JJ[0]['home_token'];
  869. if( $OID ){
  870. $onvif->ptz_RemovePreset( $TK, $TOKEN );
  871. };
  872. $onvif->ptz_SetPreset( $TK, $TOKEN );
  873. if( $OID ){
  874. $QS = "UPDATE `cameras_presets` SET `column`={$CCOL},`row`={$CROW} WHERE `id`={$OID}";
  875. } else {
  876. $QS = "INSERT INTO `cameras_presets`(`preset_id`,`role`,`token`,`column`,`row`) VALUES({$CameraID},1,'{$TOKEN}',{$CCOL},{$CROW})";
  877. };
  878. $DATABASE->Query( $QS );
  879. $Data['status'] = 'ok';
  880. } else {
  881. $Data['msg'] = 'OnVif Query Device Fault!';
  882. }
  883. } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
  884. $Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() );
  885. };
  886. } else $Data['status'] = 'nocam';
  887. } else $Data['status'] = 'nopresetspace';
  888. break;
  889. };
  890. case 29:{
  891. $PID = intval( $_POST['OPCODE'] );
  892. if( $PID ){
  893. $QS = "SELECT `token` FROM `cameras_presets` WHERE `id`={$PID}";
  894. $RR = $DATABASE->Query( $QS );
  895. if( count( $RR ) ){
  896. $TOKEN = $RR[0]['token'];
  897. // remove Camera Position Preset
  898. require_once('../php/onvif/toto.php');
  899. $onvif = new Ponvif();
  900. $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}";
  901. $JJ = $DATABASE->Query( $QS );
  902. if( count( $JJ ) ){
  903. $IP = $JJ[0]['ip'];
  904. $PORT = intval($JJ[0]['port']);
  905. $EUser = $JJ[0]['access_login'];
  906. $EPass = $JJ[0]['access_pass'];
  907. $AUTH = intval($JJ[0]['auth_mode']);
  908. try {
  909. $Data['status'] = 'try';
  910. if( $PORT ){
  911. $onvif->setIPAddress( $IP.':'.$PORT );
  912. } else {
  913. $onvif->setIPAddress( $IP );
  914. };
  915. $onvif->setUsername( $EUser );
  916. $onvif->setPassword( $EPass );
  917. $onvif->setAuthMethod( $AUTH );
  918. $onvif->initialize();
  919. if ( !$onvif->isFault( $devices = $onvif->getSources())){
  920. $TK = '';
  921. $Data['status'] = 'notoken';
  922. foreach( $devices[0] as $source ) if( is_array( $source ) ){
  923. $TK = $source['profiletoken'];
  924. break;
  925. };
  926. if( $TK == '' ) break;
  927. $Data['token'] = $TK;
  928. $onvif->ptz_RemovePreset( $TK, $TOKEN );
  929. $QS = "DELETE FROM `cameras_presets` WHERE `id`={$PID}";
  930. $RR = $DATABASE->Query( $QS );
  931. $Data['status'] = 'ok';
  932. } else {
  933. $Data['msg'] = 'OnVif Query Device Fault!';
  934. }
  935. } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
  936. $Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() );
  937. };
  938. } else $Data['status'] = 'nocam';
  939. } else $Data['status'] = 'nopreset';
  940. } else $Data['status'] = 'nocam';
  941. break;
  942. };
  943. case 30:{
  944. $PID = intval( $_POST['OPCODE'] );
  945. if( $PID ){
  946. $QS = "SELECT `token` FROM `cameras_presets` WHERE `id`={$PID}";
  947. $RR = $DATABASE->Query( $QS );
  948. if( count( $RR ) ){
  949. $TOKEN = $RR[0]['token'];
  950. // Set Camera Position Preset
  951. require_once('../php/onvif/toto.php');
  952. $onvif = new Ponvif();
  953. $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}";
  954. $JJ = $DATABASE->Query( $QS );
  955. if( count( $JJ ) ){
  956. $IP = $JJ[0]['ip'];
  957. $PORT = intval($JJ[0]['port']);
  958. $EUser = $JJ[0]['access_login'];
  959. $EPass = $JJ[0]['access_pass'];
  960. $AUTH = intval($JJ[0]['auth_mode']);
  961. try {
  962. $Data['status'] = 'try';
  963. if( $PORT ){
  964. $onvif->setIPAddress( $IP.':'.$PORT );
  965. } else {
  966. $onvif->setIPAddress( $IP );
  967. };
  968. $onvif->setUsername( $EUser );
  969. $onvif->setPassword( $EPass );
  970. $onvif->setAuthMethod( $AUTH );
  971. $onvif->initialize();
  972. if ( !$onvif->isFault( $devices = $onvif->getSources())){
  973. $TK = '';
  974. $Data['status'] = 'notoken';
  975. foreach( $devices[0] as $source ) if( is_array( $source ) ){
  976. $TK = $source['profiletoken'];
  977. break;
  978. };
  979. if( $TK == '' ) break;
  980. $Data['token'] = $TK;
  981. $Data['p_token'] = $TOKEN;
  982. $onvif->ptz_GotoPreset( $TK, $TOKEN, 1.0, 1.0, 1.0 );
  983. $Data['status'] = 'ok';
  984. } else {
  985. $Data['msg'] = 'OnVif Query Device Fault!';
  986. }
  987. } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
  988. $Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() );
  989. };
  990. } else $Data['status'] = 'nocam';
  991. } else $Data['status'] = 'nopreset';
  992. } else $Data['status'] = 'nocam';
  993. break;
  994. };
  995. case 31:{
  996. //Set MaxPreset Count
  997. $NCT = intval( $_POST['OPCODE'] );
  998. if( $NCT ){
  999. $QS = "UPDATE `cameras_preset_sets` SET `maxCount`={$NCT} WHERE `camera_id`={$CameraID}";
  1000. $DATABASE->Query( $QS );
  1001. $Data['status'] = 'ok31';
  1002. };
  1003. break;
  1004. };
  1005. case 32:{
  1006. //Set MaxColumnt Count
  1007. $NCT = intval( $_POST['OPCODE'] );
  1008. if( $NCT ){
  1009. $QS = "UPDATE `cameras_preset_sets` SET `p_segs`={$NCT} WHERE `camera_id`={$CameraID}";
  1010. $DATABASE->Query( $QS );
  1011. $Data['status'] = 'ok32';
  1012. };
  1013. break;
  1014. };
  1015. case 33:{
  1016. //Set MaxRow Count
  1017. $NCT = intval( $_POST['OPCODE'] );
  1018. if( $NCT ){
  1019. $QS = "UPDATE `cameras_preset_sets` SET `z_segs`={$NCT} WHERE `camera_id`={$CameraID}";
  1020. $DATABASE->Query( $QS );
  1021. $Data['status'] = 'ok33';
  1022. };
  1023. break;
  1024. };
  1025. case 34:{
  1026. //Delete all presets
  1027. $QS = "SELECT `id`,`token` FROM `cameras_presets` WHERE `role`=1 AND `preset_id`={$CameraID}";
  1028. $RR = $DATABASE->Query( $QS );
  1029. if( count( $RR ) ){
  1030. foreach( $RR as $R ){
  1031. $QS = "DELETE FROM `cameras_presets` WHERE `id`={$R['id']}";
  1032. $DATABASE->Query( $QS );
  1033. };
  1034. };
  1035. // Set Camera Position Preset
  1036. require_once('../php/onvif/toto.php');
  1037. $onvif = new Ponvif();
  1038. $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}";
  1039. $JJ = $DATABASE->Query( $QS );
  1040. if( count( $JJ ) ){
  1041. $IP = $JJ[0]['ip'];
  1042. $PORT = intval($JJ[0]['port']);
  1043. $EUser = $JJ[0]['access_login'];
  1044. $EPass = $JJ[0]['access_pass'];
  1045. $AUTH = intval($JJ[0]['auth_mode']);
  1046. try {
  1047. $Data['status'] = 'try';
  1048. if( $PORT ){
  1049. $onvif->setIPAddress( $IP.':'.$PORT );
  1050. } else {
  1051. $onvif->setIPAddress( $IP );
  1052. };
  1053. $onvif->setUsername( $EUser );
  1054. $onvif->setPassword( $EPass );
  1055. $onvif->setAuthMethod( $AUTH );
  1056. $onvif->initialize();
  1057. if ( !$onvif->isFault( $devices = $onvif->getSources())){
  1058. $TK = '';
  1059. $Data['status'] = 'notoken';
  1060. foreach( $devices[0] as $source ) if( is_array( $source ) ){
  1061. $TK = $source['profiletoken'];
  1062. break;
  1063. };
  1064. if( $TK == '' ) break;
  1065. $Data['token'] = $TK;
  1066. for( $i=2; $i<32; $i++ ){ // '1' = token for home position
  1067. $CTT = $i.'';
  1068. $onvif->ptz_RemovePreset( $TK, $CTT );
  1069. };
  1070. $Data['status'] = 'ok';
  1071. } else {
  1072. $Data['msg'] = 'OnVif Query Device Fault!';
  1073. }
  1074. } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
  1075. $Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() );
  1076. };
  1077. } else $Data['status'] = 'nocam';
  1078. break;
  1079. };
  1080. case 35:{
  1081. //Set IR Off
  1082. $NCT = intval( $_POST['OPCODE'] );
  1083. $QS = "DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=5";
  1084. $DATABASE->Query( $QS );
  1085. if( $NCT ){
  1086. $QS = "REPLACE INTO `cameras_presets`( `preset_id`,`role`,`token`) VALUES ({$CameraID},5,'{$NCT}')";
  1087. $DATABASE->Query( $QS );
  1088. };
  1089. $Data['status'] = 'ok35';
  1090. break;
  1091. };
  1092. case 36:{
  1093. //Set IR On
  1094. $NCT = intval( $_POST['OPCODE'] );
  1095. $QS = "DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=4";
  1096. $DATABASE->Query( $QS );
  1097. if( $NCT ){
  1098. $QS = "REPLACE INTO `cameras_presets`( `preset_id`,`role`,`token`) VALUES ({$CameraID},4,'{$NCT}')";
  1099. $DATABASE->Query( $QS );
  1100. };
  1101. $Data['status'] = 'ok36';
  1102. break;
  1103. };
  1104. case 37:{
  1105. //Set IR Auto
  1106. $NCT = intval( $_POST['OPCODE'] );
  1107. $QS = "DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=3";
  1108. $DATABASE->Query( $QS );
  1109. if( $NCT ){
  1110. $QS = "REPLACE INTO `cameras_presets`( `preset_id`,`role`,`token`) VALUES ({$CameraID},3,'{$NCT}')";
  1111. $DATABASE->Query( $QS );
  1112. };
  1113. $Data['status'] = 'ok37';
  1114. break;
  1115. };
  1116. case 38:{
  1117. //Set Wiper
  1118. $NCT = intval( $_POST['OPCODE'] );
  1119. $QS = "DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=6";
  1120. $DATABASE->Query( $QS );
  1121. if( $NCT ){
  1122. $QS = "REPLACE INTO `cameras_presets`( `preset_id`,`role`,`token`) VALUES ({$CameraID},6,'{$NCT}')";
  1123. $DATABASE->Query( $QS );
  1124. };
  1125. $Data['status'] = 'ok38';
  1126. break;
  1127. };
  1128. case 39:{
  1129. //IR ECO Mode
  1130. $Param = intval( $_POST['OPCODE'] );
  1131. if( $Param ){
  1132. $QS = "UPDATE `cameras` SET `eco_ir`=1 WHERE `id`={$CameraID}";
  1133. } else {
  1134. $QS = "UPDATE `cameras` SET `eco_ir`=0 WHERE `id`={$CameraID}";
  1135. };
  1136. $DATABASE->Query( $QS );
  1137. $Data['status'] = 'ok-39';
  1138. break;
  1139. };
  1140. case 40:{
  1141. //Prefered Only Targets
  1142. $Param = intval( $_POST['OPCODE'] );
  1143. if( $Param ){
  1144. $QS = "UPDATE `cameras` SET `prefered_events_only`=1 WHERE `id`={$CameraID}";
  1145. } else {
  1146. $QS = "UPDATE `cameras` SET `prefered_events_only`=0 WHERE `id`={$CameraID}";
  1147. };
  1148. $DATABASE->Query( $QS );
  1149. $Data['status'] = 'ok-39';
  1150. break;
  1151. };
  1152. case 41:{
  1153. //Set Enable - Disable
  1154. // CamID == Node ID
  1155. $Param = intval( $_POST['OPCODE'] );
  1156. $QS = "UPDATE `nodes` SET `enable`={$Param} WHERE `id`={$CameraID}";
  1157. $DATABASE->Query( $QS );
  1158. $Data['status'] = 'ok-41';
  1159. break;
  1160. };
  1161. case 42:{
  1162. // Set Cam Zoom Model / Upgrade DB
  1163. $QS = "SELECT * FROM `cameras` WHERE `id`={$CameraID}";
  1164. $J = $DATABASE->Query( $QS );
  1165. if( count( $J ) ) if( !isset( $J[0]['flip_mode'] ) ){
  1166. $QS = "ALTER TABLE `cameras` ADD `flip_mode` INTEGER DEFAULT 0";
  1167. $DATABASE->Query( $QS );
  1168. };
  1169. $Param = intval( $_POST['OPCODE'] );
  1170. $QS = "UPDATE `cameras` SET `flip_mode`={$Param} WHERE `id`={$CameraID}";
  1171. $DATABASE->Query( $QS );
  1172. $Data['status'] = 'ok-42';
  1173. break;
  1174. };
  1175. };
  1176. break;
  1177. };
  1178. };
  1179. echo json_encode( $Data );
  1180. } else {
  1181. header('location: /');
  1182. };
  1183. ?>