]> git.proxmox.com Git - mirror_acme.sh.git/blame - dnsapi/dns_unoeuro.sh
Merge pull request #3734 from acmesh-official/dev
[mirror_acme.sh.git] / dnsapi / dns_unoeuro.sh
CommitLineData
0ca31410
A
1#!/usr/bin/env sh
2
3#
f9b8d7a9 4#UNO_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
0ca31410 5#
f9b8d7a9 6#UNO_User="UExxxxxx"
0ca31410 7
cdf8f789 8Uno_Api="https://api.simply.com/1"
0ca31410
A
9
10######## Public functions #####################
11
12#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
13dns_unoeuro_add() {
14 fulldomain=$1
15 txtvalue=$2
16
f9b8d7a9
A
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
20 UNO_Key=""
21 UNO_User=""
0ca31410
A
22 _err "You haven't specified a UnoEuro api key and account yet."
23 _err "Please create your key and try again."
24 return 1
25 fi
26
0ca31410 27 #save the api key and email to the account conf file.
f9b8d7a9
A
28 _saveaccountconf_mutable UNO_Key "$UNO_Key"
29 _saveaccountconf_mutable UNO_User "$UNO_User"
0ca31410
A
30
31 _debug "First detect the root zone"
32 if ! _get_root "$fulldomain"; then
33 _err "invalid domain"
34 return 1
35 fi
36 _debug _domain_id "$_domain_id"
37 _debug _sub_domain "$_sub_domain"
38 _debug _domain "$_domain"
39
40 _debug "Getting txt records"
41 _uno_rest GET "my/products/$h/dns/records"
42
43 if ! _contains "$response" "\"status\": 200" >/dev/null; then
44 _err "Error"
45 return 1
46 fi
81135489 47 _info "Adding record"
0ca31410 48
0ffd5de6 49 if _uno_rest POST "my/products/$h/dns/records" "{\"name\":\"$fulldomain\",\"type\":\"TXT\",\"data\":\"$txtvalue\",\"ttl\":120,\"priority\":0}"; then
0ca31410 50 if _contains "$response" "\"status\": 200" >/dev/null; then
81135489 51 _info "Added, OK"
0ca31410 52 return 0
81135489
A
53 else
54 _err "Add txt record error."
55 return 1
0ca31410 56 fi
0ca31410 57 fi
0ca31410
A
58}
59
60#fulldomain txtvalue
61dns_unoeuro_rm() {
62 fulldomain=$1
63 txtvalue=$2
64
f9b8d7a9
A
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
68 UNO_Key=""
69 UNO_User=""
0ca31410
A
70 _err "You haven't specified a UnoEuro api key and account yet."
71 _err "Please create your key and try again."
72 return 1
73 fi
74
f9b8d7a9
A
75 if ! _contains "$UNO_User" "UE"; then
76 _err "It seems that the UNO_User=$UNO_User is not a valid username."
4a9f607d
J
77 _err "Please check and retry."
78 return 1
79 fi
80
0ca31410
A
81 _debug "First detect the root zone"
82 if ! _get_root "$fulldomain"; then
83 _err "invalid domain"
84 return 1
85 fi
86 _debug _domain_id "$_domain_id"
87 _debug _sub_domain "$_sub_domain"
88 _debug _domain "$_domain"
89
90 _debug "Getting txt records"
91 _uno_rest GET "my/products/$h/dns/records"
92
f763e1ed 93 if ! _contains "$response" "\"status\": 200"; then
0ca31410
A
94 _err "Error"
95 return 1
96 fi
97
f763e1ed 98 if ! _contains "$response" "$_sub_domain"; then
0ca31410
A
99 _info "Don't need to remove."
100 else
81135489
A
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"
106
107 if [ -z "$record_id" ]; then
108 _err "Can not get record id to remove."
109 return 1
110 fi
0ca31410 111
81135489
A
112 if ! _uno_rest DELETE "my/products/$h/dns/records/$record_id"; then
113 _err "Delete record error."
114 return 1
115 fi
116 _contains "$response" "\"status\": 200"
8b6986ba 117 done
0ca31410 118 fi
0ca31410
A
119}
120
121#################### Private functions below ##################################
122#_acme-challenge.www.domain.com
123#returns
124# _sub_domain=_acme-challenge.www
125# _domain=domain.com
126# _domain_id=sdjkglgdfewsdfg
127_get_root() {
128 domain=$1
129 i=2
130 p=1
131 while true; do
132 h=$(printf "%s" "$domain" | cut -d . -f $i-100)
133 _debug h "$h"
134 if [ -z "$h" ]; then
135 #not valid
136 return 1
137 fi
138
139 if ! _uno_rest GET "my/products/$h/dns/records"; then
140 return 1
141 fi
142
f763e1ed 143 if _contains "$response" "\"status\": 200"; then
0ca31410
A
144 _domain_id=$h
145 if [ "$_domain_id" ]; then
146 _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
147 _domain=$h
148 return 0
149 fi
150 return 1
151 fi
152 p=$i
153 i=$(_math "$i" + 1)
154 done
155 return 1
156}
157
158_uno_rest() {
159 m=$1
160 ep="$2"
161 data="$3"
162 _debug "$ep"
163
0ca31410
A
164 export _H1="Content-Type: application/json"
165
166 if [ "$m" != "GET" ]; then
167 _debug data "$data"
f9b8d7a9 168 response="$(_post "$data" "$Uno_Api/$UNO_User/$UNO_Key/$ep" "" "$m")"
0ca31410 169 else
f9b8d7a9 170 response="$(_get "$Uno_Api/$UNO_User/$UNO_Key/$ep")"
0ca31410
A
171 fi
172
173 if [ "$?" != "0" ]; then
174 _err "error $ep"
175 return 1
176 fi
177 _debug2 response "$response"
178 return 0
179}