Fix auth not getting realm from auth headers due to them being an array now. Get auth and ip from Path if not set in ControlAddress.
This commit is contained in:
parent
3ee649406c
commit
4a51253aa9
|
@ -51,11 +51,21 @@ sub open {
|
|||
my $self = shift;
|
||||
|
||||
$self->loadMonitor();
|
||||
|
||||
if ($self->{Monitor}->{ControlAddress} and ($self->{Monitor}->{ControlAddress} ne 'user:pass@ip')) {
|
||||
Debug("Getting connection details from Control Address " . $self->{Monitor}->{ControlAddress});
|
||||
if ( $self->{Monitor}->{ControlAddress} !~ /^\w+:\/\// ) {
|
||||
# Has no scheme at the beginning, so won't parse as a URI
|
||||
$self->{Monitor}->{ControlAddress} = 'http://'.$self->{Monitor}->{ControlAddress};
|
||||
}
|
||||
$uri = URI->new($self->{Monitor}->{ControlAddress});
|
||||
} elsif ($self->{Monitor}->{Path}) {
|
||||
Debug("Getting connection details from Path " . $self->{Monitor}->{Path});
|
||||
$uri = URI->new($self->{Monitor}->{Path});
|
||||
$uri->scheme('http');
|
||||
$uri->port(80);
|
||||
$uri->path('');
|
||||
}
|
||||
|
||||
use LWP::UserAgent;
|
||||
$self->{ua} = LWP::UserAgent->new;
|
||||
|
@ -64,6 +74,7 @@ sub open {
|
|||
$self->{state} = 'closed';
|
||||
|
||||
my ( $username, $password, $host ) = ( $uri->authority() =~ /^([^:]+):([^@]*)@(.+)$/ );
|
||||
Debug("Have username: $username password: $password host: $host from authority:" . $uri->authority());
|
||||
|
||||
$uri->userinfo(undef);
|
||||
|
||||
|
@ -82,16 +93,22 @@ sub open {
|
|||
$self->{state} = 'open';
|
||||
return;
|
||||
}
|
||||
if ($res->status_line() eq '404 Not Found') {
|
||||
#older style
|
||||
$url = 'axis-cgi/com/ptz.cgi';
|
||||
$res = $self->{ua}->get($uri->canonical().$url);
|
||||
Debug("Result from getting ".$uri->canonical().$url . ':' . $res->status_line());
|
||||
}
|
||||
|
||||
if ($res->status_line() eq '401 Unauthorized') {
|
||||
|
||||
my $headers = $res->headers();
|
||||
foreach my $k ( keys %$headers ) {
|
||||
Debug("Initial Header $k => $$headers{$k}");
|
||||
}
|
||||
|
||||
if ( $$headers{'www-authenticate'} ) {
|
||||
my ( $auth, $tokens ) = $$headers{'www-authenticate'} =~ /^(\w+)\s+(.*)$/;
|
||||
foreach my $auth_header ( ref $$headers{'www-authenticate'} eq 'ARRAY' ? @{$$headers{'www-authenticate'}} : ($$headers{'www-authenticate'})) {
|
||||
my ( $auth, $tokens ) = $auth_header =~ /^(\w+)\s+(.*)$/;
|
||||
if ( $tokens =~ /\w+="([^"]+)"/i ) {
|
||||
if ( $realm ne $1 ) {
|
||||
$realm = $1;
|
||||
|
@ -109,6 +126,7 @@ sub open {
|
|||
} else {
|
||||
Error('Failed to match realm in tokens');
|
||||
} # end if
|
||||
} # end foreach auth header
|
||||
} else {
|
||||
Debug('No headers line');
|
||||
} # end if headers
|
||||
|
|
Loading…
Reference in New Issue