]>
Commit | Line | Data |
---|---|---|
4d4b6edb | 1 | #!/usr/bin/env sh |
2 | ||
3 | #use dns-01 at DNSExit.com | |
4 | ||
5 | #Author: Samuel Jimenez | |
6 | #Report Bugs here: https://github.com/acmesh-official/acme.sh | |
7 | ||
8 | #DNSEXIT_API_KEY=ABCDEFGHIJ0123456789abcdefghij | |
9 | #DNSEXIT_AUTH_USER=login@email.address | |
10 | #DNSEXIT_AUTH_PASS=aStrongPassword | |
11 | DNSEXIT_API_URL="https://api.dnsexit.com/dns/" | |
12 | DNSEXIT_HOSTS_URL="https://update.dnsexit.com/ipupdate/hosts.jsp" | |
13 | ||
14 | ######## Public functions ##################### | |
15 | #Usage: dns_dnsexit_add _acme-challenge.*.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" | |
16 | dns_dnsexit_add() { | |
17 | fulldomain=$1 | |
18 | txtvalue=$2 | |
19 | _info "Using DNSExit.com" | |
20 | _debug fulldomain "$fulldomain" | |
21 | _debug txtvalue "$txtvalue" | |
22 | ||
23 | _debug 'Load account auth' | |
24 | if ! get_account_info; then | |
25 | return 1 | |
26 | fi | |
27 | ||
28 | _debug 'First detect the root zone' | |
29 | if ! _get_root "$fulldomain"; then | |
30 | return 1 | |
31 | fi | |
32 | _debug _sub_domain "$_sub_domain" | |
33 | _debug _domain "$_domain" | |
34 | ||
35 | if ! _dnsexit_rest "{\"domain\":\"$_domain\",\"add\":{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"content\":\"$txtvalue\",\"ttl\":0,\"overwrite\":false}}"; then | |
36 | _err "$response" | |
37 | return 1 | |
38 | fi | |
39 | ||
40 | _debug2 _response "$response" | |
41 | return 0 | |
42 | } | |
43 | ||
44 | #Usage: fulldomain txtvalue | |
45 | #Remove the txt record after validation. | |
46 | dns_dnsexit_rm() { | |
47 | fulldomain=$1 | |
48 | txtvalue=$2 | |
49 | _info "Using DNSExit.com" | |
50 | _debug fulldomain "$fulldomain" | |
51 | _debug txtvalue "$txtvalue" | |
52 | ||
53 | _debug 'Load account auth' | |
54 | if ! get_account_info; then | |
55 | return 1 | |
56 | fi | |
57 | ||
58 | _debug 'First detect the root zone' | |
59 | if ! _get_root "$fulldomain"; then | |
60 | _err "$response" | |
61 | return 1 | |
62 | fi | |
63 | _debug _sub_domain "$_sub_domain" | |
64 | _debug _domain "$_domain" | |
65 | ||
66 | if ! _dnsexit_rest "{\"domain\":\"$_domain\",\"delete\":{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"content\":\"$txtvalue\"}}"; then | |
67 | _err "$response" | |
68 | return 1 | |
69 | fi | |
70 | ||
71 | _debug2 _response "$response" | |
72 | return 0 | |
73 | } | |
74 | ||
75 | #################### Private functions below ################################## | |
76 | #_acme-challenge.www.domain.com | |
77 | #returns | |
78 | # _sub_domain=_acme-challenge.www | |
79 | # _domain=domain.com | |
80 | _get_root() { | |
81 | domain=$1 | |
82 | i=1 | |
83 | while true; do | |
84 | _domain=$(printf "%s" "$domain" | cut -d . -f $i-100) | |
85 | _debug h "$_domain" | |
86 | if [ -z "$_domain" ]; then | |
87 | return 1 | |
88 | fi | |
89 | ||
90 | _debug login "$DNSEXIT_AUTH_USER" | |
91 | _debug password "$DNSEXIT_AUTH_PASS" | |
92 | _debug domain "$_domain" | |
93 | ||
94 | _dnsexit_http "login=$DNSEXIT_AUTH_USER&password=$DNSEXIT_AUTH_PASS&domain=$_domain" | |
95 | ||
96 | if _contains "$response" "0=$_domain"; then | |
97 | _sub_domain="$(echo "$fulldomain" | sed "s/\\.$_domain\$//")" | |
98 | return 0 | |
99 | else | |
100 | _debug "Go to next level of $_domain" | |
101 | fi | |
102 | i=$(_math "$i" + 1) | |
103 | done | |
104 | ||
105 | return 1 | |
106 | } | |
107 | ||
108 | _dnsexit_rest() { | |
109 | m=POST | |
110 | ep="" | |
111 | data="$1" | |
112 | _debug _dnsexit_rest "$ep" | |
113 | _debug data "$data" | |
114 | ||
115 | api_key_trimmed=$(echo "$DNSEXIT_API_KEY" | tr -d '"') | |
116 | ||
117 | export _H1="apikey: $api_key_trimmed" | |
118 | export _H2='Content-Type: application/json' | |
119 | ||
120 | if [ "$m" != "GET" ]; then | |
121 | _debug data "$data" | |
122 | response="$(_post "$data" "$DNSEXIT_API_URL/$ep" "" "$m")" | |
123 | else | |
124 | response="$(_get "$DNSEXIT_API_URL/$ep")" | |
125 | fi | |
126 | ||
127 | if [ "$?" != "0" ]; then | |
128 | _err "Error $ep" | |
129 | return 1 | |
130 | fi | |
131 | ||
132 | _debug2 response "$response" | |
133 | return 0 | |
134 | } | |
135 | ||
136 | _dnsexit_http() { | |
137 | m=GET | |
138 | param="$1" | |
139 | _debug param "$param" | |
140 | _debug get "$DNSEXIT_HOSTS_URL?$param" | |
141 | ||
142 | response="$(_get "$DNSEXIT_HOSTS_URL?$param")" | |
143 | ||
144 | _debug response "$response" | |
145 | ||
146 | if [ "$?" != "0" ]; then | |
147 | _err "Error $param" | |
148 | return 1 | |
149 | fi | |
150 | ||
151 | _debug2 response "$response" | |
152 | return 0 | |
153 | } | |
154 | ||
155 | get_account_info() { | |
156 | ||
157 | DNSEXIT_API_KEY="${DNSEXIT_API_KEY:-$(_readaccountconf_mutable DNSEXIT_API_KEY)}" | |
158 | if test -z "$DNSEXIT_API_KEY"; then | |
159 | DNSEXIT_API_KEY='' | |
160 | _err 'DNSEXIT_API_KEY was not exported' | |
161 | return 1 | |
162 | fi | |
163 | ||
164 | _saveaccountconf_mutable DNSEXIT_API_KEY "$DNSEXIT_API_KEY" | |
165 | ||
166 | DNSEXIT_AUTH_USER="${DNSEXIT_AUTH_USER:-$(_readaccountconf_mutable DNSEXIT_AUTH_USER)}" | |
167 | if test -z "$DNSEXIT_AUTH_USER"; then | |
168 | DNSEXIT_AUTH_USER="" | |
169 | _err 'DNSEXIT_AUTH_USER was not exported' | |
170 | return 1 | |
171 | fi | |
172 | ||
173 | _saveaccountconf_mutable DNSEXIT_AUTH_USER "$DNSEXIT_AUTH_USER" | |
174 | ||
175 | DNSEXIT_AUTH_PASS="${DNSEXIT_AUTH_PASS:-$(_readaccountconf_mutable DNSEXIT_AUTH_PASS)}" | |
176 | if test -z "$DNSEXIT_AUTH_PASS"; then | |
177 | DNSEXIT_AUTH_PASS="" | |
178 | _err 'DNSEXIT_AUTH_PASS was not exported' | |
179 | return 1 | |
180 | fi | |
181 | ||
182 | _saveaccountconf_mutable DNSEXIT_AUTH_PASS "$DNSEXIT_AUTH_PASS" | |
183 | ||
184 | return 0 | |
185 | } |