#!/usr/bin/env sh # shellcheck disable=SC2034 dns_ali_info='AlibabaCloud.com Domains: Aliyun.com Site: AlibabaCloud.com Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_ali Options: Ali_Key API Key Ali_Secret API Secret ' # NOTICE: # This file is referenced by Alibaba Cloud Services deploy hooks # https://github.com/acmesh-official/acme.sh/pull/5205#issuecomment-2357867276 # Be careful when modifying this file, especially when making breaking changes for common functions Ali_DNS_API="https://alidns.aliyuncs.com/" #Usage: dns_ali_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" dns_ali_add() { fulldomain=$1 txtvalue=$2 _prepare_ali_credentials || return 1 _debug "First detect the root zone" if ! _get_root "$fulldomain"; then return 1 fi _debug "Add record" _add_record_query "$_domain" "$_sub_domain" "$txtvalue" && _ali_rest "Add record" } 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 } #################### Alibaba Cloud common functions below #################### _prepare_ali_credentials() { 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="" _err "You don't specify aliyun api key and secret yet." return 1 fi #save the api key and secret to the account conf file. _saveaccountconf_mutable Ali_Key "$Ali_Key" _saveaccountconf_mutable Ali_Secret "$Ali_Secret" } # act ign mtd _ali_rest() { act="$1" ign="$2" mtd="${3:-GET}" signature=$(printf "%s" "$mtd&%2F&$(printf "%s" "$query" | _url_encode upper-hex)" | _hmac "sha1" "$(printf "%s" "$Ali_Secret&" | _hex_dump | tr -d " ")" | _base64) signature=$(printf "%s" "$signature" | _url_encode upper-hex) url="$endpoint?Signature=$signature" if [ "$mtd" = "GET" ]; then url="$url&$query" response="$(_get "$url")" else response="$(_post "$query" "$url" "" "$mtd" "application/x-www-form-urlencoded")" fi _ret="$?" _debug2 response "$response" if [ "$_ret" != "0" ]; then _err "Error <$act>" return 1 fi if [ -z "$ign" ]; then message="$(echo "$response" | _egrep_o "\"Message\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")" if [ "$message" ]; then _err "$message" return 1 fi fi } _ali_nonce() { #_head_n 1