]> git.proxmox.com Git - mirror_acme.sh.git/blame - dnsapi/dns_gd.sh
fix dp
[mirror_acme.sh.git] / dnsapi / dns_gd.sh
CommitLineData
30de13b4 1#!/usr/bin/env sh
2
3#Godaddy domain api
4#
5#GD_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
6#
7#GD_Secret="asdfsdfsfsdfsdfdfsdf"
8
30de13b4 9GD_Api="https://api.godaddy.com/v1"
10
11######## Public functions #####################
12
13#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
4c2a3841 14dns_gd_add() {
30de13b4 15 fulldomain=$1
16 txtvalue=$2
4c2a3841 17
18 if [ -z "$GD_Key" ] || [ -z "$GD_Secret" ]; then
422e5026 19 GD_Key=""
20 GD_Secret=""
30de13b4 21 _err "You don't specify godaddy api key and secret yet."
22 _err "Please create you key and try again."
23 return 1
24 fi
4c2a3841 25
30de13b4 26 #save the api key and email to the account conf file.
27 _saveaccountconf GD_Key "$GD_Key"
28 _saveaccountconf GD_Secret "$GD_Secret"
4c2a3841 29
30de13b4 30 _debug "First detect the root zone"
c7b16249 31 if ! _get_root "$fulldomain"; then
30de13b4 32 _err "invalid domain"
33 return 1
34 fi
e440223b 35
30de13b4 36 _debug _sub_domain "$_sub_domain"
37 _debug _domain "$_domain"
30de13b4 38
39 _info "Adding record"
4c2a3841 40 if _gd_rest PUT "domains/$_domain/records/TXT/$_sub_domain" "[{\"data\":\"$txtvalue\"}]"; then
41 if [ "$response" = "{}" ]; then
30de13b4 42 _info "Added, sleeping 10 seconds"
db504629 43 _sleep 10
30de13b4 44 #todo: check if the record takes effect
45 return 0
46 else
47 _err "Add txt record error."
48 _err "$response"
49 return 1
50 fi
51 fi
52 _err "Add txt record error."
30de13b4 53
4c2a3841 54}
30de13b4 55
5d6fd809 56#fulldomain
57dns_gd_rm() {
58 fulldomain=$1
59
60}
61
329174b6 62#################### Private functions below ##################################
30de13b4 63#_acme-challenge.www.domain.com
64#returns
65# _sub_domain=_acme-challenge.www
66# _domain=domain.com
30de13b4 67_get_root() {
68 domain=$1
69 i=2
70 p=1
c7b16249 71 while true; do
72 h=$(printf "%s" "$domain" | cut -d . -f $i-100)
4c2a3841 73 if [ -z "$h" ]; then
30de13b4 74 #not valid
4c2a3841 75 return 1
30de13b4 76 fi
4c2a3841 77
78 if ! _gd_rest GET "domains/$h"; then
30de13b4 79 return 1
80 fi
4c2a3841 81
c7b16249 82 if _contains "$response" '"code":"NOT_FOUND"'; then
30de13b4 83 _debug "$h not found"
84 else
c7b16249 85 _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
86 _domain="$h"
30de13b4 87 return 0
88 fi
e9f9f515 89 p="$i"
90 i=$(_math "$i" + 1)
30de13b4 91 done
92 return 1
93}
94
95_gd_rest() {
96 m=$1
97 ep="$2"
98 data="$3"
c7b16249 99 _debug "$ep"
4c2a3841 100
3ca93f4a
BB
101 export _H1="Authorization: sso-key $GD_Key:$GD_Secret"
102 export _H2="Content-Type: application/json"
4c2a3841 103
104 if [ "$data" ]; then
30de13b4 105 _debug data "$data"
69925ce8 106 response="$(_post "$data" "$GD_Api/$ep" "" "$m")"
30de13b4 107 else
108 response="$(_get "$GD_Api/$ep")"
109 fi
4c2a3841 110
111 if [ "$?" != "0" ]; then
30de13b4 112 _err "error $ep"
113 return 1
114 fi
115 _debug2 response "$response"
116 return 0
117}