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);
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')};
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')};
}
@ -1444,8 +1446,7 @@ sub update_nics {
$config{$h}{'wantip'} = $ipv4 if (!$ip && $ipv4);
$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);
next;
}
@ -1761,18 +1762,14 @@ sub _read_config {
## verify that keywords are valid...and check the value
for my $k (keys %locals) {
# Handle '_env' keyword suffix
if ($k =~ /(.*)_env$/)
{
if ($k =~ /(.*)_env$/) {
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
$locals{$1} = $ENV{$locals{$k}};
# Remove the '_env' suffix from the key
$k = $1;
}
else
{
} else {
warning("Environment variable '$locals{$k}' not set for keyword '$k' (ignored)");
delete $locals{$k};
next;
@ -1789,7 +1786,9 @@ sub _read_config {
if (!defined($value)) {
warning("Invalid Value for keyword '%s' = '%s'", $k, $locals{$k});
delete $locals{$k};
} else { $locals{$k} = $value; }
} else {
$locals{$k} = $value;
}
}
}
if (exists($locals{'host'})) {
@ -1818,7 +1817,7 @@ sub _read_config {
$config{$h} = {%locals, %{$config{$h}}};
} else {
## save a copy of the current globals
$config{$h} = { %locals };
$config{$h} = {%locals};
$config{$h}{'host'} = $h;
}
}
@ -1973,8 +1972,8 @@ sub init_config {
$proto = $config{$h}{'protocol'};
$proto = opt('protocol') if !defined($proto);
load_sha1_support($proto) if (grep (/^$proto$/, ("freedns", "nfsn")));
load_json_support($proto) if (grep (/^$proto$/, ("1984", "cloudflare", "digitalocean", "gandi", "godaddy", "hetzner", "yandex", "nfsn", "njalla", "porkbun", "dnsexit2")));
load_sha1_support($proto) if (grep(/^$proto$/, ("freedns", "nfsn")));
load_json_support($proto) if (grep(/^$proto$/, ("1984", "cloudflare", "digitalocean", "gandi", "godaddy", "hetzner", "yandex", "nfsn", "njalla", "porkbun", "dnsexit2")));
if (!exists($services{$proto})) {
warning("skipping host: %s: unrecognized protocol '%s'", $h, $proto);
@ -1982,7 +1981,7 @@ sub init_config {
} else {
my $svars = $services{$proto}{'variables'};
my $conf = { 'protocol' => $proto };
my $conf = {'protocol' => $proto};
for my $k (keys %$svars) {
# Make sure any _env suffixed variables look at their original entry
@ -2546,11 +2545,11 @@ sub check_value {
} elsif ($type eq T_USEV4) {
$value = lc $value;
return undef if ! exists $ipv4_strategies{$value};
return undef if !exists $ipv4_strategies{$value};
} elsif ($type eq T_USEV6) {
$value = lc $value;
return undef if ! exists $ipv6_strategies{$value};
return undef if !exists $ipv6_strategies{$value};
} elsif ($type eq T_FILE) {
return undef if $value eq "";
@ -2828,29 +2827,23 @@ sub get_ip {
$ip = undef;
}
$arg = 'ip';
} elsif ($use eq 'if') {
$ip = get_ip_from_interface($arg);
} elsif ($use eq 'cmd') {
if ($arg) {
$skip = opt('cmd-skip', $h);
$reply = `$arg`;
$reply = '' if $?;
}
} elsif ($use eq 'web') {
$url = opt('web', $h) // '';
$skip = opt('web-skip', $h);
if (exists $builtinweb{$url}) {
warning("googledomains is deprecated! See https://github.com/ddclient/ddclient/issues/622 for more info.") if ($url eq 'googledomains');
$skip //= $builtinweb{$url}->{'skip'};
$url = $builtinweb{$url}->{'url'};
}
$arg = $url;
if ($url) {
$reply = geturl(
proxy => opt('proxy', $h),
@ -2858,11 +2851,9 @@ sub get_ip {
ssl_validate => opt('web-ssl-validate', $h),
) // '';
}
} elsif ($use eq 'disabled') {
## This is a no-op... Do not get an IP address for this host/service
$reply = '';
} elsif ($use eq 'fw' || defined(my $fw = $builtinfw{$use})) {
# Note that --use=firewallname uses --fw=arg, not --firewallname=arg.
$arg = opt('fw', $h) // '';
@ -2877,7 +2868,6 @@ sub get_ip {
$url = "http://$url$fw->{'url'}" unless $url =~ /\//;
}
}
if ($url) {
$reply = geturl(
url => $url,
@ -2887,7 +2877,6 @@ sub get_ip {
ssl_validate => opt('fw-ssl-validate', $h),
) // '';
}
} else {
warning("ignoring unsupported '--use=$use'");
}
@ -3215,7 +3204,6 @@ sub get_ip_from_interface {
sub get_ipv4 {
my $usev4 = lc(shift); ## Method to obtain IP address
my $h = shift; ## Host/service making the request
my $ipv4 = undef; ## Found IPv4 address
my $reply = ''; ## Text returned from various methods
my $url = ''; ## URL of website or firewall
@ -3226,15 +3214,13 @@ sub get_ipv4 {
## Static IPv4 address is provided in "ipv4=<address>"
$ipv4 = $arg;
if (!is_ipv4($ipv4)) {
warning("'%s' is not a valid IPv4",$ipv4 // '');
warning("'%s' is not a valid IPv4", $ipv4 // '');
$ipv4 = undef;
}
$arg = 'ipv4'; # For debug message at end of function
} elsif ($usev4 eq 'ifv4') {
## 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') {
## Obtain IPv4 address by executing the command in "cmdv4=<command>"
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 = '' if $?;
}
} elsif ($usev4 eq 'webv4') {
## Obtain IPv4 address by accessing website at url in "webv4=<url>"
$url = $arg;
$skip = opt('webv4-skip', $h);
if (exists $builtinweb{$url}) {
warning("googledomains is deprecated! See https://github.com/ddclient/ddclient/issues/622 for more info.") if ($url eq 'googledomains');
$skip //= $builtinweb{$url}->{'skip'};
$url = $builtinweb{$url}->{'url'};
$arg = $url;
}
if ($url) {
$reply = geturl( proxy => opt('proxy', $h),
$reply = geturl(
proxy => opt('proxy', $h),
url => $url,
ipversion => 4, # when using a URL to find IPv4 address we should force use of IPv4
ssl_validate => opt('web-ssl-validate', $h),
) // '';
}
} elsif ($usev4 eq 'disabled') {
## This is a no-op... Do not get an IPv4 address for this host/service
$reply = '';
} elsif ($usev4 eq 'fwv4' || defined(my $fw = $builtinfw{$usev4})) {
warning("'--fw' is deprecated for '--usev4=$usev4'; use '--fwv4' instead")
if (!defined(opt('fwv4', $h)) && defined(opt('fw', $h)));
@ -3295,7 +3278,6 @@ sub get_ipv4 {
ssl_validate => opt('fw-ssl-validate', $h),
) // '';
}
} else {
warning("ignoring unsupported '--usev4=$usev4'");
}
@ -3321,7 +3303,6 @@ sub get_ipv6 {
my $usev6 = lc(shift); ## Method to obtain IP address
$usev6 = 'disabled' if ($usev6 eq 'no'); # backward compatibility
my $h = shift; ## Host/service making the request
my $ipv6 = undef; ## Found IPv6 address
my $reply = ''; ## Text returned from various methods
my $url = ''; ## URL of website or firewall
@ -3336,19 +3317,17 @@ sub get_ipv6 {
}
$ipv6 = $arg;
if (!is_ipv6($ipv6)) {
warning("'%s' is not a valid IPv6",$ipv6 // '');
warning("'%s' is not a valid IPv6", $ipv6 // '');
$ipv6 = undef;
}
$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>"
if ($usev6 eq 'if') {
warning("'--usev6=if' is deprecated. Use '--usev6=ifv6'");
$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') {
## Obtain IPv6 address by executing the command in "cmdv6=<command>"
if ($usev6 eq 'cmd') {
@ -3361,7 +3340,6 @@ sub get_ipv6 {
$reply = qx{$sys_cmd};
$reply = '' if $?;
}
} elsif ($usev6 eq 'webv6' || $usev6 eq 'web') {
## Obtain IPv6 address by accessing website at url in "webv6=<url>"
if ($usev6 eq 'web') {
@ -3374,7 +3352,6 @@ sub get_ipv6 {
$skip = opt('webv6-skip', $h);
if (exists $builtinweb{$url}) {
warning("googledomains is deprecated! See https://github.com/ddclient/ddclient/issues/622 for more info.") if ($url eq 'googledomains');
$skip //= $builtinweb{$url}->{'skip'};
$url = $builtinweb{$url}->{'url'};
$arg = $url;
@ -3387,10 +3364,8 @@ sub get_ipv6 {
ssl_validate => opt('web-ssl-validate', $h),
) // '';
}
} elsif ($usev6 eq 'disabled') {
$reply = '';
} elsif ($usev6 eq 'fwv6' || defined(my $fw = $builtinfw{$usev6})) {
$skip = opt('fwv6-skip', $h) // $fw->{'skip'};
if ($fw && defined(my $query = $fw->{'queryv6'})) {
@ -3399,10 +3374,8 @@ sub get_ipv6 {
} else {
warning("'--usev6=%s' is not implemented and does nothing", $usev6);
}
} else {
warning("ignoring unsupported '--usev6=$usev6'");
}
## Set to loopback address if no text set yet
@ -3587,8 +3560,8 @@ sub nic_updateable {
);
$update = 1;
} elsif ( ($use ne 'disabled')
&& ((!exists($cache{$host}{'ip'})) || ("$cache{$host}{'ip'}" ne "$ip"))) {
} elsif (($use ne 'disabled') && ((!exists($cache{$host}{'ip'})) ||
("$cache{$host}{'ip'}" ne "$ip"))) {
## Check whether to update IP address for the "--use" method"
if ((($cache{$host}{'status'} // '') eq 'good') &&
!interval_expired($host, 'mtime', 'min-interval')) {
@ -3607,9 +3580,8 @@ sub nic_updateable {
} elsif ((($cache{$host}{'status'} // '') ne 'good') &&
!interval_expired($host, 'atime', 'min-error-interval')) {
if ( opt('verbose')
|| ( ! $cache{$host}{'warned-min-error-interval'}
&& (($warned_ip{$host} // 0) < $inv_ip_warn_count)) ) {
if (opt('verbose') || (!$cache{$host}{'warned-min-error-interval'} &&
(($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.",
$host,
@ -3632,8 +3604,8 @@ sub nic_updateable {
$update = 1;
}
} elsif ( ($usev4 ne 'disabled')
&& ((!exists($cache{$host}{'ipv4'})) || ("$cache{$host}{'ipv4'}" ne "$ipv4"))) {
} elsif (($usev4 ne 'disabled') && ((!exists($cache{$host}{'ipv4'})) ||
("$cache{$host}{'ipv4'}" ne "$ipv4"))) {
## Check whether to update IPv4 address for the "--usev4" method"
if ((($cache{$host}{'status-ipv4'} // '') eq 'good') &&
!interval_expired($host, 'mtime', 'min-interval')) {
@ -3652,9 +3624,8 @@ sub nic_updateable {
} elsif ((($cache{$host}{'status-ipv4'} // '') ne 'good') &&
!interval_expired($host, 'atime', 'min-error-interval')) {
if ( opt('verbose')
|| ( ! $cache{$host}{'warned-min-error-interval'}
&& (($warned_ipv4{$host} // 0) < $inv_ip_warn_count)) ) {
if (opt('verbose') || (!$cache{$host}{'warned-min-error-interval'} &&
(($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.",
$host,
@ -3677,8 +3648,8 @@ sub nic_updateable {
$update = 1;
}
} elsif ( ($usev6 ne 'disabled')
&& ((!exists($cache{$host}{'ipv6'})) || ("$cache{$host}{'ipv6'}" ne "$ipv6"))) {
} elsif (($usev6 ne 'disabled') && ((!exists($cache{$host}{'ipv6'})) ||
("$cache{$host}{'ipv6'}" ne "$ipv6"))) {
## Check whether to update IPv6 address for the "--usev6" method"
if ((($cache{$host}{'status-ipv6'} // '') eq 'good') &&
!interval_expired($host, 'mtime', 'min-interval')) {
@ -3697,9 +3668,8 @@ sub nic_updateable {
} elsif ((($cache{$host}{'status-ipv6'} // '') ne 'good') &&
!interval_expired($host, 'atime', 'min-error-interval')) {
if ( opt('verbose')
|| ( ! $cache{$host}{'warned-min-error-interval'}
&& (($warned_ipv6{$host} // 0) < $inv_ip_warn_count)) ) {
if (opt('verbose') || (!$cache{$host}{'warned-min-error-interval'} &&
(($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.",
$host,
@ -4917,8 +4887,6 @@ EoEXAMPLE
##
######################################################################
sub nic_namecheap_update {
debug("\nnic_namecheap1_update -------------------");
## update each configured host
@ -5334,8 +5302,6 @@ EoEXAMPLE
##
######################################################################
sub nic_sitelutions_update {
debug("\nnic_sitelutions_update -------------------");
## update each configured host
@ -5637,8 +5603,6 @@ EoEXAMPLE
##
######################################################################
sub nic_changeip_update {
debug("\nnic_changeip_update -------------------");
## update each configured host
@ -7587,11 +7551,9 @@ sub nic_gandi_update {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
$config{$h}{"status-$ipv"} = "good";
success("%s -- Updated successfully to %s.", $h, $ip);
} else {
$config{$h}{"status-$ipv"} = "bad";
if (defined($response->{status}) && $response->{status} eq "error") {
my @errors;
for my $err (@{$response->{errors}}) {
@ -7656,15 +7618,12 @@ sub nic_keysystems_update {
}
last if !header_ok($h, $reply);
if ($reply =~ /code = 200/)
{
if ($reply =~ /code = 200/) {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good';
success("updating %s: good: IP address set to %s", $h, $ip);
}
else
{
} else {
$config{$h}{'status'} = 'failed';
failed("updating %s: Server said: '$reply'", $h);
}
@ -7718,15 +7677,12 @@ sub nic_regfishde_update {
}
last if !header_ok($h, $reply);
if ($reply =~ /success/)
{
if ($reply =~ /success/) {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good';
success("updating %s: good: IP address set to %s", $h, $ip);
}
else
{
} else {
$config{$h}{'status'} = 'failed';
failed("updating %s: Server said: '$reply'", $h);
}