4 # ULTRA_USR="your_user_goes_here"
6 # ULTRA_PWD="some_password_goes_here"
8 ULTRA_API
="https://api.ultradns.com/v3/"
9 ULTRA_AUTH_API
="https://api.ultradns.com/v2/"
11 #Usage: add _acme-challenge.www.domain.com "some_long_string_of_characters_go_here_from_lets_encrypt"
16 ULTRA_USR
="${ULTRA_USR:-$(_readaccountconf_mutable ULTRA_USR)}"
17 ULTRA_PWD
="${ULTRA_PWD:-$(_readaccountconf_mutable ULTRA_PWD)}"
18 if [ -z "$ULTRA_USR" ] ||
[ -z "$ULTRA_PWD" ]; then
21 _err
"You didn't specify an UltraDNS username and password yet"
24 # save the username and password to the account conf file.
25 _saveaccountconf_mutable ULTRA_USR
"$ULTRA_USR"
26 _saveaccountconf_mutable ULTRA_PWD
"$ULTRA_PWD"
27 _debug
"First detect the root zone"
28 if ! _get_root
"$fulldomain"; then
32 _debug _domain_id
"${_domain_id}"
33 _debug _sub_domain
"${_sub_domain}"
34 _debug _domain
"${_domain}"
35 _debug
"Getting txt records"
36 _ultra_rest GET
"zones/${_domain_id}/rrsets/TXT?q=value:${fulldomain}"
37 if printf "%s" "$response" |
grep \"totalCount
\" >/dev
/null
; then
38 _err
"Error, it would appear that this record already exists. Please review existing TXT records for this domain."
43 if _ultra_rest POST
"zones/$_domain_id/rrsets/TXT/${_sub_domain}" '{"ttl":300,"rdata":["'"${txtvalue}"'"]}'; then
44 if _contains "$response" "Successful
"; then
47 elif _contains "$response" "Resource Record of
type 16 with these attributes already exists
"; then
48 _info "Already exists
, OK
"
51 _err "Add txt record error.
"
55 _err "Add txt record error.
"
63 ULTRA_USR="${ULTRA_USR:-$(_readaccountconf_mutable ULTRA_USR)}"
64 ULTRA_PWD="${ULTRA_PWD:-$(_readaccountconf_mutable ULTRA_PWD)}"
65 if [ -z "$ULTRA_USR" ] || [ -z "$ULTRA_PWD" ]; then
68 _err "You didn
't specify an UltraDNS username and password yet"
72 _debug "First detect the root zone"
73 if ! _get_root "$fulldomain"; then
77 _debug _domain_id "${_domain_id}"
78 _debug _sub_domain "${_sub_domain}"
79 _debug _domain "${domain}"
81 _debug "Getting TXT records"
82 _ultra_rest GET "zones/${_domain_id}/rrsets?q=kind:RECORDS+owner:${_sub_domain}"
84 if ! printf "%s" "$response" | grep \"resultInfo\" >/dev/null; then
85 _err "There was an error in obtaining the resource records for ${_domain_id}"
89 count=$(echo "$response" | _egrep_o "\"returnedCount\":[^,]*" | cut -d: -f2 | cut -d'}' -f1)
90 _debug count "${count}"
91 if [ "${count}" = "" ]; then
92 _info "Text record is not present, will not delete anything."
94 if ! _ultra_rest DELETE "zones/$_domain_id/rrsets/TXT/${_sub_domain}" '{"ttl":300,"rdata":["'"${txtvalue}"'"]}'; then
95 _err
"Deleting the record did not succeed, please verify/check."
98 _contains
"$response" ""
103 #################### Private functions below ##################################
104 #_acme-challenge.www.domain.com
106 # _sub_domain=_acme-challenge.www
108 # _domain_id=sdjkglgdfewsdfg
114 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
116 _debug response
"$response"
121 if ! _ultra_rest GET
"zones"; then
124 if _contains
"${response}" "${h}." >/dev
/null
; then
125 _domain_id
=$
(echo "$response" | _egrep_o
"${h}" |
head -1)
126 if [ "$_domain_id" ]; then
127 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
129 _debug sub_domain
"${_sub_domain}"
130 _debug domain
"${_domain}"
146 if [ -z "$AUTH_TOKEN" ]; then
149 _debug TOKEN
"$AUTH_TOKEN"
151 export _H1
="Content-Type: application/json"
152 export _H2
="Authorization: Bearer $AUTH_TOKEN"
154 if [ "$m" != "GET" ]; then
156 response
="$(_post "$data" "$ULTRA_API$ep" "" "$m")"
158 response
="$(_get "$ULTRA_API$ep")"
165 AUTH_TOKEN
=$
(_post
"grant_type=password&username=${ULTRA_USR}&password=${ULTRA_PWD}" "${ULTRA_AUTH_API}authorization/token" | cut
-d, -f3 | cut
-d\" -f4)