]>
Commit | Line | Data |
---|---|---|
d1030eb0 | 1 | #!/usr/bin/env sh |
2 | ||
3 | #Created by RaidenII, to use DuckDNS's API to add/remove text records | |
d1030eb0 | 4 | #modified by helbgd @ 03/13/2018 to support ddnss.de |
5 | #modified by mod242 @ 04/24/2018 to support different ddnss domains | |
6 | #Please note: the Wildcard Feature must be turned on for the Host record | |
7 | #and the checkbox for TXT needs to be enabled | |
8 | ||
d1030eb0 | 9 | # Pass credentials before "acme.sh --issue --dns dns_ddnss ..." |
10 | # -- | |
11 | # export DDNSS_Token="aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" | |
12 | # -- | |
13 | # | |
14 | ||
d1030eb0 | 15 | DDNSS_DNS_API="https://ddnss.de/upd.php" |
16 | ||
17 | ######## Public functions ##################### | |
18 | ||
19 | #Usage: dns_ddnss_add _acme-challenge.domain.ddnss.de "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" | |
20 | dns_ddnss_add() { | |
21 | fulldomain=$1 | |
22 | txtvalue=$2 | |
23 | ||
24 | DDNSS_Token="${DDNSS_Token:-$(_readaccountconf_mutable DDNSS_Token)}" | |
25 | if [ -z "$DDNSS_Token" ]; then | |
26 | _err "You must export variable: DDNSS_Token" | |
27 | _err "The token for your DDNSS account is necessary." | |
28 | _err "You can look it up in your DDNSS account." | |
29 | return 1 | |
30 | fi | |
31 | ||
32 | # Now save the credentials. | |
33 | _saveaccountconf_mutable DDNSS_Token "$DDNSS_Token" | |
34 | ||
35 | # Unfortunately, DDNSS does not seems to support lookup domain through API | |
36 | # So I assume your credentials (which are your domain and token) are correct | |
37 | # If something goes wrong, we will get a KO response from DDNSS | |
38 | ||
39 | if ! _ddnss_get_domain; then | |
40 | return 1 | |
41 | fi | |
42 | ||
43 | # Now add the TXT record to DDNSS DNS | |
44 | _info "Trying to add TXT record" | |
45 | if _ddnss_rest GET "key=$DDNSS_Token&host=$_ddnss_domain&txtm=1&txt=$txtvalue"; then | |
46 | if [ "$response" = "Updated 1 hostname." ]; then | |
47 | _info "TXT record has been successfully added to your DDNSS domain." | |
48 | _info "Note that all subdomains under this domain uses the same TXT record." | |
49 | return 0 | |
50 | else | |
51 | _err "Errors happened during adding the TXT record, response=$response" | |
52 | return 1 | |
53 | fi | |
54 | else | |
55 | _err "Errors happened during adding the TXT record." | |
56 | return 1 | |
57 | fi | |
58 | } | |
59 | ||
60 | #Usage: fulldomain txtvalue | |
61 | #Remove the txt record after validation. | |
62 | dns_ddnss_rm() { | |
63 | fulldomain=$1 | |
64 | txtvalue=$2 | |
65 | ||
66 | DDNSS_Token="${DDNSS_Token:-$(_readaccountconf_mutable DDNSS_Token)}" | |
67 | if [ -z "$DDNSS_Token" ]; then | |
68 | _err "You must export variable: DDNSS_Token" | |
69 | _err "The token for your DDNSS account is necessary." | |
70 | _err "You can look it up in your DDNSS account." | |
71 | return 1 | |
72 | fi | |
73 | ||
74 | if ! _ddnss_get_domain; then | |
75 | return 1 | |
76 | fi | |
77 | ||
78 | # Now remove the TXT record from DDNS DNS | |
79 | _info "Trying to remove TXT record" | |
80 | if _ddnss_rest GET "key=$DDNSS_Token&host=$_ddnss_domain&txtm=1&txt=."; then | |
81 | if [ "$response" = "Updated 1 hostname." ]; then | |
82 | _info "TXT record has been successfully removed from your DDNSS domain." | |
83 | return 0 | |
84 | else | |
85 | _err "Errors happened during removing the TXT record, response=$response" | |
86 | return 1 | |
87 | fi | |
88 | else | |
89 | _err "Errors happened during removing the TXT record." | |
90 | return 1 | |
91 | fi | |
92 | } | |
93 | ||
94 | #################### Private functions below ################################## | |
95 | ||
96 | #fulldomain=_acme-challenge.domain.ddnss.de | |
97 | #returns | |
98 | # _ddnss_domain=domain | |
99 | _ddnss_get_domain() { | |
100 | ||
101 | # We'll extract the domain/username from full domain | |
102 | _ddnss_domain="$(echo "$fulldomain" | _lower_case | _egrep_o '[.][^.][^.]*[.](ddnss|dyn-ip24|dyndns|dyn|dyndns1|home-webserver|myhome-server|dynip)\..*' | cut -d . -f 2-)" | |
103 | ||
104 | if [ -z "$_ddnss_domain" ]; then | |
105 | _err "Error extracting the domain." | |
106 | return 1 | |
107 | fi | |
108 | ||
109 | return 0 | |
110 | } | |
111 | ||
112 | #Usage: method URI | |
113 | _ddnss_rest() { | |
114 | method=$1 | |
115 | param="$2" | |
116 | _debug param "$param" | |
117 | url="$DDNSS_DNS_API?$param" | |
118 | _debug url "$url" | |
119 | ||
120 | # DDNSS uses GET to update domain info | |
121 | if [ "$method" = "GET" ]; then | |
1b062ab9 | 122 | response="$(_get "$url" | sed 's/<[a-zA-Z\/][^>]*>//g' | _tail_n 1)" |
d1030eb0 | 123 | else |
124 | _err "Unsupported method" | |
125 | return 1 | |
126 | fi | |
127 | ||
128 | _debug2 response "$response" | |
129 | return 0 | |
130 | } |