4 # Get API key and secret from https://developer.godaddy.com/
6 # GD_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
7 # GD_Secret="asdfsdfsfsdfsdfdfsdf"
9 # Ex.: acme.sh --issue --staging --dns dns_gd -d "*.s.example.com" -d "s.example.com"
11 GD_Api
="https://api.godaddy.com/v1"
13 ######## Public functions #####################
15 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
20 GD_Key
="${GD_Key:-$(_readaccountconf_mutable GD_Key)}"
21 GD_Secret
="${GD_Secret:-$(_readaccountconf_mutable GD_Secret)}"
22 if [ -z "$GD_Key" ] ||
[ -z "$GD_Secret" ]; then
25 _err
"You don't specify godaddy api key and secret yet."
26 _err
"Please create you key and try again."
30 #save the api key and email to the account conf file.
31 _saveaccountconf_mutable GD_Key
"$GD_Key"
32 _saveaccountconf_mutable GD_Secret
"$GD_Secret"
34 _debug
"First detect the root zone"
35 if ! _get_root
"$fulldomain"; then
40 _debug _sub_domain
"$_sub_domain"
41 _debug _domain
"$_domain"
43 _debug
"Getting existing records"
44 if ! _gd_rest GET
"domains/$_domain/records/TXT/$_sub_domain"; then
48 if _contains
"$response" "$txtvalue"; then
49 _info
"The record is existing, skip"
53 _add_data
="{\"data\":\"$txtvalue\"}"
54 for t
in $
(echo "$response" |
tr '{' "\n" |
grep "\"name\":\"$_sub_domain\"" |
tr ',' "\n" |
grep '"data"' | cut
-d : -f 2); do
56 # ignore empty (previously removed) records, to prevent useless _acme-challenge TXT entries
57 if [ "$t" ] && [ "$t" != '""' ]; then
58 _add_data
="$_add_data,{\"data\":$t}"
61 _debug2 _add_data
"$_add_data"
64 if _gd_rest PUT
"domains/$_domain/records/TXT/$_sub_domain" "[$_add_data]"; then
65 _debug
"Checking updated records of '${fulldomain}'"
67 if ! _gd_rest GET
"domains/$_domain/records/TXT/$_sub_domain"; then
68 _err
"Validating TXT record for '${fulldomain}' with rest error [$?]." "$response"
72 if ! _contains
"$response" "$txtvalue"; then
73 _err
"TXT record '${txtvalue}' for '${fulldomain}', value wasn't set!"
77 _err
"Add txt record error, value '${txtvalue}' for '${fulldomain}' was not set."
82 _info
"Added TXT record '${txtvalue}' for '${fulldomain}'."
91 GD_Key
="${GD_Key:-$(_readaccountconf_mutable GD_Key)}"
92 GD_Secret
="${GD_Secret:-$(_readaccountconf_mutable GD_Secret)}"
94 _debug
"First detect the root zone"
95 if ! _get_root
"$fulldomain"; then
100 _debug _sub_domain
"$_sub_domain"
101 _debug _domain
"$_domain"
103 _debug
"Getting existing records"
104 if ! _gd_rest GET
"domains/$_domain/records/TXT/$_sub_domain"; then
108 if ! _contains
"$response" "$txtvalue"; then
109 _info
"The record does not exist, skip"
114 for t
in $
(echo "$response" |
tr '{' "\n" |
grep "\"name\":\"$_sub_domain\"" |
tr ',' "\n" |
grep '"data"' | cut
-d : -f 2); do
116 if [ "$t" ] && [ "$t" != "\"$txtvalue\"" ]; then
117 if [ "$_add_data" ]; then
118 _add_data
="$_add_data,{\"data\":$t}"
120 _add_data
="{\"data\":$t}"
124 if [ -z "$_add_data" ]; then
125 # delete empty record
126 _debug
"Delete last record for '${fulldomain}'"
127 if ! _gd_rest DELETE
"domains/$_domain/records/TXT/$_sub_domain"; then
128 _err
"Cannot delete empty TXT record for '$fulldomain'"
132 # remove specific TXT value, keeping other entries
133 _debug2 _add_data
"$_add_data"
134 if ! _gd_rest PUT
"domains/$_domain/records/TXT/$_sub_domain" "[$_add_data]"; then
135 _err
"Cannot update TXT record for '$fulldomain'"
141 #################### Private functions below ##################################
142 #_acme-challenge.www.domain.com
144 # _sub_domain=_acme-challenge.www
151 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
157 if ! _gd_rest GET
"domains/$h"; then
161 if _contains
"$response" '"code":"NOT_FOUND"'; then
162 _debug
"$h not found"
164 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
180 export _H1
="Authorization: sso-key $GD_Key:$GD_Secret"
181 export _H2
="Content-Type: application/json"
183 if [ "$data" ] ||
[ "$m" = "DELETE" ]; then
184 _debug
"data ($m): " "$data"
185 response
="$(_post "$data" "$GD_Api/$ep" "" "$m")"
187 response
="$(_get "$GD_Api/$ep")"
190 if [ "$?" != "0" ]; then
191 _err
"error on rest call ($m): $ep"
194 _debug2 response
"$response"
195 if _contains
"$response" "UNABLE_TO_AUTHENTICATE"; then
196 _err
"It seems that your api key or secret is not correct."