From: Stefan Schantl Date: Sat, 21 Jun 2014 12:15:03 +0000 (+0200) Subject: Add Namecheap as new provider. X-Git-Tag: 001~35^2 X-Git-Url: http://git.ipfire.org/?p=oddments%2Fddns.git;a=commitdiff_plain;h=d1cd57ebdfdd37a125093883c0e829eeda81c6c6;hp=54d3efc8b2f93ecb486cfbca4e9dc7947d477117 Add Namecheap as new provider. --- diff --git a/ddns.conf.sample b/ddns.conf.sample index 1fb2071..209f4ae 100644 --- a/ddns.conf.sample +++ b/ddns.conf.sample @@ -49,6 +49,10 @@ # token = token # proto = ipv4 OR ipv6 +# [test.namecheap.com] +# provider = namecheap.com +# password = pass + # [test.no-ip.org] # provider = no-ip.com # username = user diff --git a/src/ddns/__init__.py b/src/ddns/__init__.py index bb9c748..7ee6a20 100644 --- a/src/ddns/__init__.py +++ b/src/ddns/__init__.py @@ -98,6 +98,7 @@ class DDNSCore(object): DDNSProviderDynU, DDNSProviderEasyDNS, DDNSProviderFreeDNSAfraidOrg, + DDNSProviderNamecheap, DDNSProviderNOIP, DDNSProviderLightningWireLabs, DDNSProviderOVH, diff --git a/src/ddns/providers.py b/src/ddns/providers.py index 85d3a37..9ffd264 100644 --- a/src/ddns/providers.py +++ b/src/ddns/providers.py @@ -20,6 +20,7 @@ ############################################################################### import logging +import xml.dom.minidom from i18n import _ @@ -504,6 +505,77 @@ class DDNSProviderLightningWireLabs(DDNSProvider): raise DDNSUpdateError +class DDNSProviderNamecheap(DDNSProvider): + INFO = { + "handle" : "namecheap.com", + "name" : "Namecheap", + "website" : "http://namecheap.com", + "protocols" : ["ipv4",] + } + + # Information about the format of the HTTP request is to be found + # https://www.namecheap.com/support/knowledgebase/article.aspx/9249/0/nc-dynamic-dns-to-dyndns-adapter + # https://community.namecheap.com/forums/viewtopic.php?f=6&t=6772 + + url = "https://dynamicdns.park-your-domain.com/update" + + def parse_xml(self, document, content): + # Send input to the parser. + xmldoc = xml.dom.minidom.parseString(document) + + # Get XML elements by the given content. + element = xmldoc.getElementsByTagName(content) + + # If no element has been found, we directly can return None. + if not element: + return None + + # Only get the first child from an element, even there are more than one. + firstchild = element[0].firstChild + + # Get the value of the child. + value = firstchild.nodeValue + + # Return the value. + return value + + def update(self): + # Namecheap requires the hostname splitted into a host and domain part. + host, domain = self.hostname.split(".", 1) + + data = { + "ip" : self.get_address("ipv4"), + "password" : self.password, + "host" : host, + "domain" : domain + } + + # 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 self.parse_xml(output, "IP") == self.get_address("ipv4"): + return + + # Handle error codes. + errorcode = self.parse_xml(output, "ResponseNumber") + + if errorcode == "304156": + raise DDNSAuthenticationError + elif errorcode == "316153": + raise DDNSRequestError(_("Domain not found.")) + elif errorcode == "316154": + raise DDNSRequestError(_("Domain not active.")) + elif errorcode in ("380098", "380099"): + raise DDNSInternalServerError + + # If we got here, some other update error happened. + raise DDNSUpdateError + + class DDNSProviderNOIP(DDNSProviderDynDNS): INFO = { "handle" : "no-ip.com",