]>
Commit | Line | Data |
---|---|---|
6dc6de4c SS |
1 | commit ebdb37245e2033b065cce5a19597be4ef1c8875c |
2 | Author: Carl Mascott <cmascott@yahoo.com> | |
3 | Date: Wed Dec 2 11:39:20 2020 +0100 | |
4 | ||
5 | DuckDNS: Update to use new API. | |
6 | ||
7 | The new API supports IPv6 and a token based auth. | |
8 | ||
9 | Reference #12415. | |
10 | ||
11 | Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org> | |
12 | ||
13 | diff --git a/src/ddns/providers.py b/src/ddns/providers.py | |
14 | index 46d8a67..a1ca3f3 100644 | |
15 | --- a/src/ddns/providers.py | |
16 | +++ b/src/ddns/providers.py | |
17 | @@ -802,16 +802,62 @@ class DDNSProviderDtDNS(DDNSProvider): | |
18 | raise DDNSUpdateError | |
19 | ||
20 | ||
21 | -class DDNSProviderDuckDNS(DDNSProtocolDynDNS2, DDNSProvider): | |
22 | +class DDNSProviderDuckDNS(DDNSProvider): | |
23 | handle = "duckdns.org" | |
24 | name = "Duck DNS" | |
25 | website = "http://www.duckdns.org/" | |
26 | - protocols = ("ipv4",) | |
27 | + protocols = ("ipv6", "ipv4",) | |
28 | ||
29 | # Information about the format of the request is to be found | |
30 | - # https://www.duckdns.org/install.jsp | |
31 | + # https://www.duckdns.org/spec.jsp | |
32 | + | |
33 | + url = "https://www.duckdns.org/update" | |
34 | + can_remove_records = False | |
35 | + | |
36 | + def update(self): | |
37 | + # Raise an error if no auth details are given. | |
38 | + if not self.token: | |
39 | + raise DDNSConfigurationError | |
40 | + | |
41 | + data = { | |
42 | + "domains" : self.hostname, | |
43 | + "token" : self.token, | |
44 | + } | |
45 | + | |
46 | + # Check if we update an IPv4 address. | |
47 | + address4 = self.get_address("ipv4") | |
48 | + if address4: | |
49 | + data["ip"] = address4 | |
50 | ||
51 | - url = "https://www.duckdns.org/nic/update" | |
52 | + # Check if we update an IPv6 address. | |
53 | + address6 = self.get_address("ipv6") | |
54 | + if address6: | |
55 | + data["ipv6"] = address6 | |
56 | + | |
57 | + # Raise an error if no address is given. | |
58 | + if "ip" not in data and "ipv6" not in data: | |
59 | + raise DDNSConfigurationError | |
60 | + | |
61 | + # Send update to the server. | |
62 | + response = self.send_request(self.url, data=data) | |
63 | + | |
64 | + # Get the full response message. | |
65 | + output = response.read().decode() | |
66 | + | |
67 | + # Remove all leading and trailing whitespace. | |
68 | + output = output.strip() | |
69 | + | |
70 | + # Handle success messages. | |
71 | + if output == "OK": | |
72 | + return | |
73 | + | |
74 | + # The provider does not give detailed information | |
75 | + # if the update fails. Only a "KO" will be sent back. | |
76 | + if output == "KO": | |
77 | + raise DDNSUpdateError | |
78 | + | |
79 | + # If we got here, some other update error happened. | |
80 | + raise DDNSUpdateError | |
81 | ||
82 | ||
83 | class DDNSProviderDyFi(DDNSProtocolDynDNS2, DDNSProvider): |