3 # Dnspod.com Domain api
7 #DPI_Key="sADDsdasdgdsf"
9 REST_API
="https://api.dnspod.com"
11 ######## Public functions #####################
13 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
18 DPI_Id
="${DPI_Id:-$(_readaccountconf_mutable DPI_Id)}"
19 DPI_Key
="${DPI_Key:-$(_readaccountconf_mutable DPI_Key)}"
20 if [ -z "$DPI_Id" ] ||
[ -z "$DPI_Key" ]; then
23 _err
"You don't specify dnspod api key and key id yet."
24 _err
"Please create you key and try again."
28 #save the api key and email to the account conf file.
29 _saveaccountconf_mutable DPI_Id
"$DPI_Id"
30 _saveaccountconf_mutable DPI_Key
"$DPI_Key"
32 _debug
"First detect the root zone"
33 if ! _get_root
"$fulldomain"; then
38 add_record
"$_domain" "$_sub_domain" "$txtvalue"
47 DPI_Id
="${DPI_Id:-$(_readaccountconf_mutable DPI_Id)}"
48 DPI_Key
="${DPI_Key:-$(_readaccountconf_mutable DPI_Key)}"
50 _debug
"First detect the root zone"
51 if ! _get_root
"$fulldomain"; then
56 if ! _rest POST
"Record.List" "user_token=$DPI_Id,$DPI_Key&format=json&domain_id=$_domain_id&sub_domain=$_sub_domain"; then
57 _err
"Record.Lis error."
61 if _contains
"$response" 'No records'; then
62 _info
"Don't need to remove."
66 record_id
=$
(echo "$response" | _egrep_o
'{[^{]*"value":"'"$txtvalue"'"' | cut
-d , -f 1 | cut
-d : -f 2 |
tr -d \")
67 _debug record_id
"$record_id"
68 if [ -z "$record_id" ]; then
69 _err
"Can not get record id."
73 if ! _rest POST
"Record.Remove" "user_token=$DPI_Id,$DPI_Key&format=json&domain_id=$_domain_id&record_id=$record_id"; then
74 _err
"Record.Remove error."
78 _contains
"$response" "Action completed successful"
83 #usage: root sub txtvalue
88 fulldomain
="$sub.$root"
92 if ! _rest POST
"Record.Create" "user_token=$DPI_Id,$DPI_Key&format=json&domain_id=$_domain_id&sub_domain=$_sub_domain&record_type=TXT&value=$txtvalue&record_line=default"; then
96 _contains
"$response" "Action completed successful" || _contains
"$response" "Domain record already exists"
99 #################### Private functions below ##################################
100 #_acme-challenge.www.domain.com
102 # _sub_domain=_acme-challenge.www
104 # _domain_id=sdjkglgdfewsdfg
110 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
116 if ! _rest POST
"Domain.Info" "user_token=$DPI_Id,$DPI_Key&format=json&domain=$h"; then
120 if _contains
"$response" "Action completed successful"; then
121 _domain_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"id\":\"[^\"]*\"" | cut
-d : -f 2 |
tr -d \")
122 _debug _domain_id
"$_domain_id"
123 if [ "$_domain_id" ]; then
124 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
125 _debug _sub_domain
"$_sub_domain"
127 _debug _domain
"$_domain"
138 #Usage: method URI data
148 if [ "$m" = "GET" ]; then
149 response
="$(_get "$url" | tr -d '\r')"
152 response
="$(_post "$data" "$url" | tr -d '\r')"
155 if [ "$?" != "0" ]; then
159 _debug2 response
"$response"