]> git.proxmox.com Git - mirror_acme.sh.git/blame - dnsapi/dns_gd.sh
bugfix
[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
30de13b4 19 _err "You don't specify godaddy api key and secret yet."
20 _err "Please create you key and try again."
21 return 1
22 fi
4c2a3841 23
30de13b4 24 #save the api key and email to the account conf file.
25 _saveaccountconf GD_Key "$GD_Key"
26 _saveaccountconf GD_Secret "$GD_Secret"
4c2a3841 27
30de13b4 28 _debug "First detect the root zone"
4c2a3841 29 if ! _get_root $fulldomain; then
30de13b4 30 _err "invalid domain"
31 return 1
32 fi
33 _debug _domain_id "$_domain_id"
34 _debug _sub_domain "$_sub_domain"
35 _debug _domain "$_domain"
30de13b4 36
37 _info "Adding record"
4c2a3841 38 if _gd_rest PUT "domains/$_domain/records/TXT/$_sub_domain" "[{\"data\":\"$txtvalue\"}]"; then
39 if [ "$response" = "{}" ]; then
30de13b4 40 _info "Added, sleeping 10 seconds"
41 sleep 10
42 #todo: check if the record takes effect
43 return 0
44 else
45 _err "Add txt record error."
46 _err "$response"
47 return 1
48 fi
49 fi
50 _err "Add txt record error."
30de13b4 51
4c2a3841 52}
30de13b4 53
5d6fd809 54#fulldomain
55dns_gd_rm() {
56 fulldomain=$1
57
58}
59
30de13b4 60#################### Private functions bellow ##################################
61#_acme-challenge.www.domain.com
62#returns
63# _sub_domain=_acme-challenge.www
64# _domain=domain.com
65# _domain_id=sdjkglgdfewsdfg
66_get_root() {
67 domain=$1
68 i=2
69 p=1
4c2a3841 70 while [ '1' ]; do
30de13b4 71 h=$(printf $domain | cut -d . -f $i-100)
4c2a3841 72 if [ -z "$h" ]; then
30de13b4 73 #not valid
4c2a3841 74 return 1
30de13b4 75 fi
4c2a3841 76
77 if ! _gd_rest GET "domains/$h"; then
30de13b4 78 return 1
79 fi
4c2a3841 80
81 if printf "$response" | grep '"code":"NOT_FOUND"' >/dev/null; then
30de13b4 82 _debug "$h not found"
83 else
84 _sub_domain=$(printf $domain | cut -d . -f 1-$p)
85 _domain=$h
86 return 0
87 fi
88 p=$i
89 i=$(expr $i + 1)
90 done
91 return 1
92}
93
94_gd_rest() {
95 m=$1
96 ep="$2"
97 data="$3"
98 _debug $ep
4c2a3841 99
30de13b4 100 _H1="Authorization: sso-key $GD_Key:$GD_Secret"
101 _H2="Content-Type: application/json"
4c2a3841 102
103 if [ "$data" ]; then
30de13b4 104 _debug data "$data"
105 response="$(_post "$data" "$GD_Api/$ep" "" $m)"
106 else
107 response="$(_get "$GD_Api/$ep")"
108 fi
4c2a3841 109
110 if [ "$?" != "0" ]; then
30de13b4 111 _err "error $ep"
112 return 1
113 fi
114 _debug2 response "$response"
115 return 0
116}