Whitespace fixes

This commit is contained in:
Richard Hansen 2024-06-13 00:19:21 -04:00
parent afa6db8129
commit 288a30ab1e

View file

@ -1274,10 +1274,12 @@ sub main {
read_cache(opt('cache'), \%cache); read_cache(opt('cache'), \%cache);
print_info() if opt('debug') && opt('verbose'); print_info() if opt('debug') && opt('verbose');
fatal("invalid argument '--use=%s'; possible values are:\n%s", $opt{'use'}, join("\n", ip_strategies_usage())) fatal("invalid argument '--use=%s'; possible values are:\n%s",
$opt{'use'}, join("\n", ip_strategies_usage()))
unless exists $ip_strategies{lc opt('use')}; unless exists $ip_strategies{lc opt('use')};
if (defined($opt{'usev6'})) { if (defined($opt{'usev6'})) {
usage("invalid argument '--usev6=%s'; possible values are:\n%s", $opt{'usev6'}, join("\n",ipv6_strategies_usage())) usage("invalid argument '--usev6=%s'; possible values are:\n%s",
$opt{'usev6'}, join("\n", ipv6_strategies_usage()))
unless exists $ipv6_strategies{lc opt('usev6')}; unless exists $ipv6_strategies{lc opt('usev6')};
} }
@ -1444,8 +1446,7 @@ sub update_nics {
$config{$h}{'wantip'} = $ipv4 if (!$ip && $ipv4); $config{$h}{'wantip'} = $ipv4 if (!$ip && $ipv4);
$config{$h}{'wantip'} = $ipv6 if (!$ip && !$ipv4 && $ipv6); $config{$h}{'wantip'} = $ipv6 if (!$ip && !$ipv4 && $ipv6);
if (!$ip && !$ipv4 && !$ipv6) if (!$ip && !$ipv4 && !$ipv6) {
{
warning("Could not determine an IP for %s", $h); warning("Could not determine an IP for %s", $h);
next; next;
} }
@ -1761,18 +1762,14 @@ sub _read_config {
## verify that keywords are valid...and check the value ## verify that keywords are valid...and check the value
for my $k (keys %locals) { for my $k (keys %locals) {
# Handle '_env' keyword suffix # Handle '_env' keyword suffix
if ($k =~ /(.*)_env$/) if ($k =~ /(.*)_env$/) {
{
debug("Loading value for $1 from environment variable $locals{$k}."); debug("Loading value for $1 from environment variable $locals{$k}.");
if (exists($ENV{$locals{$k}})) if (exists($ENV{$locals{$k}})) {
{
# Set the value to the value of the environment variable # Set the value to the value of the environment variable
$locals{$1} = $ENV{$locals{$k}}; $locals{$1} = $ENV{$locals{$k}};
# Remove the '_env' suffix from the key # Remove the '_env' suffix from the key
$k = $1; $k = $1;
} } else {
else
{
warning("Environment variable '$locals{$k}' not set for keyword '$k' (ignored)"); warning("Environment variable '$locals{$k}' not set for keyword '$k' (ignored)");
delete $locals{$k}; delete $locals{$k};
next; next;
@ -1789,7 +1786,9 @@ sub _read_config {
if (!defined($value)) { if (!defined($value)) {
warning("Invalid Value for keyword '%s' = '%s'", $k, $locals{$k}); warning("Invalid Value for keyword '%s' = '%s'", $k, $locals{$k});
delete $locals{$k}; delete $locals{$k};
} else { $locals{$k} = $value; } } else {
$locals{$k} = $value;
}
} }
} }
if (exists($locals{'host'})) { if (exists($locals{'host'})) {
@ -2828,29 +2827,23 @@ sub get_ip {
$ip = undef; $ip = undef;
} }
$arg = 'ip'; $arg = 'ip';
} elsif ($use eq 'if') { } elsif ($use eq 'if') {
$ip = get_ip_from_interface($arg); $ip = get_ip_from_interface($arg);
} elsif ($use eq 'cmd') { } elsif ($use eq 'cmd') {
if ($arg) { if ($arg) {
$skip = opt('cmd-skip', $h); $skip = opt('cmd-skip', $h);
$reply = `$arg`; $reply = `$arg`;
$reply = '' if $?; $reply = '' if $?;
} }
} elsif ($use eq 'web') { } elsif ($use eq 'web') {
$url = opt('web', $h) // ''; $url = opt('web', $h) // '';
$skip = opt('web-skip', $h); $skip = opt('web-skip', $h);
if (exists $builtinweb{$url}) { if (exists $builtinweb{$url}) {
warning("googledomains is deprecated! See https://github.com/ddclient/ddclient/issues/622 for more info.") if ($url eq 'googledomains'); warning("googledomains is deprecated! See https://github.com/ddclient/ddclient/issues/622 for more info.") if ($url eq 'googledomains');
$skip //= $builtinweb{$url}->{'skip'}; $skip //= $builtinweb{$url}->{'skip'};
$url = $builtinweb{$url}->{'url'}; $url = $builtinweb{$url}->{'url'};
} }
$arg = $url; $arg = $url;
if ($url) { if ($url) {
$reply = geturl( $reply = geturl(
proxy => opt('proxy', $h), proxy => opt('proxy', $h),
@ -2858,11 +2851,9 @@ sub get_ip {
ssl_validate => opt('web-ssl-validate', $h), ssl_validate => opt('web-ssl-validate', $h),
) // ''; ) // '';
} }
} elsif ($use eq 'disabled') { } elsif ($use eq 'disabled') {
## This is a no-op... Do not get an IP address for this host/service ## This is a no-op... Do not get an IP address for this host/service
$reply = ''; $reply = '';
} elsif ($use eq 'fw' || defined(my $fw = $builtinfw{$use})) { } elsif ($use eq 'fw' || defined(my $fw = $builtinfw{$use})) {
# Note that --use=firewallname uses --fw=arg, not --firewallname=arg. # Note that --use=firewallname uses --fw=arg, not --firewallname=arg.
$arg = opt('fw', $h) // ''; $arg = opt('fw', $h) // '';
@ -2877,7 +2868,6 @@ sub get_ip {
$url = "http://$url$fw->{'url'}" unless $url =~ /\//; $url = "http://$url$fw->{'url'}" unless $url =~ /\//;
} }
} }
if ($url) { if ($url) {
$reply = geturl( $reply = geturl(
url => $url, url => $url,
@ -2887,7 +2877,6 @@ sub get_ip {
ssl_validate => opt('fw-ssl-validate', $h), ssl_validate => opt('fw-ssl-validate', $h),
) // ''; ) // '';
} }
} else { } else {
warning("ignoring unsupported '--use=$use'"); warning("ignoring unsupported '--use=$use'");
} }
@ -3215,7 +3204,6 @@ sub get_ip_from_interface {
sub get_ipv4 { sub get_ipv4 {
my $usev4 = lc(shift); ## Method to obtain IP address my $usev4 = lc(shift); ## Method to obtain IP address
my $h = shift; ## Host/service making the request my $h = shift; ## Host/service making the request
my $ipv4 = undef; ## Found IPv4 address my $ipv4 = undef; ## Found IPv4 address
my $reply = ''; ## Text returned from various methods my $reply = ''; ## Text returned from various methods
my $url = ''; ## URL of website or firewall my $url = ''; ## URL of website or firewall
@ -3230,11 +3218,9 @@ sub get_ipv4 {
$ipv4 = undef; $ipv4 = undef;
} }
$arg = 'ipv4'; # For debug message at end of function $arg = 'ipv4'; # For debug message at end of function
} elsif ($usev4 eq 'ifv4') { } elsif ($usev4 eq 'ifv4') {
## Obtain IPv4 address from interface mamed in "ifv4=<if>" ## Obtain IPv4 address from interface mamed in "ifv4=<if>"
$ipv4 = get_ip_from_interface($arg, 4); $ipv4 = get_ip_from_interface($arg, 4);
} elsif ($usev4 eq 'cmdv4') { } elsif ($usev4 eq 'cmdv4') {
## Obtain IPv4 address by executing the command in "cmdv4=<command>" ## Obtain IPv4 address by executing the command in "cmdv4=<command>"
warning("'--cmd-skip' ignored for '--usev4=$usev4'") if (opt('verbose') && opt('cmd-skip', $h)); warning("'--cmd-skip' ignored for '--usev4=$usev4'") if (opt('verbose') && opt('cmd-skip', $h));
@ -3243,30 +3229,27 @@ sub get_ipv4 {
$reply = qx{$sys_cmd}; $reply = qx{$sys_cmd};
$reply = '' if $?; $reply = '' if $?;
} }
} elsif ($usev4 eq 'webv4') { } elsif ($usev4 eq 'webv4') {
## Obtain IPv4 address by accessing website at url in "webv4=<url>" ## Obtain IPv4 address by accessing website at url in "webv4=<url>"
$url = $arg; $url = $arg;
$skip = opt('webv4-skip', $h); $skip = opt('webv4-skip', $h);
if (exists $builtinweb{$url}) { if (exists $builtinweb{$url}) {
warning("googledomains is deprecated! See https://github.com/ddclient/ddclient/issues/622 for more info.") if ($url eq 'googledomains'); warning("googledomains is deprecated! See https://github.com/ddclient/ddclient/issues/622 for more info.") if ($url eq 'googledomains');
$skip //= $builtinweb{$url}->{'skip'}; $skip //= $builtinweb{$url}->{'skip'};
$url = $builtinweb{$url}->{'url'}; $url = $builtinweb{$url}->{'url'};
$arg = $url; $arg = $url;
} }
if ($url) { if ($url) {
$reply = geturl( proxy => opt('proxy', $h), $reply = geturl(
proxy => opt('proxy', $h),
url => $url, url => $url,
ipversion => 4, # when using a URL to find IPv4 address we should force use of IPv4 ipversion => 4, # when using a URL to find IPv4 address we should force use of IPv4
ssl_validate => opt('web-ssl-validate', $h), ssl_validate => opt('web-ssl-validate', $h),
) // ''; ) // '';
} }
} elsif ($usev4 eq 'disabled') { } elsif ($usev4 eq 'disabled') {
## This is a no-op... Do not get an IPv4 address for this host/service ## This is a no-op... Do not get an IPv4 address for this host/service
$reply = ''; $reply = '';
} elsif ($usev4 eq 'fwv4' || defined(my $fw = $builtinfw{$usev4})) { } elsif ($usev4 eq 'fwv4' || defined(my $fw = $builtinfw{$usev4})) {
warning("'--fw' is deprecated for '--usev4=$usev4'; use '--fwv4' instead") warning("'--fw' is deprecated for '--usev4=$usev4'; use '--fwv4' instead")
if (!defined(opt('fwv4', $h)) && defined(opt('fw', $h))); if (!defined(opt('fwv4', $h)) && defined(opt('fw', $h)));
@ -3295,7 +3278,6 @@ sub get_ipv4 {
ssl_validate => opt('fw-ssl-validate', $h), ssl_validate => opt('fw-ssl-validate', $h),
) // ''; ) // '';
} }
} else { } else {
warning("ignoring unsupported '--usev4=$usev4'"); warning("ignoring unsupported '--usev4=$usev4'");
} }
@ -3321,7 +3303,6 @@ sub get_ipv6 {
my $usev6 = lc(shift); ## Method to obtain IP address my $usev6 = lc(shift); ## Method to obtain IP address
$usev6 = 'disabled' if ($usev6 eq 'no'); # backward compatibility $usev6 = 'disabled' if ($usev6 eq 'no'); # backward compatibility
my $h = shift; ## Host/service making the request my $h = shift; ## Host/service making the request
my $ipv6 = undef; ## Found IPv6 address my $ipv6 = undef; ## Found IPv6 address
my $reply = ''; ## Text returned from various methods my $reply = ''; ## Text returned from various methods
my $url = ''; ## URL of website or firewall my $url = ''; ## URL of website or firewall
@ -3340,7 +3321,6 @@ sub get_ipv6 {
$ipv6 = undef; $ipv6 = undef;
} }
$arg = 'ipv6'; # For debug message at end of function $arg = 'ipv6'; # For debug message at end of function
} elsif ($usev6 eq 'ifv6' || $usev6 eq 'if') { } elsif ($usev6 eq 'ifv6' || $usev6 eq 'if') {
## Obtain IPv6 address from interface mamed in "ifv6=<if>" ## Obtain IPv6 address from interface mamed in "ifv6=<if>"
if ($usev6 eq 'if') { if ($usev6 eq 'if') {
@ -3348,7 +3328,6 @@ sub get_ipv6 {
$arg = opt('ifv6', $h) // $arg; $arg = opt('ifv6', $h) // $arg;
} }
$ipv6 = get_ip_from_interface($arg, 6); $ipv6 = get_ip_from_interface($arg, 6);
} elsif ($usev6 eq 'cmdv6' || $usev6 eq 'cmd') { } elsif ($usev6 eq 'cmdv6' || $usev6 eq 'cmd') {
## Obtain IPv6 address by executing the command in "cmdv6=<command>" ## Obtain IPv6 address by executing the command in "cmdv6=<command>"
if ($usev6 eq 'cmd') { if ($usev6 eq 'cmd') {
@ -3361,7 +3340,6 @@ sub get_ipv6 {
$reply = qx{$sys_cmd}; $reply = qx{$sys_cmd};
$reply = '' if $?; $reply = '' if $?;
} }
} elsif ($usev6 eq 'webv6' || $usev6 eq 'web') { } elsif ($usev6 eq 'webv6' || $usev6 eq 'web') {
## Obtain IPv6 address by accessing website at url in "webv6=<url>" ## Obtain IPv6 address by accessing website at url in "webv6=<url>"
if ($usev6 eq 'web') { if ($usev6 eq 'web') {
@ -3374,7 +3352,6 @@ sub get_ipv6 {
$skip = opt('webv6-skip', $h); $skip = opt('webv6-skip', $h);
if (exists $builtinweb{$url}) { if (exists $builtinweb{$url}) {
warning("googledomains is deprecated! See https://github.com/ddclient/ddclient/issues/622 for more info.") if ($url eq 'googledomains'); warning("googledomains is deprecated! See https://github.com/ddclient/ddclient/issues/622 for more info.") if ($url eq 'googledomains');
$skip //= $builtinweb{$url}->{'skip'}; $skip //= $builtinweb{$url}->{'skip'};
$url = $builtinweb{$url}->{'url'}; $url = $builtinweb{$url}->{'url'};
$arg = $url; $arg = $url;
@ -3387,10 +3364,8 @@ sub get_ipv6 {
ssl_validate => opt('web-ssl-validate', $h), ssl_validate => opt('web-ssl-validate', $h),
) // ''; ) // '';
} }
} elsif ($usev6 eq 'disabled') { } elsif ($usev6 eq 'disabled') {
$reply = ''; $reply = '';
} elsif ($usev6 eq 'fwv6' || defined(my $fw = $builtinfw{$usev6})) { } elsif ($usev6 eq 'fwv6' || defined(my $fw = $builtinfw{$usev6})) {
$skip = opt('fwv6-skip', $h) // $fw->{'skip'}; $skip = opt('fwv6-skip', $h) // $fw->{'skip'};
if ($fw && defined(my $query = $fw->{'queryv6'})) { if ($fw && defined(my $query = $fw->{'queryv6'})) {
@ -3399,10 +3374,8 @@ sub get_ipv6 {
} else { } else {
warning("'--usev6=%s' is not implemented and does nothing", $usev6); warning("'--usev6=%s' is not implemented and does nothing", $usev6);
} }
} else { } else {
warning("ignoring unsupported '--usev6=$usev6'"); warning("ignoring unsupported '--usev6=$usev6'");
} }
## Set to loopback address if no text set yet ## Set to loopback address if no text set yet
@ -3587,8 +3560,8 @@ sub nic_updateable {
); );
$update = 1; $update = 1;
} elsif ( ($use ne 'disabled') } elsif (($use ne 'disabled') && ((!exists($cache{$host}{'ip'})) ||
&& ((!exists($cache{$host}{'ip'})) || ("$cache{$host}{'ip'}" ne "$ip"))) { ("$cache{$host}{'ip'}" ne "$ip"))) {
## Check whether to update IP address for the "--use" method" ## Check whether to update IP address for the "--use" method"
if ((($cache{$host}{'status'} // '') eq 'good') && if ((($cache{$host}{'status'} // '') eq 'good') &&
!interval_expired($host, 'mtime', 'min-interval')) { !interval_expired($host, 'mtime', 'min-interval')) {
@ -3607,9 +3580,8 @@ sub nic_updateable {
} elsif ((($cache{$host}{'status'} // '') ne 'good') && } elsif ((($cache{$host}{'status'} // '') ne 'good') &&
!interval_expired($host, 'atime', 'min-error-interval')) { !interval_expired($host, 'atime', 'min-error-interval')) {
if ( opt('verbose') if (opt('verbose') || (!$cache{$host}{'warned-min-error-interval'} &&
|| ( ! $cache{$host}{'warned-min-error-interval'} (($warned_ip{$host} // 0) < $inv_ip_warn_count))) {
&& (($warned_ip{$host} // 0) < $inv_ip_warn_count)) ) {
warning("skipping update of %s from %s to %s.\nlast updated %s but last attempt on %s failed.\nWait at least %s between update attempts.", warning("skipping update of %s from %s to %s.\nlast updated %s but last attempt on %s failed.\nWait at least %s between update attempts.",
$host, $host,
@ -3632,8 +3604,8 @@ sub nic_updateable {
$update = 1; $update = 1;
} }
} elsif ( ($usev4 ne 'disabled') } elsif (($usev4 ne 'disabled') && ((!exists($cache{$host}{'ipv4'})) ||
&& ((!exists($cache{$host}{'ipv4'})) || ("$cache{$host}{'ipv4'}" ne "$ipv4"))) { ("$cache{$host}{'ipv4'}" ne "$ipv4"))) {
## Check whether to update IPv4 address for the "--usev4" method" ## Check whether to update IPv4 address for the "--usev4" method"
if ((($cache{$host}{'status-ipv4'} // '') eq 'good') && if ((($cache{$host}{'status-ipv4'} // '') eq 'good') &&
!interval_expired($host, 'mtime', 'min-interval')) { !interval_expired($host, 'mtime', 'min-interval')) {
@ -3652,9 +3624,8 @@ sub nic_updateable {
} elsif ((($cache{$host}{'status-ipv4'} // '') ne 'good') && } elsif ((($cache{$host}{'status-ipv4'} // '') ne 'good') &&
!interval_expired($host, 'atime', 'min-error-interval')) { !interval_expired($host, 'atime', 'min-error-interval')) {
if ( opt('verbose') if (opt('verbose') || (!$cache{$host}{'warned-min-error-interval'} &&
|| ( ! $cache{$host}{'warned-min-error-interval'} (($warned_ipv4{$host} // 0) < $inv_ip_warn_count))) {
&& (($warned_ipv4{$host} // 0) < $inv_ip_warn_count)) ) {
warning("skipping update of %s from %s to %s.\nlast updated %s but last attempt on %s failed.\nWait at least %s between update attempts.", warning("skipping update of %s from %s to %s.\nlast updated %s but last attempt on %s failed.\nWait at least %s between update attempts.",
$host, $host,
@ -3677,8 +3648,8 @@ sub nic_updateable {
$update = 1; $update = 1;
} }
} elsif ( ($usev6 ne 'disabled') } elsif (($usev6 ne 'disabled') && ((!exists($cache{$host}{'ipv6'})) ||
&& ((!exists($cache{$host}{'ipv6'})) || ("$cache{$host}{'ipv6'}" ne "$ipv6"))) { ("$cache{$host}{'ipv6'}" ne "$ipv6"))) {
## Check whether to update IPv6 address for the "--usev6" method" ## Check whether to update IPv6 address for the "--usev6" method"
if ((($cache{$host}{'status-ipv6'} // '') eq 'good') && if ((($cache{$host}{'status-ipv6'} // '') eq 'good') &&
!interval_expired($host, 'mtime', 'min-interval')) { !interval_expired($host, 'mtime', 'min-interval')) {
@ -3697,9 +3668,8 @@ sub nic_updateable {
} elsif ((($cache{$host}{'status-ipv6'} // '') ne 'good') && } elsif ((($cache{$host}{'status-ipv6'} // '') ne 'good') &&
!interval_expired($host, 'atime', 'min-error-interval')) { !interval_expired($host, 'atime', 'min-error-interval')) {
if ( opt('verbose') if (opt('verbose') || (!$cache{$host}{'warned-min-error-interval'} &&
|| ( ! $cache{$host}{'warned-min-error-interval'} (($warned_ipv6{$host} // 0) < $inv_ip_warn_count))) {
&& (($warned_ipv6{$host} // 0) < $inv_ip_warn_count)) ) {
warning("skipping update of %s from %s to %s.\nlast updated %s but last attempt on %s failed.\nWait at least %s between update attempts.", warning("skipping update of %s from %s to %s.\nlast updated %s but last attempt on %s failed.\nWait at least %s between update attempts.",
$host, $host,
@ -4917,8 +4887,6 @@ EoEXAMPLE
## ##
###################################################################### ######################################################################
sub nic_namecheap_update { sub nic_namecheap_update {
debug("\nnic_namecheap1_update -------------------"); debug("\nnic_namecheap1_update -------------------");
## update each configured host ## update each configured host
@ -5334,8 +5302,6 @@ EoEXAMPLE
## ##
###################################################################### ######################################################################
sub nic_sitelutions_update { sub nic_sitelutions_update {
debug("\nnic_sitelutions_update -------------------"); debug("\nnic_sitelutions_update -------------------");
## update each configured host ## update each configured host
@ -5637,8 +5603,6 @@ EoEXAMPLE
## ##
###################################################################### ######################################################################
sub nic_changeip_update { sub nic_changeip_update {
debug("\nnic_changeip_update -------------------"); debug("\nnic_changeip_update -------------------");
## update each configured host ## update each configured host
@ -7587,11 +7551,9 @@ sub nic_gandi_update {
$config{$h}{'ip'} = $ip; $config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now; $config{$h}{'mtime'} = $now;
$config{$h}{"status-$ipv"} = "good"; $config{$h}{"status-$ipv"} = "good";
success("%s -- Updated successfully to %s.", $h, $ip); success("%s -- Updated successfully to %s.", $h, $ip);
} else { } else {
$config{$h}{"status-$ipv"} = "bad"; $config{$h}{"status-$ipv"} = "bad";
if (defined($response->{status}) && $response->{status} eq "error") { if (defined($response->{status}) && $response->{status} eq "error") {
my @errors; my @errors;
for my $err (@{$response->{errors}}) { for my $err (@{$response->{errors}}) {
@ -7656,15 +7618,12 @@ sub nic_keysystems_update {
} }
last if !header_ok($h, $reply); last if !header_ok($h, $reply);
if ($reply =~ /code = 200/) if ($reply =~ /code = 200/) {
{
$config{$h}{'ip'} = $ip; $config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now; $config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good'; $config{$h}{'status'} = 'good';
success("updating %s: good: IP address set to %s", $h, $ip); success("updating %s: good: IP address set to %s", $h, $ip);
} } else {
else
{
$config{$h}{'status'} = 'failed'; $config{$h}{'status'} = 'failed';
failed("updating %s: Server said: '$reply'", $h); failed("updating %s: Server said: '$reply'", $h);
} }
@ -7718,15 +7677,12 @@ sub nic_regfishde_update {
} }
last if !header_ok($h, $reply); last if !header_ok($h, $reply);
if ($reply =~ /success/) if ($reply =~ /success/) {
{
$config{$h}{'ip'} = $ip; $config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now; $config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good'; $config{$h}{'status'} = 'good';
success("updating %s: good: IP address set to %s", $h, $ip); success("updating %s: good: IP address set to %s", $h, $ip);
} } else {
else
{
$config{$h}{'status'} = 'failed'; $config{$h}{'status'} = 'failed';
failed("updating %s: Server said: '$reply'", $h); failed("updating %s: Server said: '$reply'", $h);
} }