Clean up comments

This commit is contained in:
Radek SPRTA 2020-01-22 01:59:40 +01:00
parent 69392f67e8
commit 36e0feea43
No known key found for this signature in database
GPG Key ID: 03C36A3AA4A06D51

View File

@ -15,6 +15,7 @@ CLOUDDNS_LOGIN_API='https://admin.vshosting.cloud/api/public/auth/login'
dns_clouddns_add() { dns_clouddns_add() {
fulldomain=$1 fulldomain=$1
txtvalue=$2 txtvalue=$2
_debug "fulldomain" "$fulldomain"
CLOUDDNS_CLIENT_ID="${CLOUDDNS_CLIENT_ID:-$(_readaccountconf_mutable CLOUDDNS_CLIENT_ID)}" CLOUDDNS_CLIENT_ID="${CLOUDDNS_CLIENT_ID:-$(_readaccountconf_mutable CLOUDDNS_CLIENT_ID)}"
CLOUDDNS_EMAIL="${CLOUDDNS_EMAIL:-$(_readaccountconf_mutable CLOUDDNS_EMAIL)}" CLOUDDNS_EMAIL="${CLOUDDNS_EMAIL:-$(_readaccountconf_mutable CLOUDDNS_EMAIL)}"
@ -24,7 +25,7 @@ dns_clouddns_add() {
CLOUDDNS_CLIENT_ID="" CLOUDDNS_CLIENT_ID=""
CLOUDDNS_EMAIL="" CLOUDDNS_EMAIL=""
CLOUDDNS_PASSWORD="" CLOUDDNS_PASSWORD=""
_err "You didn't specify a CloudDNS password, email and client id yet." _err "You didn't specify a CloudDNS password, email and client ID yet."
return 1 return 1
fi fi
if ! _contains "$CLOUDDNS_EMAIL" "@"; then if ! _contains "$CLOUDDNS_EMAIL" "@"; then
@ -46,8 +47,6 @@ dns_clouddns_add() {
_debug _sub_domain "$_sub_domain" _debug _sub_domain "$_sub_domain"
_debug _domain "$_domain" _debug _domain "$_domain"
# For wildcard cert, the main root domain and the wildcard domain have the same txt subdomain name, so
# we can not use updating anymore.
_info "Adding record" _info "Adding record"
if _clouddns_api POST "record-txt" "{\"type\":\"TXT\",\"name\":\"$fulldomain.\",\"value\":\"$txtvalue\",\"domainId\":\"$_domain_id\"}"; then if _clouddns_api POST "record-txt" "{\"type\":\"TXT\",\"name\":\"$fulldomain.\",\"value\":\"$txtvalue\",\"domainId\":\"$_domain_id\"}"; then
if _contains "$response" "$txtvalue"; then if _contains "$response" "$txtvalue"; then
@ -55,20 +54,19 @@ dns_clouddns_add() {
elif _contains "$response" '"code":4136'; then elif _contains "$response" '"code":4136'; then
_info "Already exists, OK" _info "Already exists, OK"
else else
_err "Add txt record error." _err "Add TXT record error."
return 1 return 1
fi fi
fi fi
# Publish challenge record
_debug "Publishing record changes" _debug "Publishing record changes"
_clouddns_api PUT "domain/$_domain_id/publish" "{\"soaTtl\":300}" _clouddns_api PUT "domain/$_domain_id/publish" "{\"soaTtl\":300}"
} }
#fulldomain txtvalue # Usage: rm _acme-challenge.www.domain.com
dns_clouddns_rm() { dns_clouddns_rm() {
fulldomain=$1 fulldomain=$1
txtvalue=$2 _debug "fulldomain" "$fulldomain"
CLOUDDNS_CLIENT_ID="${CLOUDDNS_CLIENT_ID:-$(_readaccountconf_mutable CLOUDDNS_CLIENT_ID)}" CLOUDDNS_CLIENT_ID="${CLOUDDNS_CLIENT_ID:-$(_readaccountconf_mutable CLOUDDNS_CLIENT_ID)}"
CLOUDDNS_EMAIL="${CLOUDDNS_EMAIL:-$(_readaccountconf_mutable CLOUDDNS_EMAIL)}" CLOUDDNS_EMAIL="${CLOUDDNS_EMAIL:-$(_readaccountconf_mutable CLOUDDNS_EMAIL)}"
@ -76,16 +74,16 @@ dns_clouddns_rm() {
_debug "First detect the root zone" _debug "First detect the root zone"
if ! _get_root "$fulldomain"; then if ! _get_root "$fulldomain"; then
_err "invalid domain" _err "Invalid domain"
return 1 return 1
fi fi
_debug _domain_id "$_domain_id" _debug _domain_id "$_domain_id"
_debug _sub_domain "$_sub_domain" _debug _sub_domain "$_sub_domain"
_debug _domain "$_domain" _debug _domain "$_domain"
# Get record Id # Get record ID
response="$(_clouddns_api GET "domain/$_domain_id" | tr -d '\t\r\n ')" response="$(_clouddns_api GET "domain/$_domain_id" | tr -d '\t\r\n ')"
_debug response "$response" _debug2 response "$response"
if _contains "$response" "lastDomainRecordList"; then if _contains "$response" "lastDomainRecordList"; then
re="\"lastDomainRecordList\".*\"id\":\"([^\"}]*)\"[^}]*\"name\":\"$fulldomain.\"," re="\"lastDomainRecordList\".*\"id\":\"([^\"}]*)\"[^}]*\"name\":\"$fulldomain.\","
_last_domains=$(echo "$response" | _egrep_o "$re") _last_domains=$(echo "$response" | _egrep_o "$re")
@ -93,7 +91,7 @@ dns_clouddns_rm() {
_record_id=$(echo "$_last_domains" | _egrep_o "$re2" | _head_n 1 | cut -d : -f 2 | cut -d , -f 1 | tr -d "\"") _record_id=$(echo "$_last_domains" | _egrep_o "$re2" | _head_n 1 | cut -d : -f 2 | cut -d , -f 1 | tr -d "\"")
_debug _record_id "$_record_id" _debug _record_id "$_record_id"
else else
_err "Could not retrieve record id" _err "Could not retrieve record ID"
return 1 return 1
fi fi
@ -105,14 +103,14 @@ dns_clouddns_rm() {
fi fi
fi fi
# Publish challenge record
_debug "Publishing record changes" _debug "Publishing record changes"
_clouddns_api PUT "domain/$_domain_id/publish" "{\"soaTtl\":300}" _clouddns_api PUT "domain/$_domain_id/publish" "{\"soaTtl\":300}"
} }
#################### Private functions below ################################## #################### Private functions below ##################################
#_acme-challenge.www.domain.com
#returns # Usage: _get_root _acme-challenge.www.domain.com
# Returns:
# _sub_domain=_acme-challenge.www # _sub_domain=_acme-challenge.www
# _domain=domain.com # _domain=domain.com
# _domain_id=sdjkglgdfewsdfg # _domain_id=sdjkglgdfewsdfg
@ -122,7 +120,7 @@ _get_root() {
# Get domain root # Get domain root
data="{\"search\": [{\"name\": \"clientId\", \"operator\": \"eq\", \"value\": \"$CLOUDDNS_CLIENT_ID\"}]}" data="{\"search\": [{\"name\": \"clientId\", \"operator\": \"eq\", \"value\": \"$CLOUDDNS_CLIENT_ID\"}]}"
response="$(_clouddns_api "POST" "domain/search" "$data" | tr -d '\t\r\n ')" response="$(_clouddns_api "POST" "domain/search" "$data" | tr -d '\t\r\n ')"
_debug2 "response" "$response" _debug2 response "$response"
domain_slice="$domain" domain_slice="$domain"
while [ -z "$domain_root" ]; do while [ -z "$domain_root" ]; do
if _contains "$response" "\"domainName\":\"$domain_slice\.\""; then if _contains "$response" "\"domainName\":\"$domain_slice\.\""; then
@ -150,6 +148,9 @@ _get_root() {
return 1 return 1
} }
# Usage: _clouddns_api GET domain/search '{"data": "value"}'
# Returns:
# response='{"message": "api response"}'
_clouddns_api() { _clouddns_api() {
method=$1 method=$1
endpoint="$2" endpoint="$2"
@ -172,13 +173,15 @@ _clouddns_api() {
fi fi
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
_err "error $endpoint" _err "Error $endpoint"
return 1 return 1
fi fi
printf "%s" "$response" printf "%s" "$response"
return 0 return 0
} }
# Returns:
# CLOUDDNS_TOKEN=dslfje2rj23l
_clouddns_login() { _clouddns_login() {
login_data="{\"email\": \"$CLOUDDNS_EMAIL\", \"password\": \"$CLOUDDNS_PASSWORD\"}" login_data="{\"email\": \"$CLOUDDNS_EMAIL\", \"password\": \"$CLOUDDNS_PASSWORD\"}"
response="$(_post "$login_data" "$CLOUDDNS_LOGIN_API" "" "POST" "Content-Type: application/json")" response="$(_post "$login_data" "$CLOUDDNS_LOGIN_API" "" "POST" "Content-Type: application/json")"