public inbox for ddns@lists.ipfire.org
 help / color / mirror / Atom feed
* [PATCH] duckdns.org: Support new update API
@ 2020-07-09 15:10 Stefan Schantl
  2020-07-10 13:24 ` Michael Tremer
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Schantl @ 2020-07-09 15:10 UTC (permalink / raw)
  To: ddns

[-- Attachment #1: Type: text/plain, Size: 2228 bytes --]

The provider entirely changed the update API, which now is
not longer DynDNS2 compatible, but supports IPv6 and cleaning records.

Sadly they do not provide any detailed return codes in case an update fails.

Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
---
 src/ddns/providers.py | 46 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/src/ddns/providers.py b/src/ddns/providers.py
index 46d8a67..690516f 100644
--- a/src/ddns/providers.py
+++ b/src/ddns/providers.py
@@ -802,16 +802,54 @@ class DDNSProviderDtDNS(DDNSProvider):
 		raise DDNSUpdateError
 
 
-class DDNSProviderDuckDNS(DDNSProtocolDynDNS2, DDNSProvider):
+class DDNSProviderDuckDNS(DDNSProvider):
 	handle    = "duckdns.org"
 	name      = "Duck DNS"
 	website   = "http://www.duckdns.org/"
-	protocols = ("ipv4",)
+	protocols = ("ipv6", "ipv4",)
 
 	# Information about the format of the request is to be found
-	# https://www.duckdns.org/install.jsp
+	# https://www.duckdns.org/spec.jsp
+
+	# ipv4 / ipv6 records are automatically removed during the update
+	# process ( clear=true ) and the ipv4 / ipv6 addresses appended.
+	url = "https://www.duckdns.org/update"
+
+	def update(self):
+		# Raise an error if no auth details are given.
+		if not self.token:
+			raise DDNSConfigurationError
+
+		data =  {
+			"domains" : self.hostname,
+			"token"    : self.token,
+			"ipv6" : self.get_address("ipv6", "-"),
+			"ip" : self.get_address("ipv4", "-"),
+                        "clear" : "true",
+		}
+
+		# Send update to the server.
+		response = self.send_request(self.url, data=data)
+
+		# Get the full response message.
+		output = response.read().decode()
+
+		# Remove all leading and trailing whitespace.
+		output = output.strip()
 
-	url = "https://www.duckdns.org/nic/update"
+		print(output)
+
+		# Handle success messages.
+		if output == "OK":
+			return
+
+		# The provider does not give detailed information
+		# if the update fails. Only a "KO" will be sent back.
+		if output == "KO":
+			raise DDNSUpdateError
+
+		# If we got here, some other update error happened.
+		raise DDNSUpdateError
 
 
 class DDNSProviderDyFi(DDNSProtocolDynDNS2, DDNSProvider):
-- 
2.20.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] duckdns.org: Support new update API
  2020-07-09 15:10 [PATCH] duckdns.org: Support new update API Stefan Schantl
@ 2020-07-10 13:24 ` Michael Tremer
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Tremer @ 2020-07-10 13:24 UTC (permalink / raw)
  To: ddns

[-- Attachment #1: Type: text/plain, Size: 2948 bytes --]

Hello,

Great to see some activity on here again :)

> On 9 Jul 2020, at 16:10, Stefan Schantl <stefan.schantl(a)ipfire.org> wrote:
> 
> The provider entirely changed the update API, which now is
> not longer DynDNS2 compatible, but supports IPv6 and cleaning records.
> 
> Sadly they do not provide any detailed return codes in case an update fails.
> 
> Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
> ---
> src/ddns/providers.py | 46 +++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 42 insertions(+), 4 deletions(-)
> 
> diff --git a/src/ddns/providers.py b/src/ddns/providers.py
> index 46d8a67..690516f 100644
> --- a/src/ddns/providers.py
> +++ b/src/ddns/providers.py
> @@ -802,16 +802,54 @@ class DDNSProviderDtDNS(DDNSProvider):
> 		raise DDNSUpdateError
> 
> 
> -class DDNSProviderDuckDNS(DDNSProtocolDynDNS2, DDNSProvider):
> +class DDNSProviderDuckDNS(DDNSProvider):
> 	handle    = "duckdns.org"
> 	name      = "Duck DNS"
> 	website   = "http://www.duckdns.org/"
> -	protocols = ("ipv4",)
> +	protocols = ("ipv6", "ipv4",)

Yay, IPv6!

> 	# Information about the format of the request is to be found
> -	# https://www.duckdns.org/install.jsp
> +	# https://www.duckdns.org/spec.jsp
> +
> +	# ipv4 / ipv6 records are automatically removed during the update
> +	# process ( clear=true ) and the ipv4 / ipv6 addresses appended.
> +	url = "https://www.duckdns.org/update"
> +
> +	def update(self):
> +		# Raise an error if no auth details are given.
> +		if not self.token:
> +			raise DDNSConfigurationError

In general, it would be nice to add a reason for this error like this:

  raise DDNSConfigurationError(“Missing token”)

> +
> +		data =  {
> +			"domains" : self.hostname,
> +			"token"    : self.token,
> +			"ipv6" : self.get_address("ipv6", "-"),
> +			"ip" : self.get_address("ipv4", "-"),
> +                        "clear" : "true",
> +		}
> +
> +		# Send update to the server.
> +		response = self.send_request(self.url, data=data)
> +
> +		# Get the full response message.
> +		output = response.read().decode()
> +
> +		# Remove all leading and trailing whitespace.
> +		output = output.strip()

I think this is a rather pretty solution.

Could you give this to another person for testing?

Acked-by: Michael Tremer <michael.tremer(a)ipfire.org>

Best,
-Michael

> -	url = "https://www.duckdns.org/nic/update"
> +		print(output)
> +
> +		# Handle success messages.
> +		if output == "OK":
> +			return
> +
> +		# The provider does not give detailed information
> +		# if the update fails. Only a "KO" will be sent back.
> +		if output == "KO":
> +			raise DDNSUpdateError
> +
> +		# If we got here, some other update error happened.
> +		raise DDNSUpdateError
> 
> 
> class DDNSProviderDyFi(DDNSProtocolDynDNS2, DDNSProvider):
> -- 
> 2.20.1
> 
> _______________________________________________
> ddns mailing list
> ddns(a)lists.ipfire.org
> https://lists.ipfire.org/mailman/listinfo/ddns


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-10 13:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-09 15:10 [PATCH] duckdns.org: Support new update API Stefan Schantl
2020-07-10 13:24 ` Michael Tremer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox