4 #VULTR_API_KEY=000011112222333344445555666677778888
6 VULTR_Api
="https://api.vultr.com/v1"
8 ######## Public functions #####################
10 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
14 _debug fulldomain
"$fulldomain"
15 _debug txtvalue
"$txtvalue"
17 VULTR_API_KEY
="${VULTR_API_KEY:-$(_readaccountconf_mutable VULTR_API_KEY)}"
18 if test -z "$VULTR_API_KEY"; then
20 _err
'VULTR_API_KEY was not exported'
24 _saveaccountconf_mutable VULTR_API_KEY
"$VULTR_API_KEY"
26 _debug
'First detect the root zone'
27 if ! _get_root
"$fulldomain"; then
30 _debug _sub_domain
"$_sub_domain"
31 _debug _domain
"$_domain"
33 _debug
'Getting txt records'
34 _vultr_rest GET
"dns/records?domain=$_domain"
36 if printf "%s\n" "$response" |
grep -- "\"type\":\"TXT\",\"name\":\"$fulldomain\"" >/dev
/null
; then
41 if ! _vultr_rest POST
'dns/create_record' "domain=$_domain&name=$_sub_domain&data=\"$txtvalue\"&type=TXT"; then
46 _debug2 _response
"$response"
54 _debug fulldomain
"$fulldomain"
55 _debug txtvalue
"$txtvalue"
57 VULTR_API_KEY
="${VULTR_API_KEY:-$(_readaccountconf_mutable VULTR_API_KEY)}"
58 if test -z "$VULTR_API_KEY"; then
60 _err
'VULTR_API_KEY was not exported'
64 _saveaccountconf_mutable VULTR_API_KEY
"$VULTR_API_KEY"
66 _debug
'First detect the root zone'
67 if ! _get_root
"$fulldomain"; then
70 _debug _sub_domain
"$_sub_domain"
71 _debug _domain
"$_domain"
73 _debug
'Getting txt records'
74 _vultr_rest GET
"dns/records?domain=$_domain"
76 if printf "%s\n" "$response" |
grep -- "\"type\":\"TXT\",\"name\":\"$fulldomain\"" >/dev
/null
; then
81 _record_id
="$(echo "$response" | tr '{}' '\n' | grep '"TXT
"' | grep -- "$txtvalue" | tr ',' '\n' | grep -i 'RECORDID' | cut -d : -f 2)"
82 _debug _record_id
"$_record_id"
83 if [ "$_record_id" ]; then
84 _info
"Successfully retrieved the record id for ACME challenge."
86 _info
"Empty record id, it seems no such record."
90 if ! _vultr_rest POST
'dns/delete_record' "domain=$_domain&RECORDID=$_record_id"; then
95 _debug2 _response
"$response"
99 #################### Private functions below ##################################
100 #_acme-challenge.www.domain.com
102 # _sub_domain=_acme-challenge.www
104 # _domain_id=sdjkglgdfewsdfg
109 _domain
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
111 if [ -z "$_domain" ]; then
115 if ! _vultr_rest GET
"dns/list"; then
119 if printf "%s\n" "$response" |
grep '^\[.*\]' >/dev
/null
; then
120 if _contains
"$response" "\"domain\":\"$_domain\""; then
121 _sub_domain
="$(echo "$fulldomain" | sed "s
/\\.
$_domain\$
//")"
124 _debug
"Go to next level of $_domain"
142 api_key_trimmed
=$
(echo $VULTR_API_KEY |
tr -d '"')
144 export _H1
="Api-Key: $api_key_trimmed"
145 export _H2
='Content-Type: application/x-www-form-urlencoded'
147 if [ "$m" != "GET" ]; then
149 response
="$(_post "$data" "$VULTR_Api/$ep" "" "$m")"
151 response
="$(_get "$VULTR_Api/$ep")"
154 if [ "$?" != "0" ]; then
159 _debug2 response
"$response"