2 #This file name is "dns_1984hosting.sh"
3 #So, here must be a method dns_1984hosting_add()
4 #Which will be called by acme.sh to add the txt record to your api system.
5 #returns 0 means success, otherwise error.
7 #Author: Adrian Fedoreanu
8 #Report Bugs here: https://github.com/acmesh-official/acme.sh
9 # or here... https://github.com/acmesh-official/acme.sh/issues/2851
11 ######## Public functions #####################
13 # Export 1984HOSTING username and password in following variables
15 # One984HOSTING_Username=username
16 # One984HOSTING_Password=password
18 # sessionid cookie is saved in ~/.acme.sh/account.conf
19 # username/password need to be set only when changed.
21 #Usage: dns_1984hosting_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
22 dns_1984hosting_add
() {
26 _info
"Add TXT record using 1984Hosting"
27 _debug fulldomain
"$fulldomain"
28 _debug txtvalue
"$txtvalue"
30 if ! _1984hosting_login
; then
31 _err
"1984Hosting login failed for user $One984HOSTING_Username. Check $HTTP_HEADER file"
35 _debug
"First detect the root zone"
36 if ! _get_root
"$fulldomain"; then
37 _err
"invalid domain" "$fulldomain"
40 _debug _sub_domain
"$_sub_domain"
41 _debug _domain
"$_domain"
43 _debug
"Add TXT record $fulldomain with value '$txtvalue'"
44 value
="$(printf '%s' "$txtvalue" | _url_encode)"
45 url
="https://management.1984hosting.com/domains/entry/"
48 postdata
="$postdata&type=TXT"
49 postdata
="$postdata&ttl=3600"
50 postdata
="$postdata&zone=$_domain"
51 postdata
="$postdata&host=$_sub_domain"
52 postdata
="$postdata&rdata=%22$value%22"
53 _debug2 postdata
"$postdata"
55 _authpost
"$postdata" "$url"
56 response
="$(echo "$_response" | _normalizeJson)"
57 _debug2 response
"$response"
59 if _contains
"$response" '"haserrors": true'; then
60 _err
"1984Hosting failed to add TXT record for $_sub_domain bad RC from _post"
62 elif _contains
"$response" "html>"; then
63 _err
"1984Hosting failed to add TXT record for $_sub_domain. Check $HTTP_HEADER file"
65 elif _contains
"$response" '"auth": false'; then
66 _err
"1984Hosting failed to add TXT record for $_sub_domain. Invalid or expired cookie"
70 _info
"Added acme challenge TXT record for $fulldomain at 1984Hosting"
74 #Usage: fulldomain txtvalue
75 #Remove the txt record after validation.
76 dns_1984hosting_rm
() {
80 _info
"Delete TXT record using 1984Hosting"
81 _debug fulldomain
"$fulldomain"
82 _debug txtvalue
"$txtvalue"
84 if ! _1984hosting_login
; then
85 _err
"1984Hosting login failed for user $One984HOSTING_Username. Check $HTTP_HEADER file"
89 _debug
"First detect the root zone"
90 if ! _get_root
"$fulldomain"; then
91 _err
"invalid domain" "$fulldomain"
94 _debug _sub_domain
"$_sub_domain"
95 _debug _domain
"$_domain"
97 _debug
"Delete $fulldomain TXT record"
99 url
="https://management.1984hosting.com/domains"
101 if ! _get_zone_id
"$_domain"; then
102 _err
"invalid zone" "$_domain"
106 _htmlget
"$url/$_zone_id" "$_sub_domain"
107 _debug2 _response
"$_response"
108 entry_id
="$(echo "$_response" | _egrep_o 'entry_[0-9]+' | sed 's/entry_//')"
109 _debug2 entry_id
"$entry_id"
110 if [ -z "$entry_id" ]; then
111 _err
"Error getting TXT entry_id for $1"
115 _authpost
"entry=$entry_id" "$url/delentry/"
116 response
="$(echo "$_response" | _normalizeJson)"
117 _debug2 response
"$response"
119 if ! _contains
"$response" '"ok": true'; then
120 _err
"1984Hosting failed to delete TXT record for $entry_id bad RC from _post"
124 _info
"Deleted acme challenge TXT record for $fulldomain at 1984Hosting"
128 #################### Private functions below ##################################
130 # usage: _1984hosting_login username password
132 _1984hosting_login
() {
133 if ! _check_credentials
; then return 1; fi
135 if _check_cookies
; then
136 _debug
"Already logged in"
140 _debug
"Login to 1984Hosting as user $One984HOSTING_Username"
141 username
=$
(printf '%s' "$One984HOSTING_Username" | _url_encode
)
142 password
=$
(printf '%s' "$One984HOSTING_Password" | _url_encode
)
143 url
="https://management.1984hosting.com/accounts/checkuserauth/"
145 response
="$(_post "username
=$username&password
=$password&otpkey
=" $url)"
146 response
="$(echo "$response" | _normalizeJson)"
147 _debug2 response
"$response"
149 if _contains
"$response" '"loggedin": true'; then
150 One984HOSTING_SESSIONID_COOKIE
="$(grep -i '^set-cookie:' "$HTTP_HEADER" | _egrep_o 'sessionid=[^;]*;' | tr -d ';')"
151 One984HOSTING_CSRFTOKEN_COOKIE
="$(grep -i '^set-cookie:' "$HTTP_HEADER" | _egrep_o 'csrftoken=[^;]*;' | tr -d ';')"
152 export One984HOSTING_SESSIONID_COOKIE
153 export One984HOSTING_CSRFTOKEN_COOKIE
154 _saveaccountconf_mutable One984HOSTING_SESSIONID_COOKIE
"$One984HOSTING_SESSIONID_COOKIE"
155 _saveaccountconf_mutable One984HOSTING_CSRFTOKEN_COOKIE
"$One984HOSTING_CSRFTOKEN_COOKIE"
161 _check_credentials
() {
162 if [ -z "$One984HOSTING_Username" ] ||
[ -z "$One984HOSTING_Password" ]; then
163 One984HOSTING_Username
=""
164 One984HOSTING_Password
=""
165 _err
"You haven't specified 1984Hosting username or password yet."
166 _err
"Please export as One984HOSTING_Username / One984HOSTING_Password and try again."
173 One984HOSTING_SESSIONID_COOKIE
="${One984HOSTING_SESSIONID_COOKIE:-$(_readaccountconf_mutable One984HOSTING_SESSIONID_COOKIE)}"
174 One984HOSTING_CSRFTOKEN_COOKIE
="${One984HOSTING_CSRFTOKEN_COOKIE:-$(_readaccountconf_mutable One984HOSTING_CSRFTOKEN_COOKIE)}"
175 if [ -z "$One984HOSTING_SESSIONID_COOKIE" ] ||
[ -z "$One984HOSTING_CSRFTOKEN_COOKIE" ]; then
176 _debug
"No cached cookie(s) found"
180 _authget
"https://management.1984hosting.com/accounts/loginstatus/"
181 if _contains
"$response" '"ok": true'; then
182 _debug
"Cached cookies still valid"
185 _debug
"Cached cookies no longer valid"
186 One984HOSTING_SESSIONID_COOKIE
=""
187 One984HOSTING_CSRFTOKEN_COOKIE
=""
188 _saveaccountconf_mutable One984HOSTING_SESSIONID_COOKIE
"$One984HOSTING_SESSIONID_COOKIE"
189 _saveaccountconf_mutable One984HOSTING_CSRFTOKEN_COOKIE
"$One984HOSTING_CSRFTOKEN_COOKIE"
193 #_acme-challenge.www.domain.com
195 # _sub_domain=_acme-challenge.www
202 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
209 _authget
"https://management.1984hosting.com/domains/soacheck/?zone=$h&nameserver=ns0.1984.is."
210 if _contains
"$_response" "serial" && ! _contains
"$_response" "null"; then
211 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
221 #usage: _get_zone_id domain.com
222 #returns zone id for domain.com
224 url
="https://management.1984hosting.com/domains"
226 _htmlget
"$url" "$domain"
227 _debug2 _response
"$_response"
228 _zone_id
="$(echo "$_response" | _egrep_o 'zone\/[0-9]+')"
229 _debug2 _zone_id
"$_zone_id"
230 if [ -z "$_zone_id" ]; then
231 _err
"Error getting _zone_id for $1"
237 # add extra headers to request
239 export _H1
="Cookie: $One984HOSTING_CSRFTOKEN_COOKIE;$One984HOSTING_SESSIONID_COOKIE"
240 _response
=$
(_get
"$1" | _normalizeJson
)
241 _debug2 _response
"$_response"
244 # truncate huge HTML response
245 # echo: Argument list too long
247 export _H1
="Cookie: $One984HOSTING_CSRFTOKEN_COOKIE;$One984HOSTING_SESSIONID_COOKIE"
248 _response
=$
(_get
"$1" |
grep "$2" | _head_n
1)
251 # add extra headers to request
254 csrf_header
="$(echo "$One984HOSTING_CSRFTOKEN_COOKIE" | _egrep_o "=[^
=][0-9a-zA-Z]*" | tr -d "=")"
255 export _H1
="Cookie: $One984HOSTING_CSRFTOKEN_COOKIE;$One984HOSTING_SESSIONID_COOKIE"
256 export _H2
="Referer: https://management.1984hosting.com/domains/$_zone_id"
257 export _H3
="X-CSRFToken: $csrf_header"
258 _response
=$
(_post
"$1" "$2")