_info 'Plesk XML: You have allowed insecure http connections to Plesk. Passwords and logins may be sent in plain text.\nPlease do not use this setting unless very sure of security!'
fi
# Try to convert the domain name to a plesk domain ID. This also lets us know if the URI and authentication are OK.
_info "Plesk XML: Variables loaded."
_info "Trying to connect to Plesk ($_pleskxml_uri), and request Plesk's internal reference ID for domain '${_pleskxml_domain}'"
_DBG 2"Calling API to get domain ID for $_pleskxml_domain"
_DBG 2"Calling API to get domain ID for $_pleskxml_domain"
@ -212,17 +211,17 @@ _DBG_VARDUMP 2 'Call has returned'
# OK, valid response containing a valid domain ID must have been found
# If not we should have got an error.
# Try to add the TXT record
_DBG 2"Calling API to add TXT record to domain ID #$_pleskxml_domain_id ('$_pleskxml_domain')"
_DBG 2"Calling API to add TXT record to domain ID #$_pleskxml_domain_id ('$_pleskxml_domain')"
_info "Plesk XML: Trying to add TXT record to domain ID $_pleskxml_domain_id ('$_pleskxml_domain'), host '$_pleskxml_host'. The TXT string is: '$_pleskxml_TXT_string'."
# Really, just testing return code should be enough, based on above code, but let's go "all-in" and test all variables returned
@ -233,7 +232,7 @@ _DBG_VARDUMP 2 'Call has returned'
_info 'An ACME Challenge TXT record for '"$_pleskxml_domain"' was added to Plesk. Plesk returned a successful response.\nThe TXT field was: '"'$_pleskxml_TXT_string'"
_info "(TO CHECK?: Note that all subdomains under this domain uses the same TXT record.) <-- MAY NOT BE NEEDED"
_info 'Plesk XML: You have allowed insecure http connections to Plesk. Passwords and logins may be sent in plain text.\nPlease do not use this setting unless very sure of security!'
fi
# Try to convert the domain name to a plesk domain ID. This also lets us know if the URI and authentication are OK.
_info "Plesk XML: Variables loaded."
_info "Trying to connect to Plesk ($_pleskxml_uri), and request Plesk's internal reference ID for domain '${_pleskxml_domain}'"
_DBG 2"Calling API to get domain ID for $_pleskxml_domain"
_DBG 2"Calling API to get domain ID for $_pleskxml_domain"
# Really, just testing return code should be enough, based on above code, but let's go "all-in" and test all variables returned
@ -312,7 +311,7 @@ _DBG_VARDUMP 2 'Call has returned'
_info 'A TXT record for '"$_pleskxml_domain"' was removed from Plesk. Plesk returned a successful response.\nThe TXT field was: '"'$_pleskxml_TXT_string'"
_pleskxml_errors="$_pleskxml_errors"'\nBad or unacceptable URI (If non-SSL HTTP is required, did you set "pleskxml_allow_insecure_uri"?).\nYou should set and export '"$pleskxml_uri"', containing the URI for your Plesk XML API.\nThe URI usually looks like this: https://my_plesk_uri.tld:8443'
# USER is "valid enough" to use - Plesk doesn't stipulate valid chars, but thewse are probably "safe enough". We will find out if they aren't, the hard way :)
# Note, we cannot assume "safe" characters when we use this value!
_DBG 2"Entered _pleskxml_api_request($*), to make an XML request.${_pleskxml_newline} arg1=^$1^${_pleskxml_newline} arg2=^$2^${_pleskxml_newline} arg3=^$3^${_pleskxml_newline} arg4=^$4^"
_DBG 2"Entered _pleskxml_api_request($*), to make an XML request.${_pleskxml_newline} arg1=^$1^${_pleskxml_newline} arg2=^$2^${_pleskxml_newline} arg3=^$3^${_pleskxml_newline} arg4=^$4^"
_pleskxml_errors=''
_pleskxml_result=''
@ -409,7 +408,7 @@ _DBG 2 "Entered _pleskxml_api_request($*), to make an XML request.${_pleskxml_ne
# Of all the API commands we use, just one of them can return multiple results sections
# so the validation process after cURL returns, will differ for that case.....
if["$1"="$_pleskxml_tplt_get_dns_records"];then
_pleskxml_multiple_results_allowed=1
else
@ -434,24 +433,24 @@ _DBG 2 "Entered _pleskxml_api_request($*), to make an XML request.${_pleskxml_ne
# Error - should have <?xml><packet>...</packet>. Abort
_pleskxml_errors="Error when querying Plesk XML API. The API did not return a valid XML response. The response was:${_pleskxml_newline}${_pleskxml_prettyprint_result}${_pleskxml_newline}The collapsed version was:${_pleskxml_newline}'${_pleskxml_result}'${_pleskxml_newline}"
_DBG 2"$_pleskxml_errors"
_DBG 2"$_pleskxml_errors"
return1
else
# So far so good. Strip the <?xml> and <packet>...</packet> tags and continue
@ -485,41 +484,41 @@ _DBG 2 "$_pleskxml_errors"
)"
fi
_DBG 2"Checking <system> tags don't exist..."
_DBG 2"Checking <system> tags don't exist..."
# <system> section found anywhere in response?
# This usually means some kind of basic API error such as login failure, bad XML request, etc
_pleskxml_errors='Error when querying Plesk XML API. The result contained a <system> tag.\nThis usually indicates an invalid login, badly formatted API request or other error. The response was:\n'"$_pleskxml_prettyprint_result"'\n'
_DBG 2"$_pleskxml_errors"
_DBG 2"$_pleskxml_errors"
return1
fi
_DBG 2'Checking 1 or >=1 <result> tag (or tags) found, each containing 'status:ok'...'
_DBG 2'Checking 1 or >=1 <result> tag (or tags) found, each containing 'status:ok'...'
# Check results section. Most commands only have one results section.
# Check results section. Most commands only have one results section.
# But some (i.e., get all DNS records for a domain) have many results sections,
# and we will need to check each <results>...</results> section separately.
# So this gets a bit messy, especially as we don't have non-greedy regex
# and we will have to work around that as well.
# For this, we will split the string up again with exactly 1 <result> section per line.
# We check there is at least one result section. Then we add newlines before and after
# We check there is at least one result section. Then we add newlines before and after
# any <result>...</result> and ignore any lines that don't contain '<result>'.
_pleskxml_errors='Error when querying Plesk XML API. The result did not contain a <result> section.\nThis is unexpected: something has gone wrong. Please raise this as a bug/issue in the module. The response was:\n'"$_pleskxml_prettyprint_result"'\n'
_DBG 2"$_pleskxml_errors"
_DBG 2"$_pleskxml_errors"
return1
fi
_DBG 2'Found at least 1 <result> section. Splitting each result section to a separate line'
_DBG 2'Found at least 1 <result> section. Splitting each result section to a separate line'
_pleskxml_errors='Error when querying Plesk XML API. The result contained more than one <result> section.\nThis is unexpected: something has gone wrong. Please raise this as a bug/issue in the module. The response was:\n'"$_pleskxml_prettyprint_result"'\n'
_DBG 2"$_pleskxml_errors"
_DBG 2"$_pleskxml_errors"
return1
fi
_DBG 2"Found ${_pleskxml_linecount} <result> section(s), checking each has status:ok..."
# Loop through each <result> section, checking every line has exactly one result section,
_DBG 2"Found ${_pleskxml_linecount} <result> section(s), checking each has status:ok..."
# Loop through each <result> section, checking every line has exactly one result section,
# containing exactly one status section, which contains <status>ok</status>
whileIFS=read -r _pleskxml_line;do
# _pleskxml_line *should* contain a single result section.
# Check this is correct.
# _DBG "Checking a <result> section... content is ${_pleskxml_line}"
@ -560,25 +559,25 @@ _DBG 2 "Found ${_pleskxml_linecount} <result> section(s), checking each has stat
_pleskxml_errors='Error when querying Plesk XML API. A <result> section was not found where expected.\nThis is unexpected: something has gone wrong. Please raise this as a bug/issue in the module. The response was:\n'"$_pleskxml_prettyprint_result"'\n'
return1
fi
# Now strip the <results> tag and check there is precisely one <status> section and its ciontents are "ok"
_pleskxml_line="$(printf'%s'"$_pleskxml_line"| sed -E 's/^<result>(.*)<\/result>$/\1/')"
_pleskxml_errors='Error when querying Plesk XML API. A <result> section did not contain a <status> section.\nThis is unexpected: something has gone wrong. Please raise this as a bug/issue in the module. The response was:\n'"$_pleskxml_prettyprint_result"'\n'
_pleskxml_errors='Error when querying Plesk XML API. A <result> section contained more than one <status> section.\nThis is unexpected: something has gone wrong. Please raise this as a bug/issue in the module. The response was:\n'"$_pleskxml_prettyprint_result"'\n'
_pleskxml_errors='Error when querying Plesk XML API. A <status> tag did not contain "<status>ok</status>". The response was:\n'"$_pleskxml_prettyprint_result"'\n'
_DBG 2"$_pleskxml_errors"
_DBG 2"$_pleskxml_errors"
return1
fi
@ -590,7 +589,7 @@ EOL
# So far so good. Remove all <status>ok</status> sections as they're checked now.
_DBG 2"All results lines had status:ok. Exiting loop, and removing all <status>ok</status> tags now they've been checked"
_DBG 2"All results lines had status:ok. Exiting loop, and removing all <status>ok</status> tags now they've been checked"
_pleskxml_errors='Error when querying Plesk XML API. The API did not comprise a <result> section containing all other data.\nThis is unexpected: something has gone wrong. Please raise this as a bug/issue in the module. The response was:\n'"$_pleskxml_prettyprint_result"'\nand the exact test string was:\n'"$_pleskxml_result"'\n'
_pleskxml_errors='Error when querying Plesk XML API. The API contained more than one <result> section.\nThis is unexpected: something has gone wrong. Please raise this as a bug/issue in the module. The response was:\n'"$_pleskxml_prettyprint_result"'\nand the exact test string was:\n'"$_pleskxml_result"'\n'
_DBG 2"$_pleskxml_errors"
_DBG 2"$_pleskxml_errors"
return1
else
# So far so good. Remove the <result>...</result> section and continue
@ -659,18 +658,18 @@ _DBG 2 "$_pleskxml_errors"
fi
# Result should contain precisely one <filter-id> section, containing the domain name inquired.
_DBG 2'Testing API return data for one <filter-id> and removing if so'
_DBG 2'Testing API return data for one <filter-id> and removing if so'
_pleskxml_errors='Error when querying Plesk XML API. The API did not contain the expected <filter-id> section containing the domain name.\nThis is unexpected: something has gone wrong. Please raise this as a bug/issue in the module. The response was:\n'"$_pleskxml_prettyprint_result"'\nand the exact test string was:\n'"$_pleskxml_result"'\n'
_pleskxml_errors='Error when querying Plesk XML API. The API contained more than one <filter-id> section.\nThis is unexpected: something has gone wrong. Please raise this as a bug/issue in the module. The response was:\n'"$_pleskxml_prettyprint_result"'\nand the exact test string was:\n'"$_pleskxml_result"'\n'
_DBG 2"$_pleskxml_errors"
_DBG 2"$_pleskxml_errors"
return1
else
# So far so good. Remove the <filter-id>...</filter-id> section and continue
@ -680,25 +679,25 @@ _DBG 2 "$_pleskxml_errors"
fi
# All that should be left is one section, containing <id>DOMAIN_ID</id>
_DBG 2"Remaining part of result is now: '$_pleskxml_result' "
_DBG 2"Remaining part of result is now: '$_pleskxml_result' "
# Error - doesn't contain just <id>NUMBERS</id>. Something's wrong. Abort
_pleskxml_errors='Error when querying Plesk XML API. The API did not contain the expected <id>[NUMERIC_ID]</id> section, or contained other unexpected values as well.\nThis is unexpected: something has gone wrong. Please raise this as a bug/issue in the module. The response was:\n'"$_pleskxml_prettyprint_result"'\nand the exact test string was:\n'"$_pleskxml_result"'\n'
_DBG 2"$_pleskxml_errors"
_DBG 2"$_pleskxml_errors"
return1
fi
# SUCCESS! Remove the surrounding <id> tag and return the value!
# Error - doesn't contain just <id>NUMBERS</id>. Something's wrong. Abort
_pleskxml_errors='Error when calling Plesk XML API. The API did not contain the expected <id>[PLESK_NEW_DNS_RECORD_ID]</id> section, or contained other unexpected values as well.\nThis is unexpected: something has gone wrong. Please raise this as a bug/issue in the module. The response was:\n'"$_pleskxml_prettyprint_result"'\nand the exact test string was:\n'"$_pleskxml_result"'\n'
_DBG 2"$_pleskxml_errors"
_DBG 2"$_pleskxml_errors"
return1
fi
# SUCCESS! Remove the surrounding <result><id> tags and return the value!
# (although we don't actually use it!
@ -787,35 +785,35 @@ _DBG 2 "$_pleskxml_errors"
sed -E "s/^<result><id>([0-9]+)<\/id><\/result>$/\1/"\
_pleskxml_errors='Error when querying Plesk XML API. The API contained more than one <result> section.\nThis is unexpected: something has gone wrong. Please raise this as a bug/issue in the module. The response was:\n'"$_pleskxml_prettyprint_result"'\nand the exact test string was:\n'"$_pleskxml_result"'\n'