From a91ca7a19949511cf2899b92130620ba298df98f Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 16:48:00 -0400 Subject: [PATCH 01/20] s/foreach/for/g for consistency --- ddclient.in | 228 ++++++++++++++++++++++++++-------------------------- 1 file changed, 114 insertions(+), 114 deletions(-) diff --git a/ddclient.in b/ddclient.in index 9ce0d1d..1313ba7 100755 --- a/ddclient.in +++ b/ddclient.in @@ -1343,12 +1343,12 @@ sub update_nics { my %ipv4list = (); my %ipv6list = (); - foreach my $s (sort keys %services) { + for my $s (sort keys %services) { my (@hosts, %ipsv4, %ipsv6) = (); my $updateable = $services{$s}{'updateable'}; my $update = $services{$s}{'update'}; - foreach my $h (sort keys %config) { + for my $h (sort keys %config) { next if $config{$h}{'protocol'} ne lc($s); $examined{$h} = 1; # we only do this once per 'use' and argument combination @@ -1464,7 +1464,7 @@ sub update_nics { # The new '--usev*' parameters set 'wantipv*' and the new providers set 'ipv*' and 'status-ipv*'. # To allow gradual transition, we make sure both the old 'status' and 'ip' are being set # accordingly to what new providers returned in the new 'status-ipv*' and 'ipv*' fields respectively. - foreach my $h (@hosts) { + for my $h (@hosts) { $config{$h}{'status'} //= $config{$h}{'status-ipv4'} // $config{$h}{'status-ipv6'}; $config{$h}{'ip'} //= $config{$h}{'ipv4'} // $config{$h}{'ipv6'}; } @@ -1472,7 +1472,7 @@ sub update_nics { runpostscript(join ' ', keys %ipsv4, keys %ipsv6); } } - foreach my $h (sort keys %config) { + for my $h (sort keys %config) { if (!exists $examined{$h}) { failed("%s was not updated because protocol %s is not supported.", $h, $config{$h}{'protocol'} // ''); @@ -1515,7 +1515,7 @@ sub write_cache { my ($file) = @_; ## merge the updated host entries into the cache. - foreach my $h (keys %config) { + for my $h (keys %config) { if (!exists $cache{$h} || $config{$h}{'update'}) { map { defined($config{$h}{$_}) ? ($cache{$h}{$_} = $config{$h}{$_}) : () } @{$config{$h}{'cacheable'}}; } else { @@ -1525,7 +1525,7 @@ sub write_cache { ## construct the cache file. my $cache = ""; - foreach my $h (sort keys %cache) { + for my $h (sort keys %cache) { my $opt = join(',', map { "$_=" . ($cache{$h}{$_} // '') } sort keys %{$cache{$h}}); $cache .= sprintf "%s%s%s\n", $opt, ($opt ? ' ' : ''), $h; @@ -1573,9 +1573,9 @@ sub read_cache { $saved_cache = _read_config($config, $globals, "##\\s*$program-$version\\s*", $file); %opt = %saved; - foreach my $h (keys %cache) { + for my $h (keys %cache) { if (exists $config->{$h}) { - foreach (qw(atime mtime wtime ip status)) { + for (qw(atime mtime wtime ip status)) { $config->{$h}{$_} = $cache{$h}{$_} if exists $cache{$h}{$_}; } } @@ -1757,7 +1757,7 @@ sub _read_config { my @args = split; ## verify that keywords are valid...and check the value - foreach my $k (keys %locals) { + for my $k (keys %locals) { # Handle '_env' keyword suffix if ($k =~ /(.*)_env$/) { @@ -1810,7 +1810,7 @@ sub _read_config { $locals{'password'} = $password if defined $password; ## allow {host} to be a comma separated list of hosts - foreach my $h (split_by_comma($host)) { + for my $h (split_by_comma($host)) { if ($config{$h}) { ## host already defined, merging configs $config{$h} = {%locals, %{$config{$h}}}; @@ -1878,7 +1878,7 @@ sub init_config { if (exists $opt{'options'} && defined $opt{'options'}) { ## collect cmdline configuration options. my %options = (); - foreach my $opt (split_by_comma($opt{'options'})) { + for my $opt (split_by_comma($opt{'options'})) { my ($name, $var) = split /\s*=\s*/, $opt; if ($name eq 'fw-banlocal' || $name eq 'if-skip') { warning("'$name' is deprecated and does nothing"); @@ -1889,20 +1889,20 @@ sub init_config { ## determine hosts specified with --host my @hosts = (); if (exists $opt{'host'}) { - foreach my $h (split_by_comma($opt{'host'})) { + for my $h (split_by_comma($opt{'host'})) { push @hosts, $h; } } ## and those in --options=... if (exists $options{'host'}) { - foreach my $h (split_by_comma($options{'host'})) { + for my $h (split_by_comma($options{'host'})) { push @hosts, $h; } delete $options{'host'}; } ## merge options into host definitions or globals if (@hosts) { - foreach my $h (@hosts) { + for my $h (@hosts) { $config{$h} = {%{$config{$h}}, %options}; } $opt{'host'} = join(',', @hosts); @@ -1912,7 +1912,7 @@ sub init_config { } ## override global options with those on the command-line. - foreach my $o (keys %opt) { + for my $o (keys %opt) { if (defined $opt{$o} && exists $variables{'global-defaults'}{$o}) { $globals{$o} = $opt{$o}; } @@ -1939,9 +1939,9 @@ sub init_config { map { delete $config{$_} unless exists $hosts{$_} } keys %config; ## collect the cacheable variables. - foreach my $proto (keys %services) { + for my $proto (keys %services) { my @cacheable = (); - foreach my $k (keys %{$services{$proto}{'variables'}}) { + for my $k (keys %{$services{$proto}{'variables'}}) { push @cacheable, $k if $services{$proto}{'variables'}{$k}{'cache'}; } $services{$proto}{'cacheable'} = [ @cacheable ]; @@ -1950,7 +1950,7 @@ sub init_config { ## sanity check.. ## make sure config entries have all defaults and they meet minimums ## first the globals... - foreach my $k (keys %globals) { + for my $k (keys %globals) { # Make sure any _env suffixed variables look at their original entry $k = $1 if $k =~ /^(.*)_env$/; @@ -1966,7 +1966,7 @@ sub init_config { ## now the host definitions... HOST: - foreach my $h (keys %config) { + for my $h (keys %config) { my $proto; $proto = $config{$h}{'protocol'}; $proto = opt('protocol') if !defined($proto); @@ -1982,7 +1982,7 @@ sub init_config { my $svars = $services{$proto}{'variables'}; my $conf = { 'protocol' => $proto }; - foreach my $k (keys %$svars) { + for my $k (keys %$svars) { # Make sure any _env suffixed variables look at their original entry $k = $1 if $k =~ /^(.*)_env$/; @@ -2010,7 +2010,7 @@ sub process_args { my @spec = (); my $usage = ""; - foreach (@_) { + for (@_) { if (ref $_) { my ($key, $specifier, $arg_usage) = @$_; my $value = default($key); @@ -2068,14 +2068,14 @@ sub test_possible_ip { `command -v ifconfig >/dev/null && ifconfig -a`) if $? || !@ifs; @ifs = () if $?; warning("failed to get list of interfaces") if !@ifs; - foreach my $if (@ifs) { + for my $if (@ifs) { local $opt{'if'} = $if; printf "use=if, if=%s address is %s\n", opt('if'), get_ip('if') // 'NOT FOUND'; } } if (opt('fw')) { if (opt('fw') !~ m%/%) { - foreach my $fw (sort keys %builtinfw) { + for my $fw (sort keys %builtinfw) { local $opt{'use'} = $fw; printf "use=%s address is %s\n", $fw, get_ip($fw) // 'NOT FOUND'; } @@ -2087,7 +2087,7 @@ sub test_possible_ip { } { local $opt{'use'} = 'web'; - foreach my $web (sort keys %builtinweb) { + for my $web (sort keys %builtinweb) { local $opt{'web'} = $web; printf "use=web, web=%s address is %s\n", $web, get_ip('web') // 'NOT FOUND'; } @@ -2113,14 +2113,14 @@ sub test_possible_ip { `command -v ifconfig >/dev/null && ifconfig -a`) if $? || !@ifs; @ifs = () if $?; warning("failed to get list of interfaces") if !@ifs; - foreach my $if (@ifs) { + for my $if (@ifs) { local $opt{'ifv4'} = $if; printf "use=ifv4, ifv4=%s address is %s\n", opt('ifv4'), get_ipv4('ifv4') // 'NOT FOUND'; } } { local $opt{'usev4'} = 'webv4'; - foreach my $web (sort keys %builtinweb) { + for my $web (sort keys %builtinweb) { local $opt{'webv4'} = $web; printf "use=webv4, webv4=$web address is %s\n", get_ipv4('webv4') // 'NOT FOUND' if ($web !~ "6") ## Don't bother if web site only supports IPv6; @@ -2147,14 +2147,14 @@ sub test_possible_ip { `command -v ifconfig >/dev/null && ifconfig -a`) if $? || !@ifs; @ifs = () if $?; warning("failed to get list of interfaces") if !@ifs; - foreach my $if (@ifs) { + for my $if (@ifs) { local $opt{'ifv6'} = $if; printf "use=ifv6, ifv6=%s address is %s\n", opt('ifv6'), get_ipv6('ifv6') // 'NOT FOUND'; } } { local $opt{'usev6'} = 'webv6'; - foreach my $web (sort keys %builtinweb) { + for my $web (sort keys %builtinweb) { local $opt{'webv6'} = $web; printf "use=webv6, webv6=$web address is %s\n", get_ipv6('webv6') // 'NOT FOUND' if ($web !~ "4"); ## Don't bother if web site only supports IPv4 @@ -2247,7 +2247,7 @@ sub _print_hash { if (!defined($ptr)) { $value = ""; } elsif (ref $ptr eq 'HASH') { - foreach my $key (sort keys %$ptr) { + for my $key (sort keys %$ptr) { if (($key eq "login") || ($key eq "password")) { $value = ""; } else { @@ -2366,14 +2366,14 @@ sub opt { } sub min { my $min = shift; - foreach my $arg (@_) { + for my $arg (@_) { $min = $arg if $arg < $min; } return $min; } sub max { my $max = shift; - foreach my $arg (@_) { + for my $arg (@_) { $max = $arg if $arg > $max; } return $max; @@ -2386,10 +2386,10 @@ sub ynu { return $no if !($value // ''); return $yes if $value eq '1'; - foreach (qw(yes true)) { + for (qw(yes true)) { return $yes if $_ =~ /^$value/i; } - foreach (qw(no false)) { + for (qw(no false)) { return $no if $_ =~ /^$value/i; } return $undef; @@ -2765,7 +2765,7 @@ sub geturl { # Each header line is added individually @header_lines = split('\n', $headers); - $_ = "header=\"".escape_curl_param($_).'"' foreach (@header_lines); + $_ = "header=\"".escape_curl_param($_).'"' for (@header_lines); push(@curlopt, @header_lines); # Add in the data if any was provided (for POST/PATCH) @@ -2780,7 +2780,7 @@ sub geturl { # don't include ${url} as that might expose login credentials $0 = sprintf("%s - Curl system cmd sending to %s", $program, "${protocol}://${server}"); verbose("SENDING:", "Curl system cmd to %s", "${protocol}://${server}"); - verbose("SENDING:", "%s", $_) foreach (@curlopt); + verbose("SENDING:", "%s", $_) for (@curlopt); $reply = curl_cmd(@curlopt); verbose("RECEIVE:", "%s", $reply // ""); @@ -3079,7 +3079,7 @@ sub get_default_interface { debug("Default routes found for IPv%s :\n%s", $ipver, join("\n",@list)); # now check each interface to make sure it is global (not loopback). - foreach my $line (@list) { + for my $line (@list) { ## Interface will be after "dev" or the last word in the line. Must accept blank spaces ## at the end. Interface name may not have any whitespace or forward slash. $line =~ /\bdev\b\s*\K[^\s\/]+|\b[^\s\/]+(?=[\s\/]*$)/; @@ -3426,7 +3426,7 @@ sub group_hosts_by { my %attrs = (map({ ($_ => 1) } @$attributes), 'wantip' => 1); my @attrs = sort(keys(%attrs)); my %groups = (); - foreach my $h (@$hosts) { + for my $h (@$hosts) { my $sig = join(',', map({ sprintf("%s=%s", $_, $config{$h}{$_} // '') } @attrs)); push @{$groups{$sig}}, $h; } @@ -3442,7 +3442,7 @@ sub encode_www_form_urlencoded { my $must_encode = qr'[<>"#%{}|\\^~\[\]`;/?:=&+]'; my $encoded; my $i = 0; - foreach my $k (keys %$formdata) { + for my $k (keys %$formdata) { my $kenc = $k; my $venc = $formdata->{$k}; @@ -3468,7 +3468,7 @@ sub encode_www_form_urlencoded { sub nic_examples { my $examples = ""; my $separator = ""; - foreach my $s (sort keys %services) { + for my $s (sort keys %services) { my $subr = $services{$s}{'examples'}; my $example; @@ -3852,7 +3852,7 @@ EoEXAMPLE sub nic_dyndns1_update { debug("\nnic_dyndns1_update -------------------"); ## update each configured host - foreach my $h (@_) { + for my $h (@_) { my $ip = delete $config{$h}{'wantip'}; info("setting IP address to %s for %s", $ip, $h); verbose("UPDATE:", "updating %s", $h); @@ -3883,7 +3883,7 @@ sub nic_dyndns1_update { my @reply = split /\n/, $reply; my ($title, $return_code, $error_code) = ('', '', ''); - foreach my $line (@reply) { + for my $line (@reply) { $title = $1 if $line =~ m%\s*(.*)\s*%i; $return_code = $1 if $line =~ m%^return\s+code\s*:\s*(.*)\s*$%i; $error_code = $1 if $line =~ m%^error\s+code\s*:\s*(.*)\s*$%i; @@ -4002,14 +4002,14 @@ sub nic_dyndns2_update { ); ## update each set of hosts that had similar configurations - foreach my $sig (keys %groups) { + for my $sig (keys %groups) { my @hosts = @{$groups{$sig}}; my $hosts = join(',', @hosts); my $h = $hosts[0]; my $ipv4 = $config{$h}{'wantipv4'}; my $ipv6 = $config{$h}{'wantipv6'}; - delete $config{$_}{'wantipv4'} foreach @hosts; - delete $config{$_}{'wantipv6'} foreach @hosts; + delete $config{$_}{'wantipv4'} for @hosts; + delete $config{$_}{'wantipv6'} for @hosts; info("setting IPv4 address to %s for %s", $ipv4, $hosts) if $ipv4; info("setting IPv6 address to %s for %s", $ipv6, $hosts) if $ipv6; @@ -4059,7 +4059,7 @@ sub nic_dyndns2_update { my @reply = split /\n/, $reply; my $state = 'header'; - foreach my $line (@reply) { + for my $line (@reply) { if ($state eq 'header') { $state = 'body'; @@ -4073,13 +4073,13 @@ sub nic_dyndns2_update { # we can't use the returned IP my ($status, $returnedips) = split / /, lc $line; - foreach my $h (@hosts) { + for my $h (@hosts) { $config{$h}{'status-ipv4'} = $status if $ipv4; $config{$h}{'status-ipv6'} = $status if $ipv6; } if ($status eq 'good') { - foreach my $h (@hosts) { + for my $h (@hosts) { $config{$h}{'ipv4'} = $ipv4 if $ipv4; $config{$h}{'ipv6'} = $ipv6 if $ipv6; $config{$h}{'mtime'} = $now; @@ -4092,7 +4092,7 @@ sub nic_dyndns2_update { if ($status eq 'nochg') { warning("updating %s: %s: %s", $hosts, $status, $errors{$status}); - foreach my $h (@hosts) { + for my $h (@hosts) { $config{$h}{'ipv4'} = $ipv4 if $ipv4; $config{$h}{'ipv6'} = $ipv6 if $ipv6; $config{$h}{'mtime'} = $now; @@ -4113,7 +4113,7 @@ sub nic_dyndns2_update { ($scale, $units) = (60*60, 'hours') if $units eq 'h'; $sec = $wait * $scale; - foreach my $h (@hosts) { + for my $h (@hosts) { $config{$h}{'wtime'} = $now + $sec; } @@ -4173,7 +4173,7 @@ sub nic_dnsexit2_update { debug("\nnic_dnsexit2_update -------------------"); ## Update each configured host (hosts cannot be grouped on this API) - foreach my $h (@_) { + for my $h (@_) { # All the known status my %status = ( '0' => [ 'good', 'Success! Actions got executed successfully.' ], @@ -4191,7 +4191,7 @@ sub nic_dnsexit2_update { # Updates for ipv4 and ipv6 need to be combined in a single API call, create Hash of Arrays for tracking my %total_payload; - foreach my $ip ($ipv4, $ipv6){ + for my $ip ($ipv4, $ipv6){ next if (!$ip); my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4'; my $type = ($ip eq ($ipv6 // '')) ? 'AAAA' : 'A'; @@ -4293,7 +4293,7 @@ sub nic_dnsexit2_update { if ($status eq 'good') { $config{$h}{'mtime'} = $now; my $tracked_ipv; - foreach $tracked_ipv ( keys %total_payload ){ + for $tracked_ipv ( keys %total_payload ){ $config{$h}{"ipv$tracked_ipv"} = $total_payload{$tracked_ipv}{content}; $config{$h}{"status-ipv$tracked_ipv"} = 'good'; success("%s", $message); @@ -4340,14 +4340,14 @@ sub nic_noip_update { ); ## update each set of hosts that had similar configurations - foreach my $sig (keys %groups) { + for my $sig (keys %groups) { my @hosts = @{$groups{$sig}}; my $hosts = join(',', @hosts); my $h = $hosts[0]; my $ipv4 = $config{$h}{'wantipv4'}; my $ipv6 = $config{$h}{'wantipv6'}; - delete $config{$_}{'wantipv4'} foreach @hosts; - delete $config{$_}{'wantipv6'} foreach @hosts; + delete $config{$_}{'wantipv4'} for @hosts; + delete $config{$_}{'wantipv6'} for @hosts; info("setting IPv4 address to %s for %s", $ipv4, $hosts) if $ipv4; info("setting IPv6 address to %s for %s", $ipv6, $hosts) if $ipv6; @@ -4374,7 +4374,7 @@ sub nic_noip_update { my @reply = split /\n/, $reply; my $state = 'header'; - foreach my $line (@reply) { + for my $line (@reply) { if ($state eq 'header') { $state = 'body'; @@ -4387,7 +4387,7 @@ sub nic_noip_update { my ($status, $returnedips) = split / /, lc $line; my $h = shift @hosts; - foreach my $ip (split_by_comma($returnedips)) { + for my $ip (split_by_comma($returnedips)) { next if (!$ip); my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4'; $config{$h}{"status-ipv$ipv"} = $status; @@ -4395,7 +4395,7 @@ sub nic_noip_update { if ($status eq 'good') { $config{$h}{'mtime'} = $now; - foreach my $ip (split_by_comma($returnedips)) { + for my $ip (split_by_comma($returnedips)) { next if (!$ip); my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4'; $config{$h}{"ipv$ipv"} = $ip; @@ -4406,7 +4406,7 @@ sub nic_noip_update { if ($status eq 'nochg') { warning("updating %s: %s: %s", $h, $status, $errors{$status}); $config{$h}{'mtime'} = $now; - foreach my $ip (split_by_comma($returnedips)) { + for my $ip (split_by_comma($returnedips)) { next if (!$ip); my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4'; $config{$h}{"ipv$ipv"} = $ip; @@ -4499,7 +4499,7 @@ EoEXAMPLE sub nic_dslreports1_update { debug("\nnic_dslreports1_update -------------------"); ## update each configured host - foreach my $h (@_) { + for my $h (@_) { my $ip = delete $config{$h}{'wantip'}; info("setting IP address to %s for %s", $ip, $h); verbose("UPDATE:", "updating %s", $h); @@ -4524,7 +4524,7 @@ sub nic_dslreports1_update { my @reply = split /\n/, $reply; my $return_code = ''; - foreach my $line (@reply) { + for my $line (@reply) { $return_code = $1 if $line =~ m%^return\s+code\s*:\s*(.*)\s*$%i; } @@ -4581,7 +4581,7 @@ sub nic_domeneshop_update { ## update each configured host ## should improve to update in one pass - foreach my $h (@_) { + for my $h (@_) { my $ip = delete $config{$h}{'wantip'}; info("Setting IP address to %s for %s", $ip, $h); verbose("UPDATE:", "Updating %s", $h); @@ -4676,12 +4676,12 @@ sub nic_zoneedit1_update { my %groups = group_hosts_by([ @_ ], [ qw(login password server zone) ]); ## update each set of hosts that had similar configurations - foreach my $sig (keys %groups) { + for my $sig (keys %groups) { my @hosts = @{$groups{$sig}}; my $hosts = join(',', @hosts); my $h = $hosts[0]; my $ip = $config{$h}{'wantip'}; - delete $config{$_}{'wantip'} foreach @hosts; + delete $config{$_}{'wantip'} for @hosts; info("setting IP address to %s for %s", $ip, $hosts); verbose("UPDATE:", "updating %s", $hosts); @@ -4705,7 +4705,7 @@ sub nic_zoneedit1_update { next if !header_ok($hosts, $reply); my @reply = split /\n/, $reply; - foreach my $line (@reply) { + for my $line (@reply) { if ($h && $line =~ /^[^<]*<(SUCCESS|ERROR)\s+([^>]+)>(.*)/) { my ($status, $assignments, $rest) = ($1, $2, $3); my ($left, %var) = parse_assignments($assignments); @@ -4823,14 +4823,14 @@ sub nic_easydns_update { ); ## update each set of hosts that had similar configurations - foreach my $sig (keys %groups) { + for my $sig (keys %groups) { my @hosts = @{$groups{$sig}}; my $hosts = join(',', @hosts); my $h = $hosts[0]; my $ipv4 = $config{$h}{'wantipv4'}; my $ipv6 = $config{$h}{'wantipv6'}; - delete $config{$_}{'wantipv4'} foreach @hosts; - delete $config{$_}{'wantipv6'} foreach @hosts; + delete $config{$_}{'wantipv4'} for @hosts; + delete $config{$_}{'wantipv6'} for @hosts; info("setting IP address to %s %s for %s", $ipv4, $ipv6, $hosts); verbose("UPDATE:", "updating %s", $hosts); @@ -4842,7 +4842,7 @@ sub nic_easydns_update { $url .= "hostname=$hosts"; $url .= "&myip="; $url .= $ipv4 if $ipv4; - foreach my $ipv6a ($ipv6) { + for my $ipv6a ($ipv6) { $url .= "&myip="; $url .= $ipv6a } @@ -4867,7 +4867,7 @@ sub nic_easydns_update { my @reply = split /\n/, $reply; my $state = 'header'; - foreach my $line (@reply) { + for my $line (@reply) { if ($state eq 'header') { $state = 'body'; @@ -4958,7 +4958,7 @@ sub nic_namecheap_update { debug("\nnic_namecheap1_update -------------------"); ## update each configured host - foreach my $h (@_) { + for my $h (@_) { my $ip = delete $config{$h}{'wantip'}; info("setting IP address to %s for %s", $ip, $h); verbose("UPDATE:", "updating %s", $h); @@ -5150,7 +5150,7 @@ sub nic_nfsn_update { debug("\nnic_nfsn_update -------------------"); ## update each configured host - foreach my $h (@_) { + for my $h (@_) { my $zone = $config{$h}{'zone'}; my $name; @@ -5264,7 +5264,7 @@ EoEXAMPLE sub nic_njalla_update { debug("\nnic_njalla_update -------------------"); - foreach my $h (@_) { + for my $h (@_) { # Read input params my $ipv4 = delete $config{$h}{'wantipv4'}; my $ipv6 = delete $config{$h}{'wantipv6'}; @@ -5274,7 +5274,7 @@ sub nic_njalla_update { # Build url my $url = "https://$config{$h}{'server'}/update/?h=$h&k=$config{$h}{'password'}"; my $auto = 1; - foreach my $ip ($ipv4, $ipv6) { + for my $ip ($ipv4, $ipv6) { next if (!$ip); $auto = 0; my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4'; @@ -5375,7 +5375,7 @@ sub nic_sitelutions_update { debug("\nnic_sitelutions_update -------------------"); ## update each configured host - foreach my $h (@_) { + for my $h (@_) { my $ip = delete $config{$h}{'wantip'}; info("setting IP address to %s for %s", $ip, $h); verbose("UPDATE:", "updating %s", $h); @@ -5498,7 +5498,7 @@ sub nic_freedns_update { $record_list_error = "failed to get record list from $url_tmpl"; } - foreach my $h (@_) { + for my $h (@_) { next if (!$h); my $ipv4 = delete $config{$h}{'wantipv4'}; my $ipv6 = delete $config{$h}{'wantipv6'}; @@ -5511,7 +5511,7 @@ sub nic_freedns_update { } # IPv4 and IPv6 handling are similar enough to do in a loop... - foreach my $ip ($ipv4, $ipv6) { + for my $ip ($ipv4, $ipv6) { next if (!$ip); my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4'; my $type = ($ip eq ($ipv6 // '')) ? 'AAAA' : 'A'; @@ -5594,7 +5594,7 @@ EoEXAMPLE ###################################################################### sub nic_1984_update { debug("\nnic_1984_update -------------------"); - foreach my $host (@_) { + for my $host (@_) { my $ip = delete $config{$host}{'wantip'}; info("setting IP address to %s for %s", $ip, $host); verbose("UPDATE:", "updating %s", $host); @@ -5678,7 +5678,7 @@ sub nic_changeip_update { debug("\nnic_changeip_update -------------------"); ## update each configured host - foreach my $h (@_) { + for my $h (@_) { my $ip = delete $config{$h}{'wantip'}; info("setting IP address to %s for %s", $ip, $h); verbose("UPDATE:", "updating %s", $h); @@ -5763,7 +5763,7 @@ sub nic_godaddy_update { my %groups = group_hosts_by([ @_ ], [ qw(server login password zone) ]); ## update each set of hosts that had similar configurations - foreach my $sig (keys %groups) { + for my $sig (keys %groups) { my @hosts = @{$groups{$sig}}; # Update each set configured host. @@ -5774,7 +5774,7 @@ sub nic_godaddy_update { my $zone = $config{$host}{'zone'}; (my $hostname = $host) =~ s/\.\Q$zone\E$//; - foreach my $ip ($ipv4, $ipv6) { + for my $ip ($ipv4, $ipv6) { next if (!$ip); info("%s.%s -- Setting IP address to %s.", $hostname, $zone, $ip); @@ -5900,7 +5900,7 @@ sub nic_googledomains_update { my %groups = group_hosts_by([ @_ ], [ qw(server login password) ]); ## update each set of hosts that had similar configurations - foreach my $sig (keys %groups) { + for my $sig (keys %groups) { my @hosts = @{$groups{$sig}}; my $key = $hosts[0]; my $ip = $config{$key}{'wantip'}; @@ -5985,10 +5985,10 @@ sub nic_mythicdyn_update { debug("\nnic_mythicdyn_update --------------------"); # Update each configured host. - foreach my $h (@_) { + for my $h (@_) { info("%s -- Setting IP address.", $h); - foreach my $mythver ('4','6') { + for my $mythver ('4','6') { my $ip = $config{$h}{"wantipv$mythver"}; if (defined($ip)) { @@ -6080,7 +6080,7 @@ sub nic_nsupdate_update { my %groups = group_hosts_by([ @_ ], [ qw(login password server zone) ]); ## update each set of hosts that had similar configurations - foreach my $sig (keys %groups) { + for my $sig (keys %groups) { my @hosts = @{$groups{$sig}}; my $hosts = join(',', @hosts); my $h = $hosts[0]; @@ -6092,8 +6092,8 @@ sub nic_nsupdate_update { my $zone = $config{$h}{'zone'}; my $ipv4 = $config{$h}{'wantipv4'}; my $ipv6 = $config{$h}{'wantipv6'}; - delete $config{$_}{'wantipv4'} foreach @hosts; - delete $config{$_}{'wantipv6'} foreach @hosts; + delete $config{$_}{'wantipv4'} for @hosts; + delete $config{$_}{'wantipv6'} for @hosts; info("setting IPv4 address to %s for %s", $ipv4, $hosts) if ($ipv4); info("setting IPv6 address to %s for %s", $ipv6, $hosts) if ($ipv6); @@ -6104,8 +6104,8 @@ sub nic_nsupdate_update { server $server zone $zone. EoINSTR1 - foreach (@hosts) { - foreach my $ip ($ipv4, $ipv6) { + for (@hosts) { + for my $ip ($ipv4, $ipv6) { next if (!$ip); my $type = ($ip eq ($ipv6 // '')) ? 'AAAA' : 'A'; $instructions .= <<"EoINSTR2"; @@ -6125,9 +6125,9 @@ EoINSTR4 my $status = pipecmd($command, $instructions); if ($status eq 1) { - foreach (@hosts) { + for (@hosts) { $config{$_}{'mtime'} = $now; - foreach my $ip ($ipv4, $ipv6) { + for my $ip ($ipv4, $ipv6) { next if (!$ip); my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4'; $config{$_}{"ipv$ipv"} = $ip; @@ -6136,7 +6136,7 @@ EoINSTR4 } } } else { - foreach (@hosts) { + for (@hosts) { failed("updating %s", $_); } } @@ -6197,7 +6197,7 @@ sub nic_cloudflare_update { my %groups = group_hosts_by([ @_ ], [ qw(ssh login password server wildcard mx backupmx zone) ]); ## update each set of hosts that had similar configurations - foreach my $sig (keys %groups) { + for my $sig (keys %groups) { my @hosts = @{$groups{$sig}}; my $hosts = join(',', @hosts); my $key = $hosts[0]; @@ -6248,7 +6248,7 @@ sub nic_cloudflare_update { # IPv4 and IPv6 handling are similar enough to do in a loop... - foreach my $ip ($ipv4, $ipv6) { + for my $ip ($ipv4, $ipv6) { next if (!$ip); my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4'; my $type = ($ip eq ($ipv6 // '')) ? 'AAAA' : 'A'; @@ -6345,7 +6345,7 @@ sub nic_hetzner_update { my %groups = group_hosts_by([ @_ ], [ qw(ssh login password server wildcard mx backupmx zone) ]); ## update each set of hosts that had similar configurations - foreach my $sig (keys %groups) { + for my $sig (keys %groups) { my @hosts = @{$groups{$sig}}; my $hosts = join(',', @hosts); my $key = $hosts[0]; @@ -6391,7 +6391,7 @@ sub nic_hetzner_update { # IPv4 and IPv6 handling are similar enough to do in a loop... - foreach my $ip ($ipv4, $ipv6) { + for my $ip ($ipv4, $ipv6) { next if (!$ip); my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4'; my $type = ($ip eq ($ipv6 // '')) ? 'AAAA' : 'A'; @@ -6502,7 +6502,7 @@ sub nic_yandex_update { my %groups = group_hosts_by([ @_ ], [ qw(server login pasword) ]); ## update each set of hosts that had similar configurations - foreach my $sig (keys %groups) { + for my $sig (keys %groups) { my @hosts = @{$groups{$sig}}; my $key = $hosts[0]; my $ip = $config{$key}{'wantip'}; @@ -6617,7 +6617,7 @@ sub nic_duckdns_update { ## update each configured host ## should improve to update in one pass - foreach my $h (@_) { + for my $h (@_) { my $ipv4 = delete $config{$h}{'wantipv4'}; my $ipv6 = delete $config{$h}{'wantipv6'}; info("setting IPv4 address to %s for %s", $ipv4, $h) if $ipv4; @@ -6648,7 +6648,7 @@ sub nic_duckdns_update { my $state = 'noresult'; my $line = ''; - foreach $line (@reply) { + for $line (@reply) { if ($line eq 'OK') { $config{$h}{'ipv4'} = $ipv4 if $ipv4; $config{$h}{'ipv6'} = $ipv6 if $ipv6; @@ -6707,7 +6707,7 @@ EoEXAMPLE sub nic_freemyip_update { debug("\nnic_freemyip_update -------------------"); - foreach my $h (@_) { + for my $h (@_) { my $ip = delete $config{$h}{'wantip'}; info("setting IP address to %s for %s", $ip, $h); verbose("UPDATE:", "updating %s", $h); @@ -6864,7 +6864,7 @@ sub nic_woima_update { my $state = 'header'; my $returnedip = $ip; - foreach my $line (@reply) { + for my $line (@reply) { if ($state eq 'header') { $state = 'body'; @@ -6950,7 +6950,7 @@ sub nic_dondominio_update { ## update each configured host ## should improve to update in one pass - foreach my $h (@_) { + for my $h (@_) { my $ip = delete $config{$h}{'wantip'}; info("setting IP address to %s for %s", $ip, $h); verbose("UPDATE:", "updating %s", $h); @@ -7040,7 +7040,7 @@ sub nic_dnsmadeeasy_update { ## update each configured host ## should improve to update in one pass - foreach my $h (@_) { + for my $h (@_) { my $ip = delete $config{$h}{'wantip'}; info("Setting IP address to %s for %s", $ip, $h); verbose("UPDATE:", "Updating %s", $h); @@ -7114,7 +7114,7 @@ sub nic_ovh_update { ## update each configured host ## should improve to update in one pass - foreach my $h (@_) { + for my $h (@_) { my $ip = delete $config{$h}{'wantip'}; info("setting IP address to %s for %s", $ip, $h); verbose("UPDATE:","updating %s", $h); @@ -7235,7 +7235,7 @@ EoEXAMPLE sub nic_porkbun_update { debug("\nnic_porkbun_update -------------------"); - foreach my $host (@_) { + for my $host (@_) { my ($sub_domain, $domain); if ($config{$host}{'root-domain'} ne '') { # Process 'root-domain' option @@ -7262,7 +7262,7 @@ sub nic_porkbun_update { } info("subdomain %s, root domain %s", $sub_domain, $domain) if $sub_domain ne ''; - foreach my $ipv ('ipv4', 'ipv6') { + for my $ipv ('ipv4', 'ipv6') { my $ip = delete $config{$host}{"want$ipv"}; if (!$ip) { next; @@ -7547,8 +7547,8 @@ EoEXAMPLE sub nic_gandi_update { debug("\nnic_gandi_update -------------------"); # Update each set configured host. - foreach my $h (@_) { - foreach my $ipv ('ipv4', 'ipv6') { + for my $h (@_) { + for my $ipv ('ipv4', 'ipv6') { my $ip = delete $config{$h}{"want$ipv"}; if(!$ip) { next; @@ -7676,7 +7676,7 @@ sub nic_keysystems_update { ## update each configured host ## should improve to update in one pass - foreach my $h (@_) { + for my $h (@_) { my $ip = delete $config{$h}{'wantip'}; info("KEYSYSTEMS setting IP address to %s for %s", $ip, $h); @@ -7812,7 +7812,7 @@ EoEXAMPLE sub nic_enom_update { debug("\nenom_update -------------------"); ## update each configured host - foreach my $h (@_) { + for my $h (@_) { my $ip = delete $config{$h}{'wantip'}; info("setting IP address to %s for %s", $ip, $h); verbose("UPDATE:","updating %s", $h); @@ -7956,7 +7956,7 @@ sub nic_digitalocean_update_one { sub nic_digitalocean_update { debug("\nnic_digitalocean_update -------------------"); - foreach my $h (@_) { + for my $h (@_) { my $ipv4 = delete $config{$h}{'wantipv4'}; my $ipv6 = delete $config{$h}{'wantipv6'}; @@ -8024,9 +8024,9 @@ EoEXAMPLE sub nic_infomaniak_update { debug("\nnic_infomaniak_update -------------------"); - foreach my $h (@_) { + for my $h (@_) { INFOMANIAK_IP_LOOP: - foreach my $v (4, 6) { + for my $v (4, 6) { my $ip = delete $config{$h}{"wantipv$v"}; if (!defined $ip) { @@ -8062,7 +8062,7 @@ sub nic_infomaniak_update { my $reply; - foreach my $url ($url1, $url2) { + for my $url ($url1, $url2) { info("trying update with %s", $url); $reply = geturl(proxy => opt('proxy'), url => $url); if (!defined($reply) || !$reply) { From 0040fc96082428bbabceb9fdd6391dc1a5043248 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 27 May 2024 18:10:55 -0400 Subject: [PATCH 02/20] dnsexit2: Whitespace fixes --- ddclient.in | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/ddclient.in b/ddclient.in index 1313ba7..e46f373 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4176,14 +4176,14 @@ sub nic_dnsexit2_update { for my $h (@_) { # All the known status my %status = ( - '0' => [ 'good', 'Success! Actions got executed successfully.' ], - '1' => [ 'warning', 'Some execution problems. May not indicate actions failures. Some action may got executed fine and some may have problems.' ], - '2' => [ 'badauth', 'API Key Authentication Error. The API Key is missing or wrong.' ], - '3' => [ 'error', 'Missing Required Definitions. Your JSON file may missing some required definitions.' ], - '4' => [ 'error', 'JSON Data Syntax Error. Your JSON file has syntax error.' ], - '5' => [ 'error', 'JSON Defined Record Type not Supported. Your JSON may try to update some record type not supported by our system.' ], - '6' => [ 'error', 'System Error. Our system problem. May not be your problem. Contact our support if you got such error.' ], - '7' => [ 'error', 'Error getting post data. Our server has problem to receive your JSON posting.' ], + '0' => ['good', 'Success! Actions got executed successfully.'], + '1' => ['warning', 'Some execution problems. May not indicate actions failures. Some action may got executed fine and some may have problems.'], + '2' => ['badauth', 'API Key Authentication Error. The API Key is missing or wrong.'], + '3' => ['error', 'Missing Required Definitions. Your JSON file may missing some required definitions.'], + '4' => ['error', 'JSON Data Syntax Error. Your JSON file has syntax error.'], + '5' => ['error', 'JSON Defined Record Type not Supported. Your JSON may try to update some record type not supported by our system.'], + '6' => ['error', 'System Error. Our system problem. May not be your problem. Contact our support if you got such error.'], + '7' => ['error', 'Error getting post data. Our server has problem to receive your JSON posting.'], ); my $ipv4 = delete $config{$h}{'wantipv4'}; my $ipv6 = delete $config{$h}{'wantipv6'}; @@ -4191,9 +4191,9 @@ sub nic_dnsexit2_update { # Updates for ipv4 and ipv6 need to be combined in a single API call, create Hash of Arrays for tracking my %total_payload; - for my $ip ($ipv4, $ipv6){ + for my $ip ($ipv4, $ipv6) { next if (!$ip); - my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4'; + my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4'; my $type = ($ip eq ($ipv6 // '')) ? 'AAAA' : 'A'; info("Going to update IPv$ipv address to %s for %s.", $ip, $h); @@ -4212,7 +4212,7 @@ sub nic_dnsexit2_update { my $header = "Content-Type: application/json\nAccept: application/json"; # Set the zone if empty - if ( not defined $config{$h}{'zone'}){ + if (not defined $config{$h}{'zone'}) { debug("Zone not defined, setting to default hostname: %s", $h); $config{$h}{'zone'} = $h } else { @@ -4229,15 +4229,15 @@ sub nic_dnsexit2_update { # Make the call my $reply = geturl( - proxy => opt('proxy'), - url => $url, - headers => $header, - method => 'POST', - data => $data + proxy => opt('proxy'), + url => $url, + headers => $header, + method => 'POST', + data => $data ); # No reply, declare as failed - unless ($reply && header_ok($h, $reply)){ + unless ($reply && header_ok($h, $reply)) { failed("updating %s: Could not connect to %s%s.", $h, $config{$h}{'server'}, $config{$h}{'path'}); last; }; @@ -4249,7 +4249,7 @@ sub nic_dnsexit2_update { debug("HTTP response code: %s", $http_status); # If not 200, bail - if ( $http_status ne '200' ){ + if ($http_status ne '200') { failed("Failed to update Host\n%s", $h); failed("HTTP response code\n%s", $http_status); failed("Full reply\n%s", $reply) unless opt('verbose'); @@ -4262,8 +4262,7 @@ sub nic_dnsexit2_update { debug("%s", $strip_status); if ($strip_status) { debug("HTTP headers are stripped."); - } - else { + } else { warning("Unexpected: no HTTP headers stripped!"); } @@ -4274,16 +4273,16 @@ sub nic_dnsexit2_update { if (defined($response->{'code'}) and defined($response->{'message'})) { if (exists $status{$response->{'code'}}) { # Add the server response data to the applicable array - push( @{ $status {$response->{'code'} } }, $response->{'message'}); + push(@{$status{$response->{'code'}}}, $response->{'message'}); if (defined($response->{'details'})) { - push ( @{ $status {$response->{'code'} } }, $response->{'details'}[0]); + push(@{$status{$response->{'code'}}}, $response->{'details'}[0]); } else { # Keep it symmetrical for simplicity - push ( @{ $status {$response->{'code'} } }, "no details received"); + push(@{$status{$response->{'code'}}}, "no details received"); } # Set data from array - my ($status, $message, $srv_message, $srv_details) = @{ $status {$response->{'code'} } }; + my ($status, $message, $srv_message, $srv_details) = @{$status{$response->{'code'}}}; info("Status: %s -- Message: %s", $status, $message); info("Server Message: %s -- Server Details: %s", $srv_message, $srv_details); $config{$h}{'status-ipv4'} = $status if $ipv4; @@ -4291,9 +4290,9 @@ sub nic_dnsexit2_update { # Handle statuses if ($status eq 'good') { - $config{$h}{'mtime'} = $now; + $config{$h}{'mtime'} = $now; my $tracked_ipv; - for $tracked_ipv ( keys %total_payload ){ + for $tracked_ipv (keys %total_payload) { $config{$h}{"ipv$tracked_ipv"} = $total_payload{$tracked_ipv}{content}; $config{$h}{"status-ipv$tracked_ipv"} = 'good'; success("%s", $message); @@ -4318,6 +4317,7 @@ sub nic_dnsexit2_update { } } } + ###################################################################### ## nic_noip_update ## Note: uses same features as nic_dyndns2_update, less return codes From 63989d96fb549f04251992b834bbd5dcb852311e Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 17:00:30 -0400 Subject: [PATCH 03/20] dnsexit2: Move variable declaration to loop scope --- ddclient.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ddclient.in b/ddclient.in index e46f373..235628c 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4291,8 +4291,7 @@ sub nic_dnsexit2_update { # Handle statuses if ($status eq 'good') { $config{$h}{'mtime'} = $now; - my $tracked_ipv; - for $tracked_ipv (keys %total_payload) { + for my $tracked_ipv (keys %total_payload) { $config{$h}{"ipv$tracked_ipv"} = $total_payload{$tracked_ipv}{content}; $config{$h}{"status-ipv$tracked_ipv"} = 'good'; success("%s", $message); From 6cdf5da9f455b928b411c3ffd918953f168da031 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 17:05:54 -0400 Subject: [PATCH 04/20] dnsexit2: Rename variable for brevity --- ddclient.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ddclient.in b/ddclient.in index 235628c..2908849 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4291,11 +4291,11 @@ sub nic_dnsexit2_update { # Handle statuses if ($status eq 'good') { $config{$h}{'mtime'} = $now; - for my $tracked_ipv (keys %total_payload) { - $config{$h}{"ipv$tracked_ipv"} = $total_payload{$tracked_ipv}{content}; - $config{$h}{"status-ipv$tracked_ipv"} = 'good'; + for my $ipv (keys %total_payload) { + $config{$h}{"ipv$ipv"} = $total_payload{$ipv}{content}; + $config{$h}{"status-ipv$ipv"} = 'good'; success("%s", $message); - success("Updated %s successfully to IPv$tracked_ipv address %s at time %s", $h, $total_payload{$tracked_ipv}{content}, prettytime($config{$h}{'mtime'})); + success("Updated %s successfully to IPv$ipv address %s at time %s", $h, $total_payload{$ipv}{content}, prettytime($config{$h}{'mtime'})); } } elsif ($status eq 'warning') { warning("%s", $message); From 3a5e86b4d237beed85ea2e764036996d11aafeb7 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 17:10:06 -0400 Subject: [PATCH 05/20] dnsexit2: Convert string interpolation to `sprintf` format specifier Rationale: * For consistency. * It's generally not a good idea to mix interpolation with `sprintf` because the interpolated string itself might coincidentally (or maliciously) contain format specifiers. --- ddclient.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ddclient.in b/ddclient.in index 2908849..8055787 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4196,7 +4196,7 @@ sub nic_dnsexit2_update { my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4'; my $type = ($ip eq ($ipv6 // '')) ? 'AAAA' : 'A'; - info("Going to update IPv$ipv address to %s for %s.", $ip, $h); + info("Going to update IPv%s address to %s for %s.", $ipv, $ip, $h); $config{$h}{'status-ipv$ipv'} = 'failed'; $total_payload{$ipv} = { name => $h, @@ -4295,7 +4295,7 @@ sub nic_dnsexit2_update { $config{$h}{"ipv$ipv"} = $total_payload{$ipv}{content}; $config{$h}{"status-ipv$ipv"} = 'good'; success("%s", $message); - success("Updated %s successfully to IPv$ipv address %s at time %s", $h, $total_payload{$ipv}{content}, prettytime($config{$h}{'mtime'})); + success("Updated %s successfully to IPv%s address %s at time %s", $h, $ipv, $total_payload{$ipv}{content}, prettytime($config{$h}{'mtime'})); } } elsif ($status eq 'warning') { warning("%s", $message); From 9b1a785c6dcda0822ee0d83f887c2d9171f84f88 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 17:15:24 -0400 Subject: [PATCH 06/20] dnsexit2: Don't repeat the same success message --- ddclient.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddclient.in b/ddclient.in index 8055787..6e23bdb 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4290,11 +4290,11 @@ sub nic_dnsexit2_update { # Handle statuses if ($status eq 'good') { + success("%s", $message); $config{$h}{'mtime'} = $now; for my $ipv (keys %total_payload) { $config{$h}{"ipv$ipv"} = $total_payload{$ipv}{content}; $config{$h}{"status-ipv$ipv"} = 'good'; - success("%s", $message); success("Updated %s successfully to IPv%s address %s at time %s", $h, $ipv, $total_payload{$ipv}{content}, prettytime($config{$h}{'mtime'})); } } elsif ($status eq 'warning') { From 3e91fd02bf2ef49ef93f88324375229559a7e1ce Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 17:21:39 -0400 Subject: [PATCH 07/20] dnsexit2: Invert conditions to improve readability Instead of: if ($success1) { if ($success2) { if ($success3) { # yay } else { # fail } } else { # fail } } else { # fail } do: if (!$success1) { # fail } if (!$success2) { # fail } if (!$success3) { # fail } # yay --- ddclient.in | 82 +++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/ddclient.in b/ddclient.in index 6e23bdb..ee2068e 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4270,49 +4270,51 @@ sub nic_dnsexit2_update { my $response = decode_json($reply); # It should at least have a 'code' and 'message'. - if (defined($response->{'code'}) and defined($response->{'message'})) { - if (exists $status{$response->{'code'}}) { - # Add the server response data to the applicable array - push(@{$status{$response->{'code'}}}, $response->{'message'}); - if (defined($response->{'details'})) { - push(@{$status{$response->{'code'}}}, $response->{'details'}[0]); - } else { - # Keep it symmetrical for simplicity - push(@{$status{$response->{'code'}}}, "no details received"); - } - - # Set data from array - my ($status, $message, $srv_message, $srv_details) = @{$status{$response->{'code'}}}; - info("Status: %s -- Message: %s", $status, $message); - info("Server Message: %s -- Server Details: %s", $srv_message, $srv_details); - $config{$h}{'status-ipv4'} = $status if $ipv4; - $config{$h}{'status-ipv6'} = $status if $ipv6; - - # Handle statuses - if ($status eq 'good') { - success("%s", $message); - $config{$h}{'mtime'} = $now; - for my $ipv (keys %total_payload) { - $config{$h}{"ipv$ipv"} = $total_payload{$ipv}{content}; - $config{$h}{"status-ipv$ipv"} = 'good'; - success("Updated %s successfully to IPv%s address %s at time %s", $h, $ipv, $total_payload{$ipv}{content}, prettytime($config{$h}{'mtime'})); - } - } elsif ($status eq 'warning') { - warning("%s", $message); - warning("Server response: %s", $srv_message); - } elsif ($status =~ m'^(badauth|error)$') { - failed("%s", $message); - failed("Server response: %s", $srv_message); - } else { - failed("This should not be possible"); - } - } else { - failed("Status code %s is unknown!", $response->{'code'}); - } - } else { + if (!defined($response->{'code'}) || !defined($response->{'message'})) { failed("Did not receive expected \"code\" and \"message\" keys in server response."); failed("Response:"); failed("%s", $response); + next; + } + if (!exists($status{$response->{'code'}})) { + failed("Status code %s is unknown!", $response->{'code'}); + next; + } + # Add the server response data to the applicable array + push(@{$status{$response->{'code'}}}, $response->{'message'}); + if (defined($response->{'details'})) { + push(@{$status{$response->{'code'}}}, $response->{'details'}[0]); + } else { + # Keep it symmetrical for simplicity + push(@{$status{$response->{'code'}}}, "no details received"); + } + + # Set data from array + my ($status, $message, $srv_message, $srv_details) = @{$status{$response->{'code'}}}; + info("Status: %s -- Message: %s", $status, $message); + info("Server Message: %s -- Server Details: %s", $srv_message, $srv_details); + $config{$h}{'status-ipv4'} = $status if $ipv4; + $config{$h}{'status-ipv6'} = $status if $ipv6; + + # Handle statuses + if ($status ne 'good') { + if ($status eq 'warning') { + warning("%s", $message); + warning("Server response: %s", $srv_message); + } elsif ($status =~ m'^(badauth|error)$') { + failed("%s", $message); + failed("Server response: %s", $srv_message); + } else { + failed("This should not be possible"); + } + next; + } + success("%s", $message); + $config{$h}{'mtime'} = $now; + for my $ipv (keys %total_payload) { + $config{$h}{"ipv$ipv"} = $total_payload{$ipv}{content}; + $config{$h}{"status-ipv$ipv"} = 'good'; + success("Updated %s successfully to IPv%s address %s at time %s", $h, $ipv, $total_payload{$ipv}{content}, prettytime($config{$h}{'mtime'})); } } } From ed7f4a68a4a77895ba7c37670c2225599456aa81 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 17:34:51 -0400 Subject: [PATCH 08/20] dnsexit2: Rewrite circuitous variable assignments --- ddclient.in | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/ddclient.in b/ddclient.in index ee2068e..468817f 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4280,19 +4280,10 @@ sub nic_dnsexit2_update { failed("Status code %s is unknown!", $response->{'code'}); next; } - # Add the server response data to the applicable array - push(@{$status{$response->{'code'}}}, $response->{'message'}); - if (defined($response->{'details'})) { - push(@{$status{$response->{'code'}}}, $response->{'details'}[0]); - } else { - # Keep it symmetrical for simplicity - push(@{$status{$response->{'code'}}}, "no details received"); - } - - # Set data from array - my ($status, $message, $srv_message, $srv_details) = @{$status{$response->{'code'}}}; + my ($status, $message) = @{$status{$response->{'code'}}}; info("Status: %s -- Message: %s", $status, $message); - info("Server Message: %s -- Server Details: %s", $srv_message, $srv_details); + info("Server Message: %s -- Server Details: %s", $response->{'message'}, + defined($response->{'details'}) ? $response->{'details'}[0] : "no details received"); $config{$h}{'status-ipv4'} = $status if $ipv4; $config{$h}{'status-ipv6'} = $status if $ipv6; @@ -4300,10 +4291,10 @@ sub nic_dnsexit2_update { if ($status ne 'good') { if ($status eq 'warning') { warning("%s", $message); - warning("Server response: %s", $srv_message); + warning("Server response: %s", $response->{'message'}); } elsif ($status =~ m'^(badauth|error)$') { failed("%s", $message); - failed("Server response: %s", $srv_message); + failed("Server response: %s", $response->{'message'}); } else { failed("This should not be possible"); } From df81075e4991588c898eadb2f9c85320cb5725b7 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 17:39:29 -0400 Subject: [PATCH 09/20] dnsexit2: Rename variable to avoid confusion --- ddclient.in | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ddclient.in b/ddclient.in index 468817f..b1dcaab 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4174,8 +4174,7 @@ sub nic_dnsexit2_update { ## Update each configured host (hosts cannot be grouped on this API) for my $h (@_) { - # All the known status - my %status = ( + my %codemeaning = ( '0' => ['good', 'Success! Actions got executed successfully.'], '1' => ['warning', 'Some execution problems. May not indicate actions failures. Some action may got executed fine and some may have problems.'], '2' => ['badauth', 'API Key Authentication Error. The API Key is missing or wrong.'], @@ -4276,11 +4275,11 @@ sub nic_dnsexit2_update { failed("%s", $response); next; } - if (!exists($status{$response->{'code'}})) { + if (!exists($codemeaning{$response->{'code'}})) { failed("Status code %s is unknown!", $response->{'code'}); next; } - my ($status, $message) = @{$status{$response->{'code'}}}; + my ($status, $message) = @{$codemeaning{$response->{'code'}}}; info("Status: %s -- Message: %s", $status, $message); info("Server Message: %s -- Server Details: %s", $response->{'message'}, defined($response->{'details'}) ? $response->{'details'}[0] : "no details received"); From 61d34a9157a480f64a50731041689dc97f1d8d3d Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 17:37:15 -0400 Subject: [PATCH 10/20] dnsexit2: Move code meanings closer to where it is used --- ddclient.in | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ddclient.in b/ddclient.in index b1dcaab..068fe7e 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4174,16 +4174,6 @@ sub nic_dnsexit2_update { ## Update each configured host (hosts cannot be grouped on this API) for my $h (@_) { - my %codemeaning = ( - '0' => ['good', 'Success! Actions got executed successfully.'], - '1' => ['warning', 'Some execution problems. May not indicate actions failures. Some action may got executed fine and some may have problems.'], - '2' => ['badauth', 'API Key Authentication Error. The API Key is missing or wrong.'], - '3' => ['error', 'Missing Required Definitions. Your JSON file may missing some required definitions.'], - '4' => ['error', 'JSON Data Syntax Error. Your JSON file has syntax error.'], - '5' => ['error', 'JSON Defined Record Type not Supported. Your JSON may try to update some record type not supported by our system.'], - '6' => ['error', 'System Error. Our system problem. May not be your problem. Contact our support if you got such error.'], - '7' => ['error', 'Error getting post data. Our server has problem to receive your JSON posting.'], - ); my $ipv4 = delete $config{$h}{'wantipv4'}; my $ipv6 = delete $config{$h}{'wantipv6'}; @@ -4275,6 +4265,16 @@ sub nic_dnsexit2_update { failed("%s", $response); next; } + my %codemeaning = ( + '0' => ['good', 'Success! Actions got executed successfully.'], + '1' => ['warning', 'Some execution problems. May not indicate actions failures. Some action may got executed fine and some may have problems.'], + '2' => ['badauth', 'API Key Authentication Error. The API Key is missing or wrong.'], + '3' => ['error', 'Missing Required Definitions. Your JSON file may missing some required definitions.'], + '4' => ['error', 'JSON Data Syntax Error. Your JSON file has syntax error.'], + '5' => ['error', 'JSON Defined Record Type not Supported. Your JSON may try to update some record type not supported by our system.'], + '6' => ['error', 'System Error. Our system problem. May not be your problem. Contact our support if you got such error.'], + '7' => ['error', 'Error getting post data. Our server has problem to receive your JSON posting.'], + ); if (!exists($codemeaning{$response->{'code'}})) { failed("Status code %s is unknown!", $response->{'code'}); next; From 18007dda8afd10cf6bb4817941d4f5a648b4cbe1 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 17:51:00 -0400 Subject: [PATCH 11/20] dnsexit2: Delete unnecessary comments Comments should only be used if the code is doing something subtle/tricky/non-obvious/unusual, otherwise they're distracting and might get out of sync with the code (in which case it becomes difficult to tell if it's the comment or the code that's wrong). If the code is difficult to understand without comments but is doing something ordinary, then the code needs to be modified to improve readability. --- ddclient.in | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/ddclient.in b/ddclient.in index 068fe7e..b534b69 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4194,29 +4194,20 @@ sub nic_dnsexit2_update { ttl => $config{$h}{'ttl'}, }; }; - # Set the URL of the API endpoint my $url = "https://$config{$h}{'server'}$config{$h}{'path'}"; - - # Set additional headers my $header = "Content-Type: application/json\nAccept: application/json"; - - # Set the zone if empty if (not defined $config{$h}{'zone'}) { debug("Zone not defined, setting to default hostname: %s", $h); $config{$h}{'zone'} = $h } else { debug("Zone is: %s", $config{$h}{'zone'}); } - - # Build total JSON payload my @payload_values = values %total_payload; my $data = encode_json({ apikey => $config{$h}{'password'}, domain => $config{$h}{'zone'}, update => \@payload_values }); - - # Make the call my $reply = geturl( proxy => opt('proxy'), url => $url, @@ -4224,20 +4215,13 @@ sub nic_dnsexit2_update { method => 'POST', data => $data ); - - # No reply, declare as failed unless ($reply && header_ok($h, $reply)) { failed("updating %s: Could not connect to %s%s.", $h, $config{$h}{'server'}, $config{$h}{'path'}); last; }; - - # Reply found debug("%s", $reply); - # Extract the HTTP response code (my $http_status) = ($reply =~ m%^s*HTTP/.*\s+(\d+)%i); debug("HTTP response code: %s", $http_status); - - # If not 200, bail if ($http_status ne '200') { failed("Failed to update Host\n%s", $h); failed("HTTP response code\n%s", $http_status); @@ -4254,11 +4238,7 @@ sub nic_dnsexit2_update { } else { warning("Unexpected: no HTTP headers stripped!"); } - - # Decode the remaining reply, it should be JSON. my $response = decode_json($reply); - - # It should at least have a 'code' and 'message'. if (!defined($response->{'code'}) || !defined($response->{'message'})) { failed("Did not receive expected \"code\" and \"message\" keys in server response."); failed("Response:"); @@ -4285,8 +4265,6 @@ sub nic_dnsexit2_update { defined($response->{'details'}) ? $response->{'details'}[0] : "no details received"); $config{$h}{'status-ipv4'} = $status if $ipv4; $config{$h}{'status-ipv6'} = $status if $ipv6; - - # Handle statuses if ($status ne 'good') { if ($status eq 'warning') { warning("%s", $message); From 40d1bc8e51c6da5868dacc21d2177b33c7f6eded Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 28 May 2024 03:08:30 -0400 Subject: [PATCH 12/20] dnsexit2: Clarify comments --- ddclient.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ddclient.in b/ddclient.in index b534b69..87aa995 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4172,12 +4172,12 @@ EoEXAMPLE sub nic_dnsexit2_update { debug("\nnic_dnsexit2_update -------------------"); - ## Update each configured host (hosts cannot be grouped on this API) + # The DNSExit API does not support updating multiple hosts at a time. for my $h (@_) { my $ipv4 = delete $config{$h}{'wantipv4'}; my $ipv6 = delete $config{$h}{'wantipv6'}; - # Updates for ipv4 and ipv6 need to be combined in a single API call, create Hash of Arrays for tracking + # The IPv4 and IPv6 addresses must be updated together in a single API call. my %total_payload; for my $ip ($ipv4, $ipv6) { From 7c4fe28babc5c94157a80e097f8575c4c2d5e77f Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 17:57:20 -0400 Subject: [PATCH 13/20] dnsexit2: Simplify IP version loop --- ddclient.in | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/ddclient.in b/ddclient.in index 87aa995..019dc42 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4174,17 +4174,11 @@ sub nic_dnsexit2_update { # The DNSExit API does not support updating multiple hosts at a time. for my $h (@_) { - my $ipv4 = delete $config{$h}{'wantipv4'}; - my $ipv6 = delete $config{$h}{'wantipv6'}; - # The IPv4 and IPv6 addresses must be updated together in a single API call. my %total_payload; - - for my $ip ($ipv4, $ipv6) { - next if (!$ip); - my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4'; - my $type = ($ip eq ($ipv6 // '')) ? 'AAAA' : 'A'; - + for my $ipv ('4', '6') { + my $ip = delete($config{$h}{"wantipv$ipv"}) or next; + my $type = ($ipv eq '6') ? 'AAAA' : 'A'; info("Going to update IPv%s address to %s for %s.", $ipv, $ip, $h); $config{$h}{'status-ipv$ipv'} = 'failed'; $total_payload{$ipv} = { @@ -4263,8 +4257,8 @@ sub nic_dnsexit2_update { info("Status: %s -- Message: %s", $status, $message); info("Server Message: %s -- Server Details: %s", $response->{'message'}, defined($response->{'details'}) ? $response->{'details'}[0] : "no details received"); - $config{$h}{'status-ipv4'} = $status if $ipv4; - $config{$h}{'status-ipv6'} = $status if $ipv6; + $config{$h}{'status-ipv4'} = $status if $total_payload{'4'}; + $config{$h}{'status-ipv6'} = $status if $total_payload{'6'}; if ($status ne 'good') { if ($status eq 'warning') { warning("%s", $message); From 4804e15c127458619286c1e9a88d8964ba5004bb Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 18:00:29 -0400 Subject: [PATCH 14/20] dnsexit2: Add final comma after last list item for consistency, and to avoid bugs if additional items are added or the items are reordered. --- ddclient.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ddclient.in b/ddclient.in index 019dc42..915eb3e 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4200,14 +4200,14 @@ sub nic_dnsexit2_update { my $data = encode_json({ apikey => $config{$h}{'password'}, domain => $config{$h}{'zone'}, - update => \@payload_values + update => \@payload_values, }); my $reply = geturl( proxy => opt('proxy'), url => $url, headers => $header, method => 'POST', - data => $data + data => $data, ); unless ($reply && header_ok($h, $reply)) { failed("updating %s: Could not connect to %s%s.", $h, $config{$h}{'server'}, $config{$h}{'path'}); From 2bf6d348b088daf4abef16089e794af97ccf506f Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 18:05:37 -0400 Subject: [PATCH 15/20] dnsexit2: Reuse the `$url` variable --- ddclient.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddclient.in b/ddclient.in index 915eb3e..c0572b7 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4210,7 +4210,7 @@ sub nic_dnsexit2_update { data => $data, ); unless ($reply && header_ok($h, $reply)) { - failed("updating %s: Could not connect to %s%s.", $h, $config{$h}{'server'}, $config{$h}{'path'}); + failed("updating %s: Could not connect to %s%s.", $h, $url); last; }; debug("%s", $reply); From 6c89eaf4acb6a914a587700852d8eb180119388a Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 18:12:23 -0400 Subject: [PATCH 16/20] dnsexit2: Build updates array directly, not hash to array to improve readability, and to make it easier to use `group_hosts_by()` in the future to update multiple hosts at the same time. --- ddclient.in | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/ddclient.in b/ddclient.in index c0572b7..859cbd5 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4175,18 +4175,20 @@ sub nic_dnsexit2_update { # The DNSExit API does not support updating multiple hosts at a time. for my $h (@_) { # The IPv4 and IPv6 addresses must be updated together in a single API call. - my %total_payload; + my %ips; + my @updates; for my $ipv ('4', '6') { my $ip = delete($config{$h}{"wantipv$ipv"}) or next; + $ips{$ipv} = $ip; my $type = ($ipv eq '6') ? 'AAAA' : 'A'; info("Going to update IPv%s address to %s for %s.", $ipv, $ip, $h); $config{$h}{'status-ipv$ipv'} = 'failed'; - $total_payload{$ipv} = { + push(@updates, { name => $h, type => $type, content => $ip, ttl => $config{$h}{'ttl'}, - }; + }); }; my $url = "https://$config{$h}{'server'}$config{$h}{'path'}"; my $header = "Content-Type: application/json\nAccept: application/json"; @@ -4196,11 +4198,10 @@ sub nic_dnsexit2_update { } else { debug("Zone is: %s", $config{$h}{'zone'}); } - my @payload_values = values %total_payload; my $data = encode_json({ apikey => $config{$h}{'password'}, domain => $config{$h}{'zone'}, - update => \@payload_values, + update => \@updates, }); my $reply = geturl( proxy => opt('proxy'), @@ -4257,8 +4258,8 @@ sub nic_dnsexit2_update { info("Status: %s -- Message: %s", $status, $message); info("Server Message: %s -- Server Details: %s", $response->{'message'}, defined($response->{'details'}) ? $response->{'details'}[0] : "no details received"); - $config{$h}{'status-ipv4'} = $status if $total_payload{'4'}; - $config{$h}{'status-ipv6'} = $status if $total_payload{'6'}; + $config{$h}{'status-ipv4'} = $status if $ips{'4'}; + $config{$h}{'status-ipv6'} = $status if $ips{'6'}; if ($status ne 'good') { if ($status eq 'warning') { warning("%s", $message); @@ -4273,10 +4274,11 @@ sub nic_dnsexit2_update { } success("%s", $message); $config{$h}{'mtime'} = $now; - for my $ipv (keys %total_payload) { - $config{$h}{"ipv$ipv"} = $total_payload{$ipv}{content}; + keys(%ips); # Reset internal iterator. + while (my ($ipv, $ip) = each(%ips)) { + $config{$h}{"ipv$ipv"} = $ip; $config{$h}{"status-ipv$ipv"} = 'good'; - success("Updated %s successfully to IPv%s address %s at time %s", $h, $ipv, $total_payload{$ipv}{content}, prettytime($config{$h}{'mtime'})); + success("Updated %s successfully to IPv%s address %s at time %s", $h, $ipv, $ip, prettytime($config{$h}{'mtime'})); } } } From da9f39917ff6fe8c13d2487ed88699032dd493fa Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 29 May 2024 18:27:44 -0400 Subject: [PATCH 17/20] dnsexit2: Inline some unnecessary variables --- ddclient.in | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/ddclient.in b/ddclient.in index 859cbd5..0313ce0 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4180,35 +4180,32 @@ sub nic_dnsexit2_update { for my $ipv ('4', '6') { my $ip = delete($config{$h}{"wantipv$ipv"}) or next; $ips{$ipv} = $ip; - my $type = ($ipv eq '6') ? 'AAAA' : 'A'; info("Going to update IPv%s address to %s for %s.", $ipv, $ip, $h); $config{$h}{'status-ipv$ipv'} = 'failed'; push(@updates, { name => $h, - type => $type, + type => ($ipv eq '6') ? 'AAAA' : 'A', content => $ip, ttl => $config{$h}{'ttl'}, }); }; my $url = "https://$config{$h}{'server'}$config{$h}{'path'}"; - my $header = "Content-Type: application/json\nAccept: application/json"; if (not defined $config{$h}{'zone'}) { debug("Zone not defined, setting to default hostname: %s", $h); $config{$h}{'zone'} = $h } else { debug("Zone is: %s", $config{$h}{'zone'}); } - my $data = encode_json({ - apikey => $config{$h}{'password'}, - domain => $config{$h}{'zone'}, - update => \@updates, - }); my $reply = geturl( proxy => opt('proxy'), url => $url, - headers => $header, + headers => "Content-Type: application/json\nAccept: application/json", method => 'POST', - data => $data, + data => encode_json({ + apikey => $config{$h}{'password'}, + domain => $config{$h}{'zone'}, + update => \@updates, + }), ); unless ($reply && header_ok($h, $reply)) { failed("updating %s: Could not connect to %s%s.", $h, $url); From 46bca5439378a2b906a78970a5707d1efaeaf9b6 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 30 May 2024 04:04:19 -0400 Subject: [PATCH 18/20] dnsexit2: Fix string interpolation --- ddclient.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddclient.in b/ddclient.in index 0313ce0..e54b4c1 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4181,7 +4181,7 @@ sub nic_dnsexit2_update { my $ip = delete($config{$h}{"wantipv$ipv"}) or next; $ips{$ipv} = $ip; info("Going to update IPv%s address to %s for %s.", $ipv, $ip, $h); - $config{$h}{'status-ipv$ipv'} = 'failed'; + $config{$h}{"status-ipv$ipv"} = 'failed'; push(@updates, { name => $h, type => ($ipv eq '6') ? 'AAAA' : 'A', From 5b7400ae7d4588c4c2ef6b35f2fbf2fdc51b50f0 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 30 May 2024 04:48:44 -0400 Subject: [PATCH 19/20] dnsexit2: Normalize the zone up front --- ddclient.in | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ddclient.in b/ddclient.in index e54b4c1..453d810 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4174,6 +4174,12 @@ sub nic_dnsexit2_update { # The DNSExit API does not support updating multiple hosts at a time. for my $h (@_) { + if (not defined $config{$h}{'zone'}) { + debug("Zone not defined, setting to default hostname: %s", $h); + $config{$h}{'zone'} = $h + } else { + debug("Zone is: %s", $config{$h}{'zone'}); + } # The IPv4 and IPv6 addresses must be updated together in a single API call. my %ips; my @updates; @@ -4190,12 +4196,6 @@ sub nic_dnsexit2_update { }); }; my $url = "https://$config{$h}{'server'}$config{$h}{'path'}"; - if (not defined $config{$h}{'zone'}) { - debug("Zone not defined, setting to default hostname: %s", $h); - $config{$h}{'zone'} = $h - } else { - debug("Zone is: %s", $config{$h}{'zone'}); - } my $reply = geturl( proxy => opt('proxy'), url => $url, From 3c84f7a1b56f771b55d5c779afd9ed9241b8e544 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 30 May 2024 04:49:46 -0400 Subject: [PATCH 20/20] dnsexit2: Delete unnecessary debug messages --- ddclient.in | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/ddclient.in b/ddclient.in index 453d810..c9bb379 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4174,12 +4174,7 @@ sub nic_dnsexit2_update { # The DNSExit API does not support updating multiple hosts at a time. for my $h (@_) { - if (not defined $config{$h}{'zone'}) { - debug("Zone not defined, setting to default hostname: %s", $h); - $config{$h}{'zone'} = $h - } else { - debug("Zone is: %s", $config{$h}{'zone'}); - } + $config{$h}{'zone'} //= $h; # The IPv4 and IPv6 addresses must be updated together in a single API call. my %ips; my @updates;