]>
git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_nsone.sh
3 # bug reports to dev@1e.ca
6 #NS1_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
9 NS1_Api
= "https://api.nsone.net/v1"
11 ######## Public functions #####################
13 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
18 if [ -z " $NS1_Key " ]; then
20 _err
"You didn't specify nsone dns api key yet."
21 _err
"Please create you key and try again."
25 #save the api key and email to the account conf file.
26 _saveaccountconf NS1_Key
" $NS1_Key "
28 _debug
"First detect the root zone"
29 if ! _get_root
" $fulldomain " ; then
33 _debug _sub_domain
" $_sub_domain "
34 _debug _domain
" $_domain "
36 _debug
"Getting txt records"
37 _nsone_rest GET
"zones/ ${_domain} "
39 if ! _contains
" $response " " \" records \" :" ; then
44 count
= $
( printf "%s \n " " $response " | _egrep_o
" \" domain \" : \" $fulldomain \" ,[^{]* \" type \" : \" TXT \" " |
wc -l |
tr -d " " )
46 if [ " $count " = "0" ]; then
49 if _nsone_rest PUT
"zones/ $_domain / $fulldomain /TXT" "{ \" answers \" :[{ \" answer \" :[ \" $txtvalue \" ]}], \" type \" : \" TXT \" , \" domain \" : \" $fulldomain \" , \" zone \" : \" $_domain \" , \" ttl \" :0}" ; then
50 if _contains
" $response " " $fulldomain " ; then
52 #todo: check if the record takes effect
55 _err
"Add txt record error."
59 _err
"Add txt record error."
61 _info
"Updating record"
62 prev_txt
= $
( printf "%s \n " " $response " | _egrep_o
" \" domain \" : \" $fulldomain \" , \" short_answers \" :\[ \" [^,]*\]" | _head_n
1 | cut
-d : -f3 | cut
-d , -f1 )
63 _debug
"prev_txt" " $prev_txt "
65 _nsone_rest POST
"zones/ $_domain / $fulldomain /TXT" "{ \" answers \" : [{ \" answer \" : [ \" $txtvalue \" ]},{ \" answer \" : $prev_txt }], \" type \" : \" TXT \" , \" domain \" : \" $fulldomain \" , \" zone \" : \" $_domain \" , \" ttl \" :0}"
66 if [ "$?" = "0" ] && _contains
" $response " " $fulldomain " ; then
68 #todo: check if the record takes effect
81 _debug
"First detect the root zone"
82 if ! _get_root
" $fulldomain " ; then
86 _debug _sub_domain
" $_sub_domain "
87 _debug _domain
" $_domain "
89 _debug
"Getting txt records"
90 _nsone_rest GET
"zones/ ${_domain} / $fulldomain /TXT"
92 count
= $
( printf "%s \n " " $response " | _egrep_o
" \" domain \" : \" $fulldomain \" ,.* \" type \" : \" TXT \" " |
wc -l |
tr -d " " )
94 if [ " $count " = "0" ]; then
95 _info
"Don't need to remove."
97 if ! _nsone_rest DELETE
"zones/ ${_domain} / $fulldomain /TXT" ; then
98 _err
"Delete record error."
101 _contains
" $response " ""
105 #################### Private functions below ##################################
106 #_acme-challenge.www.domain.com
108 # _sub_domain=_acme-challenge.www
110 # _domain_id=sdjkglgdfewsdfg
115 if ! _nsone_rest GET
"zones" ; then
119 h
= $
( printf "%s" " $domain " | cut
-d .
-f $i -100 )
126 if _contains
" $response " " \" zone \" : \" $h \" " ; then
127 _sub_domain
= $
( printf "%s" " $domain " | cut
-d .
-f 1 - $p )
143 export _H1
= "Accept: application/json"
144 export _H2
= "X-NSONE-Key: $NS1_Key "
145 if [ " $m " != "GET" ]; then
147 response
= "$(_post " $data " " $NS1_Api / $ep " " " " $m ")"
149 response
= "$(_get " $NS1_Api / $ep ")"
152 if [ "$?" != "0" ]; then
156 _debug2 response
" $response "