4 # ULTRA_USR="your_user_goes_here"
6 # ULTRA_PWD="some_password_goes_here"
8 ULTRA_API
="https://restapi.ultradns.com/v2/"
10 #Usage: add _acme-challenge.www.domain.com "some_long_string_of_characters_go_here_from_lets_encrypt"
15 ULTRA_USR
="${ULTRA_USR:-$(_readaccountconf_mutable ULTRA_USR)}"
16 ULTRA_PWD
="${ULTRA_PWD:-$(_readaccountconf_mutable ULTRA_PWD)}"
17 if [ -z "$ULTRA_USR" ] ||
[ -z "$ULTRA_PWD" ]; then
20 _err
"You didn't specify an UltraDNS username and password yet"
23 # save the username and password to the account conf file.
24 _saveaccountconf_mutable ULTRA_USR
"$ULTRA_USR"
25 _saveaccountconf_mutable ULTRA_PWD
"$ULTRA_PWD"
26 _debug
"First detect the root zone"
27 if ! _get_root
"$fulldomain"; then
31 _debug _domain_id
"${_domain_id}"
32 _debug _sub_domain
"${_sub_domain}"
33 _debug _domain
"${_domain}"
34 _debug
"Getting txt records"
35 _ultra_rest GET
"zones/${_domain_id}/rrsets/TXT?q=value:${fulldomain}"
36 if printf "%s" "$response" |
grep \"totalCount
\" >/dev
/null
; then
37 _err
"Error, it would appear that this record already exists. Please review existing TXT records for this domain."
42 if _ultra_rest POST
"zones/$_domain_id/rrsets/TXT/${_sub_domain}" '{"ttl":300,"rdata":["'"${txtvalue}"'"]}'; then
43 if _contains "$response" "Successful
"; then
46 elif _contains "$response" "Resource Record of
type 16 with these attributes already exists
"; then
47 _info "Already exists
, OK
"
50 _err "Add txt record error.
"
54 _err "Add txt record error.
"
62 ULTRA_USR="${ULTRA_USR:-$(_readaccountconf_mutable ULTRA_USR)}"
63 ULTRA_PWD="${ULTRA_PWD:-$(_readaccountconf_mutable ULTRA_PWD)}"
64 if [ -z "$ULTRA_USR" ] || [ -z "$ULTRA_PWD" ]; then
67 _err "You didn
't specify an UltraDNS username and password yet"
71 _debug "First detect the root zone"
72 if ! _get_root "$fulldomain"; then
76 _debug _domain_id "${_domain_id}"
77 _debug _sub_domain "${_sub_domain}"
78 _debug _domain "${domain}"
80 _debug "Getting TXT records"
81 _ultra_rest GET "zones/${_domain_id}/rrsets?q=kind:RECORDS+owner:${_sub_domain}"
83 if ! printf "%s" "$response" | grep \"resultInfo\" >/dev/null; then
84 _err "There was an error in obtaining the resource records for ${_domain_id}"
88 count=$(echo "$response" | _egrep_o "\"returnedCount\":[^,]*" | cut -d: -f2 | cut -d'}' -f1)
89 _debug count "${count}"
90 if [ "${count}" = "" ]; then
91 _info "Text record is not present, will not delete anything."
93 if ! _ultra_rest DELETE "zones/$_domain_id/rrsets/TXT/${_sub_domain}" '{"ttl":300,"rdata":["'"${txtvalue}"'"]}'; then
94 _err
"Deleting the record did not succeed, please verify/check."
97 _contains
"$response" ""
102 #################### Private functions below ##################################
103 #_acme-challenge.www.domain.com
105 # _sub_domain=_acme-challenge.www
107 # _domain_id=sdjkglgdfewsdfg
113 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
115 _debug response
"$response"
120 if ! _ultra_rest GET
"zones"; then
123 if _contains
"${response}" "${h}." >/dev
/null
; then
124 _domain_id
=$
(echo "$response" | _egrep_o
"${h}")
125 if [ "$_domain_id" ]; then
126 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
128 _debug sub_domain
"${_sub_domain}"
129 _debug domain
"${_domain}"
145 _debug TOKEN
"${AUTH_TOKEN}"
148 export _H1
="Content-Type: application/json"
149 export _H2
="Authorization: Bearer ${AUTH_TOKEN}"
151 if [ "$m" != "GET" ]; then
152 _debug data
"${data}"
153 response
="$(_post "${data}" "${ULTRA_API}"/"${ep}" "" "${m}")"
155 response
="$(_get "$ULTRA_API/$ep")"
162 AUTH_TOKEN
=$
(_post
"grant_type=password&username=${ULTRA_USR}&password=${ULTRA_PWD}" "${ULTRA_API}authorization/token" | cut
-d, -f3 | cut
-d\" -f4)