Browse Source

Formatting fixes for Travis

pull/2562/head
stilez 5 years ago
committed by GitHub
parent
commit
a6614abd24
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 52
      dnsapi/dns_pleskxml

52
dnsapi/dns_pleskxml

@ -47,12 +47,15 @@ pleskxml_tplt_get_domains="<packet><customer><get-domain-list><filter/></get-dom
# Get a list of domains that PLESK can manage, so we can check root domain + host for acme.sh # Get a list of domains that PLESK can manage, so we can check root domain + host for acme.sh
# Also used to test credentials and URI. # Also used to test credentials and URI.
# No args. # No args.
pleskxml_tplt_get_dns_records="<packet><dns><get_rec><filter><site-id>%s</site-id></filter></get_rec></dns></packet>" pleskxml_tplt_get_dns_records="<packet><dns><get_rec><filter><site-id>%s</site-id></filter></get_rec></dns></packet>"
# Get all DNS records for a Plesk domain ID. # Get all DNS records for a Plesk domain ID.
# ARG = Plesk domain id to query # ARG = Plesk domain id to query
pleskxml_tplt_add_txt_record="<packet><dns><add_rec><site-id>%s</site-id><type>TXT</type><host>%s</host><value>%s</value></add_rec></dns></packet>" pleskxml_tplt_add_txt_record="<packet><dns><add_rec><site-id>%s</site-id><type>TXT</type><host>%s</host><value>%s</value></add_rec></dns></packet>"
# Add a TXT record to a domain. # Add a TXT record to a domain.
# ARGS = (1) Plesk internal domain ID, (2) "hostname" for the new record, eg '_acme_challenge', (3) TXT record value # ARGS = (1) Plesk internal domain ID, (2) "hostname" for the new record, eg '_acme_challenge', (3) TXT record value
pleskxml_tplt_rmv_dns_record="<packet><dns><del_rec><filter><id>%s</id></filter></del_rec></dns></packet>" pleskxml_tplt_rmv_dns_record="<packet><dns><del_rec><filter><id>%s</id></filter></del_rec></dns></packet>"
# Add a TXT record to a domain. # Add a TXT record to a domain.
# ARG = the Plesk internal ID for the dns record to be deleted # ARG = the Plesk internal ID for the dns record to be deleted
@ -135,10 +138,10 @@ dns_pleskxml_rm() {
fi fi
# Reduce output to one line per DNS record, filtered for TXT records with a record ID only (which they should all have) # Reduce output to one line per DNS record, filtered for TXT records with a record ID only (which they should all have)
reclist="$( _api_response_split "$pleskxml_prettyprint_result" 'result' '<status>ok</status>' | \
grep "<site-id>${root_domain_id}</site-id>" | \
grep -E '<id>[0-9]+</id>' | \
grep '<type>TXT</type>' \
reclist="$(_api_response_split "$pleskxml_prettyprint_result" 'result' '<status>ok</status>' \
| grep "<site-id>${root_domain_id}</site-id>" \
| grep -E '<id>[0-9]+</id>' \
| grep '<type>TXT</type>' \
)" )"
if [ -z "$reclist" ]; then if [ -z "$reclist" ]; then
@ -148,15 +151,14 @@ dns_pleskxml_rm() {
_debug "Got list of DNS TXT records for root domain '$root_domain_name'"':\n'"$reclist" _debug "Got list of DNS TXT records for root domain '$root_domain_name'"':\n'"$reclist"
recid="$( _value "$reclist" | \
grep "<host>$1.</host>" | \
grep "<value>$txtvalue</value>" | \
sed -E 's/(^.*<id>|<\/id>.*$)//g' \
recid="$(_value "$reclist" \
| grep "<host>$1.</host>" \
| grep "<value>$txtvalue</value>" \
| sed -E 's/(^.*<id>|<\/id>.*$)//g' \
)" )"
_debug "List of DNS TXT records for host:"'\n'"$(_value "$reclist" | grep "<host>$1.</host>")" _debug "List of DNS TXT records for host:"'\n'"$(_value "$reclist" | grep "<host>$1.</host>")"
if ! _value "$recid" | grep -Eq '^[0-9]+$'; then if ! _value "$recid" | grep -Eq '^[0-9]+$'; then
_err "DNS records for root domain '${root_domain_name}' (Plesk ID ${root_domain_id}) + host '${sub_domain_name}' do not contain the TXT record '${txtvalue}'" _err "DNS records for root domain '${root_domain_name}' (Plesk ID ${root_domain_id}) + host '${sub_domain_name}' do not contain the TXT record '${txtvalue}'"
_err "Cannot delete TXT record. Exiting." _err "Cannot delete TXT record. Exiting."
@ -214,11 +216,11 @@ _valuecut() {
# $2 - tag to resplit on (usually "result" or "domain") # $2 - tag to resplit on (usually "result" or "domain")
# $3 - regex to recognise useful return lines # $3 - regex to recognise useful return lines
_api_response_split() { _api_response_split() {
printf '%s' "$1" | \
sed -E 's/(^[[:space:]]+|[[:space:]]+$)//g' | \
tr -d '\n\r' | \
sed -E "s/<\/?$2>/${NEWLINE}/g" | \
grep -E "$3"
printf '%s' "$1" \
| sed -E 's/(^[[:space:]]+|[[:space:]]+$)//g' \
| tr -d '\n\r' \
| sed -E "s/<\/?$2>/${NEWLINE}/g" \
| grep -E "$3"
} }
@ -247,11 +249,10 @@ _call_api() {
if _value "$statuslines" | grep -qv '<status>ok</status>'; then if _value "$statuslines" | grep -qv '<status>ok</status>'; then
# We have some status lines that aren't "ok". Get the details # We have some status lines that aren't "ok". Get the details
errtext="$( \
_value "$pleskxml_prettyprint_result" | \
grep -iE "(<status>|<errcode>|<errtext>)" | \
sed -E 's/(^[[:space:]]+|<\/[a-z]+$)//g' | \
sed -E 's/^<([a-z]+)>/\1: /' \
errtext="$( _value "$pleskxml_prettyprint_result" \
| grep -iE "(<status>|<errcode>|<errtext>)" \
| sed -E 's/(^[[:space:]]+|<\/[a-z]+$)//g' \
| sed -E 's/^<([a-z]+)>/\1: /' \
)" )"
elif ! _value "$statuslines" | grep -q '<status>ok</status>'; then elif ! _value "$statuslines" | grep -q '<status>ok</status>'; then
@ -326,14 +327,17 @@ _credential_check() {
# For a FQDN, identify the root domain managed by Plesk, its domain ID in Plesk, and the host if any. # For a FQDN, identify the root domain managed by Plesk, its domain ID in Plesk, and the host if any.
# IMPORTANT NOTE: a result with host = empty string is OK for this API, see
# https://docs.plesk.com/en-US/obsidian/api-rpc/about-xml-api/reference/managing-dns/managing-dns-records/adding-dns-record.34798
# See notes at top of this file
_pleskxml_get_root_domain() { _pleskxml_get_root_domain() {
_debug "Identifying DNS root domain for '$1' that is managed by the Plesk account." _debug "Identifying DNS root domain for '$1' that is managed by the Plesk account."
# test if the domain is valid for splitting. # test if the domain is valid for splitting.
if _value "$root_domain_name" | grep -qvE '^[^.]+\.[^.]+\.[^.]'; then if _value "$root_domain_name" | grep -qvE '^[^.]+\.[^.]+\.[^.]'; then
### COMMENTED OUT ALSO FOR SAME REASON
### _err "Invalid domain. The ACME domain must contain at least three parts (aa.bb.tld) to identify a host, domain, and tld for the TXT record."
_err "Invalid domain. The ACME domain must contain at least two parts (aa.bb) to identify a domain and tld for the TXT record." _err "Invalid domain. The ACME domain must contain at least two parts (aa.bb) to identify a domain and tld for the TXT record."
return 1 return 1
fi fi
@ -350,6 +354,7 @@ _pleskxml_get_root_domain() {
# for non-Western character sets. # for non-Western character sets.
# Output will be one line per known domain, containing 1 or 2 <name> tages and an <id> tag # Output will be one line per known domain, containing 1 or 2 <name> tages and an <id> tag
# We don't actually need to check for type, name, *and* id, but it guarantees only usable lines are returned. # We don't actually need to check for type, name, *and* id, but it guarantees only usable lines are returned.
output="$(_api_response_split "$pleskxml_prettyprint_result" 'domain' '<type>domain</type>' | sed -E 's/<(\/?)ascii-name>/<\1name>/g' | grep '<name>' | grep '<id>')" output="$(_api_response_split "$pleskxml_prettyprint_result" 'domain' '<type>domain</type>' | sed -E 's/<(\/?)ascii-name>/<\1name>/g' | grep '<name>' | grep '<id>')"
_debug 'Domains managed by Plesk server are (ignore the hacked output):\n' "$output" _debug 'Domains managed by Plesk server are (ignore the hacked output):\n' "$output"
@ -368,9 +373,8 @@ _pleskxml_get_root_domain() {
if [ -n "$root_domain_id" ]; then if [ -n "$root_domain_id" ]; then
# Found a match # Found a match
# Note that a result with host = empty string is OK for this API, see
# https://docs.plesk.com/en-US/obsidian/api-rpc/about-xml-api/reference/managing-dns/managing-dns-records/adding-dns-record.34798
# See notes at top of this file
# SEE IMPORTANT NOTE ABOVE - THIS FUNCTION CAN RETURN HOST='', AND THAT'S OK FOR PLESK XML API WHICH ALLOWS IT.
# SO WE HANDLE IT AND DON'T PREVENT IT
sub_domain_name="$(_value "$1" | sed -E "s/\.?${root_domain_name}"'$//')" sub_domain_name="$(_value "$1" | sed -E "s/\.?${root_domain_name}"'$//')"
_info "Matched host '$1' to: DOMAIN '${root_domain_name}' (Plesk ID '${root_domain_id}'), HOST '${sub_domain_name}'. Returning." _info "Matched host '$1' to: DOMAIN '${root_domain_name}' (Plesk ID '${root_domain_id}'), HOST '${sub_domain_name}'. Returning."
return 0 return 0

Loading…
Cancel
Save