4 #UNO_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
8 Uno_Api
="https://api.simply.com/1"
10 ######## Public functions #####################
12 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
17 UNO_Key
="${UNO_Key:-$(_readaccountconf_mutable UNO_Key)}"
18 UNO_User
="${UNO_User:-$(_readaccountconf_mutable UNO_User)}"
19 if [ -z "$UNO_Key" ] ||
[ -z "$UNO_User" ]; then
22 _err
"You haven't specified a UnoEuro api key and account yet."
23 _err
"Please create your key and try again."
27 #save the api key and email to the account conf file.
28 _saveaccountconf_mutable UNO_Key
"$UNO_Key"
29 _saveaccountconf_mutable UNO_User
"$UNO_User"
31 _debug
"First detect the root zone"
32 if ! _get_root
"$fulldomain"; then
36 _debug _domain_id
"$_domain_id"
37 _debug _sub_domain
"$_sub_domain"
38 _debug _domain
"$_domain"
40 _debug
"Getting txt records"
41 _uno_rest GET
"my/products/$h/dns/records"
43 if ! _contains
"$response" "\"status\": 200" >/dev
/null
; then
49 if _uno_rest POST
"my/products/$h/dns/records" "{\"name\":\"$fulldomain\",\"type\":\"TXT\",\"data\":\"$txtvalue\",\"ttl\":120,\"priority\":0}"; then
50 if _contains
"$response" "\"status\": 200" >/dev
/null
; then
54 _err
"Add txt record error."
65 UNO_Key
="${UNO_Key:-$(_readaccountconf_mutable UNO_Key)}"
66 UNO_User
="${UNO_User:-$(_readaccountconf_mutable UNO_User)}"
67 if [ -z "$UNO_Key" ] ||
[ -z "$UNO_User" ]; then
70 _err
"You haven't specified a UnoEuro api key and account yet."
71 _err
"Please create your key and try again."
75 if ! _contains
"$UNO_User" "UE"; then
76 _err
"It seems that the UNO_User=$UNO_User is not a valid username."
77 _err
"Please check and retry."
81 _debug
"First detect the root zone"
82 if ! _get_root
"$fulldomain"; then
86 _debug _domain_id
"$_domain_id"
87 _debug _sub_domain
"$_sub_domain"
88 _debug _domain
"$_domain"
90 _debug
"Getting txt records"
91 _uno_rest GET
"my/products/$h/dns/records"
93 if ! _contains
"$response" "\"status\": 200"; then
98 if ! _contains
"$response" "$_sub_domain"; then
99 _info
"Don't need to remove."
101 for record_line_number
in $
(echo "$response" |
grep -n "$_sub_domain" | cut
-d : -f 1); do
102 record_line_number
=$
(_math
"$record_line_number" - 1)
103 _debug
"record_line_number" "$record_line_number"
104 record_id
=$
(echo "$response" | _head_n
"$record_line_number" | _tail_n
1 1 | _egrep_o
"[0-9]{1,}")
105 _debug
"record_id" "$record_id"
107 if [ -z "$record_id" ]; then
108 _err
"Can not get record id to remove."
112 if ! _uno_rest DELETE
"my/products/$h/dns/records/$record_id"; then
113 _err
"Delete record error."
116 _contains
"$response" "\"status\": 200"
121 #################### Private functions below ##################################
122 #_acme-challenge.www.domain.com
124 # _sub_domain=_acme-challenge.www
126 # _domain_id=sdjkglgdfewsdfg
132 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
139 if ! _uno_rest GET
"my/products/$h/dns/records"; then
143 if _contains
"$response" "\"status\": 200"; then
145 if [ "$_domain_id" ]; then
146 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
164 export _H1
="Content-Type: application/json"
166 if [ "$m" != "GET" ]; then
168 response
="$(_post "$data" "$Uno_Api/$UNO_User/$UNO_Key/$ep" "" "$m")"
170 response
="$(_get "$Uno_Api/$UNO_User/$UNO_Key/$ep")"
173 if [ "$?" != "0" ]; then
177 _debug2 response
"$response"