]> git.ipfire.org Git - oddments/ddns.git/blobdiff - src/ddns/providers.py
zzzz.io: Also support IPv6
[oddments/ddns.git] / src / ddns / providers.py
index 512d663480361c58c05fe45f72957e26213c7c18..acec95b7a6e0ffd1afba2d36cd76a7101243d056 100644 (file)
@@ -129,12 +129,16 @@ class DDNSProvider(object):
 
                # Check if we actually need to update this host.
                elif self.is_uptodate(self.protocols):
-                       logger.debug(_("%s is already up to date") % self.hostname)
+                       logger.debug(_("The dynamic host %(hostname)s (%(provider)s) is already up to date") % \
+                               { "hostname" : self.hostname, "provider" : self.name })
                        return
 
                # Execute the update.
                self.update()
 
+               logger.info(_("Dynamic DNS update for %(hostname)s (%(provider)s) successful") % \
+                       { "hostname" : self.hostname, "provider" : self.name })
+
        def update(self):
                raise NotImplementedError
 
@@ -210,7 +214,7 @@ class DDNSProtocolDynDNS2(object):
                # Handle error codes.
                if output == "badauth":
                        raise DDNSAuthenticationError
-               elif output == "aduse":
+               elif output == "abuse":
                        raise DDNSAbuseError
                elif output == "notfqdn":
                        raise DDNSRequestError(_("No valid FQDN was given."))
@@ -220,6 +224,8 @@ class DDNSProtocolDynDNS2(object):
                        raise DDNSInternalServerError
                elif output == "dnserr":
                        raise DDNSInternalServerError(_("DNS error encountered."))
+               elif output == "badagent":
+                       raise DDNSBlockedError
 
                # If we got here, some other update error happened.
                raise DDNSUpdateError(_("Server response: %s") % output)
@@ -316,6 +322,11 @@ class DDNSProviderBindNsupdate(DDNSProvider):
                if server:
                        scriptlet.append("server %s" % server)
 
+               # Set the DNS zone the host should be added to.
+               zone = self.get("zone", None)
+               if zone:
+                       scriptlet.append("zone %s" % zone)
+
                key = self.get("key", None)
                if key:
                        secret = self.get("secret")
@@ -509,12 +520,14 @@ class DDNSProviderDynU(DDNSProtocolDynDNS2, DDNSProvider):
        url = "https://api.dynu.com/nic/update"
 
        def _prepare_request_data(self):
-               data = DDNSProviderDynDNS._prepare_request_data(self)
+               data = DDNSProtocolDynDNS2._prepare_request_data(self)
 
                # This one supports IPv6
-               data.update({
-                       "myipv6"   : self.get_address("ipv6"),
-               })
+               myipv6 = self.get_address("ipv6")
+
+               # Add update information if we have an IPv6 address.
+               if myipv6:
+                       data["myipv6"] = myipv6
 
                return data
 
@@ -532,6 +545,61 @@ class DDNSProviderEasyDNS(DDNSProtocolDynDNS2, DDNSProvider):
        url = "http://api.cp.easydns.com/dyn/tomato.php"
 
 
+class DDNSProviderDomopoli(DDNSProtocolDynDNS2, DDNSProvider):
+       handle    = "domopoli.de"
+       name      = "domopoli.de"
+       website   = "http://domopoli.de/"
+       protocols = ("ipv4",)
+
+       # https://www.domopoli.de/?page=howto#DynDns_start
+
+       url = "http://dyndns.domopoli.de/nic/update"
+
+
+class DDNSProviderDynsNet(DDNSProvider):
+       handle    = "dyns.net"
+       name      = "DyNS"
+       website   = "http://www.dyns.net/"
+       protocols = ("ipv4",)
+
+       # There is very detailed informatio about how to send the update request and
+       # the possible response codes. (Currently we are using the v1.1 proto)
+       # http://www.dyns.net/documentation/technical/protocol/
+
+       url = "http://www.dyns.net/postscript011.php"
+
+       def update(self):
+               data = {
+                       "ip"       : self.get_address("ipv4"),
+                       "host"     : self.hostname,
+                       "username" : self.username,
+                       "password" : self.password,
+               }
+
+               # Send update to the server.
+               response = self.send_request(self.url, data=data)
+
+               # Get the full response message.
+               output = response.read()
+
+               # Handle success messages.
+               if output.startswith("200"):
+                       return
+
+               # Handle error codes.
+               if output.startswith("400"):
+                       raise DDNSRequestError(_("Malformed request has been sent."))
+               elif output.startswith("401"):
+                       raise DDNSAuthenticationError
+               elif output.startswith("402"):
+                       raise DDNSRequestError(_("Too frequent update requests have been sent."))
+               elif output.startswith("403"):
+                       raise DDNSInternalServerError
+
+               # If we got here, some other update error happened.
+               raise DDNSUpdateError(_("Server response: %s") % output) 
+
+
 class DDNSProviderEnomCom(DDNSResponseParserXML, DDNSProvider):
        handle    = "enom.com"
        name      = "eNom Inc."
@@ -574,6 +642,46 @@ class DDNSProviderEnomCom(DDNSResponseParserXML, DDNSProvider):
                raise DDNSUpdateError
 
 
+class DDNSProviderEntryDNS(DDNSProvider):
+       handle    = "entrydns.net"
+       name      = "EntryDNS"
+       website   = "http://entrydns.net/"
+       protocols = ("ipv4",)
+
+       # Some very tiny details about their so called "Simple API" can be found
+       # here: https://entrydns.net/help
+       url = "https://entrydns.net/records/modify"
+
+       def update(self):
+               data = {
+                       "ip" : self.get_address("ipv4")
+               }
+
+               # Add auth token to the update url.
+               url = "%s/%s" % (self.url, self.token)
+
+               # Send update to the server.
+               try:
+                       response = self.send_request(url, data=data)
+
+               # Handle error codes
+               except urllib2.HTTPError, e:
+                       if e.code == 404:
+                               raise DDNSAuthenticationError
+
+                       elif e.code == 422:
+                               raise DDNSRequestError(_("An invalid IP address was submitted"))
+
+                       raise
+
+               # Handle success messages.
+               if response.code == 200:
+                       return
+
+               # If we got here, some other update error happened.
+               raise DDNSUpdateError
+
+
 class DDNSProviderFreeDNSAfraidOrg(DDNSProvider):
        handle    = "freedns.afraid.org"
        name      = "freedns.afraid.org"
@@ -733,11 +841,11 @@ class DDNSProviderNOIP(DDNSProtocolDynDNS2, DDNSProvider):
 class DDNSProviderNsupdateINFO(DDNSProtocolDynDNS2, DDNSProvider):
        handle    = "nsupdate.info"
        name      = "nsupdate.info"
-       website   = "http://www.nsupdate.info/"
+       website   = "http://nsupdate.info/"
        protocols = ("ipv6", "ipv4",)
 
        # Information about the format of the HTTP request can be found
-       # after login on the provider user intrface and here:
+       # after login on the provider user interface and here:
        # http://nsupdateinfo.readthedocs.org/en/latest/user.html
 
        # Nsupdate.info uses the hostname as user part for the HTTP basic auth,
@@ -772,6 +880,30 @@ class DDNSProviderNsupdateINFO(DDNSProtocolDynDNS2, DDNSProvider):
                return data
 
 
+class DDNSProviderOpenDNS(DDNSProtocolDynDNS2, DDNSProvider):
+       handle    = "opendns.com"
+       name      = "OpenDNS"
+       website   = "http://www.opendns.com"
+
+       # Detailed information about the update request and possible
+       # response codes can be obtained from here:
+       # https://support.opendns.com/entries/23891440
+
+       url = "https://updates.opendns.com/nic/update"
+
+       @property
+       def proto(self):
+               return self.get("proto")
+
+       def _prepare_request_data(self):
+               data = {
+                       "hostname" : self.hostname,
+                       "myip"     : self.get_address(self.proto)
+               }
+
+               return data
+
+
 class DDNSProviderOVH(DDNSProtocolDynDNS2, DDNSProvider):
        handle    = "ovh.com"
        name      = "OVH"
@@ -875,7 +1007,7 @@ class DDNSProviderSelfhost(DDNSProtocolDynDNS2, DDNSProvider):
        url = "https://carol.selfhost.de/nic/update"
 
        def _prepare_request_data(self):
-               data = DDNSProviderDynDNS._prepare_request_data(self)
+               data = DDNSProtocolDynDNS2._prepare_request_data(self)
                data.update({
                        "hostname" : "1",
                })
@@ -898,6 +1030,14 @@ class DDNSProviderSPDNS(DDNSProtocolDynDNS2, DDNSProvider):
 
        url = "https://update.spdns.de/nic/update"
 
+       @property
+       def username(self):
+               return self.get("username") or self.hostname
+
+       @property
+       def password(self):
+               return self.get("username") or self.token
+
 
 class DDNSProviderStrato(DDNSProtocolDynDNS2, DDNSProvider):
        handle    = "strato.com"
@@ -1012,3 +1152,56 @@ class DDNSProviderZoneedit(DDNSProtocolDynDNS2, DDNSProvider):
 
                # If we got here, some other update error happened.
                raise DDNSUpdateError
+
+
+class DDNSProviderZZZZ(DDNSProvider):
+       handle    = "zzzz.io"
+       name      = "zzzz"
+       website   = "https://zzzz.io"
+       protocols = ("ipv6", "ipv4",)
+
+       # Detailed information about the update request can be found here:
+       # https://zzzz.io/faq/
+
+       # Details about the possible response codes have been provided in the bugtracker:
+       # https://bugzilla.ipfire.org/show_bug.cgi?id=10584#c2
+
+       url = "https://zzzz.io/api/v1/update"
+
+       def update(self):
+               for protocol in self.protocols:
+                       address = self.get_address(protocol)
+
+                       if address:
+                               self.update_for_protocol(protocol, address)
+
+       def update_for_protocol(self, proto, address):
+               data = {
+                       "ip"    : address,
+                       "token" : self.token,
+               }
+
+               if proto == "ipv6":
+                       data["type"] = "aaaa"
+
+               # zzzz uses the host from the full hostname as part
+               # of the update url.
+               host, domain = self.hostname.split(".", 1)
+
+               # Add host value to the update url.
+               url = "%s/%s" % (self.url, host)
+
+               # Send update to the server.
+               try:
+                       response = self.send_request(url, data=data)
+
+               # Handle error codes.
+               except DDNSNotFound:
+                       raise DDNSRequestError(_("Invalid hostname specified"))
+
+               # Handle success messages.
+               if response.code == 200:
+                       return
+
+               # If we got here, some other update error happened.
+               raise DDNSUpdateError