yandex: Remove unnecessary host groupings
Each host is already updated individually so there's no point in grouping the hosts.
This commit is contained in:
parent
216c9c6010
commit
5d2a1e864a
1 changed files with 64 additions and 71 deletions
135
ddclient.in
135
ddclient.in
|
@ -6398,80 +6398,73 @@ EoEXAMPLE
|
||||||
######################################################################
|
######################################################################
|
||||||
sub nic_yandex_update {
|
sub nic_yandex_update {
|
||||||
debug("\nnic_yandex_update -------------------");
|
debug("\nnic_yandex_update -------------------");
|
||||||
my %groups = group_hosts_by(\@_, [qw(server login pasword wantip)]);
|
for my $host (@_) {
|
||||||
for my $sig (keys %groups) {
|
my $ip = delete $config{$host}{'wantip'};
|
||||||
my @hosts = @{$groups{$sig}};
|
my $headers = "PddToken: $config{$host}{'password'}\n";
|
||||||
my $key = $hosts[0];
|
|
||||||
my $ip = $config{$key}{'wantip'};
|
|
||||||
my $headers = "PddToken: $config{$key}{'password'}\n";
|
|
||||||
|
|
||||||
for my $host (@hosts) {
|
info("setting IP address to %s for %s", $ip, $host);
|
||||||
delete $config{$host}{'wantip'};
|
verbose("UPDATE:", "updating %s", $host);
|
||||||
|
|
||||||
info("setting IP address to %s for %s", $ip, $host);
|
# Get record ID for host
|
||||||
verbose("UPDATE:", "updating %s", $host);
|
my $url = "https://$config{$host}{'server'}/api2/admin/dns/list?";
|
||||||
|
$url .= "domain=";
|
||||||
# Get record ID for host
|
$url .= $config{$host}{'login'};
|
||||||
my $url = "https://$config{$host}{'server'}/api2/admin/dns/list?";
|
my $reply = geturl(proxy => opt('proxy'), url => $url, headers => $headers);
|
||||||
$url .= "domain=";
|
unless ($reply) {
|
||||||
$url .= $config{$key}{'login'};
|
failed("updating %s: Could not connect to %s.", $host, $config{$host}{'server'});
|
||||||
my $reply = geturl(proxy => opt('proxy'), url => $url, headers => $headers);
|
next;
|
||||||
unless ($reply) {
|
|
||||||
failed("updating %s: Could not connect to %s.", $host, $config{$key}{'server'});
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
next if !header_ok($host, $reply);
|
|
||||||
|
|
||||||
# Strip header
|
|
||||||
$reply =~ s/^.*?\n\n//s;
|
|
||||||
my $response = eval { decode_json($reply) };
|
|
||||||
if ($response->{success} eq 'error') {
|
|
||||||
failed("%s", $response->{error});
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Pull the ID out of the json
|
|
||||||
my ($id) = map { $_->{fqdn} eq $host ? $_->{record_id} : () } @{$response->{records}};
|
|
||||||
unless ($id) {
|
|
||||||
failed("updating %s: DNS record ID not found.", $host);
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Update the DNS record
|
|
||||||
$url = "https://$config{$host}{'server'}/api2/admin/dns/edit";
|
|
||||||
my $data = "domain=";
|
|
||||||
$data .= $config{$key}{'login'};
|
|
||||||
$data .= "&record_id=";
|
|
||||||
$data .= $id;
|
|
||||||
$data .= "&content=";
|
|
||||||
$data .= $ip if $ip;
|
|
||||||
|
|
||||||
$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;
|
|
||||||
}
|
|
||||||
next if !header_ok($host, $reply);
|
|
||||||
|
|
||||||
# Strip header
|
|
||||||
$reply =~ s/^.*?\n\n//s;
|
|
||||||
$response = eval { decode_json($reply) };
|
|
||||||
if ($response->{success} eq 'error') {
|
|
||||||
failed("%s", $response->{error});
|
|
||||||
} else {
|
|
||||||
success("%s -- Updated Successfully to %s", $host, $ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
$config{$host}{'ip'} = $ip;
|
|
||||||
$config{$host}{'mtime'} = $now;
|
|
||||||
$config{$host}{'status'} = 'good';
|
|
||||||
}
|
}
|
||||||
|
next if !header_ok($host, $reply);
|
||||||
|
|
||||||
|
# Strip header
|
||||||
|
$reply =~ s/^.*?\n\n//s;
|
||||||
|
my $response = eval { decode_json($reply) };
|
||||||
|
if ($response->{success} eq 'error') {
|
||||||
|
failed("%s", $response->{error});
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Pull the ID out of the json
|
||||||
|
my ($id) = map { $_->{fqdn} eq $host ? $_->{record_id} : () } @{$response->{records}};
|
||||||
|
unless ($id) {
|
||||||
|
failed("updating %s: DNS record ID not found.", $host);
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Update the DNS record
|
||||||
|
$url = "https://$config{$host}{'server'}/api2/admin/dns/edit";
|
||||||
|
my $data = "domain=";
|
||||||
|
$data .= $config{$host}{'login'};
|
||||||
|
$data .= "&record_id=";
|
||||||
|
$data .= $id;
|
||||||
|
$data .= "&content=";
|
||||||
|
$data .= $ip if $ip;
|
||||||
|
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
next if !header_ok($host, $reply);
|
||||||
|
|
||||||
|
# Strip header
|
||||||
|
$reply =~ s/^.*?\n\n//s;
|
||||||
|
$response = eval { decode_json($reply) };
|
||||||
|
if ($response->{success} eq 'error') {
|
||||||
|
failed("%s", $response->{error});
|
||||||
|
} else {
|
||||||
|
success("%s -- Updated Successfully to %s", $host, $ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
$config{$host}{'ip'} = $ip;
|
||||||
|
$config{$host}{'mtime'} = $now;
|
||||||
|
$config{$host}{'status'} = 'good';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue