From 8b1e720fb75faff79c23085d2d3b4b98f79a1236 Mon Sep 17 00:00:00 2001 From: Costas Tyfoxylos Date: Sun, 12 Mar 2023 14:05:31 +0100 Subject: [PATCH] Add support for godaddy and fix typos. Signed-off-by: Costas Tyfoxylos Signed-off-by: Stefan Schantl --- README | 3 ++- ddns.conf.sample | 6 +++++ src/ddns/providers.py | 52 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/README b/README index b6decb3..f0df1ff 100644 --- 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 diff --git a/ddns.conf.sample b/ddns.conf.sample index 61a608a..f93c738 100644 --- a/ddns.conf.sample +++ b/ddns.conf.sample @@ -100,6 +100,12 @@ # username = user # password = pass +# [test.godaddy.com] +# provider = godaddy.com +# username = key +# password = secret + + # [test.google.com] # provider = domains.google.com # username = user diff --git a/src/ddns/providers.py b/src/ddns/providers.py index 5b2a82d..8025720 100644 --- a/src/ddns/providers.py +++ b/src/ddns/providers.py @@ -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" -- 2.39.5