_err "WEDOS Account do not contain primary domain to fullfill add of ${fulldomain}!"
_err "WEDOS Account do not contain primary domain to fullfill add of ${fulldomain}!"
return1
return1
@ -113,14 +112,13 @@ dns_wedos_rm() {
if _wapi_find_row "${_domain}""${_sub_domain}""${txtvalue}";then
if _wapi_find_row "${_domain}""${_sub_domain}""${txtvalue}";then
_info "WEDOS WAPI: dns record found with id '${_row_id}'"
_info "WEDOS WAPI: dns record found with id '${_row_id}'"
if _wapi_delete_row "${_domain}""${_row_id}";then
if _wapi_delete_row "${_domain}""${_row_id}";then
_info "WEDOS WAPI: dns row were deleted and changes commited!"
_info "WEDOS WAPI: dns row were deleted and changes commited!"
return0
return0
fi
fi
fi
fi
_err "Requested dns row were not found or was imposible to delete it, do it manually"
_err "Requested dns row were not found or was imposible to delete it, do it manually"
_err "Delete: ${fulldomain}"
_err "Delete: ${fulldomain}"
_err "Value: ${txtvalue}"
_err "Value: ${txtvalue}"
@ -174,8 +172,8 @@ _wapi_post() {
request="${request}\
request="${request}\
</request>"
</request>"
_debug "Request to WAPI is: ${request}"
_debug "Request to WAPI is: ${request}"
if ! response="$(_post "${request}""$WEDOS_WAPI_ENDPOINT")";then
if ! response="$(_post "${request}""$WEDOS_WAPI_ENDPOINT")";then
_err "Error contacting WEDOS WAPI with command ${command}"
_err "Error contacting WEDOS WAPI with command ${command}"
return1
return1
@ -187,22 +185,21 @@ _wapi_post() {
return"$?"
return"$?"
}
}
# _get_root() function, for provided full domain, like _acme_challenge.www.example.com verify if WEDOS contains a primary active domain and found what is subdomain
# _get_root() function, for provided full domain, like _acme_challenge.www.example.com verify if WEDOS contains a primary active domain and found what is subdomain
# $1 - full domain to verify, ie _acme_challenge.www.example.com
# $1 - full domain to verify, ie _acme_challenge.www.example.com
# build ${_domain} found at WEDOS, like example.com and ${_sub_domain} from provided full domain, like _acme_challenge.www
# build ${_domain} found at WEDOS, like example.com and ${_sub_domain} from provided full domain, like _acme_challenge.www
_get_root(){
_get_root(){
domain=$1
domain=$1
if[ -z "${domain}"];then
if[ -z "${domain}"];then
_err "Function _get_root was called without argument, implementation error!"
_err "Function _get_root was called without argument, implementation error!"
return1;
return1
fi
fi
_debug "Get root for domain: ${domain}"
_debug "Get root for domain: ${domain}"
_debug "Getting list of domains using WAPI ..."
_debug "Getting list of domains using WAPI ..."
if ! _wapi_post "dns-domains-list";then
if ! _wapi_post "dns-domains-list";then
_err "Error on WAPI request for list of domains, response : ${response}"
_err "Error on WAPI request for list of domains, response : ${response}"
return1
return1
@ -210,25 +207,24 @@ _get_root() {
_debug "DNS list were successfully retrieved, response : ${response}"
_debug "DNS list were successfully retrieved, response : ${response}"
fi
fi
for xml_domain in $(echo"${response}"| tr -d '\012\015'| grep -o -E "<domain>( )*<name>.*</name>( )*<type>primary</type>( )*<status>active</status>"| grep -o -E "<name>.*</name>")
do
for xml_domain in $(echo"${response}"| tr -d '\012\015'| grep -o -E "<domain>( )*<name>.*</name>( )*<type>primary</type>( )*<status>active</status>"| grep -o -E "<name>.*</name>");do
_debug "Active and primary XML DOMAIN found: ${xml_domain}"
_debug "Active and primary XML DOMAIN found: ${xml_domain}"
_err "Invalid request to add record, domain: '${domain}', sub_domain: '${sub_domain}', value: '${value}' and ttl: '${ttl}', on of required input were not provided, implementation error!"
_err "Invalid request to add record, domain: '${domain}', sub_domain: '${sub_domain}', value: '${value}' and ttl: '${ttl}', on of required input were not provided, implementation error!"
return1;
return1
fi
fi
# Prepare data for request to WAPI
# Prepare data for request to WAPI
@ -280,7 +276,7 @@ _wapi_row_add() {
<rdata>${value}</rdata>\
<rdata>${value}</rdata>\
<auth_comment>Created using WAPI from acme.sh</auth_comment>\
<auth_comment>Created using WAPI from acme.sh</auth_comment>\
</data>"
</data>"
_debug "Adding row using WAPI ..."
_debug "Adding row using WAPI ..."
if ! _wapi_post "dns-row-add""${data}";then
if ! _wapi_post "dns-row-add""${data}";then
@ -324,19 +320,18 @@ _wapi_find_row() {
sub_domain_regex=$(echo"${sub_domain}"| sed "s/\./\\\\./g")
sub_domain_regex=$(echo"${sub_domain}"| sed "s/\./\\\\./g")
_debug "Subdomain regex '${sub_domain_regex}'"
_debug "Subdomain regex '${sub_domain_regex}'"
for xml_row in $(echo"${response}"| tr -d '\012\015'| grep -o -E "<row>( )*<ID>[0-9]*</ID>( )*<name>${sub_domain_regex}</name>( )*<ttl>[0-9]*</ttl>( )*<rdtype>TXT</rdtype>( )*<rdata>${value}</rdata>"| grep -o -e "<ID>[0-9]*</ID>")
do
for xml_row in $(echo"${response}"| tr -d '\012\015'| grep -o -E "<row>( )*<ID>[0-9]*</ID>( )*<name>${sub_domain_regex}</name>( )*<ttl>[0-9]*</ttl>( )*<rdtype>TXT</rdtype>( )*<rdata>${value}</rdata>"| grep -o -e "<ID>[0-9]*</ID>");do
_debug "Found row in DNS with ID : ${xml_row}"
_debug "Found row in DNS with ID : ${xml_row}"
_row_id=$(echo"${xml_row}"| grep -o -E "[0-9]*")
_row_id=$(echo"${xml_row}"| grep -o -E "[0-9]*")
_info "WEDOS API: Found DNS row id ${_row_id} for domain ${domain}"
_info "WEDOS API: Found DNS row id ${_row_id} for domain ${domain}"
return0
return0
done
done
_info "WEDOS API: No TXT row found for domain '${domain}' with name '${sub_domain}' and value '${value}'"
_info "WEDOS API: No TXT row found for domain '${domain}' with name '${sub_domain}' and value '${value}'"