4 #UNO_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
8 Uno_Api
="https://api.unoeuro.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 if ! _contains
"$UNO_User" "UE"; then
28 _err
"It seems that the UNO_User=$UNO_User is not a valid username."
29 _err
"Please check and retry."
33 #save the api key and email to the account conf file.
34 _saveaccountconf_mutable UNO_Key
"$UNO_Key"
35 _saveaccountconf_mutable UNO_User
"$UNO_User"
37 _debug
"First detect the root zone"
38 if ! _get_root
"$fulldomain"; then
42 _debug _domain_id
"$_domain_id"
43 _debug _sub_domain
"$_sub_domain"
44 _debug _domain
"$_domain"
46 _debug
"Getting txt records"
47 _uno_rest GET
"my/products/$h/dns/records"
49 if ! _contains
"$response" "\"status\": 200" >/dev
/null
; then
55 if _uno_rest POST
"my/products/$h/dns/records" "{\"name\":\"$fulldomain\",\"type\":\"TXT\",\"data\":\"$txtvalue\",\"ttl\":120}"; then
56 if _contains
"$response" "\"status\": 200" >/dev
/null
; then
60 _err
"Add txt record error."
71 UNO_Key
="${UNO_Key:-$(_readaccountconf_mutable UNO_Key)}"
72 UNO_User
="${UNO_User:-$(_readaccountconf_mutable UNO_User)}"
73 if [ -z "$UNO_Key" ] ||
[ -z "$UNO_User" ]; then
76 _err
"You haven't specified a UnoEuro api key and account yet."
77 _err
"Please create your key and try again."
81 if ! _contains
"$UNO_User" "UE"; then
82 _err
"It seems that the UNO_User=$UNO_User is not a valid username."
83 _err
"Please check and retry."
87 _debug
"First detect the root zone"
88 if ! _get_root
"$fulldomain"; then
92 _debug _domain_id
"$_domain_id"
93 _debug _sub_domain
"$_sub_domain"
94 _debug _domain
"$_domain"
96 _debug
"Getting txt records"
97 _uno_rest GET
"my/products/$h/dns/records"
99 if ! _contains
"$response" "\"status\": 200"; then
104 if ! _contains
"$response" "$_sub_domain"; then
105 _info
"Don't need to remove."
107 for record_line_number
in $
(echo "$response" |
grep -n "$_sub_domain" | cut
-d : -f 1); do
108 record_line_number
=$
(_math
"$record_line_number" - 1)
109 _debug
"record_line_number" "$record_line_number"
110 record_id
=$
(echo "$response" | _head_n
"$record_line_number" | _tail_n
1 1 | _egrep_o
"[0-9]{1,}")
111 _debug
"record_id" "$record_id"
113 if [ -z "$record_id" ]; then
114 _err
"Can not get record id to remove."
118 if ! _uno_rest DELETE
"my/products/$h/dns/records/$record_id"; then
119 _err
"Delete record error."
122 _contains
"$response" "\"status\": 200"
127 #################### Private functions below ##################################
128 #_acme-challenge.www.domain.com
130 # _sub_domain=_acme-challenge.www
132 # _domain_id=sdjkglgdfewsdfg
138 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
145 if ! _uno_rest GET
"my/products/$h/dns/records"; then
149 if _contains
"$response" "\"status\": 200"; then
151 if [ "$_domain_id" ]; then
152 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
170 export _H1
="Content-Type: application/json"
172 if [ "$m" != "GET" ]; then
174 response
="$(_post "$data" "$Uno_Api/$UNO_User/$UNO_Key/$ep" "" "$m")"
176 response
="$(_get "$Uno_Api/$UNO_User/$UNO_Key/$ep")"
179 if [ "$?" != "0" ]; then
183 _debug2 response
"$response"