1
1
#! /usr/bin/env sh
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.
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.
6
6
7
- # Author: Adrian Fedoreanu
8
- # Report Bugs here: https://github.com/acmesh-official/acme.sh
7
+ # Author: Adrian Fedoreanu
8
+ # Report Bugs here: https://github.com/acmesh-official/acme.sh
9
9
# or here... https://github.com/acmesh-official/acme.sh/issues/2851
10
- #
11
- # ####### Public functions #####################
10
+
11
+ # ####### Public functions #####################
12
12
13
13
# Export 1984HOSTING username and password in following variables
14
14
#
15
15
# One984HOSTING_Username=username
16
16
# One984HOSTING_Password=password
17
17
#
18
- # sessionid cookie is saved in ~/.acme.sh/account.conf
19
- # username/password need to be set only when changed.
18
+ # username/password and csrftoken/sessionid cookies are saved in ~/.acme.sh/account.conf
20
19
21
- # Usage: dns_1984hosting_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
20
+ # Usage: dns_1984hosting_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
21
+ # Add a text record.
22
22
dns_1984hosting_add () {
23
23
fulldomain=$1
24
24
txtvalue=$2
25
25
26
- _info " Add TXT record using 1984Hosting"
26
+ _info " Add TXT record using 1984Hosting. "
27
27
_debug fulldomain " $fulldomain "
28
28
_debug txtvalue " $txtvalue "
29
29
30
30
if ! _1984hosting_login; then
31
- _err " 1984Hosting login failed for user $One984HOSTING_Username . Check $HTTP_HEADER file"
31
+ _err " 1984Hosting login failed for user $One984HOSTING_Username . Check $HTTP_HEADER file. "
32
32
return 1
33
33
fi
34
34
35
- _debug " First detect the root zone"
35
+ _debug " First detect the root zone. "
36
36
if ! _get_root " $fulldomain " ; then
37
- _err " invalid domain" " $fulldomain "
37
+ _err " Invalid domain ' $fulldomain '. "
38
38
return 1
39
39
fi
40
40
_debug _sub_domain " $_sub_domain "
41
41
_debug _domain " $_domain "
42
42
43
- _debug " Add TXT record $fulldomain with value '$txtvalue '"
43
+ _debug " Add TXT record $fulldomain with value '$txtvalue '. "
44
44
value=" $( printf ' %s' " $txtvalue " | _url_encode) "
45
45
url=" https://1984.hosting/domains/entry/"
46
46
@@ -53,93 +53,97 @@ dns_1984hosting_add() {
53
53
_debug2 postdata " $postdata "
54
54
55
55
_authpost " $postdata " " $url "
56
- response=" $( echo " $_response " | _normalizeJson) "
57
- _debug2 response " $response "
58
-
59
- if _contains " $response " ' "haserrors": true' ; then
60
- _err " 1984Hosting failed to add TXT record for $_sub_domain bad RC from _post"
56
+ if _contains " $_response " ' "haserrors": true' ; then
57
+ _err " 1984Hosting failed to add TXT record for $_sub_domain bad RC from _post."
61
58
return 1
62
- elif _contains " $response " " html>" ; then
63
- _err " 1984Hosting failed to add TXT record for $_sub_domain . Check $HTTP_HEADER file"
59
+ elif _contains " $_response " " html>" ; then
60
+ _err " 1984Hosting failed to add TXT record for $_sub_domain . Check $HTTP_HEADER file. "
64
61
return 1
65
- elif _contains " $response " ' "auth": false' ; then
66
- _err " 1984Hosting failed to add TXT record for $_sub_domain . Invalid or expired cookie"
62
+ elif _contains " $_response " ' "auth": false' ; then
63
+ _err " 1984Hosting failed to add TXT record for $_sub_domain . Invalid or expired cookie. "
67
64
return 1
68
65
fi
69
66
70
- _info " Added acme challenge TXT record for $fulldomain at 1984Hosting"
67
+ _info " Added acme challenge TXT record for $fulldomain at 1984Hosting. "
71
68
return 0
72
69
}
73
70
74
- # Usage: fulldomain txtvalue
75
- # Remove the txt record after validation.
71
+ # Usage: fulldomain txtvalue
72
+ # Remove the txt record after validation.
76
73
dns_1984hosting_rm () {
77
74
fulldomain=$1
78
75
txtvalue=$2
79
76
80
- _info " Delete TXT record using 1984Hosting"
77
+ _info " Delete TXT record using 1984Hosting. "
81
78
_debug fulldomain " $fulldomain "
82
79
_debug txtvalue " $txtvalue "
83
80
84
81
if ! _1984hosting_login; then
85
- _err " 1984Hosting login failed for user $One984HOSTING_Username . Check $HTTP_HEADER file"
82
+ _err " 1984Hosting login failed for user $One984HOSTING_Username . Check $HTTP_HEADER file. "
86
83
return 1
87
84
fi
88
85
89
- _debug " First detect the root zone"
86
+ _debug " First detect the root zone. "
90
87
if ! _get_root " $fulldomain " ; then
91
- _err " invalid domain" " $fulldomain "
88
+ _err " Invalid domain ' $fulldomain '. "
92
89
return 1
93
90
fi
94
91
_debug _sub_domain " $_sub_domain "
95
92
_debug _domain " $_domain "
96
- _debug " Delete $fulldomain TXT record"
93
+ _debug " Delete $fulldomain TXT record. "
97
94
98
95
url=" https://1984.hosting/domains"
99
96
if ! _get_zone_id " $url " " $_domain " ; then
100
- _err " invalid zone" " $_domain "
97
+ _err " Invalid zone ' $_domain '. "
101
98
return 1
102
99
fi
103
100
104
101
_htmlget " $url /$_zone_id " " $txtvalue "
105
- _debug2 _response " $_response "
106
102
entry_id=" $( echo " $_response " | _egrep_o ' entry_[0-9]+' | sed ' s/entry_//' ) "
107
103
_debug2 entry_id " $entry_id "
108
104
if [ -z " $entry_id " ]; then
109
- _err " Error getting TXT entry_id for $1 "
105
+ _err " Error getting TXT entry_id for $1 . "
110
106
return 1
111
107
fi
112
108
113
109
_authpost " entry=$entry_id " " $url /delentry/"
114
- response=" $( echo " $_response " | _normalizeJson) "
115
- _debug2 response " $response "
116
-
117
- if ! _contains " $response " ' "ok": true' ; then
118
- _err " 1984Hosting failed to delete TXT record for $entry_id bad RC from _post"
110
+ if ! _contains " $_response " ' "ok": true' ; then
111
+ _err " 1984Hosting failed to delete TXT record for $entry_id bad RC from _post."
119
112
return 1
120
113
fi
121
114
122
- _info " Deleted acme challenge TXT record for $fulldomain at 1984Hosting"
115
+ _info " Deleted acme challenge TXT record for $fulldomain at 1984Hosting. "
123
116
return 0
124
117
}
125
118
126
119
# ################### Private functions below ##################################
127
-
128
- # usage: _1984hosting_login username password
129
- # returns 0 success
130
120
_1984hosting_login () {
131
121
if ! _check_credentials; then return 1; fi
132
122
133
123
if _check_cookies; then
134
- _debug " Already logged in"
124
+ _debug " Already logged in. "
135
125
return 0
136
126
fi
137
127
138
- _debug " Login to 1984Hosting as user $One984HOSTING_Username "
128
+ _debug " Login to 1984Hosting as user $One984HOSTING_Username . "
139
129
username=$( printf ' %s' " $One984HOSTING_Username " | _url_encode)
140
130
password=$( printf ' %s' " $One984HOSTING_Password " | _url_encode)
141
131
url=" https://1984.hosting/accounts/checkuserauth/"
142
132
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 ' ;' ) "
136
+
137
+ if [ -z " $csrftoken " ] || [ -z " $sessionid " ]; then
138
+ _err " One or more cookies are empty: '$csrftoken ', '$sessionid '."
139
+ return 1
140
+ fi
141
+
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 "
146
+
143
147
response=" $( _post " username=$username &password=$password &otpkey=" $url ) "
144
148
response=" $( echo " $response " | _normalizeJson) "
145
149
_debug2 response " $response "
@@ -149,6 +153,8 @@ _1984hosting_login() {
149
153
One984HOSTING_CSRFTOKEN_COOKIE=" $( grep -i ' ^set-cookie:' " $HTTP_HEADER " | _egrep_o ' csrftoken=[^;]*;' | tr -d ' ;' ) "
150
154
export One984HOSTING_SESSIONID_COOKIE
151
155
export One984HOSTING_CSRFTOKEN_COOKIE
156
+ _saveaccountconf_mutable One984HOSTING_Username " $One984HOSTING_Username "
157
+ _saveaccountconf_mutable One984HOSTING_Password " $One984HOSTING_Password "
152
158
_saveaccountconf_mutable One984HOSTING_SESSIONID_COOKIE " $One984HOSTING_SESSIONID_COOKIE "
153
159
_saveaccountconf_mutable One984HOSTING_CSRFTOKEN_COOKIE " $One984HOSTING_CSRFTOKEN_COOKIE "
154
160
return 0
@@ -157,9 +163,13 @@ _1984hosting_login() {
157
163
}
158
164
159
165
_check_credentials () {
166
+ One984HOSTING_Username=" ${One984HOSTING_Username:- $(_readaccountconf_mutable One984HOSTING_Username)} "
167
+ One984HOSTING_Password=" ${One984HOSTING_Password:- $(_readaccountconf_mutable One984HOSTING_Password)} "
160
168
if [ -z " $One984HOSTING_Username " ] || [ -z " $One984HOSTING_Password " ]; then
161
169
One984HOSTING_Username=" "
162
170
One984HOSTING_Password=" "
171
+ _clearaccountconf_mutable One984HOSTING_Username
172
+ _clearaccountconf_mutable One984HOSTING_Password
163
173
_err " You haven't specified 1984Hosting username or password yet."
164
174
_err " Please export as One984HOSTING_Username / One984HOSTING_Password and try again."
165
175
return 1
@@ -171,42 +181,43 @@ _check_cookies() {
171
181
One984HOSTING_SESSIONID_COOKIE=" ${One984HOSTING_SESSIONID_COOKIE:- $(_readaccountconf_mutable One984HOSTING_SESSIONID_COOKIE)} "
172
182
One984HOSTING_CSRFTOKEN_COOKIE=" ${One984HOSTING_CSRFTOKEN_COOKIE:- $(_readaccountconf_mutable One984HOSTING_CSRFTOKEN_COOKIE)} "
173
183
if [ -z " $One984HOSTING_SESSIONID_COOKIE " ] || [ -z " $One984HOSTING_CSRFTOKEN_COOKIE " ]; then
174
- _debug " No cached cookie(s) found"
184
+ _debug " No cached cookie(s) found. "
175
185
return 1
176
186
fi
177
187
178
188
_authget " https://1984.hosting/accounts/loginstatus/"
179
- if _contains " $response " ' "ok": true' ; then
180
- _debug " Cached cookies still valid"
189
+ if _contains " $_response " ' "ok": true' ; then
190
+ _debug " Cached cookies still valid. "
181
191
return 0
182
192
fi
183
- _debug " Cached cookies no longer valid"
193
+
194
+ _debug " Cached cookies no longer valid. Clearing cookies."
184
195
One984HOSTING_SESSIONID_COOKIE=" "
185
196
One984HOSTING_CSRFTOKEN_COOKIE=" "
186
- _saveaccountconf_mutable One984HOSTING_SESSIONID_COOKIE " $One984HOSTING_SESSIONID_COOKIE "
187
- _saveaccountconf_mutable One984HOSTING_CSRFTOKEN_COOKIE " $One984HOSTING_CSRFTOKEN_COOKIE "
197
+ _clearaccountconf_mutable One984HOSTING_SESSIONID_COOKIE
198
+ _clearaccountconf_mutable One984HOSTING_CSRFTOKEN_COOKIE
188
199
return 1
189
200
}
190
201
191
- # _acme-challenge.www.domain.com
192
- # returns
193
- # _sub_domain=_acme-challenge.www
194
- # _domain=domain.com
202
+ # _acme-challenge.www.domain.com
203
+ # Returns
204
+ # _sub_domain=_acme-challenge.www
205
+ # _domain=domain.com
195
206
_get_root () {
196
207
domain=" $1 "
197
208
i=1
198
209
p=1
199
210
while true ; do
200
- h=$( printf " %s" " $domain " | cut -d . -f $i -100)
211
+ h=$( printf " %s" " $domain " | cut -d . -f " $i " -100)
201
212
213
+ # not valid
202
214
if [ -z " $h " ]; then
203
- # not valid
204
215
return 1
205
216
fi
206
217
207
218
_authget " https://1984.hosting/domains/soacheck/?zone=$h &nameserver=ns0.1984.is."
208
219
if _contains " $_response " " serial" && ! _contains " $_response " " null" ; then
209
- _sub_domain=$( printf " %s" " $domain " | cut -d . -f 1-$p )
220
+ _sub_domain=$( printf " %s" " $domain " | cut -d . -f 1-" $p " )
210
221
_domain=" $h "
211
222
return 0
212
223
fi
@@ -216,46 +227,47 @@ _get_root() {
216
227
return 1
217
228
}
218
229
219
- # usage : _get_zone_id url domain.com
220
- # returns zone id for domain.com
230
+ # Usage : _get_zone_id url domain.com
231
+ # Returns zone id for domain.com
221
232
_get_zone_id () {
222
233
url=$1
223
234
domain=$2
224
235
_htmlget " $url " " $domain "
225
- _debug2 _response " $_response "
226
236
_zone_id=" $( echo " $_response " | _egrep_o ' zone\/[0-9]+' | _head_n 1) "
227
237
_debug2 _zone_id " $_zone_id "
228
238
if [ -z " $_zone_id " ]; then
229
- _err " Error getting _zone_id for $2 "
239
+ _err " Error getting _zone_id for $2 . "
230
240
return 1
231
241
fi
232
242
return 0
233
243
}
234
244
235
- # add extra headers to request
245
+ # Add extra headers to request
236
246
_authget () {
237
- export _H1=" Cookie: $One984HOSTING_CSRFTOKEN_COOKIE ;$One984HOSTING_SESSIONID_COOKIE "
247
+ export _H1=" Cookie: $One984HOSTING_CSRFTOKEN_COOKIE ; $One984HOSTING_SESSIONID_COOKIE "
238
248
_response=$( _get " $1 " | _normalizeJson)
239
249
_debug2 _response " $_response "
240
250
}
241
251
242
- # truncate huge HTML response
243
- # echo : Argument list too long
252
+ # Truncate huge HTML response
253
+ # Echo : Argument list too long
244
254
_htmlget () {
245
- export _H1=" Cookie: $One984HOSTING_CSRFTOKEN_COOKIE ;$One984HOSTING_SESSIONID_COOKIE "
255
+ export _H1=" Cookie: $One984HOSTING_CSRFTOKEN_COOKIE ; $One984HOSTING_SESSIONID_COOKIE "
246
256
_response=$( _get " $1 " | grep " $2 " )
247
257
if _contains " $_response " " @$2 " ; then
248
258
_response=$( echo " $_response " | grep -v " [@]" | _head_n 1)
249
259
fi
260
+ _debug2 _response " $_response "
250
261
}
251
262
252
- # add extra headers to request
263
+ # Add extra headers to request
253
264
_authpost () {
254
265
url=" https://1984.hosting/domains"
255
266
_get_zone_id " $url " " $_domain "
256
267
csrf_header=" $( echo " $One984HOSTING_CSRFTOKEN_COOKIE " | _egrep_o " =[^=][0-9a-zA-Z]*" | tr -d " =" ) "
257
- export _H1=" Cookie: $One984HOSTING_CSRFTOKEN_COOKIE ;$One984HOSTING_SESSIONID_COOKIE "
268
+ export _H1=" Cookie: $One984HOSTING_CSRFTOKEN_COOKIE ; $One984HOSTING_SESSIONID_COOKIE "
258
269
export _H2=" Referer: https://1984.hosting/domains/$_zone_id "
259
270
export _H3=" X-CSRFToken: $csrf_header "
260
- _response=$( _post " $1 " " $2 " )
271
+ _response=" $( _post " $1 " " $2 " | _normalizeJson) "
272
+ _debug2 _response " $_response "
261
273
}
0 commit comments