Browse Source

Fix review issues

All "reviewed functions" replaced with acme.sh functions. Added time zone for authentication token. Fix all XML list search with proper descriptions.
pull/3165/head
mxtuma 4 years ago
committed by GitHub
parent
commit
55f9c4d2cc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 65
      dnsapi/dns_wedos.sh

65
dnsapi/dns_wedos.sh

@ -36,7 +36,7 @@ dns_wedos_add() {
#build WEDOS_Authtoken #build WEDOS_Authtoken
_debug "WEDOS Authtoken were not saved yet, building" _debug "WEDOS Authtoken were not saved yet, building"
WEDOS_Authtoken=$(printf '%s' "${WEDOS_Wapipass}" | sha1sum | head -c 40)
WEDOS_Authtoken=$(printf '%s' "${WEDOS_Wapipass}" | _digest "sha1" "true" | head -c 40)
_debug "WEDOS_Authtoken step 1, WAPI PASS sha1 sum: '${WEDOS_Authtoken}'" _debug "WEDOS_Authtoken step 1, WAPI PASS sha1 sum: '${WEDOS_Authtoken}'"
WEDOS_Authtoken="${WEDOS_Username}${WEDOS_Authtoken}" WEDOS_Authtoken="${WEDOS_Username}${WEDOS_Authtoken}"
_debug "WEDOS_Authtoken step 2, username concat with token without hours: '${WEDOS_Authtoken}'" _debug "WEDOS_Authtoken step 2, username concat with token without hours: '${WEDOS_Authtoken}'"
@ -144,8 +144,8 @@ _wapi_post() {
fi fi
# Prepare authentification token # Prepare authentification token
hour=$(date +%H)
token=$(printf '%s' "${WEDOS_Authtoken}${hour}" | sha1sum | head -c 40)
hour=$(TZ='Europe/Prague' date +%H)
token=$(printf '%s' "${WEDOS_Authtoken}${hour}" | _digest "sha1" "true" | head -c 40)
_debug "Authentification token is '${token}'" _debug "Authentification token is '${token}'"
# Build xml request # Build xml request
@ -180,7 +180,7 @@ _wapi_post() {
fi fi
_debug "Response : ${response}" _debug "Response : ${response}"
echo "${response}" | grep "<code>1000</code>" 1>/dev/null 2>/dev/null
_contains "${response}" "<code>1000</code>"
return "$?" return "$?"
} }
@ -207,26 +207,36 @@ _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
_debug "Active and primary XML DOMAIN found: ${xml_domain}"
end_of_name=$((${#xml_domain} - 7))
xml_domain_name=$(echo "${xml_domain}" | cut -c 7-${end_of_name})
_debug "Found primary active domain: ${xml_domain_name}"
regex=".*\\."$(echo "${xml_domain_name}" | sed 's/\./\\./g')
_debug "Regex for matching domain: '${regex}'"
# In for each cycle, try parse the response to find primary active domains
# For cycle description:
# 1st tr -d '\011\012\015' = remove all newlines and tab characters - whole XML became single line
# 2nd sed "s/^.*<data>[ ]*//g" = remove all the xml data from the beggining of the XML - XML now start with the content of <data> element
# 3rd sed "s/<\/data>.*$//g" = remove all the data after the data xml element - XML now contains only the content of data xml element
# 4th sed "s/>[ ]*<\([^\/]\)/><\1/g" = remove all spaces between XML tag and XML start tag - XML now contains content of data xml element and is without spaces between end and start xml tags
# 5th sed "s/<domain>//g" = remove all domain xml start tags - XML now contains only <name>...</name><type>...</type><status>...</status> </domain>(next xml domain)
# 6th sed "s/[ ]*<\/domain>/\n/g"= replace all "spaces</domain>" by new line - now we create multiple lines each should contain only <name>...</name><type>...</type><status>...</status>
# 7th sed -n "/<name>\([a-zA-Z0-9_\-\.]\+\)<\/name><type>primary<\/type><status>active<\/status>/p" = remove all non primary or non active domains lines
# 8th sed "s/<name>\([a-zA-Z0-9_\-\.]\+\)<\/name><type>primary<\/type><status>active<\/status>/\1/g" = substitute for domain names only
for xml_domain in $(echo "${response}" | tr -d '\011\012\015' | sed "s/^.*<data>[ ]*//g" | sed "s/<\/data>.*$//g" | sed "s/>[ ]*<\([^\/]\)/><\1/g" | sed "s/<domain>//g" | sed "s/[ ]*<\/domain>/\n/g" | sed -n "/<name>\([a-zA-Z0-9_\-\.]\+\)<\/name><type>primary<\/type><status>active<\/status>/p" | sed "s/<name>\([a-zA-Z0-9_\-\.]\+\)<\/name><type>primary<\/type><status>active<\/status>/\1/g"); do
_debug "Found primary active domain: ${xml_domain}"
if _endswith "${domain}" "${xml_domain}"; then
length_difference=$(_math "${#domain} - ${#xml_domain}")
possible_subdomain=$(echo "${domain}" | cut -c -"${length_difference}")
if _endswith "${possible_subdomain}" "."; then
length_difference=$(_math "${length_difference} - 1")
_domain=${xml_domain}
_sub_domain=$(echo "${possible_subdomain}" | cut -c -"${length_difference}")
if ! echo "${domain}" | grep -E "${regex}" 1>/dev/null 2>/dev/null; then
_debug "found domain do not match required"
else
end_of_name=$((${#domain} - ${#xml_domain_name} - 1))
_domain=${xml_domain_name}
_sub_domain=$(echo "${domain}" | cut -c -${end_of_name})
_info "Domain '${_domain}' was found at WEDOS account as primary, and subdomain is '${_sub_domain}'!" _info "Domain '${_domain}' was found at WEDOS account as primary, and subdomain is '${_sub_domain}'!"
return 0 return 0
fi fi
fi
_debug " ... found domain does not match required!"
done done
return 1 return 1
} }
# for provided domain, it commites all performed changes # for provided domain, it commites all performed changes
@ -317,13 +327,28 @@ _wapi_find_row() {
_debug "Domain rows found, response : ${response}" _debug "Domain rows found, response : ${response}"
# Prepare sub domain regex which will be later used for search domain row
# from _acme_challenge.sub it should be _acme_challenge\.sub
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
_debug "Found row in DNS with ID : ${xml_row}"
_row_id=$(echo "${xml_row}" | grep -o -E "[0-9]*")
# In for each cycle loops over the domains rows, description:
# 1st tr -d '\011\012\015' = delete all newlines and tab characters - XML became a single line
# 2nd sed "s/^.*<data>[ ]*//g" = remove all from the beggining to the start of the content of the data xml element - XML is without unusefull beginning
# 3rd sed "s/[ ]*<\/data>.*$//g" = remove the end of the xml starting with xml end tag data - XML contains only the content of data xml element and is trimmed
# 4th sed "s/>[ ]*<\([^\/]\)/><\1/g" = remove all spaces between XML tag and XML start tag - XML now contains content of data xml element and is without spaces between end and start xml tags
# 5th sed "s/<row>//g" = remove all row xml start tags - XML now contains rows xml element content and its end tag
# 6th sed "s/[ ]*<\/row>/\n/g" = replace all "spaces</row>" by new line - now we create multiple lines each should contain only single row xml content
# 7th sed -n "/<name>${sub_domain_regex}<\/name>.*<rdtype>TXT<\/rdtype>/p" = remove all non TXT and non name matching row lines - now we have only xml lines with TXT rows matching requested values
# 8th sed "s/^<ID>\([0-9]\+\)<\/ID>.*<rdata>\(.*\)<\/rdata>.*$/\1-\2/" = replace the whole lines to ID-value pairs
# -- now there are only lines with ID-value but value might contain spaces (BAD FOR FOREACH LOOP) or special characters (BAD FOR REGEX MATCHING)
# 9th grep "${value}" = match only a line containg searched value
# 10th sed "s/^\([0-9]\+\).*$/\1/" = get only ID from the row
for xml_row in $(echo "${response}" | tr -d '\011\012\015' | sed "s/^.*<data>[ ]*//g" | sed "s/[ ]*<\/data>.*$//g" | sed "s/>[ ]*<\([^\/]\)/><\1/g" | sed "s/<row>//g" | sed "s/[ ]*<\/row>/\n/g" | sed -n "/<name>${sub_domain_regex}<\/name>.*<rdtype>TXT<\/rdtype>/p" | sed "s/^<ID>\([0-9]\+\)<\/ID>.*<rdata>\(.*\)<\/rdata>.*$/\1-\2/" | grep "${value}" | sed "s/^\([0-9]\+\).*$/\1/"); do
_row_id="${xml_row}"
_info "WEDOS API: Found DNS row id ${_row_id} for domain ${domain}" _info "WEDOS API: Found DNS row id ${_row_id} for domain ${domain}"
return 0 return 0
done done

Loading…
Cancel
Save