3 # Author: Boyan Peychev <boyan at cloudns dot net>
4 # Repository: https://github.com/ClouDNS/acme.sh/
5 # Editor: I Komang Suryadana
8 #CLOUDNS_SUB_AUTH_ID=XXXXX
9 #CLOUDNS_AUTH_PASSWORD="YYYYYYYYY"
10 CLOUDNS_API
="https://api.cloudns.net"
14 ######## Public functions #####################
16 #Usage: dns_cloudns_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
20 if ! _dns_cloudns_init_check
; then
24 zone
="$(_dns_cloudns_get_zone_name "$1")"
25 if [ -z "$zone" ]; then
26 _err
"Missing DNS zone at ClouDNS. Please log into your control panel and create the required DNS zone for the initial setup."
30 host="$(echo "$1" | sed "s
/\.
$zone\$
//")"
35 _debug record
"$record"
37 _info
"Adding the TXT record for $1"
38 _dns_cloudns_http_api_call
"dns/add-record.json" "domain-name=$zone&record-type=TXT&host=$host&record=$record&ttl=60"
39 if ! _contains
"$response" "\"status\":\"Success\""; then
40 _err
"Record cannot be added."
48 #Usage: dns_cloudns_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
52 if ! _dns_cloudns_init_check
; then
56 if [ -z "$zone" ]; then
57 zone
="$(_dns_cloudns_get_zone_name "$1")"
58 if [ -z "$zone" ]; then
59 _err
"Missing DNS zone at ClouDNS. Please log into your control panel and create the required DNS zone for the initial setup."
64 host="$(echo "$1" | sed "s
/\.
$zone\$
//")"
67 _dns_cloudns_get_zone_info
"$zone"
69 _debug
"Type" "$DOMAIN_TYPE"
70 _debug
"Cloud Master" "$DOMAIN_MASTER"
71 if _contains
"$DOMAIN_TYPE" "cloud"; then
76 _dns_cloudns_http_api_call
"dns/records.json" "domain-name=$zone&host=$host&type=TXT"
77 if ! _contains
"$response" "\"id\":"; then
81 for i
in $
(echo "$response" |
tr '{' "\n" |
grep "$record"); do
82 record_id
=$
(echo "$i" |
tr ',' "\n" |
grep -E '^"id"' |
sed -re 's/^\"id\"\:\"([0-9]+)\"$/\1/g')
84 if [ -n "$record_id" ]; then
87 _debug record
"$record"
88 _debug record_id
"$record_id"
90 _info
"Deleting the TXT record for $1"
91 _dns_cloudns_http_api_call
"dns/delete-record.json" "domain-name=$zone&record-id=$record_id"
93 if ! _contains
"$response" "\"status\":\"Success\""; then
94 _err
"The TXT record for $1 cannot be deleted."
104 #################### Private functions below ##################################
105 _dns_cloudns_init_check
() {
106 if [ -n "$CLOUDNS_INIT_CHECK_COMPLETED" ]; then
110 CLOUDNS_AUTH_ID
="${CLOUDNS_AUTH_ID:-$(_readaccountconf_mutable CLOUDNS_AUTH_ID)}"
111 CLOUDNS_SUB_AUTH_ID
="${CLOUDNS_SUB_AUTH_ID:-$(_readaccountconf_mutable CLOUDNS_SUB_AUTH_ID)}"
112 CLOUDNS_AUTH_PASSWORD
="${CLOUDNS_AUTH_PASSWORD:-$(_readaccountconf_mutable CLOUDNS_AUTH_PASSWORD)}"
113 if [ -z "$CLOUDNS_AUTH_ID$CLOUDNS_SUB_AUTH_ID" ] ||
[ -z "$CLOUDNS_AUTH_PASSWORD" ]; then
115 CLOUDNS_SUB_AUTH_ID
=""
116 CLOUDNS_AUTH_PASSWORD
=""
117 _err
"You don't specify cloudns api id and password yet."
118 _err
"Please create you id and password and try again."
122 if [ -z "$CLOUDNS_AUTH_ID" ] && [ -z "$CLOUDNS_SUB_AUTH_ID" ]; then
123 _err
"CLOUDNS_AUTH_ID or CLOUDNS_SUB_AUTH_ID is not configured"
127 if [ -z "$CLOUDNS_AUTH_PASSWORD" ]; then
128 _err
"CLOUDNS_AUTH_PASSWORD is not configured"
132 _dns_cloudns_http_api_call
"dns/login.json" ""
134 if ! _contains
"$response" "\"status\":\"Success\""; then
135 _err
"Invalid CLOUDNS_AUTH_ID or CLOUDNS_AUTH_PASSWORD. Please check your login credentials."
139 # save the api id and password to the account conf file.
140 _saveaccountconf_mutable CLOUDNS_AUTH_ID
"$CLOUDNS_AUTH_ID"
141 _saveaccountconf_mutable CLOUDNS_SUB_AUTH_ID
"$CLOUDNS_SUB_AUTH_ID"
142 _saveaccountconf_mutable CLOUDNS_AUTH_PASSWORD
"$CLOUDNS_AUTH_PASSWORD"
144 CLOUDNS_INIT_CHECK_COMPLETED
=1
149 _dns_cloudns_get_zone_info
() {
151 _dns_cloudns_http_api_call
"dns/get-zone-info.json" "domain-name=$zone"
152 if ! _contains
"$response" "\"status\":\"Failed\""; then
153 DOMAIN_TYPE
=$
(echo "$response" | _egrep_o
'"type":"[^"]*"' | cut
-d : -f 2 |
tr -d '"')
154 if _contains
"$DOMAIN_TYPE" "cloud"; then
155 DOMAIN_MASTER
=$
(echo "$response" | _egrep_o
'"cloud-master":"[^"]*"' | cut
-d : -f 2 |
tr -d '"')
161 _dns_cloudns_get_zone_name
() {
164 zoneForCheck
=$
(printf "%s" "$1" | cut
-d .
-f $i-100)
166 if [ -z "$zoneForCheck" ]; then
170 _debug zoneForCheck
"$zoneForCheck"
172 _dns_cloudns_http_api_call
"dns/get-zone-info.json" "domain-name=$zoneForCheck"
174 if ! _contains
"$response" "\"status\":\"Failed\""; then
184 _dns_cloudns_http_api_call
() {
187 _debug CLOUDNS_AUTH_ID
"$CLOUDNS_AUTH_ID"
188 _debug CLOUDNS_SUB_AUTH_ID
"$CLOUDNS_SUB_AUTH_ID"
189 _debug CLOUDNS_AUTH_PASSWORD
"$CLOUDNS_AUTH_PASSWORD"
191 if [ -n "$CLOUDNS_SUB_AUTH_ID" ]; then
192 auth_user
="sub-auth-id=$CLOUDNS_SUB_AUTH_ID"
194 auth_user
="auth-id=$CLOUDNS_AUTH_ID"
198 data
="$auth_user&auth-password=$CLOUDNS_AUTH_PASSWORD"
200 data
="$auth_user&auth-password=$CLOUDNS_AUTH_PASSWORD&$2"
203 response
="$(_get "$CLOUDNS_API/$method?
$data")"
205 _debug response
"$response"