From 134e47b61d1896f48e3f302286b146d35e9c5d58 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 25 Jun 2024 21:50:51 -0400 Subject: [PATCH 01/10] infomaniak: Delete unnecessary newlines --- ddclient.in | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/ddclient.in b/ddclient.in index 88419a6..5062119 100755 --- a/ddclient.in +++ b/ddclient.in @@ -7989,19 +7989,15 @@ EoEXAMPLE ###################################################################### sub nic_infomaniak_update { debug("\nnic_infomaniak_update -------------------"); - for my $h (@_) { INFOMANIAK_IP_LOOP: for my $v (4, 6) { my $ip = delete $config{$h}{"wantipv$v"}; - if (!defined $ip) { debug("ipv%d not wanted, skipping", $v); next; } - info("setting IP address to %s for %s", $ip, $h); - # No change in IP => nochg # Bad auth => badauth # Bad domain name => nohost @@ -8014,20 +8010,16 @@ sub nic_infomaniak_update { 'nohost' => (0, sprintf("Bad domain name %s or bad IP %s", $h, $ip)), 'badauth' => (0, sprintf("Bad authentication for %s", $h)), ); - my $url1 = "https://$config{$h}{'login'}:$config{$h}{'password'}"; $url1 .= "\@infomaniak.com/nic/update"; $url1 .= "?hostname=$h"; $url1 .= "&myip=$ip"; - my $url2 = "https://infomaniak.com/nic/update"; $url2 .= "?hostname=$h"; $url2 .= "&myip=$ip"; $url2 .= "&username=$config{$h}{'login'}"; $url2 .= "&password=$config{$h}{'password'}"; - my $reply; - for my $url ($url1, $url2) { info("trying update with %s", $url); $reply = geturl(proxy => opt('proxy'), url => $url); @@ -8035,23 +8027,19 @@ sub nic_infomaniak_update { info("could not update %s using url %s, trying next one", $h, $url); next; } - my ($status) = split / /, $reply, 1; my ($updated, $msg) = $statuses{$status} // (0, sprintf("Unknown reply from Infomaniak: %s", $reply)); - if (defined $updated && $updated) { info($msg); $config{$h}{"ipv$v"} = $ip; $config{$h}{'mtime'} = $now; $config{$h}{"status-ipv$v"} = 'good'; next INFOMANIAK_IP_LOOP; - } - else { + } else { warning($msg); } } - $config{$h}{"status-ipv$v"} = 'failed'; failed("updating %s: could not update IP on Infomaniak", $h); } From bab9d9483e2ebecae04d99bfccbd3a828942c639 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 25 Jun 2024 21:55:46 -0400 Subject: [PATCH 02/10] infomaniak: Move variable declaration to definition --- ddclient.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ddclient.in b/ddclient.in index 5062119..a5ce3fd 100755 --- a/ddclient.in +++ b/ddclient.in @@ -8019,10 +8019,9 @@ sub nic_infomaniak_update { $url2 .= "&myip=$ip"; $url2 .= "&username=$config{$h}{'login'}"; $url2 .= "&password=$config{$h}{'password'}"; - my $reply; for my $url ($url1, $url2) { info("trying update with %s", $url); - $reply = geturl(proxy => opt('proxy'), url => $url); + my $reply = geturl(proxy => opt('proxy'), url => $url); if (!defined($reply) || !$reply) { info("could not update %s using url %s, trying next one", $h, $url); next; From ac9f937c88892923120bbbc7204e33b452c589a4 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 25 Jun 2024 21:56:12 -0400 Subject: [PATCH 03/10] infomaniak: Delete unnecessary defined checks `undef` is falsy so there's no need to check whether the value is defined. --- ddclient.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ddclient.in b/ddclient.in index a5ce3fd..b8f8f34 100755 --- a/ddclient.in +++ b/ddclient.in @@ -8022,14 +8022,14 @@ sub nic_infomaniak_update { for my $url ($url1, $url2) { info("trying update with %s", $url); my $reply = geturl(proxy => opt('proxy'), url => $url); - if (!defined($reply) || !$reply) { + if (!$reply) { info("could not update %s using url %s, trying next one", $h, $url); next; } my ($status) = split / /, $reply, 1; my ($updated, $msg) = $statuses{$status} // (0, sprintf("Unknown reply from Infomaniak: %s", $reply)); - if (defined $updated && $updated) { + if ($updated) { info($msg); $config{$h}{"ipv$v"} = $ip; $config{$h}{'mtime'} = $now; From a5dedeed3c6f894bb23dbc9d56bb50739c3c1612 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 25 Jun 2024 22:06:34 -0400 Subject: [PATCH 04/10] infomaniak: Fix geturl call * Pass login and password via `login` and `password` options to avoid issues with escaping special characters. * Don't attempt twice -- if the first attempt fails, the second will almost certainly fail as well. (The two attempted URLs were equivalent, differing only in how the login and password were passed.) --- ddclient.in | 52 +++++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/ddclient.in b/ddclient.in index b8f8f34..a8ec647 100755 --- a/ddclient.in +++ b/ddclient.in @@ -7990,7 +7990,6 @@ EoEXAMPLE sub nic_infomaniak_update { debug("\nnic_infomaniak_update -------------------"); for my $h (@_) { - INFOMANIAK_IP_LOOP: for my $v (4, 6) { my $ip = delete $config{$h}{"wantipv$v"}; if (!defined $ip) { @@ -8010,37 +8009,28 @@ sub nic_infomaniak_update { 'nohost' => (0, sprintf("Bad domain name %s or bad IP %s", $h, $ip)), 'badauth' => (0, sprintf("Bad authentication for %s", $h)), ); - my $url1 = "https://$config{$h}{'login'}:$config{$h}{'password'}"; - $url1 .= "\@infomaniak.com/nic/update"; - $url1 .= "?hostname=$h"; - $url1 .= "&myip=$ip"; - my $url2 = "https://infomaniak.com/nic/update"; - $url2 .= "?hostname=$h"; - $url2 .= "&myip=$ip"; - $url2 .= "&username=$config{$h}{'login'}"; - $url2 .= "&password=$config{$h}{'password'}"; - for my $url ($url1, $url2) { - info("trying update with %s", $url); - my $reply = geturl(proxy => opt('proxy'), url => $url); - if (!$reply) { - info("could not update %s using url %s, trying next one", $h, $url); - next; - } - my ($status) = split / /, $reply, 1; - my ($updated, $msg) = - $statuses{$status} // (0, sprintf("Unknown reply from Infomaniak: %s", $reply)); - if ($updated) { - info($msg); - $config{$h}{"ipv$v"} = $ip; - $config{$h}{'mtime'} = $now; - $config{$h}{"status-ipv$v"} = 'good'; - next INFOMANIAK_IP_LOOP; - } else { - warning($msg); - } + my $reply = geturl( + proxy => opt('proxy'), + url => "https://infomaniak.com/nic/update?hostname=$h&myip=$ip", + login => $config{$h}{'login'}, + password => $config{$h}{'password'}, + ); + if (!$reply) { + failed("could not update %s", $h); + next; + } + my ($status) = split / /, $reply, 1; + my ($updated, $msg) = + $statuses{$status} // (0, sprintf("Unknown reply from Infomaniak: %s", $reply)); + if ($updated) { + success($msg); + $config{$h}{"ipv$v"} = $ip; + $config{$h}{'mtime'} = $now; + $config{$h}{"status-ipv$v"} = 'good'; + next; + } else { + failed($msg); } - $config{$h}{"status-ipv$v"} = 'failed'; - failed("updating %s: could not update IP on Infomaniak", $h); } } } From 29e86d9a9155a7a8cb9cef286a32c28fa492627d Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 25 Jun 2024 22:10:30 -0400 Subject: [PATCH 05/10] infomaniak: Rename variable for readability --- ddclient.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ddclient.in b/ddclient.in index a8ec647..8fc38a7 100755 --- a/ddclient.in +++ b/ddclient.in @@ -8020,9 +8020,9 @@ sub nic_infomaniak_update { next; } my ($status) = split / /, $reply, 1; - my ($updated, $msg) = + my ($ok, $msg) = $statuses{$status} // (0, sprintf("Unknown reply from Infomaniak: %s", $reply)); - if ($updated) { + if ($ok) { success($msg); $config{$h}{"ipv$v"} = $ip; $config{$h}{'mtime'} = $now; From d2f0e042f495c311ffccb26523c1408d47f146ba Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 25 Jun 2024 22:12:08 -0400 Subject: [PATCH 06/10] infomaniak: Invert condition to improve readability --- ddclient.in | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ddclient.in b/ddclient.in index 8fc38a7..1a2594f 100755 --- a/ddclient.in +++ b/ddclient.in @@ -8022,15 +8022,14 @@ sub nic_infomaniak_update { my ($status) = split / /, $reply, 1; my ($ok, $msg) = $statuses{$status} // (0, sprintf("Unknown reply from Infomaniak: %s", $reply)); - if ($ok) { - success($msg); - $config{$h}{"ipv$v"} = $ip; - $config{$h}{'mtime'} = $now; - $config{$h}{"status-ipv$v"} = 'good'; - next; - } else { + if (!$ok) { failed($msg); + next; } + success($msg); + $config{$h}{"ipv$v"} = $ip; + $config{$h}{'mtime'} = $now; + $config{$h}{"status-ipv$v"} = 'good'; } } } From 8e24c92b1e4951aca4f85b84ee8bab9beb654e74 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 25 Jun 2024 22:16:49 -0400 Subject: [PATCH 07/10] infomaniak: Fix response parsing --- ChangeLog.md | 2 ++ ddclient.in | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 8f1eba9..b6e7622 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -83,6 +83,8 @@ repository history](https://github.com/ddclient/ddclient/commits/master). hostname. [#673](https://github.com/ddclient/ddclient/issues/673) * `infomaniak`: Fixed frequent forced updates after 25 days (`max-interval`). [#691](https://github.com/ddclient/ddclient/issues/691) + * `infomaniak`: Fixed incorrect parsing of server response. + [#692](https://github.com/ddclient/ddclient/issues/692) * `regfishde`: Fixed IPv6 support. [#691](https://github.com/ddclient/ddclient/issues/691) diff --git a/ddclient.in b/ddclient.in index 1a2594f..df3c168 100755 --- a/ddclient.in +++ b/ddclient.in @@ -8019,9 +8019,10 @@ sub nic_infomaniak_update { failed("could not update %s", $h); next; } - my ($status) = split / /, $reply, 1; + (my $body = $reply) =~ s/^.*?\n\n//s; + my ($status) = split(/ /, $body, 2); my ($ok, $msg) = - $statuses{$status} // (0, sprintf("Unknown reply from Infomaniak: %s", $reply)); + $statuses{$status} // (0, sprintf("Unknown reply from Infomaniak: %s", $body)); if (!$ok) { failed($msg); next; From 7d99da77cc179bd1b1fbd21423771be1e57e3b56 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 25 Jun 2024 22:22:02 -0400 Subject: [PATCH 08/10] header_ok: Fail if the reply is falsy --- ddclient.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ddclient.in b/ddclient.in index df3c168..877d8a3 100755 --- a/ddclient.in +++ b/ddclient.in @@ -3791,6 +3791,10 @@ sub nic_updateable { ###################################################################### sub header_ok { my ($host, $line) = @_; + if (!$line) { + failed("updating %s: no response from server", $host); + return 0; + } $line =~ s/\r?\n.*//s; my ($code, $msg) = ($line =~ qr%^\s*HTTP/.*\s+(\d+)\s*(?:\s+([^\s].*))?$%i); if (!defined($code)) { From 9ba583175a5213f0fb2ff9ee75b3ca24f6b4aeae Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 25 Jun 2024 22:23:27 -0400 Subject: [PATCH 09/10] infomaniak: Fail if the HTTP status code is not 2xx --- ddclient.in | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ddclient.in b/ddclient.in index 877d8a3..7142ff9 100755 --- a/ddclient.in +++ b/ddclient.in @@ -8019,10 +8019,7 @@ sub nic_infomaniak_update { login => $config{$h}{'login'}, password => $config{$h}{'password'}, ); - if (!$reply) { - failed("could not update %s", $h); - next; - } + next if !header_ok($h, $reply); (my $body = $reply) =~ s/^.*?\n\n//s; my ($status) = split(/ /, $body, 2); my ($ok, $msg) = From 948567c456cf7b845885d549288b6f350921b978 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 25 Jun 2024 22:27:55 -0400 Subject: [PATCH 10/10] infomaniak: Unrequire `server` setting The `infomaniak` protocol doesn't use `server`. --- ddclient.in | 1 + 1 file changed, 1 insertion(+) diff --git a/ddclient.in b/ddclient.in index 7142ff9..8409b93 100755 --- a/ddclient.in +++ b/ddclient.in @@ -1114,6 +1114,7 @@ my %protocols = ( 'examples' => \&nic_infomaniak_examples, 'variables' => { %{$variables{'protocol-common-defaults'}}, + 'server' => undef, }, }, 'emailonly' => {