From a534f9b4294f9cb0a190daeaa6ecc537d7cfa1bc Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 1 Sep 2025 09:35:16 -0400 Subject: [PATCH] Return uri from guess_credentials. Add a warning when no ip in ping --- scripts/ZoneMinder/lib/ZoneMinder/Control.pm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Control.pm b/scripts/ZoneMinder/lib/ZoneMinder/Control.pm index 1ee4e8968..895ebad91 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Control.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Control.pm @@ -405,6 +405,7 @@ sub guess_credentials { my $self = shift; require URI; + my $uri; # Extract the username/password host/port from ControlAddress if ($self->{Monitor}{ControlAddress} @@ -414,7 +415,7 @@ sub guess_credentials { $self->{Monitor}{ControlAddress} ne 'user:port@ip' ) { Debug("Using ControlAddress for credentials: $self->{Monitor}{ControlAddress}"); - my $uri = URI->new($self->{Monitor}->{ControlAddress}); + $uri = URI->new($self->{Monitor}->{ControlAddress}); $uri = URI->new('http://'.$self->{Monitor}->{ControlAddress}) if ref($uri) eq 'URI::_foreign'; $$self{host} = $uri->host(); if ( $uri->userinfo()) { @@ -443,7 +444,7 @@ sub guess_credentials { $$self{username}= $self->{Monitor}->{User} if $self->{Monitor}->{User} and !$$self{username}; $$self{password} = $self->{Monitor}->{Pass} if $self->{Monitor}->{Pass} and !$$self{password}; } - my $uri = URI->new($self->{Monitor}->{Path}); + $uri = URI->new($self->{Monitor}->{Path}); $uri->scheme('http'); $uri->port(80); $uri->path(''); @@ -452,6 +453,7 @@ sub guess_credentials { } else { Debug('Unable to guess credentials'); } + return $uri; } sub get_realm { @@ -501,7 +503,10 @@ sub get_realm { sub ping { my $self = shift; my $ip = @_ ? shift : $$self{host}; - return undef if ! $ip; + if (!$ip) { + Warning("No ip to ping. Please either pass ip or populate self{host}"); + return undef; + } require Net::Ping; Debug("Pinging $ip");