]> git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_internetbs.sh
removed the _clearaccountconf() call for erroneous requests
[mirror_acme.sh.git] / dnsapi / dns_internetbs.sh
1 #!/usr/bin/env sh
2
3 #This is the Internet.BS api wrapper for acme.sh
4 #
5 #Author: <alexey@nelexa.ru> Ne-Lexa
6 #Report Bugs here: https://github.com/Ne-Lexa/acme.sh
7
8 #INTERNETBS_API_KEY="sdfsdfsdfljlbjkljlkjsdfoiwje"
9 #INTERNETBS_API_PASSWORD="sdfsdfsdfljlbjkljlkjsdfoiwje"
10 INTERNETBS_API_URL="https://api.internet.bs"
11
12 ######## Public functions #####################
13
14 #Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
15 dns_internetbs_add() {
16 fulldomain=$1
17 txtvalue=$2
18
19 if [ -z "$INTERNETBS_API_KEY" ] || [ -z "$INTERNETBS_API_PASSWORD" ]; then
20 INTERNETBS_API_KEY=""
21 INTERNETBS_API_PASSWORD=""
22 _err "You didn't specify the INTERNET.BS api key and password yet."
23 _err "Please create you key and try again."
24 return 1
25 fi
26
27 _saveaccountconf INTERNETBS_API_KEY "$INTERNETBS_API_KEY"
28 _saveaccountconf INTERNETBS_API_PASSWORD "$INTERNETBS_API_PASSWORD"
29
30 _debug "First detect the root zone"
31 if ! _get_root "$fulldomain"; then
32 _err "invalid domain"
33 return 1
34 fi
35
36 _debug _sub_domain "$_sub_domain"
37 _debug _domain "$_domain"
38
39 # https://testapi.internet.bs/Domain/DnsRecord/Add?ApiKey=testapi&Password=testpass&FullRecordName=w3.test-api-domain7.net&Type=CNAME&Value=www.internet.bs%&ResponseFormat=json
40 if _internetbs_rest POST "Domain/DnsRecord/Add" "FullRecordName=${_sub_domain}.${_domain}&Type=TXT&Value=${txtvalue}&ResponseFormat=json"; then
41 if ! _contains "$response" "\"status\":\"SUCCESS\""; then
42 _err "ERROR add TXT record"
43 _err "$response"
44 return 1
45 fi
46
47 _info "txt record add success."
48 return 0
49 fi
50
51 return 1
52 }
53
54 #Usage: fulldomain txtvalue
55 #Remove the txt record after validation.
56 dns_internetbs_rm() {
57 fulldomain=$1
58 txtvalue=$2
59
60 _debug "First detect the root zone"
61 if ! _get_root "$fulldomain"; then
62 _err "invalid domain"
63 return 1
64 fi
65
66 _debug _sub_domain "$_sub_domain"
67 _debug _domain "$_domain"
68
69 _debug "Getting txt records"
70 # https://testapi.internet.bs/Domain/DnsRecord/List?ApiKey=testapi&Password=testpass&Domain=test-api-domain7.net&FilterType=CNAME&ResponseFormat=json
71 _internetbs_rest POST "Domain/DnsRecord/List" "Domain=$_domain&FilterType=TXT&ResponseFormat=json"
72
73 if ! _contains "$response" "\"status\":\"SUCCESS\""; then
74 _err "ERROR list dns records"
75 _err "$response"
76 return 1
77 fi
78
79 if _contains "$response" "\name\":\"${_sub_domain}.${_domain}\""; then
80 _info "txt record find."
81
82 # https://testapi.internet.bs/Domain/DnsRecord/Remove?ApiKey=testapi&Password=testpass&FullRecordName=www.test-api-domain7.net&Type=cname&ResponseFormat=json
83 _internetbs_rest POST "Domain/DnsRecord/Remove" "FullRecordName=${_sub_domain}.${_domain}&Type=TXT&ResponseFormat=json"
84
85 if ! _contains "$response" "\"status\":\"SUCCESS\""; then
86 _err "ERROR remove dns record"
87 _err "$response"
88 return 1
89 fi
90
91 _info "txt record deleted success."
92 return 0
93 fi
94
95 return 1
96 }
97
98 #################### Private functions below ##################################
99 #_acme-challenge.www.domain.com
100 #returns
101 # _sub_domain=_acme-challenge.www
102 # _domain=domain.com
103 # _domain_id=12345
104 _get_root() {
105 domain=$1
106 i=2
107 p=1
108
109 # https://testapi.internet.bs/Domain/List?ApiKey=testapi&Password=testpass&CompactList=yes&ResponseFormat=json
110 if _internetbs_rest POST "Domain/List" "CompactList=yes&ResponseFormat=json"; then
111
112 if ! _contains "$response" "\"status\":\"SUCCESS\""; then
113 _err "ERROR fetch domain list"
114 _err "$response"
115 return 1
116 fi
117
118 while true; do
119 h=$(printf "%s" "$domain" | cut -d . -f ${i}-100)
120 _debug h "$h"
121 if [ -z "$h" ]; then
122 #not valid
123 return 1
124 fi
125
126 if _contains "$response" "\"$h\""; then
127 _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-${p})
128 _domain=${h}
129 return 0
130 fi
131
132 p=${i}
133 i=$(_math "$i" + 1)
134 done
135 fi
136 return 1
137 }
138
139 #Usage: method URI data
140 _internetbs_rest() {
141 m="$1"
142 ep="$2"
143 data="$3"
144 url="${INTERNETBS_API_URL}/${ep}"
145
146 _debug url "$url"
147
148 apiKey="$(printf "%s" "${INTERNETBS_API_KEY}" | _url_encode)"
149 password="$(printf "%s" "${INTERNETBS_API_PASSWORD}" | _url_encode)"
150
151 if [ "$m" = "GET" ]; then
152 response="$(_get "${url}?ApiKey=${apiKey}&Password=${password}&${data}" | tr -d '\r')"
153 else
154 _debug2 data "$data"
155 response="$(_post "$data" "${url}?ApiKey=${apiKey}&Password=${password}" | tr -d '\r')"
156 fi
157
158 if [ "$?" != "0" ]; then
159 _err "error $ep"
160 return 1
161 fi
162
163 _debug2 response "$response"
164 return 0
165 }