3 #This is the euserv.eu api wrapper for acme.sh
5 #Author: Michael Brueckner
6 #Report Bugs: https://www.github.com/initit/acme.sh or mbr@initit.de
9 #EUSERV_Username="username"
11 #EUSERV_Password="password"
17 EUSERV_Api
="https://api.euserv.net"
19 ######## Public functions #####################
21 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
23 fulldomain
="$(echo "$1" | _lower_case)"
26 EUSERV_Username
="${EUSERV_Username:-$(_readaccountconf_mutable EUSERV_Username)}"
27 EUSERV_Password
="${EUSERV_Password:-$(_readaccountconf_mutable EUSERV_Password)}"
28 if [ -z "$EUSERV_Username" ] ||
[ -z "$EUSERV_Password" ]; then
31 _err
"You don't specify euserv user and password yet."
32 _err
"Please create your key and try again."
36 #save the user and email to the account conf file.
37 _saveaccountconf_mutable EUSERV_Username
"$EUSERV_Username"
38 _saveaccountconf_mutable EUSERV_Password
"$EUSERV_Password"
40 _debug
"First detect the root zone"
41 if ! _get_root
"$fulldomain"; then
45 _debug
"_sub_domain" "$_sub_domain"
46 _debug
"_domain" "$_domain"
48 if ! _euserv_add_record
"$_domain" "$_sub_domain" "$txtvalue"; then
57 fulldomain
="$(echo "$1" | _lower_case)"
60 EUSERV_Username
="${EUSERV_Username:-$(_readaccountconf_mutable EUSERV_Username)}"
61 EUSERV_Password
="${EUSERV_Password:-$(_readaccountconf_mutable EUSERV_Password)}"
62 if [ -z "$EUSERV_Username" ] ||
[ -z "$EUSERV_Password" ]; then
65 _err
"You don't specify euserv user and password yet."
66 _err
"Please create your key and try again."
70 #save the user and email to the account conf file.
71 _saveaccountconf_mutable EUSERV_Username
"$EUSERV_Username"
72 _saveaccountconf_mutable EUSERV_Password
"$EUSERV_Password"
74 _debug
"First detect the root zone"
75 if ! _get_root
"$fulldomain"; then
79 _debug
"_sub_domain" "$_sub_domain"
80 _debug
"_domain" "$_domain"
82 _debug
"Getting txt records"
84 xml_content
=$
(printf '<?xml version="1.0" encoding="UTF-8"?>
86 <methodName>domain.dns_get_active_records</methodName>
104 <name>domain_id</name>
113 </methodCall>' "$EUSERV_Username" "$EUSERV_Password" "$_euserv_domain_id")
115 export _H1
="Content-Type: text/xml"
116 response
="$(_post "$xml_content" "$EUSERV_Api" "" "POST
")"
118 if ! _contains
"$response" "<member><name>status</name><value><i4>100</i4></value></member>"; then
119 _err
"Error could not get txt records"
120 _debug
"xml_content" "$xml_content"
121 _debug
"response" "$response"
125 if ! echo "$response" |
grep '>dns_record_content<.*>'"$txtvalue"'<' >/dev
/null
; then
126 _info
"Do not need to delete record"
128 # find XML block where txtvalue is in. The record_id is allways prior this line!
129 _endLine
=$
(echo "$response" |
grep -n '>dns_record_content<.*>'"$txtvalue"'<' | cut
-d ':' -f 1)
130 # record_id is the last <name> Tag with a number before the row _endLine, identified by </name><value><struct>
131 _record_id
=$
(echo "$response" |
sed -n '1,'"$_endLine"'p' |
grep '</name><value><struct>' | _tail_n
1 |
sed 's/.*<name>\([0-9]*\)<\/name>.*/\1/')
132 _info
"Deleting record"
133 _euserv_delete_record
"$_record_id"
138 #################### Private functions below ##################################
144 # Just to read the domain_orders once
150 if ! _euserv_get_domain_orders
; then
154 # Get saved response with domain_orders
155 response
="$_euserv_domain_orders"
158 h
=$
(echo "$domain" | cut
-d .
-f $i-100)
165 if _contains
"$response" "$h"; then
166 _sub_domain
=$
(echo "$domain" | cut
-d .
-f 1-$p)
168 if ! _euserv_get_domain_id
"$_domain"; then
169 _err
"invalid domain"
181 _euserv_get_domain_orders
() {
182 # returns: _euserv_domain_orders
184 _debug
"get domain_orders"
186 xml_content
=$
(printf '<?xml version="1.0" encoding="UTF-8"?>
188 <methodName>domain.get_domain_orders</methodName>
195 <value><string>%s</string></value>
198 <name>password</name>
199 <value><string>%s</string></value>
205 </methodCall>' "$EUSERV_Username" "$EUSERV_Password")
207 export _H1
="Content-Type: text/xml"
208 response
="$(_post "$xml_content" "$EUSERV_Api" "" "POST
")"
210 if ! _contains
"$response" "<member><name>status</name><value><i4>100</i4></value></member>"; then
211 _err
"Error could not get domain orders"
212 _debug
"xml_content" "$xml_content"
213 _debug
"response" "$response"
217 # save response to reduce API calls
218 _euserv_domain_orders
="$response"
222 _euserv_get_domain_id
() {
223 # returns: _euserv_domain_id
225 _debug
"get domain_id"
227 # find line where the domain name is within the $response
228 _startLine
=$
(echo "$_euserv_domain_orders" |
grep -n '>domain_name<.*>'"$domain"'<' | cut
-d ':' -f 1)
229 # next occurency of domain_id after the domain_name is the correct one
230 _euserv_domain_id
=$
(echo "$_euserv_domain_orders" |
sed -n "$_startLine"',$p' |
grep '>domain_id<' | _head_n
1 |
sed 's/.*<i4>\([0-9]*\)<\/i4>.*/\1/')
232 if [ -z "$_euserv_domain_id" ]; then
233 _err
"Could not find domain_id for domain $domain"
234 _debug
"_euserv_domain_orders" "$_euserv_domain_orders"
241 _euserv_delete_record
() {
243 xml_content
=$
(printf '<?xml version="1.0" encoding="UTF-8"?>
245 <methodName>domain.dns_delete_record</methodName>
257 <name>password</name>
263 <name>dns_record_id</name>
272 </methodCall>' "$EUSERV_Username" "$EUSERV_Password" "$record_id")
274 export _H1
="Content-Type: text/xml"
275 response
="$(_post "$xml_content" "$EUSERV_Api" "" "POST
")"
277 if ! _contains
"$response" "<member><name>status</name><value><i4>100</i4></value></member>"; then
278 _err
"Error deleting record"
279 _debug
"xml_content" "$xml_content"
280 _debug
"response" "$response"
288 _euserv_add_record
() {
293 xml_content
=$
(printf '<?xml version="1.0" encoding="UTF-8"?>
295 <methodName>domain.dns_create_record</methodName>
307 <name>password</name>
309 <string>%s</string></value>
312 <name>domain_id</name>
318 <name>dns_record_subdomain</name>
324 <name>dns_record_type</name>
330 <name>dns_record_value</name>
336 <name>dns_record_ttl</name>
345 </methodCall>' "$EUSERV_Username" "$EUSERV_Password" "$_euserv_domain_id" "$sub_domain" "$txtval")
347 export _H1
="Content-Type: text/xml"
348 response
="$(_post "$xml_content" "$EUSERV_Api" "" "POST
")"
350 if ! _contains
"$response" "<member><name>status</name><value><i4>100</i4></value></member>"; then
351 _err
"Error could not create record"
352 _debug
"xml_content" "$xml_content"
353 _debug
"response" "$response"