]> git.proxmox.com Git - mirror_acme.sh.git/blame - dnsapi/dns_rage4.sh
fix: use update instead of remove then add
[mirror_acme.sh.git] / dnsapi / dns_rage4.sh
CommitLineData
60bcee8c
SR
1#!/usr/bin/env sh
2
3#
4#RAGE4_TOKEN="sdfsdfsdfljlbjkljlkjsdfoiwje"
5#
6#RAGE4_USERNAME="xxxx@sss.com"
7
8RAGE4_Api="https://rage4.com/rapi/"
9
10######## Public functions #####################
11
12#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
13dns_rage4_add() {
14 fulldomain=$1
15 txtvalue=$2
16
17 unquotedtxtvalue=$(echo "$txtvalue" | tr -d \")
18
19 RAGE4_USERNAME="${RAGE4_USERNAME:-$(_readaccountconf_mutable RAGE4_USERNAME)}"
20 RAGE4_TOKEN="${RAGE4_TOKEN:-$(_readaccountconf_mutable RAGE4_TOKEN)}"
21
22 if [ -z "$RAGE4_USERNAME" ] || [ -z "$RAGE4_TOKEN" ]; then
23 RAGE4_USERNAME=""
24 RAGE4_TOKEN=""
25 _err "You didn't specify a Rage4 api token and username yet."
26 return 1
27 fi
28
29 #save the api key and email to the account conf file.
30 _saveaccountconf_mutable RAGE4_USERNAME "$RAGE4_USERNAME"
31 _saveaccountconf_mutable RAGE4_TOKEN "$RAGE4_TOKEN"
32
33 _debug "First detect the root zone"
34 if ! _get_root "$fulldomain"; then
35 _err "invalid domain"
36 return 1
37 fi
38 _debug _domain_id "$_domain_id"
39
40 _rage4_rest "createrecord/?id=$_domain_id&name=$fulldomain&content=$unquotedtxtvalue&type=TXT&active=true&ttl=1"
41 return 0
42}
43
44#fulldomain txtvalue
45dns_rage4_rm() {
46 fulldomain=$1
47 txtvalue=$2
48
49 RAGE4_USERNAME="${RAGE4_USERNAME:-$(_readaccountconf_mutable RAGE4_USERNAME)}"
50 RAGE4_TOKEN="${RAGE4_TOKEN:-$(_readaccountconf_mutable RAGE4_TOKEN)}"
51
52 _debug "First detect the root zone"
53 if ! _get_root "$fulldomain"; then
54 _err "invalid domain"
55 return 1
56 fi
57 _debug _domain_id "$_domain_id"
58
59 _debug "Getting txt records"
60 _rage4_rest "getrecords/?id=${_domain_id}"
61
62 _record_id=$(echo "$response" | sed -rn 's/.*"id":([[:digit:]]+)[^\}]*'"$txtvalue"'.*/\1/p')
63 _rage4_rest "deleterecord/?id=${_record_id}"
64 return 0
65}
66
67#################### Private functions below ##################################
68#_acme-challenge.www.domain.com
69#returns
70# _domain=domain.com
71# _domain_id=sdjkglgdfewsdfg
72_get_root() {
73 domain=$1
74
75 if ! _rage4_rest "getdomains"; then
76 return 1
77 fi
78 _debug _get_root_domain "$domain"
79
80 for line in $(echo "$response" | tr '}' '\n'); do
81 __domain=$(echo "$line" | sed -rn 's/.*"name":"([^"]*)",.*/\1/p')
82 __domain_id=$(echo "$line" | sed -rn 's/.*"id":([^,]*),.*/\1/p')
83 if [ "$domain" != "${domain%"$__domain"*}" ]; then
84 _domain_id="$__domain_id"
85 break
86 fi
87 done
88
89 if [ -z "$_domain_id" ]; then
90 return 1
91 fi
92
93 return 0
94}
95
96_rage4_rest() {
97 ep="$1"
98 _debug "$ep"
99
100 username_trimmed=$(echo "$RAGE4_USERNAME" | tr -d '"')
101 token_trimmed=$(echo "$RAGE4_TOKEN" | tr -d '"')
102 auth=$(printf '%s:%s' "$username_trimmed" "$token_trimmed" | _base64)
103
104 export _H1="Content-Type: application/json"
105 export _H2="Authorization: Basic $auth"
106
107 response="$(_get "$RAGE4_Api$ep")"
108
109 if [ "$?" != "0" ]; then
110 _err "error $ep"
111 return 1
112 fi
113 _debug2 response "$response"
114 return 0
115}