diff --git a/tests/php/test_probe_views.php b/tests/php/test_probe_views.php index b1664e9c11..c37597457c 100644 --- a/tests/php/test_probe_views.php +++ b/tests/php/test_probe_views.php @@ -61,5 +61,22 @@ namespace { eval($m[0]); check("one detected entry keeps the choose text for $v", $$v[0], 'Choose'); } + + // probeProfiles() puts the credentials into the stream URL: none when there + // are none, and a username with reserved characters is encoded. + if (!preg_match('/^function probeProfiles\(.*?^\} \/\/ end function probeProfiles/ms', $op, $m)) { + echo "FAIL - probeProfiles() not found\n"; + exit(1); + } + function execONVIF($cmd, $log_cmd = null) { + return array('Profile_1, main, H264, 1920, 1080, 25, RTP-Unicast, rtsp://10.0.0.5:554/stream1'); + } + eval($m[0]); + $r = probeProfiles('http://10.0.0.5/onvif/device_service', '1', '', ''); + check('no credentials leave the stream URL without userinfo', $r[0]['Path'], 'rtsp://10.0.0.5:554/stream1'); + $r = probeProfiles('http://10.0.0.5/onvif/device_service', '1', 'ad@min', 'pw'); + check('username is URL encoded', $r[0]['Path'], 'rtsp://ad%40min:pw@10.0.0.5:554/stream1'); + $r = probeProfiles('http://10.0.0.5/onvif/device_service', '1', 'admin', ''); + check('username alone keeps the colon', $r[0]['Path'], 'rtsp://admin:@10.0.0.5:554/stream1'); exit($failures ? 1 : 0); } diff --git a/web/skins/classic/views/onvifprobe.php b/web/skins/classic/views/onvifprobe.php index ce8a0341f1..dcd95c3ee0 100644 --- a/web/skins/classic/views/onvifprobe.php +++ b/web/skins/classic/views/onvifprobe.php @@ -125,7 +125,12 @@ function probeProfiles($device_ep, $soapversion, $username, $password) { // decoded, which is also quite appropriate. However, that // also applies to the password sub-field of the Path // attribute. So, we must double encode the embedded password. - $stream_uri = $tokens[1].$username.':'.urlencode(urlencode($password)).'@'.$tokens[2]; + // Without credentials there is no userinfo at all: rtsp://:@host is not a valid URL. + $userinfo = ''; + if ((string)$username !== '' || (string)$password !== '') { + $userinfo = rawurlencode((string)$username).':'.urlencode(urlencode((string)$password)).'@'; + } + $stream_uri = $tokens[1].$userinfo.$tokens[2]; } ZM\Debug(print_r($matches, true));