diff --git a/ddclient.in b/ddclient.in index fe287d6..e2dc1b1 100755 --- a/ddclient.in +++ b/ddclient.in @@ -1539,12 +1539,12 @@ sub test_possible_ip { sub test_geturl { my $url = shift; - my $reply = geturl({ + my $reply = geturl( proxy => opt('proxy'), url => $url, login => opt('login'), password => opt('password'), - }); + ); print "URL $url\n"; print $reply // "\n"; exit; @@ -2004,15 +2004,15 @@ EOM ## geturl ###################################################################### sub geturl { - my ($params) = @_; - my $proxy = $params->{proxy}; - my $url = $params->{url}; - my $login = $params->{login}; - my $password = $params->{password}; - my $ipversion = $params->{ipversion} // ''; - my $headers = $params->{headers} // ''; - my $method = $params->{method} // 'GET'; - my $data = $params->{data} // ''; + my %params = @_; + my $proxy = $params{proxy}; + my $url = $params{url}; + my $login = $params{login}; + my $password = $params{password}; + my $ipversion = $params{ipversion} // ''; + my $headers = $params{headers} // ''; + my $method = $params{method} // 'GET'; + my $data = $params{data} // ''; my ($peer, $server, $port, $default_port, $use_ssl); my ($sd, $request, $reply); @@ -2025,7 +2025,7 @@ sub geturl { $server =~ s%[?/].*%%; $url =~ s%^[^?/]*/?%%; - if ($force_ssl || ($globals{'ssl'} && !($params->{ignore_ssl_option} // 0))) { + if ($force_ssl || ($globals{'ssl'} && !($params{ignore_ssl_option} // 0))) { $use_ssl = 1; $default_port = '443'; } else { @@ -2094,9 +2094,9 @@ sub geturl { load_ipv6_support; $socket_class = 'IO::Socket::INET6'; } - if (defined($params->{_testonly_socket_class})) { + if (defined($params{_testonly_socket_class})) { $socket_args{original_socket_class} = $socket_class; - $socket_class = $params->{_testonly_socket_class}; + $socket_class = $params{_testonly_socket_class}; } if ($ipversion eq '4') { $socket_args{Domain} = PF_INET; @@ -2211,7 +2211,7 @@ sub get_ip { $arg = $url; if ($url) { - $reply = geturl({ proxy => opt('proxy', $h), url => $url }) // ''; + $reply = geturl(proxy => opt('proxy', $h), url => $url) // ''; } } elsif (($use eq 'cisco')) { @@ -2228,12 +2228,12 @@ sub get_ip { $queryif =~ s/([\?&= ])/sprintf("%%%02x", ord($1))/ge; $url = "http://" . opt('fw', $h) . "/level/1/exec/show/ip/interface/brief/${queryif}/CR"; - $reply = geturl({ + $reply = geturl( url => $url, login => opt('fw-login', $h), password => opt('fw-password', $h), ignore_ssl_option => 1, - }) // ''; + ) // ''; $arg = $url; } elsif (($use eq 'cisco-asa')) { @@ -2250,12 +2250,12 @@ sub get_ip { $queryif =~ s/([\?&= ])/sprintf("%%%02x", ord($1))/ge; $url = "https://" . opt('fw', $h) . "/exec/show%20interface%20${queryif}"; - $reply = geturl({ + $reply = geturl( url => $url, login => opt('fw-login', $h), password => opt('fw-password', $h), ignore_ssl_option => 1, - }) // ''; + ) // ''; $arg = $url; } else { @@ -2269,12 +2269,12 @@ sub get_ip { $arg = $url; if ($url) { - $reply = geturl({ + $reply = geturl( url => $url, login => opt('fw-login', $h), password => opt('fw-password', $h), ignore_ssl_option => 1, - }) // ''; + ) // ''; } } if (!defined $reply) { @@ -2681,12 +2681,12 @@ sub nic_dyndns1_update { $url .= "&backmx=" . ynu($config{$h}{'backupmx'}, 'YES', 'NO'); } - my $reply = geturl({ + my $reply = geturl( proxy => opt('proxy'), url => $url, login => $config{$h}{'login'}, password => $config{$h}{'password'}, - }) // ''; + ) // ''; if ($reply eq '') { failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); next; @@ -2849,12 +2849,12 @@ sub nic_dyndns2_update { $url .= "&backmx=" . ynu($config{$h}{'backupmx'}, 'YES', 'NO'); } - my $reply = geturl({ + my $reply = geturl( proxy => opt('proxy'), url => $url, login => $config{$h}{'login'}, password => $config{$h}{'password'}, - }) // ''; + ) // ''; if ($reply eq '') { failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'}); next; @@ -2959,12 +2959,12 @@ sub nic_noip_update { $url .= "&myip="; $url .= $ip if $ip; - my $reply = geturl({ + my $reply = geturl( proxy => opt('proxy'), url => $url, login => $config{$h}{'login'}, password => $config{$h}{'password'}, - }) // ''; + ) // ''; if ($reply eq '') { failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'}); next; @@ -3099,12 +3099,12 @@ sub nic_dslreports1_update { $url .= "&myip="; $url .= $ip if $ip; - my $reply = geturl({ + my $reply = geturl( proxy => opt('proxy'), url => $url, login => $config{$h}{'login'}, password => $config{$h}{'password'}, - }) // ''; + ) // ''; if ($reply eq '') { failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); next; @@ -3200,12 +3200,12 @@ sub nic_zoneedit1_update { $url .= "&dnsto=$ip" if $ip; $url .= "&zone=$config{$h}{'zone'}" if defined $config{$h}{'zone'}; - my $reply = geturl({ + my $reply = geturl( proxy => opt('proxy'), url => $url, login => $config{$h}{'login'}, password => $config{$h}{'password'}, - }) // ''; + ) // ''; if ($reply eq '') { failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'}); next; @@ -3355,12 +3355,12 @@ sub nic_easydns_update { $url .= "&backmx=" . ynu($config{$h}{'backupmx'}, 'YES', 'NO'); } - my $reply = geturl({ + my $reply = geturl( proxy => opt('proxy'), url => $url, login => $config{$h}{'login'}, password => $config{$h}{'password'}, - }) // ''; + ) // ''; if ($reply eq '') { failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'}); next; @@ -3474,7 +3474,7 @@ sub nic_namecheap_update { $url .= "&ip="; $url .= $ip if $ip; - my $reply = geturl({ proxy => opt('proxy'), url => $url }) // ''; + my $reply = geturl(proxy => opt('proxy'), url => $url) // ''; if ($reply eq '') { failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); next; @@ -3605,13 +3605,13 @@ sub nic_nfsn_make_request { $header .= "Content-Type: application/x-www-form-urlencoded\n"; } - return geturl({ + return geturl( proxy => opt('proxy'), url => $url, headers => $header, method => $method, data => $body, - }); + ); } ###################################################################### @@ -3782,7 +3782,7 @@ sub nic_sitelutions_update { $url .= "&ip="; $url .= $ip if $ip; - my $reply = geturl({ proxy => opt('proxy'), url => $url }); + my $reply = geturl(proxy => opt('proxy'), url => $url); if (!defined($reply) || !$reply) { failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); next; @@ -3867,7 +3867,7 @@ sub nic_freedns_update { my $url_tmpl = "http://$config{$_[0]}{'server'}/api/?action=getdyndns&v=2&sha="; my $creds = sha1_hex("$config{$_[0]}{'login'}|$config{$_[0]}{'password'}"); (my $url = $url_tmpl) =~ s//$creds/; - my $reply = geturl({ proxy => opt('proxy'), url => $url }); + my $reply = geturl(proxy => opt('proxy'), url => $url); my $record_list_error = ''; if ($reply && header_ok($_[0], $reply)) { $reply =~ s/^.*?\n\n//s; # Strip the headers. @@ -3917,7 +3917,7 @@ sub nic_freedns_update { } else { my $url = $rec->[2] . "&address=" . $ip; debug("Update: %s", $url); - my $reply = geturl({proxy => opt('proxy'), url => $url }); + my $reply = geturl(proxy => opt('proxy'), url => $url); if (!defined($reply) || !$reply || !header_ok($h, $reply)) { $config{$h}{'status'} = 'failed'; failed("updating %s: Could not connect to %s.", $h, $url); @@ -3992,12 +3992,12 @@ sub nic_changeip_update { $url .= "&ip="; $url .= $ip if $ip; - my $reply = geturl({ + my $reply = geturl( proxy => opt('proxy'), url => $url, login => $config{$h}{'login'}, password => $config{$h}{'password'}, - }); + ); if (!defined($reply) || !$reply) { failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); next; @@ -4079,12 +4079,12 @@ sub nic_googledomains_update { $url .= "&myip="; $url .= $ip if $ip; - my $reply = geturl({ + my $reply = geturl( proxy => opt('proxy'), url => $url, login => $config{$host}{'login'}, password => $config{$host}{'password'}, - }); + ); unless ($reply) { failed("updating %s: Could not connect to %s.", $host, $config{$host}{'server'}); next; @@ -4293,7 +4293,7 @@ sub nic_cloudflare_update { my $url = "https://$config{$key}{'server'}/zones?"; $url .= "name=".$config{$key}{'zone'}; - my $reply = geturl({ proxy => opt('proxy'), url => $url, headers => $headers }); + my $reply = geturl(proxy => opt('proxy'), url => $url, headers => $headers); unless ($reply) { failed("updating %s: Could not connect to %s.", $domain, $config{$key}{'server'}); next; @@ -4324,7 +4324,7 @@ sub nic_cloudflare_update { $url .= "type=A&name=$domain"; } - $reply = geturl({ proxy => opt('proxy'), url => $url, headers => $headers }); + $reply = geturl(proxy => opt('proxy'), url => $url, headers => $headers); unless ($reply) { failed("updating %s: Could not connect to %s.", $domain, $config{$key}{'server'}); next; @@ -4350,13 +4350,13 @@ sub nic_cloudflare_update { # Set domain $url = "https://$config{$key}{'server'}/zones/$zone_id/dns_records/$dns_rec_id"; my $data = "{\"content\":\"$ip\"}"; - $reply = geturl({ + $reply = geturl( proxy => opt('proxy'), url => $url, headers => $headers, method => "PATCH", data => $data, - }); + ); unless ($reply) { failed("updating %s: Could not connect to %s.", $domain, $config{$domain}{'server'}); next; @@ -4440,7 +4440,7 @@ sub nic_yandex_update { my $url = "https://$config{$host}{'server'}/api2/admin/dns/list?"; $url .= "domain="; $url .= $config{$key}{'login'}; - my $reply = geturl({ proxy => opt('proxy'), url => $url, headers => $headers }); + my $reply = geturl(proxy => opt('proxy'), url => $url, headers => $headers); unless ($reply) { failed("updating %s: Could not connect to %s.", $host, $config{$key}{'server'}); next; @@ -4471,13 +4471,13 @@ sub nic_yandex_update { $data .= "&content="; $data .= $ip if $ip; - $reply = geturl({ + $reply = geturl( proxy => opt('proxy'), url => $url, headers => $headers, method => 'POST', data => $data, - }); + ); unless ($reply) { failed("updating %s: Could not connect to %s.", $host, $config{$host}{'server'}); next; @@ -4555,7 +4555,7 @@ sub nic_duckdns_update { # Try to get URL - my $reply = geturl({ proxy => opt('proxy'), url => $url }); + my $reply = geturl(proxy => opt('proxy'), url => $url); # No response, declare as failed if (!defined($reply) || !$reply) { @@ -4626,7 +4626,7 @@ sub nic_freemyip_update { $url .= $h; # Try to get URL - my $reply = geturl({ proxy => opt('proxy'), url => $url }); + my $reply = geturl(proxy => opt('proxy'), url => $url); # No response, declare as failed if (!defined($reply) || !$reply) { @@ -4752,12 +4752,12 @@ sub nic_woima_update { $url .= "&backmx=" . ynu($config{$h}{'backupmx'}, 'YES', 'NO'); } - my $reply = geturl({ + my $reply = geturl( proxy => opt('proxy'), url => $url, login => $config{$h}{'login'}, password => $config{$h}{'password'}, - }); + ); if (!defined($reply) || !$reply) { failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); next; @@ -4873,7 +4873,7 @@ sub nic_dondominio_update { # Try to get URL - my $reply = geturl({ proxy => opt('proxy'), url => $url }); + my $reply = geturl(proxy => opt('proxy'), url => $url); # No response, declare as failed if (!defined($reply) || !$reply) { @@ -4959,7 +4959,7 @@ sub nic_dnsmadeeasy_update { $url .= "&id=$h"; # Try to get URL - my $reply = geturl({ proxy => opt('proxy'), url => $url }); + my $reply = geturl(proxy => opt('proxy'), url => $url); # No response, declare as failed if (!defined($reply) || !$reply) { @@ -5030,12 +5030,12 @@ sub nic_ovh_update { $url .= "&myip="; $url .= $ip if $ip; - my $reply = geturl({ + my $reply = geturl( proxy => opt('proxy'), url => $url, login => $config{$h}{'login'}, password => $config{$h}{'password'}, - }); + ); if (!defined($reply) || !$reply) { failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); @@ -5099,11 +5099,11 @@ sub nic_cloudns_update { # IP is set in the header X-Forwarded-For you need to add &proxy=1 at the end of the # DynamicURL." We abuse this to pass the desired IP address to ClouDNS, which might not be # the same as the client IP address seen by ClouDNS. - my $reply = geturl({ + my $reply = geturl( proxy => opt('proxy'), url => $dynurl . '&proxy=1', headers => "X-Forwarded-For: $ip\n", - }); + ); if (($reply // '') eq '' || !header_ok($hosts, $reply)) { $config{$_}{'status'} = 'failed' for @hosts; failed("updating %s: failed to visit DynURL", $hosts); @@ -5163,12 +5163,12 @@ sub nic_dinahosting_update { $url .= "&domain=$domain"; $url .= "&command=Domain_Zone_UpdateType" . is_ipv6($ip) ? 'AAAA' : 'A'; $url .= "&ip=$ip"; - my $reply = geturl({ + my $reply = geturl( proxy => opt('proxy'), login => $config{$h}{'login'}, password => $config{$h}{'password'}, url => $url, - }); + ); $config{$h}{'status'} = 'failed'; # assume failure until otherwise determined if (!$reply) { failed("updating %s: failed to visit URL %s", $h, $url); diff --git a/t/geturl_connectivity.pl b/t/geturl_connectivity.pl index aa24422..e4a8a8c 100644 --- a/t/geturl_connectivity.pl +++ b/t/geturl_connectivity.pl @@ -84,7 +84,7 @@ for my $tc (@test_cases) { my $name = sprintf("IPv%s client to %s (-%sipv6)", $tc->{client_ipv} || '*', $uri, $tc->{ipv6_opt} ? '' : 'no'); $ddclient::globals{'ipv6'} = $tc->{ipv6_opt}; - my $got = ddclient::geturl({ url => $uri, ipversion => $tc->{client_ipv} }); + my $got = ddclient::geturl(url => $uri, ipversion => $tc->{client_ipv}); isnt($got // '', '', $name); } } diff --git a/t/geturl_ssl.pl b/t/geturl_ssl.pl index ff67859..9b0212f 100644 --- a/t/geturl_ssl.pl +++ b/t/geturl_ssl.pl @@ -228,8 +228,7 @@ for my $tc (@test_cases) { $ddclient::globals{'ssl'} = $tc->{opt_ssl} // 0; $ddclient::globals{'ssl_ca_dir'} = $tc->{opt_ssl_ca_dir}; $ddclient::globals{'ssl_ca_file'} = $tc->{opt_ssl_ca_file}; - my $resp_str = ddclient::geturl({ _testonly_socket_class => 'InterceptSocket', - %{$tc->{params}} }); + my $resp_str = ddclient::geturl(_testonly_socket_class => 'InterceptSocket', %{$tc->{params}}); TODO: { local $TODO = $tc->{todo}; subtest $tc->{name} => sub {