From 30778c5451469ec24ea86330cc60b3b846a06699 Mon Sep 17 00:00:00 2001 From: "me@so.lar.is" Date: Sun, 19 Dec 2021 00:51:15 +0100 Subject: [PATCH] Add support for 1984.is --- README.md | 1 + ddclient.in | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 14b4b5c..bc0746c 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Dynamic DNS services currently supported include: dinahosting - See https://dinahosting.com Gandi - See https://gandi.net dnsexit - See https://dnsexit.com/ for details + 1984.is - See https://www.1984.is/product/freedns/ for details DDclient now supports many of cable/dsl broadband routers. diff --git a/ddclient.in b/ddclient.in index 5a35d38..d2945f8 100755 --- a/ddclient.in +++ b/ddclient.in @@ -531,6 +531,16 @@ my %variables = ( }, ); my %services = ( + '1984' => { + 'updateable' => undef, + 'update' => \&nic_1984_update, + 'examples' => \&nic_1984_examples, + 'variables' => { + %{$variables{'service-common-defaults'}}, + 'login' => setv(T_LOGIN, 0, 0, 'unused', undef), + 'server' => setv(T_FQDNP, 1, 0, 'api.1984.is', undef), + }, + }, 'changeip' => { 'updateable' => undef, 'update' => \&nic_changeip_update, @@ -1636,7 +1646,7 @@ sub init_config { $proto = opt('protocol') if !defined($proto); load_sha1_support($proto) if (grep (/^$proto$/, ("freedns", "nfsn"))); - load_json_support($proto) if (grep (/^$proto$/, ("cloudflare", "gandi", "yandex", "nfsn"))); + load_json_support($proto) if (grep (/^$proto$/, ("1984", "cloudflare", "gandi", "yandex", "nfsn"))); if (!exists($services{$proto})) { warning("skipping host: %s: unrecognized protocol '%s'", $h, $proto); @@ -5198,6 +5208,81 @@ sub nic_freedns_update { } } +###################################################################### +## nic_1984_examples +###################################################################### +sub nic_1984_examples { + return <<"EoEXAMPLE"; + +o '1984' + +The '1984' protocol is used by DNS services offered by 1984.is. + +Configuration variables applicable to the '1984' protocol are: + protocol=1984 ## + password=api-key ## your API key + fully.qualified.host ## the domain to update + +Example ${program}.conf file entries: + ## single host update + protocol=1984, \\ + password=my-1984-api-key, \\ + myhost + +EoEXAMPLE +} + +###################################################################### +## nic_1984_update +## https://api.1984.is/1.0/freedns/?apikey=xxx&domain=mydomain&ip=myip +## The response is a JSON document containing the following entries +## - ok: true or false depending on if the request was successful or not, +## if the ip is the same as before this will be true, +## - msg: successes or why it is not working, +## - lookup: if domain or subdomain was not found lookup will contain a list of names tried +###################################################################### +sub nic_1984_update { + debug("\nnic_1984_update -------------------"); + foreach my $host (@_) { + my $ip = delete $config{$host}{'wantip'}; + info("setting IP address to %s for %s", $ip, $host); + verbose("UPDATE:", "updating %s", $host); + + my $url; + $url = "https://$config{$host}{'server'}/1.0/freedns/"; + $url .= "?apikey=$config{$host}{'password'}"; + $url .= "&domain=$host"; + $url .= "&ip=$ip"; + + my $reply = geturl( + proxy => opt('proxy'), + url => $url, + ) // ''; + if ($reply eq '') { + failed("Updating %s: Could not connect to %s.", $host, $config{$host}{'server'}); + next; + } + next if !header_ok($host, $reply); + + # Strip header + $reply =~ qr/{(?:[^{}]*|(?R))*}/mp; + my $response = eval { decode_json(${^MATCH}) }; + if ($@) { + failed("Updating %s: JSON decoding failure", $host); + next; + } + unless ($response->{ok}) { + failed("%s", $response->{msg}); + } + + if ($response->{msg} =~ /unaltered/) { + success("Updating %s: skipped: IP was already set to %s", $host, $response->{ip}); + } else { + success("%s -- Updated successfully to %s", $host, $response->{ip}); + } + } +} + ###################################################################### ## nic_changeip_examples ######################################################################