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
$QS="INSERT INTO `cameras`(hardware,type,name,uuid,mac,ip,status,onvif_ctrl,online,manual) VALUES('{$CH}',13,'{$CN}','{$CA}','{$CM}','{$CI}',0,'{$CP}',1,1) ON CONFLICT( uuid ) DO UPDATE SET ip='{$CI}', online=1";
$QS="INSERT INTO `cameras`(hardware,type,name,uuid,mac,ip,port,status,onvif_ctrl,online,manual) VALUES('{$CH}',13,'{$CN}','{$CA}','{$CM}','{$CI}',{$SPORT},0,'{$CP}',1,1) ON CONFLICT( uuid ) DO UPDATE SET ip='{$CI}', port={$SPORT}, onvif_ctrl='{$CP}', online=1";
$QS="INSERT INTO `cameras`(hardware,type,name,uuid,mac,ip,status,onvif_ctrl,online,manual) VALUES('{$CH}',13,'{$CN}','{$CA}','{$CM}','{$CI}',0,'{$CP}',1,1) ON CONFLICT( uuid ) DO UPDATE SET ip='{$CI}', online=1";
// getDeviceUri() returns the MEDIA service URL (full URL): la_mojo needs the device service path
$CP='/onvif/device_service';
$QS="INSERT INTO `cameras`(hardware,type,name,uuid,mac,ip,port,status,onvif_ctrl,online,manual) VALUES('{$CH}',13,'{$CN}','{$CA}','{$CM}','{$CI}',{$SPORT},0,'{$CP}',1,1) ON CONFLICT( uuid ) DO UPDATE SET ip='{$CI}', port={$SPORT}, onvif_ctrl='{$CP}', online=1";
$DATABASE->Query($QS,false);
$DATABASE->Query($QS,false);
$CameraID=$DATABASE->getLastInsertID();
$CameraID=$DATABASE->getLastInsertID();
};
};
@ -178,7 +226,7 @@
$Emrl=str_replace($mrl_proto.'://'.$IP,'',$Emrl);
$Emrl=str_replace($mrl_proto.'://'.$IP,'',$Emrl);
$TPArr=explode(':',$pic);
$TPArr=explode(':',$pic);
$pic_proto=$TPArr[0];
$pic_proto=$TPArr[0];
if(count($TPArr[0])>2){
if(count($TPArr)>2){
$pic_port=intval($TPArr[2]);
$pic_port=intval($TPArr[2]);
if($pic_port==0)$pic_port=80;
if($pic_port==0)$pic_port=80;
}else$pic_port=80;
}else$pic_port=80;
@ -209,6 +257,7 @@
if($CameraID){
if($CameraID){
$Data['status']='ok';
$Data['status']='ok';
if($EUser!=''){
if($EUser!=''){
if($PORT)$onvif->setIPAddress($IP.':'.$PORT);// not port 80
$onvif->setUsername($EUser);
$onvif->setUsername($EUser);
$onvif->setPassword($EPass);
$onvif->setPassword($EPass);
$onvif->setAuthMethod($AUTH);
$onvif->setAuthMethod($AUTH);
@ -300,16 +349,21 @@
//$PA[2] = $EIP;
//$PA[2] = $EIP;
//$OVC = implode('/',$PA);
//$OVC = implode('/',$PA);
$AUTH=intval($_POST['AU']);
$AUTH=intval($_POST['AU']);
$TAr=explode(':',$EIP);
if(count($TAr)>1){
$EIP=$TAr[0];
$POR=intval($TAr[1]);
//$QS = "UPDATE cameras SET access_login='$EUser', access_pass='$EPass', auth_mode={$AUTH},`ip`='{$EIP}',port={$POR}, onvif_ctrl='{$OVC}' WHERE id={$CameraID}";
$QS="UPDATE cameras SET access_login='$EUser', access_pass='$EPass', auth_mode={$AUTH},`ip`='{$EIP}',port={$POR} WHERE id={$CameraID}";
}else{
//$QS = "UPDATE cameras SET access_login='$EUser', access_pass='$EPass', auth_mode={$AUTH},`ip`='{$EIP}', port=NULL, onvif_ctrl='{$OVC}' WHERE id={$CameraID}";
$QS="UPDATE cameras SET access_login='$EUser', access_pass='$EPass', auth_mode={$AUTH},`ip`='{$EIP}', port=NULL WHERE id={$CameraID}";
$QS="UPDATE cameras SET access_login='$EUser', access_pass='$EPass', auth_mode={$AUTH},`ip`='{$EIP}', port={$SPOR}, onvif_ctrl='{$ECTRL}' WHERE id={$CameraID}";