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.

1184 lines
46 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
​
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
​
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( $_POST['PR'] ) == 0 ){
  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['msg'] = 'Camera was added.<br/>However provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']';
  309. };
  310. } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
  311. $Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() );
  312. };
  313. } else {
  314. $Data['msg'] = 'Camera Sucessfully Added<br/>Please Provide Access Credentials and Other Camera Settings';
  315. };
  316. } else {
  317. $Data['status'] = 'error';
  318. $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>';
  319. };
  320. } else {
  321. //Bosch
  322. $EUser = $DATABASE->escape( $_POST['UU'] );
  323. $EPass = $DATABASE->escape( $_POST['PP'] );
  324. $IP = $DATABASE->escape( $_POST['IP'] );
  325. $AUTH = intval( $_POST['AU'] );
  326. $PORT = intval($_POST['PO']);
  327. $CN = 'CAMERA_' . $IP;
  328. $CP = '/rcp.xml';
  329. $UUID = md5( $CN );
  330. $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";
  331. $DATABASE->Query($QS,false);
  332. $CameraID = $DATABASE->getLastInsertID();
  333. $Data['status'] = 'ok';
  334. };
  335. break;
  336. };
  337. case 4:{
  338. // change IP/Credentials
  339. if( $CameraID ){
  340. $QS ="SELECT * FROM `cameras` WHERE `id`={$CameraID}";
  341. $JJ = $DATABASE->Query( $QS );
  342. if( count( $JJ ) ){
  343. $CC = $JJ[0];
  344. //$PA = explode( '/', $CC['onvif_ctrl'] );
  345. $EUser = $DATABASE->escape( $_POST['UU'] );
  346. $EPass = $DATABASE->escape( $_POST['PP'] );
  347. $EIP = $DATABASE->escape( $_POST['UI'] );
  348. //$PA[2] = $EIP;
  349. //$OVC = implode('/',$PA);
  350. $AUTH = intval( $_POST['AU'] );
  351. /*
  352. Before: an address without ":port" set port=NULL. The editor showed the IP without the
  353. port, so changing only the credentials moved a camera on 8080 back to port 80.
  354. Now: "ip:port" sets the port, "ip" keeps the stored one. A port kept inside onvif_ctrl
  355. (":8080/onvif/...", cameras added by discovery) is moved to `port`: with both, la_mojo
  356. built http://ip:8080:8080/onvif/...
  357. */
  358. list( $EIP, $POR ) = camSplitHostPort( $_POST['UI'] );
  359. $EIP = $DATABASE->escape( $EIP );
  360. list( $CTRL, $CTRL_PORT ) = camOnvifPath( $CC['onvif_ctrl'] );
  361. if( !$POR ) $POR = intval( $CC['port'] );
  362. if( !$POR ) $POR = $CTRL_PORT;
  363. $SPOR = $POR ? $POR : 'NULL';
  364. $ECTRL = $DATABASE->escape( $CTRL );
  365. $QS = "UPDATE cameras SET access_login='$EUser', access_pass='$EPass', auth_mode={$AUTH},`ip`='{$EIP}', port={$SPOR}, onvif_ctrl='{$ECTRL}' WHERE id={$CameraID}";
  366. $DATABASE->Query( $QS, false );
  367. $Data['status'] = 'ok';
  368. } else {
  369. $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>';
  370. };
  371. } else {
  372. $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>';
  373. };
  374. break;
  375. };
  376. case 5:{
  377. // Add Analog Video Stream Camera Manully
  378. };
  379. case 6:{
  380. // Register the Camera
  381. break;
  382. };
  383. case 7:{
  384. //Remove Camera
  385. $QS ="SELECT * FROM `cameras` WHERE `id`={$CameraID}";
  386. $RR = $DATABASE->Query( $QS );
  387. if( count ( $RR ) ){
  388. $CCD = $RR[0];
  389. $QS ="DELETE FROM `nodes` WHERE `type` IN (10,11,12,13,14,15) AND `aux_id`={$CameraID}";
  390. $DATABASE->Query( $QS );
  391. if( $CCD['type'] < 12 ){//Analog
  392. $QS="UPDATE `cameras` SET `status`=0 WHERE `id`={$CameraID}";
  393. $DATABASE->Query( $QS );
  394. } else { // IP
  395. $QS ="DELETE FROM `media_streams` WHERE `source_id`={$CameraID}";
  396. $DATABASE->Query( $QS );
  397. $QS ="DELETE FROM `cameras` WHERE `id`={$CameraID}";
  398. $DATABASE->Query( $QS );
  399. };
  400. $QS="DELETE FROM `cameras_preset_sets` WHERE `camera_id`={$CameraID}";
  401. $DATABASE->Query( $QS );
  402. $QS="DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID}";
  403. $DATABASE->Query( $QS );
  404. $Data['status'] = 'ok';
  405. };
  406. break;
  407. };
  408. case 8:{
  409. // Direct PTZ Controll
  410. //$QS = "SELECT `aux_id` FROM `nodes` WHERE `id`={$CameraID}";
  411. //$RR = $DATABASE->Query( $QS );
  412. //$CameraID = intval( $RR[0]['aux_id'] );
  413. if( $CameraID && isset( $_POST['MOV'] ) ){
  414. $CCC = intval( $_POST['MOV'] );
  415. switch( $CCC ){
  416. case 0: $ACMD = 0x01; break; //Stop
  417. case 10: $ACMD = 0x21; break; //Zoom In
  418. case 11: $ACMD = 0x41; break; //Zoom Out
  419. case 27: $ACMD = 0x03; break; // Right
  420. case 28: $ACMD = 0x13; break; // RD
  421. case 29: $ACMD = 0x11; break; // Down
  422. case 30: $ACMD = 0x15; break; // LD
  423. case 31: $ACMD = 0x05; break; // Left
  424. case 32: $ACMD = 0x0d; break; // LU
  425. case 33: $ACMD = 0x09; break; // Up
  426. case 34: $ACMD = 0x0B; break; // RU
  427. case 35: $ACMD = 0x82; break; // IR Off
  428. case 36: $ACMD = 0x81; break; // IR On
  429. case 37: $ACMD = 0x84; break; // Wiper
  430. case 38: $ACMD = 0x83; break; // IR Auto
  431. case 39: $ACMD = 0x85; break; // Set Home Preset Via Comntrol
  432. };
  433. echo $CameraID . " -> " .$ACMD;
  434. if( $ACMD ){
  435. $QS = "INSERT INTO `nodes_qcq`(`cmd`,`node_id`,`status`) VALUES ({$ACMD},{$CameraID},0)";
  436. @$MEMDB = new SQLite_DB( '/dev/shm/argus/mem_db.db');
  437. $MEMDB->Query( $QS );
  438. };
  439. };
  440. break;
  441. };
  442. case 9:{
  443. // Set Camera Home Preset
  444. require_once('../php/onvif/toto.php');
  445. $onvif = new Ponvif();
  446. $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}";
  447. $JJ = $DATABASE->Query( $QS );
  448. if( count( $JJ ) ){
  449. $IP = $JJ[0]['ip'];
  450. $PORT = intval($JJ[0]['port']);
  451. $EUser = $JJ[0]['access_login'];
  452. $EPass = $JJ[0]['access_pass'];
  453. $AUTH = intval($JJ[0]['auth_mode']);
  454. try {
  455. $Data['status'] = 'try';
  456. if( $PORT ){
  457. $onvif->setIPAddress( $IP.':'.$PORT );
  458. } else {
  459. $onvif->setIPAddress( $IP );
  460. };
  461. $onvif->setUsername( $EUser );
  462. $onvif->setPassword( $EPass );
  463. $onvif->setAuthMethod( $AUTH );
  464. $onvif->initialize();
  465. if ( !$onvif->isFault( $devices = $onvif->getSources())){
  466. $TK = '';
  467. $Data['status'] = 'notoken';
  468. foreach( $devices[0] as $source ) if( is_array( $source ) ){
  469. $TK = $source['profiletoken'];
  470. break;
  471. };
  472. if( $TK == '' ) break;
  473. $Data['token'] = $TK;
  474. $HTK = $JJ[0]['home_token'];
  475. if( $HTK!='' ){
  476. $onvif->ptz_RemovePreset( $TK, $HTK );
  477. };
  478. $HTK = '1';
  479. $onvif->ptz_SetPreset( $TK, $HTK );
  480. //Old Method (LA Metro)
  481. $QS = "UPDATE `cameras` SET `home_token` = '{$HTK}' WHERE `id`={$CameraID}";
  482. $DATABASE->Query( $QS );
  483. //New Presets mode
  484. $QS="DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=2";
  485. $DATABASE->Query( $QS );
  486. $QS = "INSERT INTO `cameras_presets`(`preset_id`,`role`,`token`,`column`,`row`) VALUES({$CameraID},2,'{$HTK}',0,0)";
  487. $DATABASE->Query( $QS );
  488. $Data['status'] = 'ok';
  489. } else {
  490. $Data['msg'] = 'OnVif Query Device Fault!';
  491. }
  492. } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
  493. $Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() );
  494. };
  495. } else {
  496. $Data['status'] = 'nocam';
  497. };
  498. break;
  499. };
  500. case 11:{
  501. // Direct PTZ Controll
  502. $QS = "SELECT `id` FROM `nodes` WHERE `type` IN (10,11,12,13,14,15) AND `aux_id`={$CameraID}";
  503. $RR = $DATABASE->Query( $QS );
  504. $NID = intval( $RR[0]['id'] );
  505. if( $NID && isset( $_POST['MOV'] ) ){
  506. $CCC = intval( $_POST['MOV'] );
  507. switch( $CCC ){
  508. case 0: $ACMD = 0x01; break; //Stop
  509. case 10: $ACMD = 0x21; break; //Zoom In
  510. case 11: $ACMD = 0x41; break; //Zoom Out
  511. case 27: $ACMD = 0x03; break; // Right
  512. case 28: $ACMD = 0x13; break; // RD
  513. case 29: $ACMD = 0x11; break; // Down
  514. case 30: $ACMD = 0x15; break; // LD
  515. case 31: $ACMD = 0x05; break; // Left
  516. case 32: $ACMD = 0x0d; break; // LU
  517. case 33: $ACMD = 0x09; break; // Up
  518. case 34: $ACMD = 0x0B; break; // RU
  519. case 35: $ACMD = 0x82; break; // IR Off
  520. case 36: $ACMD = 0x81; break; // IR On
  521. case 37: $ACMD = 0x84; break; // Wiper
  522. case 38: $ACMD = 0x83; break; // IR Auto
  523. case 39: $ACMD = 0x85; break; // Set Home Preset Via Comntrol
  524. };
  525. echo $NID . " -> " .$ACMD;
  526. if( $ACMD ){
  527. $QS = "INSERT INTO `nodes_qcq`(`cmd`,`node_id`,`status`) VALUES ({$ACMD},{$NID},0)";
  528. @$MEMDB = new SQLite_DB( '/dev/shm/argus/mem_db.db');
  529. $MEMDB->Query( $QS );
  530. };
  531. };
  532. break;
  533. };
  534. case 10:{
  535. //Additionall commands
  536. $OP = intval( $_POST['OPID'] );
  537. switch( $OP ){
  538. case 1:{
  539. //Bind Stream to Camera
  540. $Param = intval( $_POST['OPCODE'] );
  541. $QS = "SELECT * FROM `cameras` WHERE `id`={$CameraID}";
  542. $JJ = $DATABASE->Query( $QS );
  543. if( count( $JJ ) ){
  544. $CC = $JJ[0];
  545. if( $CC['status'] == 3 ){
  546. $QS = "UPDATE `nodes` SET `aux_parameter`={$Param} WHERE `aux_id`={$CameraID} AND `type` IN(10,11,12,13,14,15)";
  547. $DATABASE->Query( $QS );
  548. };
  549. $QS = "UPDATE `cameras` SET `stream_id`={$Param} WHERE `id`={$CameraID}";
  550. $DATABASE->Query( $QS );
  551. $Data['status'] = 'ok-1';
  552. };
  553. break;
  554. };
  555. case 2:{
  556. //Set Lens Parameter
  557. $Param = intval( $_POST['OPCODE'] );
  558. $QS = "UPDATE `cameras` SET `imager_type`={$Param} WHERE `id`={$CameraID}";
  559. $DATABASE->Query( $QS );
  560. $Data['status'] = 'ok-2';
  561. break;
  562. };
  563. case 3:{
  564. //Set Lens Parameter
  565. $Param = intval( $_POST['OPCODE'] );
  566. $QS = "UPDATE `cameras` SET `lens_f`={$Param} WHERE `id`={$CameraID}";
  567. $DATABASE->Query( $QS );
  568. $Data['status'] = 'ok-3';
  569. break;
  570. };
  571. case 4:{
  572. //Set Lens Parameter
  573. $Param = floatval( $_POST['OPCODE'] );
  574. if( $Param > 0 ){
  575. $ZM = 1;
  576. } else {
  577. $ZM = 0;
  578. };
  579. $QS = "UPDATE `cameras` SET `zoom`={$Param}, `zoom_model`={$ZM} WHERE `id`={$CameraID}";
  580. $DATABASE->Query( $QS );
  581. $Data['status'] = 'ok-4';
  582. break;
  583. };
  584. case 5:{
  585. // Set Protocol
  586. $Param = intval( $_POST['OPCODE'] );
  587. $QS = "SELECT `id`, `type` FROM `nodes` WHERE `aux_id`={$CameraID} AND `type` IN (10,11,12,13,14,15)";
  588. $NR = $DATABASE->Query( $QS );
  589. $NODE = $NR[0];
  590. $Param = intval( $_POST['OPCODE'] );
  591. $NMODE = 0;
  592. if( $Param ){
  593. switch( $NODE['type'] ){
  594. case 10: $NMODE = 11; break;
  595. case 12: $NMODE = 13; break;
  596. };
  597. } else {
  598. switch( $NODE['type'] ){
  599. case 11: $NMODE = 10; break;
  600. case 13: $NMODE = 12; break;
  601. case 14: $NMODE = 12; break;
  602. case 15: $NMODE = 12; break;
  603. };
  604. };
  605. if( $NMODE ){
  606. $QS = "UPDATE `nodes` SET `type`={$NMODE} WHERE `id`={$NODE['id']}";
  607. $DATABASE->Query( $QS );
  608. $QS = "UPDATE `cameras` SET `type`={$NMODE} WHERE `id`={$CameraID}";
  609. $DATABASE->Query( $QS );
  610. };
  611. $QS = "UPDATE `cameras` SET `protocol`={$Param} WHERE `id`={$CameraID}";
  612. $DATABASE->Query( $QS );
  613. $Data['status'] = 'ok-5';
  614. break;
  615. };
  616. case 6:{
  617. //Set Uart Parameter
  618. $QS = "SELECT `id` FROM `uart_settings` ORDER BY `id`";
  619. $JUJA = $DATABASE->Query( $QS );
  620. $Param = intval( $_POST['OPCODE'] );
  621. $RID = intval($JUJA[$Param]['id']);
  622. $QS = "UPDATE `cameras` SET `uart_id`={$RID} WHERE `id`={$CameraID}";
  623. $DATABASE->Query( $QS );
  624. $Data['status'] = 'ok-6';
  625. break;
  626. };
  627. case 7:{
  628. //Set Protocol Parameter
  629. $Param = intval( $_POST['OPCODE'] );
  630. $QS = "UPDATE `cameras` SET `protocol_aux`={$Param} WHERE `id`={$CameraID}";
  631. $DATABASE->Query( $QS );
  632. $Data['status'] = 'ok-7';
  633. break;
  634. };
  635. case 8:{
  636. $Param = intval( $_POST['OPCODE'] );
  637. $QS = "UPDATE `cameras` SET `pan_model`={$Param} WHERE `id`={$CameraID}";
  638. $DATABASE->Query( $QS );
  639. $Data['status'] = 'ok-8';
  640. break;
  641. };
  642. case 9:{
  643. $Param = intval( $_POST['OPCODE'] );
  644. $QS = "UPDATE `cameras` SET `pan_angles`={$Param} WHERE `id`={$CameraID}";
  645. $DATABASE->Query( $QS );
  646. $Data['status'] = 'ok-9';
  647. break;
  648. };
  649. case 10:{
  650. $Param = intval( $_POST['OPCODE'] );
  651. $QS = "UPDATE `cameras` SET `tilt_model`={$Param} WHERE `id`={$CameraID}";
  652. $DATABASE->Query( $QS );
  653. $Data['status'] = 'ok-10';
  654. break;
  655. };
  656. case 11:{
  657. $Param = intval( $_POST['OPCODE'] );
  658. $QS = "UPDATE `cameras` SET `tilt_angles`={$Param} WHERE `id`={$CameraID}";
  659. $DATABASE->Query( $QS );
  660. $Data['status'] = 'ok-11';
  661. break;
  662. };
  663. case 12:{
  664. $Param = intval( $_POST['OPCODE'] );
  665. $QS = "UPDATE `cameras` SET `trigger_mode`={$Param} WHERE `id`={$CameraID}";
  666. $DATABASE->Query( $QS );
  667. $Data['status'] = 'ok-12';
  668. break;
  669. };
  670. case 13:{
  671. $Param = intval( $_POST['OPCODE'] );
  672. $QS = "UPDATE `cameras` SET `ptz_axel`={$Param} WHERE `id`={$CameraID}";
  673. $DATABASE->Query( $QS );
  674. $Data['status'] = 'ok-13';
  675. break;
  676. };
  677. case 14:{
  678. $Param = floatval( $_POST['OPCODE'] );
  679. $QS = "UPDATE `cameras` SET `x_rot`={$Param} WHERE `id`={$CameraID}";
  680. $DATABASE->Query( $QS );
  681. $Data['status'] = 'ok-14';
  682. break;
  683. };
  684. case 15:{
  685. $Param = floatval( $_POST['OPCODE'] );
  686. $QS = "UPDATE `cameras` SET `y_rot`={$Param} WHERE `id`={$CameraID}";
  687. $DATABASE->Query( $QS );
  688. $Data['status'] = 'ok-15';
  689. break;
  690. };
  691. case 16:{
  692. $Param = floatval( $_POST['OPCODE'] );
  693. $QS = "UPDATE `cameras` SET `z_rot`={$Param} WHERE `id`={$CameraID}";
  694. $DATABASE->Query( $QS );
  695. $Data['status'] = 'ok-16';
  696. break;
  697. };
  698. case 17:{
  699. $Param = floatval( $_POST['OPCODE'] );
  700. $QS = "UPDATE `cameras` SET `x`={$Param} WHERE `id`={$CameraID}";
  701. $DATABASE->Query( $QS );
  702. $Data['status'] = 'ok-17';
  703. break;
  704. };
  705. case 18:{
  706. $Param = floatval( $_POST['OPCODE'] );
  707. $QS = "UPDATE `cameras` SET `y`={$Param} WHERE `id`={$CameraID}";
  708. $DATABASE->Query( $QS );
  709. $Data['status'] = 'ok-18';
  710. break;
  711. };
  712. case 19:{
  713. $Param = floatval( $_POST['OPCODE'] );
  714. $QS = "UPDATE `cameras` SET `z`={$Param} WHERE `id`={$CameraID}";
  715. $DATABASE->Query( $QS );
  716. $Data['status'] = 'ok-19';
  717. break;
  718. };
  719. case 20:{
  720. //Set Camera Name
  721. $Param = $DATABASE->escape( $_POST['OPCODE'] );
  722. $QS = "UPDATE `nodes` SET `name`='{$Param}' WHERE `type` IN (10,11,12,13,14,15) AND `aux_id`={$CameraID}";
  723. $DATABASE->Query( $QS );
  724. $Data['status'] = 'ok-20';
  725. break;
  726. };
  727. case 21:{
  728. // Set Cam Zoom Model
  729. $Param = intval( $_POST['OPCODE'] );
  730. $QS = "UPDATE `cameras` SET `zoom_model`={$Param} WHERE `id`={$CameraID}";
  731. $DATABASE->Query( $QS );
  732. $Data['status'] = 'ok-21';
  733. break;
  734. };
  735. case 22:{
  736. // Set Cam Max Range in ZM=2
  737. $Param = floatval( $_POST['OPCODE'] );
  738. $QS = "UPDATE `cameras` SET `zoom_model`=2, `max_range`={$Param} WHERE `id`={$CameraID}";
  739. $DATABASE->Query( $QS );
  740. $Data['status'] = 'ok-22';
  741. break;
  742. };
  743. case 23:{
  744. // Set Cam Zoom PERC in ZM=2
  745. $Param = floatval( $_POST['OPCODE'] );
  746. $QS = "UPDATE `cameras` SET `zoom_model`=2, `zoom`={$Param} WHERE `id`={$CameraID}";
  747. $DATABASE->Query( $QS );
  748. $Data['status'] = 'ok-23';
  749. break;
  750. };
  751. case 24:{
  752. $Param = intval( $_POST['OPCODE'] );
  753. $QS = "UPDATE `cameras` SET `manual`={$Param} WHERE `id`={$CameraID}";
  754. $DATABASE->Query( $QS );
  755. $Data['status'] = 'ok-24';
  756. break;
  757. };
  758. case 25:{
  759. $Param = intval( $_POST['OPCODE'] );
  760. if( $Param ){
  761. $QS = "UPDATE `cameras` SET `homing_enable`=1 WHERE `id`={$CameraID}";
  762. } else {
  763. $QS = "UPDATE `cameras` SET `homing_enable`=0 WHERE `id`={$CameraID}";
  764. };
  765. $DATABASE->Query( $QS );
  766. $Data['status'] = 'ok-25';
  767. break;
  768. };
  769. case 26:{
  770. $Param = intval( $_POST['OPCODE'] );
  771. $QS = "UPDATE `cameras` SET `homing_to`={$Param} WHERE `id`={$CameraID}";
  772. $DATABASE->Query( $QS );
  773. $Data['status'] = 'ok-26';
  774. break;
  775. };
  776. case 27:{
  777. // Set Camera Presets Mode
  778. $QS = "SELECT `id`, `type` FROM `nodes` WHERE `aux_id`={$CameraID} AND `type` IN (10,11,12,13,14,15)";
  779. $NR = $DATABASE->Query( $QS );
  780. $NODE = $NR[0];
  781. $Param = intval( $_POST['OPCODE'] );
  782. $NMODE = 0;
  783. if( $Param ){
  784. switch( $NODE['type'] ){
  785. case 11: $NMODE = 15; break;
  786. case 13: $NMODE = 14; break;
  787. };
  788. } else {
  789. switch( $NODE['type'] ){
  790. case 14: $NMODE = 13; break;
  791. case 15: $NMODE = 11; break;
  792. };
  793. };
  794. if( $NMODE ){
  795. $QS = "UPDATE `nodes` SET `type`={$NMODE} WHERE `id`={$NODE['id']}";
  796. $DATABASE->Query( $QS );
  797. $QS = "UPDATE `cameras` SET `type`={$NMODE} WHERE `id`={$CameraID}";
  798. $DATABASE->Query( $QS );
  799. };
  800. $Data['status'] = 'ok-27';
  801. break;
  802. };
  803. case 28:{
  804. $TArr = explode ( '_', $_POST['OPCODE'] );
  805. $CCOL = intval( $TArr[0] );
  806. $CROW = intval( $TArr[1] );
  807. $QS = "SELECT * FROM `cameras_preset_sets` WHERE `camera_id`={$CameraID}";
  808. $RV = $DATABASE->Query( $QS );
  809. if( count( $RV ) == 0 ){
  810. $QS = "INSERT INTO `cameras_preset_sets`(`camera_id`,`maxCount`,`p_segs`,`z_segs`) VALUES( {$CameraID},8,5,3";
  811. $DATABASE->Query( $QS );
  812. $QS = "SELECT * FROM `cameras_preset_sets` WHERE `camera_id`={$CameraID}";
  813. $RV = $DATABASE->Query( $QS );
  814. };
  815. $PSS = $RV[0];
  816. $QS = "SELECT `id`,`token` FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=1 AND `row`={$CROW} AND `column`={$CCOL}";
  817. $RV = $DATABASE->Query( $QS );
  818. $OID = 0;
  819. $TOKEN = '';
  820. if( count( $RV ) ){
  821. $OID = intval( $RV[0]['id'] );
  822. $TOKEN = $RV[0]['token'];
  823. } else {
  824. $QS = "SELECT `token` FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=1 ORDER BY `token`";
  825. $RV = $DATABASE->Query( $QS );
  826. };
  827. if( $OID || ( count( $RV ) < $PSS['maxCount'] ) ){
  828. if( $TOKEN == '' ){
  829. if( count( $RV ) ){
  830. $TOKEN = ( intval( $RV[count( $RV )-1]['token'] ) + 1 ).'';
  831. } else {
  832. $TOKEN = '2';
  833. };
  834. };
  835. // Set Camera Position Preset
  836. require_once('../php/onvif/toto.php');
  837. $onvif = new Ponvif();
  838. $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}";
  839. $JJ = $DATABASE->Query( $QS );
  840. if( count( $JJ ) ){
  841. $IP = $JJ[0]['ip'];
  842. $PORT = intval($JJ[0]['port']);
  843. $EUser = $JJ[0]['access_login'];
  844. $EPass = $JJ[0]['access_pass'];
  845. $AUTH = intval($JJ[0]['auth_mode']);
  846. try {
  847. $Data['status'] = 'try';
  848. if( $PORT ){
  849. $onvif->setIPAddress( $IP.':'.$PORT );
  850. } else {
  851. $onvif->setIPAddress( $IP );
  852. };
  853. $onvif->setUsername( $EUser );
  854. $onvif->setPassword( $EPass );
  855. $onvif->setAuthMethod( $AUTH );
  856. $onvif->initialize();
  857. if ( !$onvif->isFault( $devices = $onvif->getSources())){
  858. $TK = '';
  859. $Data['status'] = 'notoken';
  860. foreach( $devices[0] as $source ) if( is_array( $source ) ){
  861. $TK = $source['profiletoken'];
  862. break;
  863. };
  864. if( $TK == '' ) break;
  865. $Data['token'] = $TK;
  866. //$HTK = $JJ[0]['home_token'];
  867. if( $OID ){
  868. $onvif->ptz_RemovePreset( $TK, $TOKEN );
  869. };
  870. $onvif->ptz_SetPreset( $TK, $TOKEN );
  871. if( $OID ){
  872. $QS = "UPDATE `cameras_presets` SET `column`={$CCOL},`row`={$CROW} WHERE `id`={$OID}";
  873. } else {
  874. $QS = "INSERT INTO `cameras_presets`(`preset_id`,`role`,`token`,`column`,`row`) VALUES({$CameraID},1,'{$TOKEN}',{$CCOL},{$CROW})";
  875. };
  876. $DATABASE->Query( $QS );
  877. $Data['status'] = 'ok';
  878. } else {
  879. $Data['msg'] = 'OnVif Query Device Fault!';
  880. }
  881. } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
  882. $Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() );
  883. };
  884. } else $Data['status'] = 'nocam';
  885. } else $Data['status'] = 'nopresetspace';
  886. break;
  887. };
  888. case 29:{
  889. $PID = intval( $_POST['OPCODE'] );
  890. if( $PID ){
  891. $QS = "SELECT `token` FROM `cameras_presets` WHERE `id`={$PID}";
  892. $RR = $DATABASE->Query( $QS );
  893. if( count( $RR ) ){
  894. $TOKEN = $RR[0]['token'];
  895. // remove Camera Position Preset
  896. require_once('../php/onvif/toto.php');
  897. $onvif = new Ponvif();
  898. $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}";
  899. $JJ = $DATABASE->Query( $QS );
  900. if( count( $JJ ) ){
  901. $IP = $JJ[0]['ip'];
  902. $PORT = intval($JJ[0]['port']);
  903. $EUser = $JJ[0]['access_login'];
  904. $EPass = $JJ[0]['access_pass'];
  905. $AUTH = intval($JJ[0]['auth_mode']);
  906. try {
  907. $Data['status'] = 'try';
  908. if( $PORT ){
  909. $onvif->setIPAddress( $IP.':'.$PORT );
  910. } else {
  911. $onvif->setIPAddress( $IP );
  912. };
  913. $onvif->setUsername( $EUser );
  914. $onvif->setPassword( $EPass );
  915. $onvif->setAuthMethod( $AUTH );
  916. $onvif->initialize();
  917. if ( !$onvif->isFault( $devices = $onvif->getSources())){
  918. $TK = '';
  919. $Data['status'] = 'notoken';
  920. foreach( $devices[0] as $source ) if( is_array( $source ) ){
  921. $TK = $source['profiletoken'];
  922. break;
  923. };
  924. if( $TK == '' ) break;
  925. $Data['token'] = $TK;
  926. $onvif->ptz_RemovePreset( $TK, $TOKEN );
  927. $QS = "DELETE FROM `cameras_presets` WHERE `id`={$PID}";
  928. $RR = $DATABASE->Query( $QS );
  929. $Data['status'] = 'ok';
  930. } else {
  931. $Data['msg'] = 'OnVif Query Device Fault!';
  932. }
  933. } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
  934. $Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() );
  935. };
  936. } else $Data['status'] = 'nocam';
  937. } else $Data['status'] = 'nopreset';
  938. } else $Data['status'] = 'nocam';
  939. break;
  940. };
  941. case 30:{
  942. $PID = intval( $_POST['OPCODE'] );
  943. if( $PID ){
  944. $QS = "SELECT `token` FROM `cameras_presets` WHERE `id`={$PID}";
  945. $RR = $DATABASE->Query( $QS );
  946. if( count( $RR ) ){
  947. $TOKEN = $RR[0]['token'];
  948. // Set Camera Position Preset
  949. require_once('../php/onvif/toto.php');
  950. $onvif = new Ponvif();
  951. $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}";
  952. $JJ = $DATABASE->Query( $QS );
  953. if( count( $JJ ) ){
  954. $IP = $JJ[0]['ip'];
  955. $PORT = intval($JJ[0]['port']);
  956. $EUser = $JJ[0]['access_login'];
  957. $EPass = $JJ[0]['access_pass'];
  958. $AUTH = intval($JJ[0]['auth_mode']);
  959. try {
  960. $Data['status'] = 'try';
  961. if( $PORT ){
  962. $onvif->setIPAddress( $IP.':'.$PORT );
  963. } else {
  964. $onvif->setIPAddress( $IP );
  965. };
  966. $onvif->setUsername( $EUser );
  967. $onvif->setPassword( $EPass );
  968. $onvif->setAuthMethod( $AUTH );
  969. $onvif->initialize();
  970. if ( !$onvif->isFault( $devices = $onvif->getSources())){
  971. $TK = '';
  972. $Data['status'] = 'notoken';
  973. foreach( $devices[0] as $source ) if( is_array( $source ) ){
  974. $TK = $source['profiletoken'];
  975. break;
  976. };
  977. if( $TK == '' ) break;
  978. $Data['token'] = $TK;
  979. $Data['p_token'] = $TOKEN;
  980. $onvif->ptz_GotoPreset( $TK, $TOKEN, 1.0, 1.0, 1.0 );
  981. $Data['status'] = 'ok';
  982. } else {
  983. $Data['msg'] = 'OnVif Query Device Fault!';
  984. }
  985. } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
  986. $Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() );
  987. };
  988. } else $Data['status'] = 'nocam';
  989. } else $Data['status'] = 'nopreset';
  990. } else $Data['status'] = 'nocam';
  991. break;
  992. };
  993. case 31:{
  994. //Set MaxPreset Count
  995. $NCT = intval( $_POST['OPCODE'] );
  996. if( $NCT ){
  997. $QS = "UPDATE `cameras_preset_sets` SET `maxCount`={$NCT} WHERE `camera_id`={$CameraID}";
  998. $DATABASE->Query( $QS );
  999. $Data['status'] = 'ok31';
  1000. };
  1001. break;
  1002. };
  1003. case 32:{
  1004. //Set MaxColumnt Count
  1005. $NCT = intval( $_POST['OPCODE'] );
  1006. if( $NCT ){
  1007. $QS = "UPDATE `cameras_preset_sets` SET `p_segs`={$NCT} WHERE `camera_id`={$CameraID}";
  1008. $DATABASE->Query( $QS );
  1009. $Data['status'] = 'ok32';
  1010. };
  1011. break;
  1012. };
  1013. case 33:{
  1014. //Set MaxRow Count
  1015. $NCT = intval( $_POST['OPCODE'] );
  1016. if( $NCT ){
  1017. $QS = "UPDATE `cameras_preset_sets` SET `z_segs`={$NCT} WHERE `camera_id`={$CameraID}";
  1018. $DATABASE->Query( $QS );
  1019. $Data['status'] = 'ok33';
  1020. };
  1021. break;
  1022. };
  1023. case 34:{
  1024. //Delete all presets
  1025. $QS = "SELECT `id`,`token` FROM `cameras_presets` WHERE `role`=1 AND `preset_id`={$CameraID}";
  1026. $RR = $DATABASE->Query( $QS );
  1027. if( count( $RR ) ){
  1028. foreach( $RR as $R ){
  1029. $QS = "DELETE FROM `cameras_presets` WHERE `id`={$R['id']}";
  1030. $DATABASE->Query( $QS );
  1031. };
  1032. };
  1033. // Set Camera Position Preset
  1034. require_once('../php/onvif/toto.php');
  1035. $onvif = new Ponvif();
  1036. $QS ="SELECT `ip`,`port`, `access_login`, `access_pass`, `auth_mode`, `ptz_token`, `home_token` FROM `cameras` WHERE `id`={$CameraID}";
  1037. $JJ = $DATABASE->Query( $QS );
  1038. if( count( $JJ ) ){
  1039. $IP = $JJ[0]['ip'];
  1040. $PORT = intval($JJ[0]['port']);
  1041. $EUser = $JJ[0]['access_login'];
  1042. $EPass = $JJ[0]['access_pass'];
  1043. $AUTH = intval($JJ[0]['auth_mode']);
  1044. try {
  1045. $Data['status'] = 'try';
  1046. if( $PORT ){
  1047. $onvif->setIPAddress( $IP.':'.$PORT );
  1048. } else {
  1049. $onvif->setIPAddress( $IP );
  1050. };
  1051. $onvif->setUsername( $EUser );
  1052. $onvif->setPassword( $EPass );
  1053. $onvif->setAuthMethod( $AUTH );
  1054. $onvif->initialize();
  1055. if ( !$onvif->isFault( $devices = $onvif->getSources())){
  1056. $TK = '';
  1057. $Data['status'] = 'notoken';
  1058. foreach( $devices[0] as $source ) if( is_array( $source ) ){
  1059. $TK = $source['profiletoken'];
  1060. break;
  1061. };
  1062. if( $TK == '' ) break;
  1063. $Data['token'] = $TK;
  1064. for( $i=2; $i<32; $i++ ){ // '1' = token for home position
  1065. $CTT = $i.'';
  1066. $onvif->ptz_RemovePreset( $TK, $CTT );
  1067. };
  1068. $Data['status'] = 'ok';
  1069. } else {
  1070. $Data['msg'] = 'OnVif Query Device Fault!';
  1071. }
  1072. } catch( Throwable $e ){ // PHP 8 Errors too: an uncaught Error ended the request without an answer
  1073. $Data['msg'] = 'Provided Credentials are Wrong! ['.$EUser.']:['.$EPass.']<br/>'.htmlspecialchars( $e->getMessage() );
  1074. };
  1075. } else $Data['status'] = 'nocam';
  1076. break;
  1077. };
  1078. case 35:{
  1079. //Set IR Off
  1080. $NCT = intval( $_POST['OPCODE'] );
  1081. $QS = "DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=5";
  1082. $DATABASE->Query( $QS );
  1083. if( $NCT ){
  1084. $QS = "REPLACE INTO `cameras_presets`( `preset_id`,`role`,`token`) VALUES ({$CameraID},5,'{$NCT}')";
  1085. $DATABASE->Query( $QS );
  1086. };
  1087. $Data['status'] = 'ok35';
  1088. break;
  1089. };
  1090. case 36:{
  1091. //Set IR On
  1092. $NCT = intval( $_POST['OPCODE'] );
  1093. $QS = "DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=4";
  1094. $DATABASE->Query( $QS );
  1095. if( $NCT ){
  1096. $QS = "REPLACE INTO `cameras_presets`( `preset_id`,`role`,`token`) VALUES ({$CameraID},4,'{$NCT}')";
  1097. $DATABASE->Query( $QS );
  1098. };
  1099. $Data['status'] = 'ok36';
  1100. break;
  1101. };
  1102. case 37:{
  1103. //Set IR Auto
  1104. $NCT = intval( $_POST['OPCODE'] );
  1105. $QS = "DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=3";
  1106. $DATABASE->Query( $QS );
  1107. if( $NCT ){
  1108. $QS = "REPLACE INTO `cameras_presets`( `preset_id`,`role`,`token`) VALUES ({$CameraID},3,'{$NCT}')";
  1109. $DATABASE->Query( $QS );
  1110. };
  1111. $Data['status'] = 'ok37';
  1112. break;
  1113. };
  1114. case 38:{
  1115. //Set Wiper
  1116. $NCT = intval( $_POST['OPCODE'] );
  1117. $QS = "DELETE FROM `cameras_presets` WHERE `preset_id`={$CameraID} AND `role`=6";
  1118. $DATABASE->Query( $QS );
  1119. if( $NCT ){
  1120. $QS = "REPLACE INTO `cameras_presets`( `preset_id`,`role`,`token`) VALUES ({$CameraID},6,'{$NCT}')";
  1121. $DATABASE->Query( $QS );
  1122. };
  1123. $Data['status'] = 'ok38';
  1124. break;
  1125. };
  1126. case 39:{
  1127. //IR ECO Mode
  1128. $Param = intval( $_POST['OPCODE'] );
  1129. if( $Param ){
  1130. $QS = "UPDATE `cameras` SET `eco_ir`=1 WHERE `id`={$CameraID}";
  1131. } else {
  1132. $QS = "UPDATE `cameras` SET `eco_ir`=0 WHERE `id`={$CameraID}";
  1133. };
  1134. $DATABASE->Query( $QS );
  1135. $Data['status'] = 'ok-39';
  1136. break;
  1137. };
  1138. case 40:{
  1139. //Prefered Only Targets
  1140. $Param = intval( $_POST['OPCODE'] );
  1141. if( $Param ){
  1142. $QS = "UPDATE `cameras` SET `prefered_events_only`=1 WHERE `id`={$CameraID}";
  1143. } else {
  1144. $QS = "UPDATE `cameras` SET `prefered_events_only`=0 WHERE `id`={$CameraID}";
  1145. };
  1146. $DATABASE->Query( $QS );
  1147. $Data['status'] = 'ok-39';
  1148. break;
  1149. };
  1150. case 41:{
  1151. //Set Enable - Disable
  1152. // CamID == Node ID
  1153. $Param = intval( $_POST['OPCODE'] );
  1154. $QS = "UPDATE `nodes` SET `enable`={$Param} WHERE `id`={$CameraID}";
  1155. $DATABASE->Query( $QS );
  1156. $Data['status'] = 'ok-41';
  1157. break;
  1158. };
  1159. case 42:{
  1160. // Set Cam Zoom Model / Upgrade DB
  1161. $QS = "SELECT * FROM `cameras` WHERE `id`={$CameraID}";
  1162. $J = $DATABASE->Query( $QS );
  1163. if( count( $J ) ) if( !isset( $J[0]['flip_mode'] ) ){
  1164. $QS = "ALTER TABLE `cameras` ADD `flip_mode` INTEGER DEFAULT 0";
  1165. $DATABASE->Query( $QS );
  1166. };
  1167. $Param = intval( $_POST['OPCODE'] );
  1168. $QS = "UPDATE `cameras` SET `flip_mode`={$Param} WHERE `id`={$CameraID}";
  1169. $DATABASE->Query( $QS );
  1170. $Data['status'] = 'ok-42';
  1171. break;
  1172. };
  1173. };
  1174. break;
  1175. };
  1176. };
  1177. echo json_encode( $Data );
  1178. } else {
  1179. header('location: /');
  1180. };
  1181. ?>