diff --git a/README.md b/README.md index 055b3c3..0b987ce 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ Dynamic DNS services currently supported include: Duckdns - See https://duckdns.org/ for details Freemyip - See https://freemyip.com for details woima.fi - See https://woima.fi/ for details + Yandex - See https://domain.yandex.com/ for details DDclient now supports many of cable/dsl broadband routers. diff --git a/ddclient b/ddclient index 09cc63a..2ebbc95 100755 --- a/ddclient +++ b/ddclient @@ -483,6 +483,9 @@ my %variables = ( 'warned-min-interval' => setv(T_ANY, 0, 1, 0, 0, undef), 'warned-min-error-interval' => setv(T_ANY, 0, 1, 0, 0, undef), }, + 'yandex-common-defaults' => { + 'server' => setv(T_FQDNP, 1, 0, 1, 'pddimp.yandex.ru', undef), + }, ); my %services = ( 'dyndns1' => { @@ -685,6 +688,16 @@ my %services = ( $variables{'woima-service-common-defaults'}, ), }, + 'yandex' => { + 'updateable' => undef, + 'update' => \&nic_yandex_update, + 'examples' => \&nic_yandex_examples, + 'variables' => merge( + { 'min-interval' => setv(T_DELAY, 0, 0, 1, interval('5m'), 0),}, + $variables{'yandex-common-defaults'}, + $variables{'service-common-defaults'}, + ), + }, ); $variables{'merged'} = merge($variables{'global-defaults'}, $variables{'service-common-defaults'}, @@ -2009,16 +2022,23 @@ sub geturl { verbose("CONNECT:", "%s", $to); $request = "$method "; - $request .= "http://$server" if $proxy; + if (!$use_ssl) { + $request .= "http://$server" if $proxy; + } else { + $request .= "https://$server" if $proxy; + } $request .= "/$url HTTP/1.0\n"; $request .= "Host: $server\n"; my $auth = encode_base64("${login}:${password}", ""); $request .= "Authorization: Basic $auth\n" if $login || $password; $request .= "User-Agent: ${program}/${version}\n"; + if ($data) { + $request .= "Content-Type: application/x-www-form-urlencoded\n"; + $request .= "Content-Length: " . length($data) . "\n"; + } $request .= "Connection: close\n"; $request .= "$headers\n"; - $request .= "Content-Length: ".length($data)."\n" if $data; $request .= "\n"; $request .= $data; @@ -4348,6 +4368,120 @@ sub nic_cloudflare_update { } } } +###################################################################### +## nic_yandex_examples +###################################################################### +sub nic_yandex_examples { + return <jsonToObj($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(opt('proxy'), $url, '', '', $headers, 'POST', $data); + unless ($reply) { + failed("updating %s: Could not connect to %s.", $host, $config{$host}{'server'}); + last; + } + last if !header_ok($host, $reply); + + # Strip header + $reply =~ s/^.*?\n\n//s; + $response = JSON::Any->jsonToObj($reply); + if ($response->{success} eq 'error') { + failed ("%s", $response->{error}); + } else { + success ("%s -- Updated Successfully to %s", $host, $ip); + } + + # Cache + $config{$host}{'ip'} = $ip; + $config{$host}{'mtime'} = $now; + $config{$host}{'status'} = 'good'; + } + } +} ###################################################################### ## nic_duckdns_examples diff --git a/sample-etc_ddclient.conf b/sample-etc_ddclient.conf index 63d8a65..ed896b7 100644 --- a/sample-etc_ddclient.conf +++ b/sample-etc_ddclient.conf @@ -261,3 +261,11 @@ ssl=yes # use ssl-support. Works with #login=domain.nsupdate.info #password='123' #domain.nsupdate.info + +## +## Yandex.Mail for Domain (domain.yandex.com) +## +# protocol=yandex, \ +# login=domain.tld, \ +# password=yandex-pdd-token \ +# my.domain.tld,other.domain.tld \