5 #GD_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
7 #GD_Secret="asdfsdfsfsdfsdfdfsdf"
9 GD_Api
="https://api.godaddy.com/v1"
11 ######## Public functions #####################
13 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
18 GD_Key
="${GD_Key:-$(_readaccountconf_mutable GD_Key)}"
19 GD_Secret
="${GD_Secret:-$(_readaccountconf_mutable GD_Secret)}"
20 if [ -z "$GD_Key" ] ||
[ -z "$GD_Secret" ]; then
23 _err
"You don't specify godaddy api key and secret yet."
24 _err
"Please create you key and try again."
28 #save the api key and email to the account conf file.
29 _saveaccountconf_mutable GD_Key
"$GD_Key"
30 _saveaccountconf_mutable GD_Secret
"$GD_Secret"
32 _debug
"First detect the root zone"
33 if ! _get_root
"$fulldomain"; then
38 _debug _sub_domain
"$_sub_domain"
39 _debug _domain
"$_domain"
41 _debug
"Getting existing records"
42 if ! _gd_rest GET
"domains/$_domain/records/TXT/$_sub_domain"; then
46 if _contains
"$response" "$txtvalue"; then
47 _info
"The record is existing, skip"
51 _add_data
="{\"data\":\"$txtvalue\"}"
52 for t
in $
(echo "$response" |
tr '{' "\n" |
grep "\"name\":\"$_sub_domain\"" |
tr ',' "\n" |
grep '"data"' | cut
-d : -f 2); do
55 _add_data
="$_add_data,{\"data\":$t}"
58 _debug2 _add_data
"$_add_data"
61 if _gd_rest PUT
"domains/$_domain/records/TXT/$_sub_domain" "[$_add_data]"; then
62 _info
"Added, sleeping 10 seconds"
64 #todo: check if the record takes effect
67 _err
"Add txt record error."
76 GD_Key
="${GD_Key:-$(_readaccountconf_mutable GD_Key)}"
77 GD_Secret
="${GD_Secret:-$(_readaccountconf_mutable GD_Secret)}"
79 _debug
"First detect the root zone"
80 if ! _get_root
"$fulldomain"; then
85 _debug _sub_domain
"$_sub_domain"
86 _debug _domain
"$_domain"
88 _debug
"Getting existing records"
89 if ! _gd_rest GET
"domains/$_domain/records/TXT/$_sub_domain"; then
93 if ! _contains
"$response" "$txtvalue"; then
94 _info
"The record is not existing, skip"
99 for t
in $
(echo "$response" |
tr '{' "\n" |
grep "\"name\":\"$_sub_domain\"" |
tr ',' "\n" |
grep '"data"' | cut
-d : -f 2); do
101 if [ "$t" ] && [ "$t" != "\"$txtvalue\"" ]; then
102 if [ "$_add_data" ]; then
103 _add_data
="$_add_data,{\"data\":$t}"
105 _add_data
="{\"data\":$t}"
109 if [ -z "$_add_data" ]; then
110 _add_data
="{\"data\":\"\"}"
112 _debug2 _add_data
"$_add_data"
114 _gd_rest PUT
"domains/$_domain/records/TXT/$_sub_domain" "[$_add_data]"
117 #################### Private functions below ##################################
118 #_acme-challenge.www.domain.com
120 # _sub_domain=_acme-challenge.www
127 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
133 if ! _gd_rest GET
"domains/$h"; then
137 if _contains
"$response" '"code":"NOT_FOUND"'; then
138 _debug
"$h not found"
140 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
156 export _H1
="Authorization: sso-key $GD_Key:$GD_Secret"
157 export _H2
="Content-Type: application/json"
161 response
="$(_post "$data" "$GD_Api/$ep" "" "$m")"
163 response
="$(_get "$GD_Api/$ep")"
166 if [ "$?" != "0" ]; then
170 _debug2 response
"$response"
171 if _contains
"$response" "UNABLE_TO_AUTHENTICATE"; then
172 _err
"It seems that your api key or secret is not correct."