fulldomain=$1
txtvalue=$2
+ Ali_Key="${Ali_Key:-$(_readaccountconf_mutable Ali_Key)}"
+ Ali_Secret="${Ali_Secret:-$(_readaccountconf_mutable Ali_Secret)}"
if [ -z "$Ali_Key" ] || [ -z "$Ali_Secret" ]; then
Ali_Key=""
Ali_Secret=""
fi
#save the api key and secret to the account conf file.
- _saveaccountconf Ali_Key "$Ali_Key"
- _saveaccountconf Ali_Secret "$Ali_Secret"
+ _saveaccountconf_mutable Ali_Key "$Ali_Key"
+ _saveaccountconf_mutable Ali_Secret "$Ali_Secret"
_debug "First detect the root zone"
if ! _get_root "$fulldomain"; then
dns_ali_rm() {
fulldomain=$1
+ txtvalue=$2
+ Ali_Key="${Ali_Key:-$(_readaccountconf_mutable Ali_Key)}"
+ Ali_Secret="${Ali_Secret:-$(_readaccountconf_mutable Ali_Secret)}"
+
+ _debug "First detect the root zone"
+ if ! _get_root "$fulldomain"; then
+ return 1
+ fi
+
_clean
}
}
_ali_rest() {
- signature=$(printf "%s" "GET&%2F&$(_ali_urlencode "$query")" | _hmac "sha1" "$(_hex "$Ali_Secret&")" | _base64)
+ signature=$(printf "%s" "GET&%2F&$(_ali_urlencode "$query")" | _hmac "sha1" "$(printf "%s" "$Ali_Secret&" | _hex_dump | tr -d " ")" | _base64)
signature=$(_ali_urlencode "$signature")
url="$Ali_API?$query&Signature=$signature"
return 1
fi
+ _debug2 response "$response"
if [ -z "$2" ]; then
- message="$(printf "%s" "$response" | _egrep_o "\"Message\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")"
- if [ -n "$message" ]; then
+ message="$(echo "$response" | _egrep_o "\"Message\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")"
+ if [ "$message" ]; then
_err "$message"
return 1
fi
fi
-
- _debug2 response "$response"
- return 0
}
_ali_urlencode() {
}
_check_exist_query() {
+ _qdomain="$1"
+ _qsubdomain="$2"
query=''
query=$query'AccessKeyId='$Ali_Key
query=$query'&Action=DescribeDomainRecords'
- query=$query'&DomainName='$1
+ query=$query'&DomainName='$_qdomain
query=$query'&Format=json'
- query=$query'&RRKeyWord=_acme-challenge'
+ query=$query'&RRKeyWord='$_qsubdomain
query=$query'&SignatureMethod=HMAC-SHA1'
query=$query"&SignatureNonce=$(_ali_nonce)"
query=$query'&SignatureVersion=1.0'
}
_clean() {
- _check_exist_query "$_domain"
+ _check_exist_query "$_domain" "$_sub_domain"
+ # do not correct grammar here
if ! _ali_rest "Check exist records" "ignore"; then
return 1
fi
- records="$(echo "$response" -n | _egrep_o "\"RecordId\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")"
- printf "%s" "$records" \
- | while read -r record_id; do
- _delete_record_query "$record_id"
- _ali_rest "Delete record $record_id" "ignore"
- done
+ record_id="$(echo "$response" | tr '{' "\n" | grep "$_sub_domain" | grep -- "$txtvalue" | tr "," "\n" | grep RecordId | cut -d '"' -f 4)"
+ _debug2 record_id "$record_id"
+
+ if [ -z "$record_id" ]; then
+ _debug "record not found, skip"
+ else
+ _delete_record_query "$record_id"
+ _ali_rest "Delete record $record_id" "ignore"
+ fi
+
}
_timestamp() {