]>
git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_dp.sh
7 #DP_Key="sADDsdasdgdsf"
9 DP_Api
= "https://dnsapi.cn"
12 ######## Public functions #####################
14 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
19 if [ -z " $DP_Id " ] ||
[ -z " $DP_Key " ]; then
20 _err
"You don't specify dnspod api key and key id yet."
21 _err
"Please create you key and try again."
27 #save the api key and email to the account conf file.
28 _saveaccountconf DP_Id
" $DP_Id "
29 _saveaccountconf DP_Key
" $DP_Key "
31 _debug
"First detect the root zone"
32 if ! _get_root
$fulldomain ; then
37 existing_records
$_domain $_sub_domain
39 if [ "$?" != "0" ]; then
40 _err
"Error get existing records."
44 if [ " $count " = "0" ]; then
45 add_record
$_domain $_sub_domain $txtvalue
47 update_record
$_domain $_sub_domain $txtvalue
58 #return if the sub record already exists.
59 #echos the existing records count.
60 # '0' means doesn't exist
62 _debug
"Getting txt records"
66 if ! _rest POST
"Record.List" "login_token= $DP_Id , $DP_Key &domain_id= $_domain_id &sub_domain= $_sub_domain " ; then
70 if printf " $response " |
grep 'No records' ; then
75 if printf " $response " |
grep "Action completed successful" >/ dev
/ null
; then
76 count
= $
( printf " $response " |
grep '<type>TXT</type>' |
wc -l )
77 record_id
= $
( printf " $response " |
grep '^<id>' |
tail -1 | cut
-d '>' -f 2 | cut
-d '<' -f 1 )
80 _err
"get existing records error."
88 #usage: root sub txtvalue
97 if ! _rest POST
"Record.Create" "login_token= $DP_Id , $DP_Key &format=json&domain_id= $_domain_id &sub_domain= $_sub_domain &record_type=TXT&value= $txtvalue &record_line=默认" ; then
101 if printf " $response " |
grep "Action completed successful" ; then
109 #update the txt record
110 #Usage: root sub txtvalue
115 fulldomain
= $sub .
$root
117 _info
"Updating record"
119 if ! _rest POST
"Record.Modify" "login_token= $DP_Id , $DP_Key &format=json&domain_id= $_domain_id &sub_domain= $_sub_domain &record_type=TXT&value= $txtvalue &record_line=默认&record_id= $record_id " ; then
123 if printf " $response " |
grep "Action completed successful" ; then
131 #################### Private functions bellow ##################################
132 #_acme-challenge.www.domain.com
134 # _sub_domain=_acme-challenge.www
136 # _domain_id=sdjkglgdfewsdfg
142 h
= $
( printf $domain | cut
-d .
-f $i -100 )
148 if ! _rest POST
"Domain.Info" "login_token= $DP_Id , $DP_Key &format=json&domain= $h " ; then
152 if printf " $response " |
grep "Action completed successful" >/ dev
/ null
; then
153 _domain_id
= $
( printf "%s \n " " $response " | _egrep_o
\" id
\" : \" [ ^
\" ]* \" | cut
-d : -f 2 |
tr -d \" )
154 _debug _domain_id
" $_domain_id "
155 if [ " $_domain_id " ]; then
156 _sub_domain
= $
( printf $domain | cut
-d .
-f 1 - $p )
157 _debug _sub_domain
$_sub_domain
159 _debug _domain
$_domain
170 #Usage: method URI data
182 response
= "$(_post $data " $url ")"
184 response
= "$(_get " $url ")"
187 if [ "$?" != "0" ]; then
191 _debug2 response
" $response "