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.

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