Skip to content

Commit

Permalink
fix: rage4 - add error 400 and TXT cleanup
Browse files Browse the repository at this point in the history
    The following error happens if the header is set
    to 'Content-Type: application/json':

        {"statusCode":400,"message":"One or more errors occurred!",
        "errors":{"serializerErrors":["The input does not contain
        any JSON tokens. Expected the input to start with a valid
        JSON token, when isFinalBlock is true. LineNumber:
        0 | BytePositionInLine: 0."]}}

    Fix TXT removal
  • Loading branch information
aorith committed Jul 5, 2024
1 parent 65868ab commit 2beb2f5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions dnsapi/dns_rage4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ dns_rage4_add() {
_debug _domain_id "$_domain_id"

_rage4_rest "createrecord/?id=$_domain_id&name=$fulldomain&content=$unquotedtxtvalue&type=TXT&active=true&ttl=1"

# Response after adding a TXT record should be something like this:
# {"status":true,"id":28160443,"error":null}
if ! _contains "$response" '"error":null' >/dev/null; then
_err "Error while adding TXT record: '$response'"
return 1
fi

return 0
}

Expand All @@ -63,7 +71,12 @@ dns_rage4_rm() {
_debug "Getting txt records"
_rage4_rest "getrecords/?id=${_domain_id}"

_record_id=$(echo "$response" | sed -rn 's/.*"id":([[:digit:]]+)[^\}]*'"$txtvalue"'.*/\1/p')
_record_id=$(echo "$response" | tr '{' '\n' | grep '"TXT"' | grep "\"$txtvalue" | sed -rn 's/.*"id":([[:digit:]]+),.*/\1/p')
if [ -z "$_record_id" ]; then
_err "error retrieving the record_id of the new TXT record in order to delete it, got: '$_record_id'."
return 1
fi

_rage4_rest "deleterecord/?id=${_record_id}"
return 0
}
Expand Down Expand Up @@ -105,8 +118,7 @@ _rage4_rest() {
token_trimmed=$(echo "$RAGE4_TOKEN" | tr -d '"')
auth=$(printf '%s:%s' "$username_trimmed" "$token_trimmed" | _base64)

export _H1="Content-Type: application/json"
export _H2="Authorization: Basic $auth"
export _H1="Authorization: Basic $auth"

response="$(_get "$RAGE4_Api$ep")"

Expand Down

0 comments on commit 2beb2f5

Please sign in to comment.