Browse Source

implement dns_ionos_rm function

pull/5110/head
zak905 8 months ago
parent
commit
f35e15204d
  1. 78
      dnsapi/dns_ionos.sh

78
dnsapi/dns_ionos.sh

@ -58,6 +58,7 @@ dns_ionos_rm() {
return 1 return 1
fi fi
if [ $_context == "core" ];then
if ! _ionos_get_record "$fulldomain" "$_zone_id" "$txtvalue"; then if ! _ionos_get_record "$fulldomain" "$_zone_id" "$txtvalue"; then
_err "Could not find _acme-challenge TXT record." _err "Could not find _acme-challenge TXT record."
return 1 return 1
@ -67,6 +68,18 @@ dns_ionos_rm() {
_info "TXT record has been deleted successfully." _info "TXT record has been deleted successfully."
return 0 return 0
fi fi
else
if ! _ionos_cloud_get_record "$fulldomain" "$_zone_id" "$txtvalue"; then
_err "Could not find _acme-challenge TXT record."
return 1
fi
if _ionos_cloud_rest DELETE "$IONOS_CLOUD_ROUTE_ZONES/$_zone_id/records/$_record_id" && [ "$_code" = "200" ]; then
_info "TXT record has been deleted successfully."
return 0
fi
fi
return 1 return 1
} }
@ -76,7 +89,7 @@ _ionos_init() {
IONOS_SECRET="${IONOS_SECRET:-$(_readaccountconf_mutable IONOS_SECRET)}" IONOS_SECRET="${IONOS_SECRET:-$(_readaccountconf_mutable IONOS_SECRET)}"
IONOS_TOKEN="${IONOS_TOKEN:-$(_readaccountconf_mutable IONOS_TOKEN)}" IONOS_TOKEN="${IONOS_TOKEN:-$(_readaccountconf_mutable IONOS_TOKEN)}"
if [ -n "$IONOS_PREFIX" ] || [ -n "$IONOS_SECRET" ]; then
if [ -n "$IONOS_PREFIX" ] && [ -n "$IONOS_SECRET" ]; then
_info "You have specified an IONOS api prefix and secret." _info "You have specified an IONOS api prefix and secret."
_info "The script will use the IONOS DNS API: $IONOS_API" _info "The script will use the IONOS DNS API: $IONOS_API"
@ -100,7 +113,7 @@ _ionos_init() {
fi fi
$_context="cloud" $_context="cloud"
else else
_err "You didn't specify an IONOS credentials yet."
_err "You didn't specify any IONOS credentials yet."
_err "If you are using the IONOS DNS API, Read https://beta.developer.hosting.ionos.de/docs/getstarted to learn how to get a prefix and secret." _err "If you are using the IONOS DNS API, Read https://beta.developer.hosting.ionos.de/docs/getstarted to learn how to get a prefix and secret."
_err "If you are using the IONOS Cloud DNS API, Read https://api.ionos.com/docs/authentication/v1/#tag/tokens/operation/tokensGenerate to learn how to get a token." _err "If you are using the IONOS Cloud DNS API, Read https://api.ionos.com/docs/authentication/v1/#tag/tokens/operation/tokensGenerate to learn how to get a token."
_err "" _err ""
@ -116,27 +129,6 @@ _ionos_init() {
return 0 return 0
} }
_get_cloud_zone() {
zone=$1
i=1
p=1
if _ionos_cloud_rest GET "$IONOS_ROUTE_ZONES?filter.zoneName=$zone"; then
_response="$(echo "$_response" | tr -d "\n")"
_zone="$(echo "$_response" | _egrep_o "\"name\":\"$zone\".*\}")"
if [ "$_zone" ]; then
_zone_id=$(printf "%s\n" "$_zone" | _egrep_o "\"id\":\"[a-fA-F0-9\-]*\"" | _head_n 1 | cut -d : -f 2 | tr -d '\"')
if [ "$_zone_id" ]; then
return 0
fi
return 1
fi
fi
return 1
}
_get_root() { _get_root() {
domain=$1 domain=$1
i=1 i=1
@ -172,6 +164,27 @@ _get_root() {
return 1 return 1
} }
_get_cloud_zone() {
zone=$1
i=1
p=1
if _ionos_cloud_rest GET "$IONOS_CLOUD_ROUTE_ZONES?filter.zoneName=$zone"; then
_response="$(echo "$_response" | tr -d "\n")"
_zone="$(echo "$_response" | _egrep_o "\"name\":\"$zone\".*\}")"
if [ "$_zone" ]; then
_zone_id=$(printf "%s\n" "$_zone" | _egrep_o "\"id\":\"[a-fA-F0-9\-]*\"" | _head_n 1 | cut -d : -f 2 | tr -d '\"')
if [ "$_zone_id" ]; then
return 0
fi
return 1
fi
fi
return 1
}
_ionos_get_record() { _ionos_get_record() {
fulldomain=$1 fulldomain=$1
zone_id=$2 zone_id=$2
@ -191,6 +204,25 @@ _ionos_get_record() {
return 1 return 1
} }
_ionos_cloud_get_record() {
fulldomain=$1
zone_id=$2
txtrecord=$3
if _ionos_cloud_rest GET "$IONOS_ROUTE_ZONES/$zone_id/records"; then
_response="$(echo "$_response" | tr -d "\n")"
_record="$(echo "$_response" | _egrep_o "\"name\":\"$fulldomain\"[^\}]*\"type\":\"TXT\"[^\}]*\"content\":\"\\\\\"$txtrecord\\\\\"\".*\}")"
if [ "$_record" ]; then
_record_id=$(printf "%s\n" "$_record" | _egrep_o "\"id\":\"[a-fA-F0-9\-]*\"" | _head_n 1 | cut -d : -f 2 | tr -d '\"')
return 0
fi
fi
return 1
}
_ionos_rest() { _ionos_rest() {
method="$1" method="$1"
route="$2" route="$2"

Loading…
Cancel
Save