From ad1df8f80a250c05cd8808e34bdd782a57f62592 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 21 Jun 2019 11:40:46 -0400 Subject: [PATCH] log the response if command fails, and add missing uthentication sections --- .../ZoneMinder/lib/ZoneMinder/Control/Netcat.pm | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Control/Netcat.pm b/scripts/ZoneMinder/lib/ZoneMinder/Control/Netcat.pm index 2d9573299..11d6ba9b3 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Control/Netcat.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Control/Netcat.pm @@ -96,8 +96,7 @@ sub open { $self->{state} = 'open'; } -sub parseControlAddress -{ +sub parseControlAddress { my $controlAddress = shift; my ($usernamepassword, $addressport) = split /@/, $controlAddress; if ( !defined $addressport ) { @@ -105,7 +104,7 @@ sub parseControlAddress $addressport = $usernamepassword; } else { my ($username , $password) = split /:/, $usernamepassword; - %identity = (username => "$username", password => "$password"); + %identity = (username => $username, password => $password); } ($address, $port) = split /:/, $addressport; } @@ -118,12 +117,11 @@ sub digestBase64 return encode_base64($shaGenerator->digest, ""); } -sub authentificationHeader -{ +sub authentificationHeader { my ($username, $password) = @_; my $nonce; $nonce .= chr(int(rand(254))) for (0 .. 20); - my $nonceBase64 = encode_base64($nonce, ""); + my $nonceBase64 = encode_base64($nonce, ''); my $currentDate = DateTime->now()->iso8601().'Z'; return '' . $username . '' . digestBase64($nonce, $currentDate, $password) . '' . $nonceBase64 . '' . $currentDate . ''; @@ -160,7 +158,7 @@ sub sendCmd { if ( $res->is_success ) { $result = !undef; } else { - Error("After sending PTZ command, camera returned the following error:'".$res->status_line()."'"); + Error("After sending PTZ command, camera returned the following error:'".$res->status_line()."'\nMSG:$msg\nResponse:".$res->content); } return $result; } @@ -236,7 +234,7 @@ sub moveConDown { Debug('Move Down'); my $self = shift; my $cmd = 'onvif/PTZ'; - my $msg ='' . $profileToken . ''; + my $msg =''.((%identity) ? authentificationHeader($identity{username}, $identity{password}) : '').'' . $profileToken . ''; my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"'; $self->sendCmd($cmd, $msg, $content_type); $self->autoStop($self->{Monitor}->{AutoStopTimeout}); @@ -316,7 +314,7 @@ sub moveConUpLeft { Debug('Move Diagonally Up Left'); my $self = shift; my $cmd = 'onvif/PTZ'; - my $msg ='' . $profileToken . ''; + my $msg =''.((%identity) ? authentificationHeader($identity{username}, $identity{password}) : '').'' . $profileToken . ''; my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"'; $self->sendCmd($cmd, $msg, $content_type); $self->autoStop($self->{Monitor}->{AutoStopTimeout});