Discover that authority also contains port. Remove redundant stuff.
This commit is contained in:
parent
9a21ebf696
commit
cac7ddd89d
|
@ -60,10 +60,6 @@ sub open {
|
|||
}
|
||||
my $uri = URI->new($self->{Monitor}->{ControlAddress});
|
||||
|
||||
$uri->port(80) if ! $uri->port();
|
||||
my $ADDRESS = $uri->scheme.'://'.$uri->authority().$uri->path().($uri->port()?':'.$uri->port():'');
|
||||
Debug("Address: $ADDRESS");
|
||||
|
||||
$self->{ua} = LWP::UserAgent->new;
|
||||
$self->{ua}->agent('ZoneMinder Control Agent/'.ZoneMinder::Base::ZM_VERSION);
|
||||
my ( $username, $password );
|
||||
|
@ -71,15 +67,15 @@ sub open {
|
|||
if ( $self->{Monitor}->{ControlAddress} ) {
|
||||
( $username, $password ) = $uri->authority() =~ /^(.*):(.*)@(.*)$/;
|
||||
|
||||
$$self{address} = $uri->authority().($uri->port() ? ':'.$uri->port() : '');
|
||||
$self->{ua}->credentials($$self{address}, $realm, $username, $password);
|
||||
$$self{address} = $uri->host_port();
|
||||
$self->{ua}->credentials($uri->host_port(), $realm, $username, $password);
|
||||
# Testing seems to show that we need the username/password in each url as well as credentials
|
||||
$$self{base_url} = $self->{Monitor}->{ControlAddress};
|
||||
Debug("Using initial credentials for $$self{address}, $realm, $username, $password, base_url: $$self{base_url} auth:".$uri->authority());
|
||||
$$self{base_url} = $uri->canonical();
|
||||
Debug('Using initial credentials for '.$uri->host_port().", $realm, $username, $password, base_url: $$self{base_url} auth:".$uri->authority());
|
||||
}
|
||||
|
||||
# Detect REALM, has to be /cgi-bin/ptz.cgi because just / accepts no auth
|
||||
my $res = $self->{ua}->get($$self{base_url}.'/cgi-bin/ptz.cgi');
|
||||
my $res = $self->{ua}->get($$self{base_url}.'cgi-bin/ptz.cgi');
|
||||
|
||||
if ( $res->is_success ) {
|
||||
$self->{state} = 'open';
|
||||
|
@ -100,7 +96,7 @@ sub open {
|
|||
$realm = $1;
|
||||
Debug("Changing REALM to ($realm)");
|
||||
$self->{ua}->credentials($$self{address}, $realm, $username, $password);
|
||||
$res = $self->{ua}->get($$self{base_url}.'/cgi-bin/ptz.cgi');
|
||||
$res = $self->{ua}->get($$self{base_url}.'cgi-bin/ptz.cgi');
|
||||
if ( $res->is_success() ) {
|
||||
$self->{state} = 'open';
|
||||
return;
|
||||
|
@ -125,7 +121,7 @@ sub open {
|
|||
Debug('No headers line');
|
||||
} # end if headers
|
||||
} else {
|
||||
Error("Failed to get $$self{base_url}/cgi-bin/ptz.cgi ".$res->status_line());
|
||||
Error("Failed to get $$self{base_url}cgi-bin/ptz.cgi ".$res->status_line());
|
||||
|
||||
} # end if $res->status_line() eq '401 Unauthorized'
|
||||
|
||||
|
@ -144,21 +140,21 @@ sub sendCmd {
|
|||
|
||||
$self->printMsg($cmd, 'Tx');
|
||||
|
||||
my $res = $self->{ua}->get($$self{base_url}.'/'.$cmd);
|
||||
my $res = $self->{ua}->get($$self{base_url}.$cmd);
|
||||
|
||||
if ( $res->is_success ) {
|
||||
$result = !undef;
|
||||
# Command to camera appears successful, write Info item to log
|
||||
Info('Camera control: \''.$res->status_line().'\' for URL '.$$self{base_url}.'/'.$cmd);
|
||||
Info('Camera control: \''.$res->status_line().'\' for URL '.$$self{base_url}.$cmd);
|
||||
# TODO: Add code to retrieve $res->message_decode or some such. Then we could do things like check the camera status.
|
||||
} else {
|
||||
# Try again
|
||||
$res = $self->{ua}->get($$self{base_url}.'/'.$cmd);
|
||||
$res = $self->{ua}->get($$self{base_url}.$cmd);
|
||||
if ( $res->is_success ) {
|
||||
# Command to camera appears successful, write Info item to log
|
||||
Info('Camera control: \''.$res->status_line().'\' for URL '.$$self{base_url}.'/'.$cmd);
|
||||
Info('Camera control 2: \''.$res->status_line().'\' for URL '.$$self{base_url}.$cmd);
|
||||
} else {
|
||||
Error('Camera control command FAILED: \''.$res->status_line().'\' for URL '.$$self{base_url}.'/'.$cmd);
|
||||
Error('Camera control command FAILED: \''.$res->status_line().'\' for URL '.$$self{base_url}.$cmd);
|
||||
$res = $self->{ua}->get('http://'.$self->{Monitor}->{ControlAddress}.'/'.$cmd);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue