Skip to content

Commit

Permalink
fix TXT record lookup and removal
Browse files Browse the repository at this point in the history
  • Loading branch information
zak905 committed Apr 24, 2024
1 parent 4c09bca commit 33b3645
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions dnsapi/dns_ionos.sh
Expand Up @@ -39,7 +39,8 @@ dns_ionos_add() {
return 0
fi
else
_body="{\"properties\":{\"name\":\"$fulldomain\", \"type\":\"TXT\", \"content\":\"$txtvalue\"}}"
_record_name=$(printf "%s" "$fulldomain" | cut -d . -f 1)
_body="{\"properties\":{\"name\":\"$_record_name\", \"type\":\"TXT\", \"content\":\"$txtvalue\"}}"

if _ionos_cloud_rest POST "$IONOS_CLOUD_ROUTE_ZONES/$_zone_id/records" "$_body" && [ "$_code" = "202" ]; then
_info "TXT record has been created successfully."
Expand Down Expand Up @@ -69,7 +70,8 @@ dns_ionos_rm() {
return 0
fi
else
if ! _ionos_cloud_get_record "$fulldomain" "$_zone_id" "$txtvalue"; then
_record_name=$(printf "%s" "$fulldomain" | cut -d . -f 1)
if ! _ionos_cloud_get_record "$_record_name" "$_zone_id" "$txtvalue"; then
_err "Could not find _acme-challenge TXT record."
return 1
fi
Expand Down Expand Up @@ -202,14 +204,14 @@ _ionos_get_record() {
}

_ionos_cloud_get_record() {
fulldomain=$1
_record_name=$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\\\\\"\".*\}")"
_record="$(echo "$_response" | _egrep_o "\"name\":\"$_record_name\"[^\}]*\"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 '\"')

Expand Down

0 comments on commit 33b3645

Please sign in to comment.