fix: ONVIF probe decodes camera scope values before showing and saving them refs #7113

This commit is contained in:
Jash committed 2026-11-21 22:34:34 +05:30
1 parent de4e032e3c
commit b4ff465898
2 files changed
+38

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
<?php
// probeCameras() must URL decode the scope values of a WS-Discovery reply
// (onvif://www.onvif.org/name/Front%20Door arrives as name='Front%20Door').
//
// Run as: php tests/php/test_onvif_probe_scopes.php
namespace ZM {
function Debug($s) {}
function Error($s) {}
}
namespace {
$failures = 0;
function check($name, $got, $want) {
global $failures;
if ($got === $want) { echo " ok $name\n"; return; }
$failures++;
echo " FAIL $name\n got: ".var_export($got, true)."\n want: ".var_export($want, true)."\n";
}
function execONVIF($cmd, $log_cmd = null) {
return array("http://10.0.0.5/onvif/device_service, 1.2, (name='Front%20Door', hardware='AXIS%20M1065-L', location/city='Sao%20Paulo')");
}
$op = file_get_contents(__DIR__.'/../../web/skins/classic/views/onvifprobe.php');
if (!preg_match('/^function probeCameras\(.*?^\} \/\/ end function probeCameras/ms', $op, $m)) {
echo "FAIL - probeCameras() not found\n";
exit(1);
}
eval($m[0]);
$c = probeCameras('');
check('one camera parsed', count($c), 1);
check('name is decoded', $c[0]['monitor']['Name'], 'Front Door');
check('model is decoded', $c[0]['model'], 'AXIS M1065-L');
check('location note is decoded', $c[0]['monitor']['Notes'], "location/city=Sao Paulo\n");
exit($failures ? 1 : 0);
}
+2
View File
@@ -83,6 +83,8 @@ function probeCameras($localIp) {
);
foreach ( preg_split('|,\s*|', $matches[3]) as $attr_val ) {
if ( preg_match('|(.+)=\'(.*)\'|', $attr_val, $tokens) ) {
// Scope values are URI encoded in the WS-Discovery reply (AXIS%20M1065-L).
$tokens[2] = rawurldecode($tokens[2]);
if ( $tokens[1] == 'hardware' ) {
$camera['model'] = $tokens[2];
} else if ( $tokens[1] == 'name' ) {