Skip to content

Commit

Permalink
Add some -> and test for ControlDevice so as not to give a warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Connor committed Jan 5, 2025
1 parent 833cc41 commit b5ee966
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions scripts/ZoneMinder/lib/ZoneMinder/Control/Amcrest_HTTP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ sub open {

if ($self->{Monitor}->{ControlAddress}
and
$self->{Monitor}{ControlAddress} ne 'user:pass@ip'
$self->{Monitor}->{ControlAddress} ne 'user:pass@ip'
and
$self->{Monitor}{ControlAddress} ne 'user:port@ip'
$self->{Monitor}->{ControlAddress} ne 'user:port@ip'
) {

if ( $self->{Monitor}->{ControlAddress} !~ /^\w+:\/\// ) {
Expand All @@ -70,7 +70,7 @@ sub open {
}
my $uri = URI->new($self->{Monitor}->{ControlAddress});

$$self{realm} = 'Login to ' . $self->{Monitor}->{ControlDevice};
$$self{realm} = 'Login to ' . $self->{Monitor}->{ControlDevice} if $self->{Monitor}->{ControlDevice};
if ($self->{Monitor}->{ControlAddress}) {
if ( $uri->userinfo()) {
@$self{'username', 'password'} = $uri->userinfo() =~ /^(.*):(.*)$/;
Expand All @@ -85,8 +85,8 @@ sub open {
$$self{base_url} = $uri->canonical();
Debug('Using initial credentials for '.$uri->host_port().join(',', '', @$self{'realm', 'username', 'password'}).", base_url: $$self{base_url} auth:".$uri->authority());
}
} elsif ( $self->{Monitor}{Path}) {
my $uri = URI->new($self->{Monitor}{Path});
} elsif ( $self->{Monitor}->{Path}) {
my $uri = URI->new($self->{Monitor}->{Path});
Debug("Using Path for credentials: $self->{Monitor}{Path} " . $uri->userinfo());
if ( $uri->userinfo()) {
@$self{'username', 'password'} = $uri->userinfo() =~ /^(.*):(.*)$/;
Expand All @@ -111,14 +111,10 @@ sub open {

my $url = $$self{base_url}.'cgi-bin/magicBox.cgi?action=getDeviceType';
# Detect REALM, has to be /cgi-bin/ptz.cgi because just / accepts no auth
my $res = $self->get_realm($url);

if ( $res->is_success ) {
if ($self->get_realm($url)) {
$self->{state} = 'open';
return !undef;
} else {
Error("Failed to get $url ".$res->status_line());
} # end if $res->status_line() eq '401 Unauthorized'
}

$self->{state} = 'closed';
return undef;
Expand Down

0 comments on commit b5ee966

Please sign in to comment.