Skip to content

Commit

Permalink
Merge pull request #8 from ccrlawrence/ISAPI-clean
Browse files Browse the repository at this point in the history
ISAPI Compatibility
  • Loading branch information
bkbilly authored Jan 28, 2024
2 parents 4f8187f + af34215 commit 53a2e5a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 51 additions & 7 deletions dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
$camNames = explode(',', $_SERVER['camNames']);
$camIPs = explode(',', $_SERVER['camIPs']);
$camAuths = explode(',', $_SERVER['camAuths']);
$camVersions = explode(',', $_SERVER['camVersions'] ?? null);


$action = $_REQUEST['action'];
Expand All @@ -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;
}

Expand Down Expand Up @@ -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://'.$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);
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);
Expand Down

0 comments on commit 53a2e5a

Please sign in to comment.