5 ARVAN_API_URL
="https://napi.arvancloud.com/cdn/4.0/domains"
7 #Author: Ehsan Aliakbar
8 #Report Bugs here: https://github.com/Neilpang/acme.sh
10 ######## Public functions #####################
12 #Usage: dns_arvan_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
18 Arvan_Token
="${Arvan_Token:-$(_readaccountconf_mutable Arvan_Token)}"
20 if [ -z "$Arvan_Token" ]; then
21 _err
"You didn't specify \"Arvan_Token\" token yet."
22 _err
"You can get yours from here https://npanel.arvancloud.com/profile/api-keys"
25 #save the api token to the account conf file.
26 _saveaccountconf_mutable Arvan_Token
"$Arvan_Token"
28 _debug
"First detect the root zone"
29 if ! _get_root
"$fulldomain"; then
34 _debug _domain_id
"$_domain_id"
35 _debug _sub_domain
"$_sub_domain"
36 _debug _domain
"$_domain"
39 if _arvan_rest POST
"$_domain/dns-records" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"value\":{\"text\":\"$txtvalue\"},\"ttl\":120}"; then
40 if _contains
"$response" "$txtvalue"; then
43 elif _contains
"$response" "Record Data is Duplicated"; then
44 _info
"Already exists, OK"
47 _err
"Add txt record error."
51 _err
"Add txt record error."
55 #Usage: fulldomain txtvalue
56 #Remove the txt record after validation.
61 _debug fulldomain
"$fulldomain"
62 _debug txtvalue
"$txtvalue"
64 Arvan_Token
="${Arvan_Token:-$(_readaccountconf_mutable Arvan_Token)}"
66 _debug
"First detect the root zone"
67 if ! _get_root
"$fulldomain"; then
71 _debug _domain_id
"$_domain_id"
72 _debug _sub_domain
"$_sub_domain"
73 _debug _domain
"$_domain"
75 _debug
"Getting txt records"
76 shorted_txtvalue
=$
(printf "%s" "$txtvalue" | cut
-d "-" -d "_" -f1)
77 _arvan_rest GET
"${_domain}/dns-records?search=$shorted_txtvalue"
79 if ! printf "%s" "$response" |
grep \"current_page
\":1 >/dev
/null
; then
80 _err
"Error on Arvan Api"
81 _err
"Please create a github issue with debbug log"
85 count
=$
(printf "%s\n" "$response" | _egrep_o
"\"total\":[^,]*" | cut
-d : -f 2)
87 if [ "$count" = "0" ]; then
88 _info
"Don't need to remove."
90 record_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"id\":\"[^\"]*\"" | cut
-d : -f 2 |
tr -d \" |
head -n 1)
91 _debug
"record_id" "$record_id"
92 if [ -z "$record_id" ]; then
93 _err
"Can not get record id to remove."
96 if ! _arvan_rest
"DELETE" "${_domain}/dns-records/$record_id"; then
97 _err
"Delete record error."
101 _contains
"$response" 'dns record deleted'
105 #################### Private functions below ##################################
107 #_acme-challenge.www.domain.com
109 # _sub_domain=_acme-challenge.www
111 # _domain_id=sdjkglgdfewsdfg
117 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
124 if ! _arvan_rest GET
"?search=$h"; then
128 if _contains
"$response" "\"domain\":\"$h\"" || _contains
"$response" '"total":1'; then
129 _domain_id
=$
(echo "$response" | _egrep_o
"\[.\"id\":\"[^\"]*\"" | _head_n
1 | cut
-d : -f 2 |
tr -d \")
130 if [ "$_domain_id" ]; then
131 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
148 token_trimmed
=$
(echo "$Arvan_Token" |
tr -d '"')
150 export _H1
="Authorization: $token_trimmed"
152 if [ "$mtd" = "DELETE" ]; then
153 #DELETE Request shouldn't have Content-Type
155 response
="$(_post "$data" "$ARVAN_API_URL/$ep" "" "$mtd")"
156 elif [ "$mtd" = "POST" ]; then
157 export _H2
="Content-Type: application/json"
159 response
="$(_post "$data" "$ARVAN_API_URL/$ep" "" "$mtd")"
161 response
="$(_get "$ARVAN_API_URL/$ep$data")"