3 # Author: Boyan Peychev <boyan at cloudns dot net>
4 # Repository: https://github.com/ClouDNS/acme.sh/
7 #CLOUDNS_SUB_AUTH_ID=XXXXX
8 #CLOUDNS_AUTH_PASSWORD="YYYYYYYYY"
9 CLOUDNS_API
="https://api.cloudns.net"
11 ######## Public functions #####################
13 #Usage: dns_cloudns_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
17 if ! _dns_cloudns_init_check
; then
21 zone
="$(_dns_cloudns_get_zone_name "$1")"
22 if [ -z "$zone" ]; then
23 _err
"Missing DNS zone at ClouDNS. Please log into your control panel and create the required DNS zone for the initial setup."
27 host="$(echo "$1" | sed "s
/\.
$zone\$
//")"
32 _debug record
"$record"
34 _info
"Adding the TXT record for $1"
35 _dns_cloudns_http_api_call
"dns/add-record.json" "domain-name=$zone&record-type=TXT&host=$host&record=$record&ttl=60"
36 if ! _contains
"$response" "\"status\":\"Success\""; then
37 _err
"Record cannot be added."
45 #Usage: dns_cloudns_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
49 if ! _dns_cloudns_init_check
; then
53 if [ -z "$zone" ]; then
54 zone
="$(_dns_cloudns_get_zone_name "$1")"
55 if [ -z "$zone" ]; then
56 _err
"Missing DNS zone at ClouDNS. Please log into your control panel and create the required DNS zone for the initial setup."
61 host="$(echo "$1" | sed "s
/\.
$zone\$
//")"
64 _dns_cloudns_http_api_call
"dns/records.json" "domain-name=$zone&host=$host&type=TXT"
65 if ! _contains
"$response" "\"id\":"; then
69 for i
in $
(echo "$response" |
tr '{' "\n" |
grep "$record"); do
70 record_id
=$
(echo "$i" |
tr ',' "\n" |
grep -E '^"id"' |
sed -re 's/^\"id\"\:\"([0-9]+)\"$/\1/g')
72 if [ ! -z "$record_id" ]; then
75 _debug record
"$record"
76 _debug record_id
"$record_id"
78 _info
"Deleting the TXT record for $1"
79 _dns_cloudns_http_api_call
"dns/delete-record.json" "domain-name=$zone&record-id=$record_id"
81 if ! _contains
"$response" "\"status\":\"Success\""; then
82 _err
"The TXT record for $1 cannot be deleted."
92 #################### Private functions below ##################################
93 _dns_cloudns_init_check
() {
94 if [ ! -z "$CLOUDNS_INIT_CHECK_COMPLETED" ]; then
98 CLOUDNS_AUTH_ID
="${CLOUDNS_AUTH_ID:-$(_readaccountconf_mutable CLOUDNS_AUTH_ID)}"
99 CLOUDNS_SUB_AUTH_ID
="${CLOUDNS_SUB_AUTH_ID:-$(_readaccountconf_mutable CLOUDNS_SUB_AUTH_ID)}"
100 CLOUDNS_AUTH_PASSWORD
="${CLOUDNS_AUTH_PASSWORD:-$(_readaccountconf_mutable CLOUDNS_AUTH_PASSWORD)}"
101 if [ -z "$CLOUDNS_AUTH_ID$CLOUDNS_SUB_AUTH_ID" ] ||
[ -z "$CLOUDNS_AUTH_PASSWORD" ]; then
103 CLOUDNS_SUB_AUTH_ID
=""
104 CLOUDNS_AUTH_PASSWORD
=""
105 _err
"You don't specify cloudns api id and password yet."
106 _err
"Please create you id and password and try again."
110 if [ -z "$CLOUDNS_AUTH_ID" ] && [ -z "$CLOUDNS_SUB_AUTH_ID" ]; then
111 _err
"CLOUDNS_AUTH_ID or CLOUDNS_SUB_AUTH_ID is not configured"
115 if [ -z "$CLOUDNS_AUTH_PASSWORD" ]; then
116 _err
"CLOUDNS_AUTH_PASSWORD is not configured"
120 _dns_cloudns_http_api_call
"dns/login.json" ""
122 if ! _contains
"$response" "\"status\":\"Success\""; then
123 _err
"Invalid CLOUDNS_AUTH_ID or CLOUDNS_AUTH_PASSWORD. Please check your login credentials."
127 # save the api id and password to the account conf file.
128 _saveaccountconf_mutable CLOUDNS_AUTH_ID
"$CLOUDNS_AUTH_ID"
129 _saveaccountconf_mutable CLOUDNS_SUB_AUTH_ID
"$CLOUDNS_SUB_AUTH_ID"
130 _saveaccountconf_mutable CLOUDNS_AUTH_PASSWORD
"$CLOUDNS_AUTH_PASSWORD"
132 CLOUDNS_INIT_CHECK_COMPLETED
=1
137 _dns_cloudns_get_zone_name
() {
140 zoneForCheck
=$
(printf "%s" "$1" | cut
-d .
-f $i-100)
142 if [ -z "$zoneForCheck" ]; then
146 _debug zoneForCheck
"$zoneForCheck"
148 _dns_cloudns_http_api_call
"dns/get-zone-info.json" "domain-name=$zoneForCheck"
150 if ! _contains
"$response" "\"status\":\"Failed\""; then
160 _dns_cloudns_http_api_call
() {
163 _debug CLOUDNS_AUTH_ID
"$CLOUDNS_AUTH_ID"
164 _debug CLOUDNS_SUB_AUTH_ID
"$CLOUDNS_SUB_AUTH_ID"
165 _debug CLOUDNS_AUTH_PASSWORD
"$CLOUDNS_AUTH_PASSWORD"
167 if [ ! -z "$CLOUDNS_SUB_AUTH_ID" ]; then
168 auth_user
="sub-auth-id=$CLOUDNS_SUB_AUTH_ID"
170 auth_user
="auth-id=$CLOUDNS_AUTH_ID"
174 data
="$auth_user&auth-password=$CLOUDNS_AUTH_PASSWORD"
176 data
="$auth_user&auth-password=$CLOUDNS_AUTH_PASSWORD&$2"
179 response
="$(_get "$CLOUDNS_API/$method?
$data")"
181 _debug response
"$response"