|
|
#!/usr/bin/env bash
|
|
|
|
|
|
# need to add your email address and key to dnspod below
|
|
|
key=${DNSPOD_API_KEY:-}
|
|
|
|
|
|
fulldomain="$1"
|
|
|
token="$2"
|
|
|
|
|
|
NumParts=$(echo "$fulldomain" | awk -F"." '{print NF}')
|
|
|
if [[ $NumParts -gt 2 ]]; then
|
|
|
domain=$(echo "$fulldomain" | awk -F\. '{print $(NF-1) FS $NF}')
|
|
|
txtname="_acme-challenge$(echo "$fulldomain" | awk -F\. '{for (i=1; i<NF-1; i++) printf "." $i}')"
|
|
|
else
|
|
|
domain=$fulldomain
|
|
|
txtname="_acme-challenge"
|
|
|
fi
|
|
|
|
|
|
response=$(curl --silent -X POST "https://dnsapi.cn/Domain.List" \
|
|
|
-H "Accept: application/json" -H "User-Agent: getssl/0.1" -H "application/x-www-form-urlencoded" \
|
|
|
-d "login_token=${key}&format=json" )
|
|
|
|
|
|
domain_id=$(echo "$response" | egrep -o "[^{]*\"name\":\"${domain}\"[^}]*"|grep -oP '\"id\":\K[^,]+')
|
|
|
|
|
|
response=$(curl --silent -X POST "https://dnsapi.cn/Record.Create" \
|
|
|
-H "Accept: application/json" -H "User-Agent: getssl/0.1" -H "application/x-www-form-urlencoded" \
|
|
|
-d "login_token=${key}&format=json&domain_id=${domain_id}&record_type=TXT&sub_domain=${txtname}&value=$token&ttl=600&record_line=默认")
|
|
|
|