@@ -42,6 +42,14 @@ dns_rage4_add() {
4242 _debug _domain_id " $_domain_id "
4343
4444 _rage4_rest " createrecord/?id=$_domain_id &name=$fulldomain &content=$unquotedtxtvalue &type=TXT&active=true&ttl=1"
45+
46+ # Response after adding a TXT record should be something like this:
47+ # {"status":true,"id":28160443,"error":null}
48+ if ! _contains " $response " ' "error":null' > /dev/null; then
49+ _err " Error while adding TXT record: '$response '"
50+ return 1
51+ fi
52+
4553 return 0
4654}
4755
@@ -63,7 +71,12 @@ dns_rage4_rm() {
6371 _debug " Getting txt records"
6472 _rage4_rest " getrecords/?id=${_domain_id} "
6573
66- _record_id=$( echo " $response " | sed -rn ' s/.*"id":([[:digit:]]+)[^\}]*' " $txtvalue " ' .*/\1/p' )
74+ _record_id=$( echo " $response " | tr ' {' ' \n' | grep ' "TXT"' | grep " \" $txtvalue " | sed -rn ' s/.*"id":([[:digit:]]+),.*/\1/p' )
75+ if [ -z " $_record_id " ]; then
76+ _err " error retrieving the record_id of the new TXT record in order to delete it, got: '$_record_id '."
77+ return 1
78+ fi
79+
6780 _rage4_rest " deleterecord/?id=${_record_id} "
6881 return 0
6982}
@@ -105,8 +118,7 @@ _rage4_rest() {
105118 token_trimmed=$( echo " $RAGE4_TOKEN " | tr -d ' "' )
106119 auth=$( printf ' %s:%s' " $username_trimmed " " $token_trimmed " | _base64)
107120
108- export _H1=" Content-Type: application/json"
109- export _H2=" Authorization: Basic $auth "
121+ export _H1=" Authorization: Basic $auth "
110122
111123 response=" $( _get " $RAGE4_Api$ep " ) "
112124
0 commit comments