]> git.ipfire.org Git - ddns.git/commitdiff
Merge branch 'lightningwirelabs'
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 9 Jun 2014 13:37:31 +0000 (15:37 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 9 Jun 2014 13:37:31 +0000 (15:37 +0200)
1  2 
src/ddns/__init__.py
src/ddns/errors.py
src/ddns/providers.py

diff --combined src/ddns/__init__.py
index ee91a602632c6812535cf817384aea6db0413170,e146720ef8a7cebec8805c745ab8a1f436326c40..e146720ef8a7cebec8805c745ab8a1f436326c40
@@@ -87,6 -87,7 +87,7 @@@ class DDNSCore(object)
                """
                for provider in (
                        DDNSProviderNOIP,
+                       DDNSProviderLightningwirelabs,
                        DDNSProviderSelfhost,
                ):
                        self.register_provider(provider)
diff --combined src/ddns/errors.py
index 018ff9cd550344dcbbf07bbbe5881d5c9e468b91,1803c98e197c8da92af6f9c6f9e9ae8ffc29080b..1803c98e197c8da92af6f9c6f9e9ae8ffc29080b
@@@ -39,6 -39,14 +39,14 @@@ class DDNSAuthenticationError(DDNSError
        pass
  
  
+ class DDNSConfigurationError(DDNSError):
+       """
+               Thrown when invalid or insufficient
+               data is provided by the configuration file.
+       """
+       pass
  class DDNSInternalServerError(DDNSError):
        """
                Thrown when the remote server reported
diff --combined src/ddns/providers.py
index 124cf2f8280e7618759725d733b0d3573492025a,3f91dd989e8ab06837dfb1cbb98e8a856c1b05a5..0a20e3ae29f97d82cae2a11cc7340f6e2c4736cf
@@@ -121,6 -121,76 +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",
        # here: http://www.no-ip.com/integrate/request and
        # here: http://www.no-ip.com/integrate/response
  
 -      url = "http://%(username)s:%(password)s@dynupdate.no-ip.com/nic/update?hostname=%(hostname)s&myip=%(address)s"
 +      url = "http://%(username)s:%(password)s@dynupdate.no-ip.com/nic/update"
  
        def __call__(self):
                url = self.url % {
 -                      "hostname" : self.hostname,
                        "username" : self.username,
                        "password" : self.password,
 +              }
 +
 +              data = {
 +                      "hostname" : self.hostname,
                        "address"  : self.get_address("ipv4"),
                }
  
                # Send update to the server.
 -              response = self.send_request(url)
 +              response = self.send_request(url, data=data)
  
                # Get the full response message.
                output = response.read()
@@@ -176,16 -243,12 +246,16 @@@ class DDNSProviderSelfhost(DDNSProvider
                "protocols" : ["ipv4",],
        }
  
 -      url = "https://carol.selfhost.de/update?username=%(username)s&password=%(password)s&textmodi=1"
 +      url = "https://carol.selfhost.de/update"
  
        def __call__(self):
 -              url = self.url % { "username" : self.username, "password" : self.password }
 +              data = {
 +                      "username" : self.username,
 +                      "password" : self.password,
 +                      "textmodi" : "1",
 +              }
  
 -              response = self.send_request(url)
 +              response = self.send_request(self.url, data=data)
  
                match = re.search("status=20(0|4)", response.read())
                if not match: