diff --git a/dnsapi/dns_ali.sh b/dnsapi/dns_ali.sh index 543a0a54..0add7af3 100755 --- a/dnsapi/dns_ali.sh +++ b/dnsapi/dns_ali.sh @@ -1,6 +1,9 @@ #!/usr/bin/env sh Ali_API="https://alidns.aliyuncs.com/" +api_version="2015-01-09" + +. "${LE_WORKING_DIR}/libs/aliyun.sh" #Ali_Key="LTqIA87hOKdjevsf5" #Ali_Secret="0p5EYueFNq501xnCPzKNbx6K51qPH2" @@ -10,26 +13,13 @@ dns_ali_add() { 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="" - _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" - _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" + _add_record_query "$_domain" "$_sub_domain" "$txtvalue" && ali_rest $Ali_API "Add record" } dns_ali_rm() { @@ -60,7 +50,7 @@ _get_root() { fi _describe_records_query "$h" - if ! _ali_rest "Get root" "ignore"; then + if ! ali_rest $Ali_API "Get root" "ignore"; then return 1 fi @@ -77,111 +67,44 @@ _get_root() { return 1 } -_ali_rest() { - 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" - - if ! response="$(_get "$url")"; then - _err "Error <$1>" - return 1 - fi - - _debug2 response "$response" - if [ -z "$2" ]; then - message="$(echo "$response" | _egrep_o "\"Message\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")" - if [ "$message" ]; then - _err "$message" - return 1 - fi - fi -} - -_ali_urlencode() { - _str="$1" - _str_len=${#_str} - _u_i=1 - while [ "$_u_i" -le "$_str_len" ]; do - _str_c="$(printf "%s" "$_str" | cut -c "$_u_i")" - case $_str_c in [a-zA-Z0-9.~_-]) - printf "%s" "$_str_c" - ;; - *) - printf "%%%02X" "'$_str_c" - ;; - esac - _u_i="$(_math "$_u_i" + 1)" - done -} - -_ali_nonce() { - #_head_n 1 " + return 1 + fi + + _debug2 response "$response" + if [ -z "$3" ]; then + message="$(echo "$response" | _egrep_o "\"Message\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")" + if [ "$message" ]; then + _err "$message" + return 1 + fi + fi +} \ No newline at end of file