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.)
This commit is contained in:
Richard Hansen 2024-06-25 22:06:34 -04:00
parent ac9f937c88
commit a5dedeed3c

View file

@ -7990,7 +7990,6 @@ 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) {
@ -8010,37 +8009,28 @@ 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 $url1 = "https://$config{$h}{'login'}:$config{$h}{'password'}"; my $reply = geturl(
$url1 .= "\@infomaniak.com/nic/update"; proxy => opt('proxy'),
$url1 .= "?hostname=$h"; url => "https://infomaniak.com/nic/update?hostname=$h&myip=$ip",
$url1 .= "&myip=$ip"; login => $config{$h}{'login'},
my $url2 = "https://infomaniak.com/nic/update"; password => $config{$h}{'password'},
$url2 .= "?hostname=$h"; );
$url2 .= "&myip=$ip"; if (!$reply) {
$url2 .= "&username=$config{$h}{'login'}"; failed("could not update %s", $h);
$url2 .= "&password=$config{$h}{'password'}"; next;
for my $url ($url1, $url2) { }
info("trying update with %s", $url); my ($status) = split / /, $reply, 1;
my $reply = geturl(proxy => opt('proxy'), url => $url); my ($updated, $msg) =
if (!$reply) { $statuses{$status} // (0, sprintf("Unknown reply from Infomaniak: %s", $reply));
info("could not update %s using url %s, trying next one", $h, $url); if ($updated) {
next; success($msg);
} $config{$h}{"ipv$v"} = $ip;
my ($status) = split / /, $reply, 1; $config{$h}{'mtime'} = $now;
my ($updated, $msg) = $config{$h}{"status-ipv$v"} = 'good';
$statuses{$status} // (0, sprintf("Unknown reply from Infomaniak: %s", $reply)); next;
if ($updated) { } else {
info($msg); failed($msg);
$config{$h}{"ipv$v"} = $ip;
$config{$h}{'mtime'} = $now;
$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);
} }
} }
} }