_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!'
_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
fi
# Try to convert the domain name to a plesk domain ID. This also lets us know if the URI and authentication are OK.
# 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 "Plesk XML: Variables are valid and loaded."
_info "Trying to connect to Plesk ($_pleskxml_uri), and request Plesk's internal reference ID for domain '${_pleskxml_domain}'"
_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 "$LINENO"3"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
# Really, just testing return code should be enough, based on above code, but let's go "all-in" and test all variables returned
_err "$_pleskxml_errors"
_err "$_pleskxml_errors"
@ -195,14 +199,15 @@ dns_pleskxml_add() {
# Try to add the TXT record
# Try to add the TXT record
_DBG 2"Calling API to add TXT record to domain ID #$_pleskxml_domain_id ('$_pleskxml_domain')"
_DBG "$LINENO"3"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'."
_info "Plesk XML: Got ID for domain. 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
# Really, just testing return code should be enough, based on above code, but let's go "all-in" and test all variables returned
@ -211,9 +216,8 @@ dns_pleskxml_add() {
fi
fi
_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 '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!'
_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
fi
# Try to convert the domain name to a plesk domain ID. This also lets us know if the URI and authentication are OK.
# 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 "Plesk XML: Variables are valid and loaded."
_info "Trying to connect to Plesk ($_pleskxml_uri), and request Plesk's internal reference ID for domain '${_pleskxml_domain}'"
_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 "$LINENO"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
# Really, just testing return code should be enough, based on above code, but let's go "all-in" and test all variables returned
@ -290,7 +296,7 @@ dns_pleskxml_rm() {
_info 'A TXT record for '"$_pleskxml_domain"' was removed from Plesk. Plesk returned a successful response.\nThe TXT field was: '"'$_pleskxml_TXT_string'"
_info 'A TXT record for '"$_pleskxml_domain"' was removed from Plesk. Plesk returned a successful response.\nThe TXT field was: '"'$_pleskxml_TXT_string'"
_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 "$LINENO"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^"
# Error - should have <?xml><packet>...</packet>. Abort
# 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}"
_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"
_err"$_pleskxml_errors"
return1
return1
else
else
# So far so good. Strip the <?xml> and <packet>...</packet> tags and continue
# So far so good. Strip the <?xml> and <packet>...</packet> tags and continue
_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'
_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"
_err"$_pleskxml_errors"
return1
return1
fi
fi
_DBG 2'Checking 1 or >=1 <result> tag (or tags) found, each containing 'status:ok'...'
_DBG "$LINENO"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,
# But some (i.e., get all DNS records for a domain) have many results sections,
_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'
_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"
_err"$_pleskxml_errors"
return1
return1
fi
fi
_DBG 2'Found at least 1 <result> section. Splitting each result section to a separate line'
_DBG "$LINENO"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'
_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"
_err"$_pleskxml_errors"
return1
return1
fi
fi
_DBG 2"Found ${_pleskxml_linecount} <result> section(s), checking each has status:ok..."
_DBG "$LINENO"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,
# Loop through each <result> section, checking every line has exactly one result section,
# containing exactly one status section, which contains <status>ok</status>
# containing exactly one status section, which contains <status>ok</status>
@ -522,11 +535,12 @@ _pleskxml_api_request() {
# _pleskxml_line *should* contain a single result section.
# _pleskxml_line *should* contain a single result section.
# Check this is correct.
# Check this is correct.
# _DBG "Checking a <result> section... content is ${_pleskxml_line}"
# _DBG "$LINENO" "Checking a <result> section... content is ${_pleskxml_line}"
_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'
_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'
_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 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 <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'
_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"
_err"$_pleskxml_errors"
return1
return1
fi
fi
# _DBG "Line is OK. Looping to next line or exiting..."
# _DBG "$LINENO" "Line is OK. Looping to next line or exiting..."
done <<EOL
done <<EOL
$_pleskxml_result
$_pleskxml_result
@ -559,7 +573,7 @@ EOL
# So far so good. Remove all <status>ok</status> sections as they're checked now.
# 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 "$LINENO"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 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'
_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"
_err"$_pleskxml_errors"
return1
return1
else
else
# So far so good. Remove the <result>...</result> section and continue
# So far so good. Remove the <result>...</result> section and continue
@ -626,17 +641,17 @@ _pleskxml_get_domain_ID() {
# Result should contain precisely one <filter-id> section, containing the domain name inquired.
# 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 "$LINENO"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 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'
_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"
_err"$_pleskxml_errors"
return1
return1
else
else
# So far so good. Remove the <filter-id>...</filter-id> section and continue
# So far so good. Remove the <filter-id>...</filter-id> section and continue
@ -647,12 +662,12 @@ _pleskxml_get_domain_ID() {
# All that should be left is one section, containing <id>DOMAIN_ID</id>
# All that should be left is one section, containing <id>DOMAIN_ID</id>
_DBG 2"Remaining part of result is now: '$_pleskxml_result' "
_DBG "$LINENO"2"Remaining part of result is now: '$_pleskxml_result' "
# Error - doesn't contain just <id>NUMBERS</id>. Something's wrong. Abort
# 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'
_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'
# Error - doesn't contain just <id>NUMBERS</id>. Something's wrong. Abort
# 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'
_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"
_err"$_pleskxml_errors"
return1
return1
fi
fi
@ -748,33 +766,35 @@ _pleskxml_add_txt_record() {
| sed -E "s/^<result><id>([0-9]+)<\/id><\/result>$/\1/"
| 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'
_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'
_info "Couldn't find a TXT record matching the requested host/value. Not an error, but a concern..."
_info "Couldn't find a TXT record matching the requested host/value. Not an error, but a concern..."
_DBG 2"Exiting Plesk _pleskxml_rmv_txt_record (without raising an error), as nothing more to do: the record requested for deletion doesn't exist"
_DBG "$LINENO"2"Exiting Plesk _pleskxml_rmv_txt_record (without raising an error), as nothing more to do: the record requested for deletion doesn't exist"