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 # username/password and csrftoken/sessionid cookies are saved in ~/.acme.sh/account.conf
20 # 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://1984.hosting/domains/entry/"
48 postdata
="$postdata&type=TXT"
49 postdata
="$postdata&ttl=900"
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 if _contains
"$_response" '"haserrors": true'; then
57 _err
"1984Hosting failed to add TXT record for $_sub_domain bad RC from _post."
59 elif _contains
"$_response" "html>"; then
60 _err
"1984Hosting failed to add TXT record for $_sub_domain. Check $HTTP_HEADER file."
62 elif _contains
"$_response" '"auth": false'; then
63 _err
"1984Hosting failed to add TXT record for $_sub_domain. Invalid or expired cookie."
67 _info
"Added acme challenge TXT record for $fulldomain at 1984Hosting."
71 # Usage: fulldomain txtvalue
72 # Remove the txt record after validation.
73 dns_1984hosting_rm
() {
77 _info
"Delete TXT record using 1984Hosting."
78 _debug fulldomain
"$fulldomain"
79 _debug txtvalue
"$txtvalue"
81 if ! _1984hosting_login
; then
82 _err
"1984Hosting login failed for user $One984HOSTING_Username. Check $HTTP_HEADER file."
86 _debug
"First detect the root zone."
87 if ! _get_root
"$fulldomain"; then
88 _err
"Invalid domain '$fulldomain'."
91 _debug _sub_domain
"$_sub_domain"
92 _debug _domain
"$_domain"
93 _debug
"Delete $fulldomain TXT record."
95 url
="https://1984.hosting/domains"
96 if ! _get_zone_id
"$url" "$_domain"; then
97 _err
"Invalid zone '$_domain'."
101 _htmlget
"$url/$_zone_id" "$txtvalue"
102 entry_id
="$(echo "$_response" | _egrep_o 'entry_[0-9]+' | sed 's/entry_//')"
103 _debug2 entry_id
"$entry_id"
104 if [ -z "$entry_id" ]; then
105 _err
"Error getting TXT entry_id for $1."
109 _authpost
"entry=$entry_id" "$url/delentry/"
110 if ! _contains
"$_response" '"ok": true'; then
111 _err
"1984Hosting failed to delete TXT record for $entry_id bad RC from _post."
115 _info
"Deleted acme challenge TXT record for $fulldomain at 1984Hosting."
119 #################### Private functions below ##################################
120 _1984hosting_login
() {
121 if ! _check_credentials
; then return 1; fi
123 if _check_cookies
; then
124 _debug
"Already logged in."
128 _debug
"Login to 1984Hosting as user $One984HOSTING_Username."
129 username
=$
(printf '%s' "$One984HOSTING_Username" | _url_encode
)
130 password
=$
(printf '%s' "$One984HOSTING_Password" | _url_encode
)
131 url
="https://1984.hosting/accounts/checkuserauth/"
133 _get
"https://1984.hosting/accounts/login/" |
grep "csrfmiddlewaretoken"
134 csrftoken
="$(grep -i '^set-cookie:' "$HTTP_HEADER" | _egrep_o 'csrftoken=[^;]*;' | tr -d ';')"
135 sessionid
="$(grep -i '^set-cookie:' "$HTTP_HEADER" | _egrep_o 'sessionid=[^;]*;' | tr -d ';')"
137 if [ -z "$csrftoken" ] ||
[ -z "$sessionid" ]; then
138 _err
"One or more cookies are empty: '$csrftoken', '$sessionid'."
142 export _H1
="Cookie: $csrftoken; $sessionid"
143 export _H2
="Referer: https://1984.hosting/accounts/login/"
144 csrf_header
=$
(echo "$csrftoken" |
sed 's/csrftoken=//' | _head_n
1)
145 export _H3
="X-CSRFToken: $csrf_header"
147 response
="$(_post "username
=$username&password
=$password&otpkey
=" $url)"
148 response
="$(echo "$response" | _normalizeJson)"
149 _debug2 response
"$response"
151 if _contains
"$response" '"loggedin": true'; then
152 One984HOSTING_SESSIONID_COOKIE
="$(grep -i '^set-cookie:' "$HTTP_HEADER" | _egrep_o 'sessionid=[^;]*;' | tr -d ';')"
153 One984HOSTING_CSRFTOKEN_COOKIE
="$(grep -i '^set-cookie:' "$HTTP_HEADER" | _egrep_o 'csrftoken=[^;]*;' | tr -d ';')"
154 export One984HOSTING_SESSIONID_COOKIE
155 export One984HOSTING_CSRFTOKEN_COOKIE
156 _saveaccountconf_mutable One984HOSTING_Username
"$One984HOSTING_Username"
157 _saveaccountconf_mutable One984HOSTING_Password
"$One984HOSTING_Password"
158 _saveaccountconf_mutable One984HOSTING_SESSIONID_COOKIE
"$One984HOSTING_SESSIONID_COOKIE"
159 _saveaccountconf_mutable One984HOSTING_CSRFTOKEN_COOKIE
"$One984HOSTING_CSRFTOKEN_COOKIE"
165 _check_credentials
() {
166 One984HOSTING_Username
="${One984HOSTING_Username:-$(_readaccountconf_mutable One984HOSTING_Username)}"
167 One984HOSTING_Password
="${One984HOSTING_Password:-$(_readaccountconf_mutable One984HOSTING_Password)}"
168 if [ -z "$One984HOSTING_Username" ] ||
[ -z "$One984HOSTING_Password" ]; then
169 One984HOSTING_Username
=""
170 One984HOSTING_Password
=""
171 _clearaccountconf_mutable One984HOSTING_Username
172 _clearaccountconf_mutable One984HOSTING_Password
173 _err
"You haven't specified 1984Hosting username or password yet."
174 _err
"Please export as One984HOSTING_Username / One984HOSTING_Password and try again."
181 One984HOSTING_SESSIONID_COOKIE
="${One984HOSTING_SESSIONID_COOKIE:-$(_readaccountconf_mutable One984HOSTING_SESSIONID_COOKIE)}"
182 One984HOSTING_CSRFTOKEN_COOKIE
="${One984HOSTING_CSRFTOKEN_COOKIE:-$(_readaccountconf_mutable One984HOSTING_CSRFTOKEN_COOKIE)}"
183 if [ -z "$One984HOSTING_SESSIONID_COOKIE" ] ||
[ -z "$One984HOSTING_CSRFTOKEN_COOKIE" ]; then
184 _debug
"No cached cookie(s) found."
188 _authget
"https://1984.hosting/accounts/loginstatus/"
189 if _contains
"$_response" '"ok": true'; then
190 _debug
"Cached cookies still valid."
194 _debug
"Cached cookies no longer valid. Clearing cookies."
195 One984HOSTING_SESSIONID_COOKIE
=""
196 One984HOSTING_CSRFTOKEN_COOKIE
=""
197 _clearaccountconf_mutable One984HOSTING_SESSIONID_COOKIE
198 _clearaccountconf_mutable One984HOSTING_CSRFTOKEN_COOKIE
202 # _acme-challenge.www.domain.com
204 # _sub_domain=_acme-challenge.www
211 h
=$
(printf "%s" "$domain" | cut
-d .
-f "$i"-100)
218 _authget
"https://1984.hosting/domains/soacheck/?zone=$h&nameserver=ns0.1984.is."
219 if _contains
"$_response" "serial" && ! _contains
"$_response" "null"; then
220 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-"$p")
230 # Usage: _get_zone_id url domain.com
231 # Returns zone id for domain.com
235 _htmlget
"$url" "$domain"
236 _zone_id
="$(echo "$_response" | _egrep_o 'zone\/[0-9]+' | _head_n 1)"
237 _debug2 _zone_id
"$_zone_id"
238 if [ -z "$_zone_id" ]; then
239 _err
"Error getting _zone_id for $2."
245 # Add extra headers to request
247 export _H1
="Cookie: $One984HOSTING_CSRFTOKEN_COOKIE; $One984HOSTING_SESSIONID_COOKIE"
248 _response
=$
(_get
"$1" | _normalizeJson
)
249 _debug2 _response
"$_response"
252 # Truncate huge HTML response
253 # Echo: Argument list too long
255 export _H1
="Cookie: $One984HOSTING_CSRFTOKEN_COOKIE; $One984HOSTING_SESSIONID_COOKIE"
256 _response
=$
(_get
"$1" |
grep "$2")
257 if _contains
"$_response" "@$2"; then
258 _response
=$
(echo "$_response" |
grep -v "[@]" | _head_n
1)
260 _debug2 _response
"$_response"
263 # Add extra headers to request
265 url
="https://1984.hosting/domains"
266 _get_zone_id
"$url" "$_domain"
267 csrf_header
="$(echo "$One984HOSTING_CSRFTOKEN_COOKIE" | _egrep_o "=[^
=][0-9a-zA-Z]*" | tr -d "=")"
268 export _H1
="Cookie: $One984HOSTING_CSRFTOKEN_COOKIE; $One984HOSTING_SESSIONID_COOKIE"
269 export _H2
="Referer: https://1984.hosting/domains/$_zone_id"
270 export _H3
="X-CSRFToken: $csrf_header"
271 _response
="$(_post "$1" "$2" | _normalizeJson)"
272 _debug2 _response
"$_response"