]> git.ipfire.org Git - oddments/ddns.git/commitdiff
DuckDNS: Update to use new API.
authorCarl Mascott <cmascott@yahoo.com>
Wed, 2 Dec 2020 10:39:20 +0000 (11:39 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Wed, 2 Dec 2020 10:39:20 +0000 (11:39 +0100)
The new API supports IPv6 and a token based auth.

Reference #12415.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
src/ddns/providers.py

index 46d8a67cf5b3b62af15f6013aa140e1933123085..a1ca3f3d58a1a50480316cd1240b581fbe01d824 100644 (file)
@@ -802,16 +802,62 @@ 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
+
+       url = "https://www.duckdns.org/update"
+       can_remove_records = False
+
+       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,
+               }
+
+               # Check if we update an IPv4 address.
+               address4 = self.get_address("ipv4")
+               if address4:
+                       data["ip"] = address4
 
-       url = "https://www.duckdns.org/nic/update"
+               # Check if we update an IPv6 address.
+               address6 = self.get_address("ipv6")
+               if address6:
+                       data["ipv6"] = address6
+
+               # Raise an error if no address is given.
+               if "ip" not in data and "ipv6" not in data:
+                       raise DDNSConfigurationError
+
+               # 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()
+
+               # 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):