From 64c00b69b0f9d269c022ff5b5438699b47ab6b31 Mon Sep 17 00:00:00 2001 From: Andriy Utkin Date: Thu, 29 Feb 2024 16:55:08 +0000 Subject: [PATCH] www/ajax/addip.php: rework postCheckOnvifPort() to use getRtspUrls.js and fall back to onvif_tool --- www/ajax/addip.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/www/ajax/addip.php b/www/ajax/addip.php index 13af5144..3c89acec 100644 --- a/www/ajax/addip.php +++ b/www/ajax/addip.php @@ -69,18 +69,25 @@ public function postCheckOnvifPort() $pass = Inp::post('pass'); $onvif_addr = $ip.":".$port; - $p = @popen("/usr/lib/bluecherry/onvif_tool \"{$onvif_addr}\" \"{$user}\" \"{$pass}\" get_stream_urls", "r"); - - if (!$p){ - data::responseJSON($stat, $msg); - exit; + $json_out = shell_exec("node /usr/share/bluecherry/onvif/getRtspUrls.js " . escapeshellarg($onvif_addr) .' '. escapeshellarg($user) .' '. escapeshellarg($pass)); + if ($json_out) { + $urls = json_decode($json_out, /*associative=*/true); + $main_stream = $urls[0]['rtspUri']; + $sub_stream = $urls[1]['rtspUri']; + } else { + $p = @popen("/usr/lib/bluecherry/onvif_tool " . escapeshellarg($onvif_addr) .' '. escapeshellarg($user) .' '. escapeshellarg($pass). " get_stream_urls", "r"); + + if (!$p){ + data::responseJSON($stat, $msg); + exit; + } + + $media_service = fgets($p); + $main_stream = fgets($p); + $sub_stream = fgets($p); + pclose($p); } - - $media_service = fgets($p); - $main_stream = fgets($p); - $sub_stream = fgets($p); - pclose($p); - if ($media_service && $main_stream){ + if ($main_stream) { $stat = 6; $msg = AIP_CHECK_ONVIF_SUCCESS;