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