forked from srvrco/getssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns_add_dnspod
executable file
·27 lines (20 loc) · 1.04 KB
/
dns_add_dnspod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/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=默认")