From 653049bab167da73183f25aee13e6473ce8a153f Mon Sep 17 00:00:00 2001 From: Chris Lawrence Date: Sat, 27 Jan 2024 23:29:40 +0000 Subject: [PATCH 1/2] ISAPI-merge --- README.md | 1 + dispatcher.php | 58 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c6e6ee8..3680837 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ This Web Application is a nice UI for all your hikvision cameras. It supports Lo * At the **SetEnv camNames** add a comma sepperated list of name the camera names which should be the same size as the camPaths. * At the **SetEnv camIPs** add a comma sepperated list of the IPs of each camera. * At the **SetEnv camAuths** add a comma sepperated list of the usernames/passwords for the authentication in this format: "admin:password" +* At the **SetEnv camVersions** *(optional)* add a comma sepperated list of whether the Hikvision/HiLook cameras are on newer firmware and need /ISAPI/ paths. 0 for old, 1 for ISAPI/new - like "0,1" for an old and new camera, or "1,1" for two new cameras. ### Dependencies diff --git a/dispatcher.php b/dispatcher.php index 434a54c..5deac4c 100644 --- a/dispatcher.php +++ b/dispatcher.php @@ -11,6 +11,7 @@ $camNames = explode(',', $_SERVER['camNames']); $camIPs = explode(',', $_SERVER['camIPs']); $camAuths = explode(',', $_SERVER['camAuths']); + $camVersions = explode(',', $_SERVER['camVersions'] ?? null); $action = $_REQUEST['action']; @@ -22,7 +23,7 @@ case 'login' : login(); break; case 'logout' : logout(); break; case 'usrStatus' : usrStatus(); break; - case 'videopicture' : videopicture($camIPs, $camAuths); break; + case 'videopicture' : videopicture($camIPs, $camAuths, $camVersions); break; default: echo "Not an Option"; break; } @@ -135,21 +136,64 @@ function getAllEvents($camPaths){ echo json_encode($allEvents); } - function videopicture($camIPs, $camAuths) + function videopicture($camIPs, $camAuths, $camVersions) { session_start(); if(isset($_SESSION['UserName'])){ if ( isset($_REQUEST['index']) ) { $camIndex = $_REQUEST['index']; header('Content-Type: image/jpeg'); - $url = 'http://'.$camAuths[$camIndex].'@'.$camIPs[$camIndex].'/Streaming/channels/102/picture'; - $fh = readfile($url); - echo $fh; + + if (($camVersions[$camIndex] ?? null) == 1) { + $ch = curl_init(); + $url = 'http://'.$camIPs[$camIndex].'/ISAPI/Streaming/Channels/101/picture'; + curl_setopt($ch, CURLOPT_URL, $url); + // curl_setopt($ch, CURLOPT_VERBOSE, true); + curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); + curl_setopt($ch, CURLOPT_USERPWD, $camAuths[$camIndex]); + + $result = curl_exec($ch); + if (curl_errno($ch)) { + error_log(curl_error($ch)); + } + curl_close($ch); + echo $result; + + } else { + $url = 'http://'.$camAuths[$camIndex].'@'.$camIPs[$camIndex].'/Streaming/channels/102/picture'; + $fh = readfile($url); + echo $fh; + } } else { $stack = new Imagick(); foreach ($camIPs as $index => $ip) { - $url = 'http://'.$camAuths[$index].'@'.$ip.'/Streaming/channels/102/picture'; - $image = file_get_contents($url); + + if (($camVersions[$index] ?? null) == 1) { + $ch = curl_init(); + $url = 'http://'.$camIPs[$camIndex].'/ISAPI/Streaming/Channels/101/picture'; + curl_setopt($ch, CURLOPT_URL, $url); + // curl_setopt($ch, CURLOPT_VERBOSE, true); + curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); + curl_setopt($ch, CURLOPT_USERPWD, $camAuths[$index]); + + $result = curl_exec($ch); + if (curl_errno($ch)) { + error_log(curl_error($ch)); + } + curl_close($ch); + $image = $result; + + } else { + $url = 'http://'.$camAuths[$index].'@'.$ip.'/Streaming/channels/102/picture'; + $image = file_get_contents($url); + } + $img = new Imagick(); $img->readImageBlob($image); $stack->addImage($img); From af3421594944503e60650851dca2f53fb523a409 Mon Sep 17 00:00:00 2001 From: ccrlawrence Date: Sat, 27 Jan 2024 23:42:19 +0000 Subject: [PATCH 2/2] Update dispatcher.php - incorrect index --- dispatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dispatcher.php b/dispatcher.php index 5deac4c..63850eb 100644 --- a/dispatcher.php +++ b/dispatcher.php @@ -173,7 +173,7 @@ function videopicture($camIPs, $camAuths, $camVersions) if (($camVersions[$index] ?? null) == 1) { $ch = curl_init(); - $url = 'http://'.$camIPs[$camIndex].'/ISAPI/Streaming/Channels/101/picture'; + $url = 'http://'.$ip.'/ISAPI/Streaming/Channels/101/picture'; curl_setopt($ch, CURLOPT_URL, $url); // curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);