]>
git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_dp.sh
7 #DP_Key="sADDsdasdgdsf"
10 DP_Api
= "https://dnsapi.cn"
14 ######## Public functions #####################
16 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
21 if [ -z " $DP_Id " ] ||
[ -z " $DP_Key " ] ; then
22 _err
"You don't specify dnspod api key and key id yet."
23 _err
"Please create you key and try again."
29 #save the api key and email to the account conf file.
30 _saveaccountconf DP_Id
" $DP_Id "
31 _saveaccountconf DP_Key
" $DP_Key "
34 _debug
"First detect the root zone"
35 if ! _get_root
$fulldomain ; then
40 existing_records
$_domain $_sub_domain
42 if [ "$?" != "0" ] ; then
43 _err
"Error get existing records."
47 if [ " $count " == "0" ] ; then
48 add_record
$_domain $_sub_domain $txtvalue
50 update_record
$_domain $_sub_domain $txtvalue
55 #return if the sub record already exists.
56 #echos the existing records count.
57 # '0' means doesn't exist
59 _debug
"Getting txt records"
63 if ! _rest POST
"Record.List" "login_token= $DP_Id , $DP_Key &domain_id= $_domain_id &sub_domain= $_sub_domain " ; then
67 if printf " $response " |
grep 'No records' ; then
72 if printf " $response " |
grep "Action completed successful" >/ dev
/ null
; then
73 count
= $
( printf " $response " |
grep '<type>TXT</type>' |
wc -l )
75 record_id
= $
( printf " $response " |
grep '^<id>' |
tail -1 | cut
-d '>' -f 2 | cut
-d '<' -f 1 )
78 _err
"get existing records error."
87 #usage: root sub txtvalue
96 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
100 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
134 #################### Private functions bellow ##################################
135 #_acme-challenge.www.domain.com
137 # _sub_domain=_acme-challenge.www
139 # _domain_id=sdjkglgdfewsdfg
145 h
= $
( printf $domain | cut
-d .
-f $i -100 )
146 if [ -z " $h " ] ; then
151 if ! _rest POST
"Domain.Info" "login_token= $DP_Id , $DP_Key &format=json&domain= $h " ; then
155 if printf " $response " |
grep "Action completed successful" ; then
156 _domain_id
= $
( printf " $response " |
grep -o \" id
\" : \" [ ^
\" ]* \" | cut
-d : -f 2 |
tr -d \" )
157 _debug _domain_id
" $_domain_id "
158 if [ " $_domain_id " ] ; then
159 _sub_domain
= $
( printf $domain | cut
-d .
-f 1 - $p )
160 _debug _sub_domain
$_sub_domain
162 _debug _domain
$_domain
174 #Usage: method URI data
186 response
= "$(curl --silent -X $m " $url " -d $data )"
188 response
= "$(curl --silent -X $m " $url " )"
191 if [ "$?" != "0" ] ; then
195 _debug2 response
" $response "