fix: poweradmin dnsapi leaves hanging txt records (#7232)

* fix: improved record txt record matching

matching txt records sometimes failed if they contained certain chars causing leftover challenges in dns zone

* fix(dns_poweradmin): use portable record and zone matching

grep -o and grep -F are not supported by Solaris /usr/bin/grep.
Split JSON objects with the core _egrep_o wrapper and match name,
type and content with case, which is literal by construction. Loop
over a here-doc since case inside $(...) breaks bash 3.2 and
Solaris sh. Apply the same to _get_root.

Drop _json_escape: hostnames and base64url challenge values cannot
contain quotes or backslashes, so escaping was a no-op.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: neil <github@neilpang.com>
Co-authored-by: Jakob Næss <jakob@itsjefen.no>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-10-03 07:48:58 +02:00
1 parent acbe85b7e9
commit b2e6173b1a
1 file changed
+34 -18
+34 -18
View File
@@ -114,21 +114,32 @@ _rm_record() {
full=$1
txtvalue=$2
if ! _poweradmin_rest "GET" "/api/v${POWERADMIN_API_VERSION}/zones/$_zone_id/records"; then
if ! _poweradmin_rest "GET" "/api/v${POWERADMIN_API_VERSION}/zones/$_zone_id/records?type=TXT"; then
_err "Failed to retrieve records"
return 1
fi
# The API returns: {"success":true,"data":[{"id":..., "name":"...", "type":"TXT", "content":"...", ...}]}
_txt_record_obj=$(
printf '%s\n' "$response" |
sed 's/^.*"data":\[//; s/\],"message":.*$//' |
awk '{ gsub(/},{/, "}\n{"); print }' |
grep -F "\"name\":\"$full\"" |
grep -F "\"type\":\"TXT\"" |
grep -F "\"content\":\"$txtvalue\"" |
_head_n 1
)
# The API returns: {"success":true,"data":{"records":[{"id":..., "name":"...", "type":"TXT", "content":"...", ...}]},"message":"..."}
_records="$(printf '%s\n' "$response" | tr -d '\r\n' | _egrep_o '\{[^{}]*\}')"
_txt_record_obj=""
while IFS= read -r _rec || [ -n "$_rec" ]; do
case "$_rec" in
*"\"name\":\"$full\""*) ;;
*) continue ;;
esac
case "$_rec" in
*"\"type\":\"TXT\""*) ;;
*) continue ;;
esac
case "$_rec" in
*"\"content\":\"$txtvalue\""*)
_txt_record_obj="$_rec"
break
;;
esac
done <<EOF
$_records
EOF
if [ -z "$_txt_record_obj" ]; then
_info "TXT record not found for $full with content $txtvalue"
@@ -173,7 +184,7 @@ _get_root() {
return 1
fi
_zones_response="$response"
_zones="$(printf '%s\n' "$response" | tr -d '\r\n' | _egrep_o '\{[^{}]*\}')"
while true; do
h=$(printf "%s" "$domain" | cut -d . -f "$i"-100)
@@ -183,12 +194,17 @@ _get_root() {
return 1
fi
zone_obj=$(
printf '%s' "$_zones_response" |
sed 's/},{/}\n{/g' |
grep -F "\"name\":\"$h\"" |
_head_n 1
)
zone_obj=""
while IFS= read -r _zone || [ -n "$_zone" ]; do
case "$_zone" in
*"\"name\":\"$h\""*)
zone_obj="$_zone"
break
;;
esac
done <<EOF
$_zones
EOF
if [ -n "$zone_obj" ]; then
_zone_id=$(printf '%s' "$zone_obj" | _egrep_o '"id":[0-9][0-9]*' | _head_n 1 | cut -d: -f2)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.