Merge pull request #692 from rhansen/infomaniak

`infomaniak` fixes
This commit is contained in:
Richard Hansen 2024-06-25 22:56:44 -04:00 committed by GitHub
commit f4c4d974d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 44 deletions

View file

@ -83,6 +83,8 @@ repository history](https://github.com/ddclient/ddclient/commits/master).
hostname. [#673](https://github.com/ddclient/ddclient/issues/673) hostname. [#673](https://github.com/ddclient/ddclient/issues/673)
* `infomaniak`: Fixed frequent forced updates after 25 days (`max-interval`). * `infomaniak`: Fixed frequent forced updates after 25 days (`max-interval`).
[#691](https://github.com/ddclient/ddclient/issues/691) [#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. * `regfishde`: Fixed IPv6 support.
[#691](https://github.com/ddclient/ddclient/issues/691) [#691](https://github.com/ddclient/ddclient/issues/691)

View file

@ -1114,6 +1114,7 @@ my %protocols = (
'examples' => \&nic_infomaniak_examples, 'examples' => \&nic_infomaniak_examples,
'variables' => { 'variables' => {
%{$variables{'protocol-common-defaults'}}, %{$variables{'protocol-common-defaults'}},
'server' => undef,
}, },
}, },
'emailonly' => { 'emailonly' => {
@ -3791,6 +3792,10 @@ sub nic_updateable {
###################################################################### ######################################################################
sub header_ok { sub header_ok {
my ($host, $line) = @_; my ($host, $line) = @_;
if (!$line) {
failed("updating %s: no response from server", $host);
return 0;
}
$line =~ s/\r?\n.*//s; $line =~ s/\r?\n.*//s;
my ($code, $msg) = ($line =~ qr%^\s*HTTP/.*\s+(\d+)\s*(?:\s+([^\s].*))?$%i); my ($code, $msg) = ($line =~ qr%^\s*HTTP/.*\s+(\d+)\s*(?:\s+([^\s].*))?$%i);
if (!defined($code)) { if (!defined($code)) {
@ -7989,19 +7994,14 @@ EoEXAMPLE
###################################################################### ######################################################################
sub nic_infomaniak_update { sub nic_infomaniak_update {
debug("\nnic_infomaniak_update -------------------"); debug("\nnic_infomaniak_update -------------------");
for my $h (@_) { for my $h (@_) {
INFOMANIAK_IP_LOOP:
for my $v (4, 6) { for my $v (4, 6) {
my $ip = delete $config{$h}{"wantipv$v"}; my $ip = delete $config{$h}{"wantipv$v"};
if (!defined $ip) { if (!defined $ip) {
debug("ipv%d not wanted, skipping", $v); debug("ipv%d not wanted, skipping", $v);
next; next;
} }
info("setting IP address to %s for %s", $ip, $h); info("setting IP address to %s for %s", $ip, $h);
# No change in IP => nochg <w.x.y.z> # No change in IP => nochg <w.x.y.z>
# Bad auth => badauth # Bad auth => badauth
# Bad domain name => nohost # Bad domain name => nohost
@ -8014,46 +8014,25 @@ sub nic_infomaniak_update {
'nohost' => (0, sprintf("Bad domain name %s or bad IP %s", $h, $ip)), 'nohost' => (0, sprintf("Bad domain name %s or bad IP %s", $h, $ip)),
'badauth' => (0, sprintf("Bad authentication for %s", $h)), 'badauth' => (0, sprintf("Bad authentication for %s", $h)),
); );
my $reply = geturl(
my $url1 = "https://$config{$h}{'login'}:$config{$h}{'password'}"; proxy => opt('proxy'),
$url1 .= "\@infomaniak.com/nic/update"; url => "https://infomaniak.com/nic/update?hostname=$h&myip=$ip",
$url1 .= "?hostname=$h"; login => $config{$h}{'login'},
$url1 .= "&myip=$ip"; password => $config{$h}{'password'},
);
my $url2 = "https://infomaniak.com/nic/update"; next if !header_ok($h, $reply);
$url2 .= "?hostname=$h"; (my $body = $reply) =~ s/^.*?\n\n//s;
$url2 .= "&myip=$ip"; my ($status) = split(/ /, $body, 2);
$url2 .= "&username=$config{$h}{'login'}"; my ($ok, $msg) =
$url2 .= "&password=$config{$h}{'password'}"; $statuses{$status} // (0, sprintf("Unknown reply from Infomaniak: %s", $body));
if (!$ok) {
my $reply; failed($msg);
for my $url ($url1, $url2) {
info("trying update with %s", $url);
$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; next;
} }
success($msg);
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}{"ipv$v"} = $ip;
$config{$h}{'mtime'} = $now; $config{$h}{'mtime'} = $now;
$config{$h}{"status-ipv$v"} = 'good'; $config{$h}{"status-ipv$v"} = 'good';
next INFOMANIAK_IP_LOOP;
}
else {
warning($msg);
}
}
$config{$h}{"status-ipv$v"} = 'failed';
failed("updating %s: could not update IP on Infomaniak", $h);
} }
} }
} }