From 57ec710fb2765f2d53d67fe1ca5f4099544a0955 Mon Sep 17 00:00:00 2001 From: Andriy Utkin Date: Thu, 29 Feb 2024 14:46:41 +0000 Subject: [PATCH] www/ajax/discoverCameras.php: rework postAdd() to use getRtspUrls.js and fall back to onvif_tool --- www/ajax/discoverCameras.php | 38 ++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/www/ajax/discoverCameras.php b/www/ajax/discoverCameras.php index 012f7787..89542c5d 100644 --- a/www/ajax/discoverCameras.php +++ b/www/ajax/discoverCameras.php @@ -313,24 +313,32 @@ public function postAdd() foreach ($passwords as $pass_arr) { foreach ($pass_arr as $login => $password) { $onvif_username = $login; - $onvif_password = $password; + $onvif_password = $password; + try { - $p = @popen("/usr/lib/bluecherry/onvif_tool \"{$onvif_addr}\" \"{$onvif_username}\" \"{$onvif_password}\" get_stream_urls", "r"); - if (!$p) - break; - - $media_service = fgets($p); - if (!$media_service) - { - $err['onvif_ip'][] = $ip; - break(2); - } - $main_stream = fgets($p); - $sub_stream = fgets($p); - pclose($p); + $json_out = shell_exec("node /usr/lib/bluecherry/getRtspUrls.js {$escaleshellarg($onvif_addr)} {$escaleshellarg($onvif_username)} {$escaleshellarg($onvif_password)}"); + if ($json_out) { + $urls = json_decode($json_out); + $main_stream = urls[0].rtspUri; + $sub_stream = urls[1].rtspUri; + } else { + $p = @popen("/usr/lib/bluecherry/onvif_tool {$escaleshellarg($onvif_addr)} {$escaleshellarg($onvif_username)} {$escaleshellarg($onvif_password)} get_stream_urls", "r"); + if (!$p) + break; + + $media_service = fgets($p); + if (!$media_service) + { + $err['onvif_ip'][] = $ip; + break(2); + } + $main_stream = fgets($p); + $sub_stream = fgets($p); + pclose($p); + } if ($main_stream) - { + { $password_ch = true; $media_uri = trim($main_stream);