4 #GCORE_Key='773$7b7adaf2a2b32bfb1b83787b4ff32a67eb178e3ada1af733e47b1411f2461f7f4fa7ed7138e2772a46124377bad7384b3bb8d87748f87b3f23db4b8bbe41b2bb'
7 GCORE_Api
="https://api.gcorelabs.com/dns/v2"
8 GCORE_Doc
="https://apidocs.gcore.com/dns"
10 ######## Public functions #####################
12 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
17 GCORE_Key
="${GCORE_Key:-$(_readaccountconf_mutable GCORE_Key)}"
19 if [ -z "$GCORE_Key" ]; then
21 _err
"You didn't specify a Gcore api key yet."
22 _err
"You can get yours from here $GCORE_Doc"
26 #save the api key to the account conf file.
27 _saveaccountconf_mutable GCORE_Key
"$GCORE_Key"
29 _debug
"First detect the zone name"
30 if ! _get_root
"$fulldomain"; then
34 _debug _zone_name
"$_zone_name"
35 _debug _sub_domain
"$_sub_domain"
36 _debug _domain
"$_domain"
38 _debug
"Getting txt records"
39 _gcore_rest GET
"zones/$_zone_name/$fulldomain/TXT"
42 if echo "$response" |
grep "record is not found" >/dev
/null
; then
43 _info
"Record doesn't exists"
44 payload
="{\"resource_records\":[{\"content\":[\"$txtvalue\"],\"enabled\":true}],\"ttl\":120}"
45 elif echo "$response" |
grep "$txtvalue" >/dev
/null
; then
46 _info
"Already exists, OK"
48 elif echo "$response" |
tr -d " " |
grep \"name
\":\""$fulldomain"\",\"type\":\"TXT
\" >/dev
/null
; then
49 _info
"Record with mismatch txtvalue, try update it"
50 payload
=$
(echo "$response" |
tr -d " " |
sed 's/"updated_at":[0-9]\+,//g' |
sed 's/"meta":{}}]}/"meta":{}},{"content":['\""$txtvalue"\"'],"enabled":true}]}/')
53 # For wildcard cert, the main root domain and the wildcard domain have the same txt subdomain name, so
54 # we can not use updating anymore.
55 # count=$(printf "%s\n" "$response" | _egrep_o "\"count\":[^,]*" | cut -d : -f 2)
56 # _debug count "$count"
57 # if [ "$count" = "0" ]; then
59 if _gcore_rest PUT
"zones/$_zone_name/$fulldomain/TXT" "$payload"; then
60 if _contains
"$response" "$txtvalue"; then
63 elif _contains
"$response" "rrset is already exists"; then
64 _info
"Already exists, OK"
67 _err
"Add txt record error."
71 _err
"Add txt record error."
80 GCORE_Key
="${GCORE_Key:-$(_readaccountconf_mutable GCORE_Key)}"
82 _debug
"First detect the root zone"
83 if ! _get_root
"$fulldomain"; then
87 _debug _zone_name
"$_zone_name"
88 _debug _sub_domain
"$_sub_domain"
89 _debug _domain
"$_domain"
91 _debug
"Getting txt records"
92 _gcore_rest GET
"zones/$_zone_name/$fulldomain/TXT"
94 if echo "$response" |
grep "record is not found" >/dev
/null
; then
95 _info
"No such txt recrod"
99 if ! echo "$response" |
tr -d " " |
grep \"name
\":\""$fulldomain"\",\"type\":\"TXT
\" >/dev
/null
; then
100 _err
"Error: $response"
104 if ! echo "$response" |
tr -d " " |
grep \""$txtvalue"\" >/dev
/null
; then
105 _info
"No such txt recrod"
109 count
="$(echo "$response" | grep -o "content
" | wc -l)"
111 if [ "$count" = "1" ]; then
112 if ! _gcore_rest DELETE
"zones/$_zone_name/$fulldomain/TXT"; then
113 _err
"Delete record error. $response"
119 payload
="$(echo "$response" | tr -d " " | sed 's/"updated_at
":[0-9]\+,//g' | sed 's/{"id
":[0-9]\+,"content
":\["'"$txtvalue"'"\],"enabled
":true,"meta
":{}}//' | sed 's/\[,/\[/' | sed 's/,,/,/' | sed 's/,\]/\]/')"
120 if ! _gcore_rest PUT
"zones/$_zone_name/$fulldomain/TXT" "$payload"; then
121 _err
"Delete record error. $response"
125 #################### Private functions below ##################################
126 #_acme-challenge.sub.domain.com
128 # _sub_domain=_acme-challenge.sub or _acme-challenge
130 # _zone_name=domain.com or sub.domain.com
137 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
144 if ! _gcore_rest GET
"zones/$h"; then
148 if _contains
"$response" "\"name\":\"$h\""; then
150 if [ "$_zone_name" ]; then
151 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
169 key_trimmed
=$
(echo "$GCORE_Key" |
tr -d '"')
171 export _H1
="Content-Type: application/json"
172 export _H2
="Authorization: APIKey $key_trimmed"
174 if [ "$m" != "GET" ]; then
176 response
="$(_post "$data" "$GCORE_Api/$ep" "" "$m")"
178 response
="$(_get "$GCORE_Api/$ep")"
181 if [ "$?" != "0" ]; then
185 _debug2 response
"$response"