Add support for the Lightning Wire Labs DNS Service.
authorStefan Schantl <stefan.schantl@ipfire.org>
Sun, 8 Jun 2014 16:03:46 +0000 (18:03 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 9 Jun 2014 13:31:50 +0000 (15:31 +0200)
ddns.conf
ddns/__init__.py
ddns/providers.py

index a40f567..b54f8ef 100644 (file)
--- a/ddns.conf
+++ b/ddns.conf
 # provider = selfhost.de
 # username = user
 # password = pass
+
+# [test.lightningwirelabs.com]
+# provider = dns.lightningwirelabs.com
+
+# Only use one of these two auth options.
+# token = token
+# username = user
+# password = pass
index ee91a60..e146720 100644 (file)
@@ -87,6 +87,7 @@ class DDNSCore(object):
                """
                for provider in (
                        DDNSProviderNOIP,
+                       DDNSProviderLightningwirelabs,
                        DDNSProviderSelfhost,
                ):
                        self.register_provider(provider)
index f764001..3f91dd9 100644 (file)
@@ -121,6 +121,76 @@ class DDNSProvider(object):
                return self.core.system.get_address(proto)
 
 
+class DDNSProviderLightningWireLabs(DDNSProvider):
+       INFO = {
+               "handle"    : "dns.lightningwirelabs.com",
+               "name"      : "Lightning Wire Labs",
+               "website"   : "http://dns.lightningwirelabs.com/",
+               "protocols" : ["ipv6", "ipv4",]
+       }
+
+       # Information about the format of the HTTPS request is to be found
+       # https://dns.lightningwirelabs.com/knowledge-base/api/ddns
+       url = "https://dns.lightningwirelabs.com/update"
+
+       @property
+       def token(self):
+               """
+                       Fast access to the token.
+               """
+               return self.get("token")
+
+       def __call__(self):
+               data =  {
+                       "hostname" : self.hostname,
+               }
+
+               # Check if we update an IPv6 address.
+               address6 = self.get_address("ipv6")
+               if address6:
+                       data["address6"] = address6
+
+               # Check if we update an IPv4 address.
+               address4 = self.get_address("ipv4")
+               if address4:
+                       data["address4"] = address4
+
+               # Raise an error if none address is given.
+               if not data.has_key("address6") and not data.has_key("address4"):
+                       raise DDNSConfigurationError
+
+               # Check if a token has been set.
+               if self.token:
+                       data["token"] = self.token
+
+               # Check for username and password.
+               elif self.username and self.password:
+                       data.update({
+                               "username" : self.username,
+                               "password" : self.password,
+                       })
+
+               # Raise an error if no auth details are given.
+               else:
+                       raise DDNSConfigurationError
+
+               # Send update to the server.
+               response = self.send_request(url, data=data)
+
+               # Handle success messages.
+               if response.code == 200:
+                       return
+
+               # Handle error codes.
+               if response.code == "403":
+                       raise DDNSAuthenticationError
+               elif response.code == "400":
+                       raise DDNSRequestError
+
+               # If we got here, some other update error happened.
+               raise DDNSUpdateError
+
+
 class DDNSProviderNOIP(DDNSProvider):
        INFO = {
                "handle"    : "no-ip.com",