]> git.ipfire.org Git - people/stevee/ddns.git/commitdiff
Add support for godaddy and fix typos.
authorCostas Tyfoxylos <costas.tyf@gmail.com>
Sun, 12 Mar 2023 13:05:31 +0000 (14:05 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Wed, 15 Mar 2023 11:18:06 +0000 (12:18 +0100)
Signed-off-by: Costas Tyfoxylos <costas.tyf@gmail.com>
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
README
ddns.conf.sample
src/ddns/providers.py

diff --git a/README b/README
index b6decb35c33878989bbc1ec4d14a4d3fdc57a905..f0df1ff4905a83e96b088af5ee1d5fe203dc35e6 100644 (file)
--- a/README
+++ b/README
@@ -27,7 +27,7 @@ LICENSE:
 INSTALLATION:
        REQUIREMENTS:
                ddns is written in Python and does not require any third-party
-               modules. The minumum version of Python that has been tested
+               modules. The minimum version of Python that has been tested
                is Python 2.7.
 
                Building the program from source code requires:
@@ -69,6 +69,7 @@ SUPPORTED PROVIDERS:
        enom.com
        entrydns.net
        freedns.afraid.org
+       godaddy.com
        inwx.com|de|at|ch|es
        itsdns.de
        joker.com
index 61a608a6585a0c9f8c6b959673bbd3bdbdca8e93..f93c7381f8e125c2651704e9df21cec0eb07e41f 100644 (file)
 # username = user
 # password = pass
 
+# [test.godaddy.com]
+# provider = godaddy.com
+# username = key
+# password = secret
+
+
 # [test.google.com]
 # provider = domains.google.com
 # username = user
index 5b2a82d1b727172c2011574277988977b8013db0..80257206786f71f94b258f38009030bd1fbc3186 100644 (file)
@@ -21,6 +21,7 @@
 
 import datetime
 import logging
+import json
 import os
 import subprocess
 import urllib.request
@@ -442,7 +443,7 @@ class DDNSProviderAllInkl(DDNSProvider):
        protocols = ("ipv4",)
 
        # There are only information provided by the vendor how to
-       # perform an update on a FRITZ Box. Grab requried informations
+       # perform an update on a FRITZ Box. Grab required information
        # from the net.
        # http://all-inkl.goetze.it/v01/ddns-mit-einfachen-mitteln/
 
@@ -1217,6 +1218,55 @@ class DDNSProviderFreeDNSAfraidOrg(DDNSProvider):
                raise DDNSUpdateError
 
 
+class DDNSProviderGodaddy(DDNSProvider):
+       handle    = "godaddy.com"
+       name      = "godaddy.com"
+       website   = "https://godaddy.com/"
+       protocols = ("ipv4",)
+
+       # Information about the format of the HTTP request is to be found
+       # here: https://developer.godaddy.com/doc/endpoint/domains#/v1/recordReplaceTypeName
+       url = "https://api.godaddy.com/v1/domains/"
+       can_remove_records = False
+
+       def update_protocol(self, proto):
+               # retrieve ip
+               ip_address = self.get_address(proto)
+
+               # set target url
+               url = f"{self.url}/{self.hostname}/records/A/@"
+
+               # prepare data
+               data = json.dumps([{"data": ip_address, "ttl": 600, "name": self.hostname, "type": "A"}]).encode("utf-8")
+
+               # Method requires authentication by special headers.
+               request = urllib.request.Request(url=url,
+                                                                                data=data,
+                                                                                headers={"Authorization": f"sso-key {self.username}:{self.password}",
+                                                                                                 "Content-Type": "application/json"},
+                                                                                method="PUT")
+               result = urllib.request.urlopen(request)
+
+               # handle success
+               if result.code == 200:
+                       return
+
+               # handle errors
+               if result.code == 400:
+                       raise DDNSRequestError(_("Malformed request received."))
+               if result.code in (401, 403):
+                       raise DDNSAuthenticationError
+               if result.code == 404:
+                       raise DDNSRequestError(_("Resource not found."))
+               if result.code == 422:
+                       raise DDNSRequestError(_("Record does not fulfill the schema."))
+               if result.code == 429:
+                       raise DDNSRequestError(_("API Rate limiting."))
+
+               # If we got here, some other update error happened.
+               raise DDNSUpdateError
+
+
 class DDNSProviderHENet(DDNSProtocolDynDNS2, DDNSProvider):
                 handle    = "he.net"
                 name      = "he.net"