+class DDNSProviderBindNsupdate(DDNSProvider):
+ handle = "nsupdate"
+ name = "BIND nsupdate utility"
+ website = "http://en.wikipedia.org/wiki/Nsupdate"
+
+ DEFAULT_TTL = 60
+
+ @staticmethod
+ def supported():
+ # Search if the nsupdate utility is available
+ paths = os.environ.get("PATH")
+
+ for path in paths.split(":"):
+ executable = os.path.join(path, "nsupdate")
+
+ if os.path.exists(executable):
+ return True
+
+ return False
+
+ def update(self):
+ scriptlet = self.__make_scriptlet()
+
+ # -v enables TCP hence we transfer keys and other data that may
+ # exceed the size of one packet.
+ # -t sets the timeout
+ command = ["nsupdate", "-v", "-t", "60"]
+
+ p = subprocess.Popen(command, shell=True,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ )
+ stdout, stderr = p.communicate(scriptlet)
+
+ if p.returncode == 0:
+ return
+
+ raise DDNSError("nsupdate terminated with error code: %s\n %s" % (p.returncode, stderr))
+
+ def __make_scriptlet(self):
+ scriptlet = []
+
+ # Set a different server the update is sent to.
+ server = self.get("server", None)
+ 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")
+
+ scriptlet.append("key %s %s" % (key, secret))
+
+ ttl = self.get("ttl", self.DEFAULT_TTL)
+
+ # Perform an update for each supported protocol.
+ for rrtype, proto in (("AAAA", "ipv6"), ("A", "ipv4")):
+ address = self.get_address(proto)
+ if not address:
+ continue
+
+ scriptlet.append("update delete %s. %s" % (self.hostname, rrtype))
+ scriptlet.append("update add %s. %s %s %s" % \
+ (self.hostname, ttl, rrtype, address))
+
+ # Send the actions to the server.
+ scriptlet.append("send")
+ scriptlet.append("quit")
+
+ logger.debug(_("Scriptlet:"))
+ for line in scriptlet:
+ # Masquerade the line with the secret key.
+ if line.startswith("key"):
+ line = "key **** ****"
+
+ logger.debug(" %s" % line)
+
+ return "\n".join(scriptlet)
+
+
+class DDNSProviderChangeIP(DDNSProvider):
+ handle = "changeip.com"
+ name = "ChangeIP.com"
+ website = "https://changeip.com"
+ protocols = ("ipv4",)
+
+ # Detailed information about the update api can be found here.
+ # http://www.changeip.com/accounts/knowledgebase.php?action=displayarticle&id=34
+
+ url = "https://nic.changeip.com/nic/update"
+ can_remove_records = False
+
+ def update_protocol(self, proto):
+ data = {
+ "hostname" : self.hostname,
+ "myip" : self.get_address(proto),
+ }
+
+ # Send update to the server.
+ try:
+ response = self.send_request(self.url, username=self.username, password=self.password,
+ data=data)
+
+ # Handle error codes.
+ except urllib2.HTTPError, e:
+ if e.code == 422:
+ raise DDNSRequestError(_("Domain not found."))
+
+ raise
+
+ # Handle success message.
+ if response.code == 200:
+ return
+
+ # If we got here, some other update error happened.
+ raise DDNSUpdateError(_("Server response: %s") % output)
+
+
+class DDNSProviderDesecIO(DDNSProtocolDynDNS2, DDNSProvider):
+ handle = "desec.io"
+ name = "desec.io"
+ website = "https://www.desec.io"
+ protocols = ("ipv6", "ipv4",)
+
+ # ipv4 / ipv6 records are automatically removed when the update
+ # request originates from the respectively other protocol and no
+ # address is explicitly provided for the unused protocol.
+
+ url = "https://update.dedyn.io"
+
+ # desec.io sends the IPv6 and IPv4 address in one request
+
+ def update(self):
+ data = DDNSProtocolDynDNS2.prepare_request_data(self, "ipv4")
+
+ # This one supports IPv6
+ myipv6 = self.get_address("ipv6")
+
+ # Add update information if we have an IPv6 address.
+ if myipv6:
+ data["myipv6"] = myipv6
+
+ self.send_request(data)
+
+
+class DDNSProviderDDNSS(DDNSProvider):
+ handle = "ddnss.de"
+ name = "DDNSS"
+ website = "http://www.ddnss.de"
+ protocols = ("ipv4",)
+
+ # Detailed information about how to send the update request and possible response
+ # codes can be obtained from here.
+ # http://www.ddnss.de/info.php
+ # http://www.megacomputing.de/2014/08/dyndns-service-response-time/#more-919
+
+ url = "http://www.ddnss.de/upd.php"
+ can_remove_records = False
+
+ def update_protocol(self, proto):
+ data = {
+ "ip" : self.get_address(proto),
+ "host" : self.hostname,
+ }
+
+ # Check if a token has been set.
+ if self.token:
+ data["key"] = self.token
+
+ # Check if username and hostname are given.
+ elif self.username and self.password:
+ data.update({
+ "user" : self.username,
+ "pwd" : self.password,
+ })
+
+ # Raise an error if no auth details are given.
+ else:
+ raise DDNSConfigurationError
+
+ # Send update to the server.
+ response = self.send_request(self.url, data=data)
+
+ # This provider sends the response code as part of the header.
+ header = response.info()
+
+ # Get status information from the header.
+ output = header.getheader('ddnss-response')
+
+ # Handle success messages.
+ if output == "good" or output == "nochg":
+ return
+
+ # Handle error codes.
+ if output == "badauth":
+ raise DDNSAuthenticationError
+ elif output == "notfqdn":
+ raise DDNSRequestError(_("No valid FQDN was given"))
+ elif output == "nohost":
+ raise DDNSRequestError(_("Specified host does not exist"))
+ elif output == "911":
+ raise DDNSInternalServerError
+ elif output == "dnserr":
+ raise DDNSInternalServerError(_("DNS error encountered"))
+ elif output == "disabled":
+ raise DDNSRequestError(_("Account disabled or locked"))
+
+ # If we got here, some other update error happened.
+ raise DDNSUpdateError
+
+