3 ########################################################################
4 # Geoscaling hook script for acme.sh
6 # Environment variables:
8 # - $GEOSCALING_Username (your Geoscaling username - this is usually NOT an amail address)
9 # - $GEOSCALING_Password (your Geoscaling password)
11 #-- dns_geoscaling_add() - Add TXT record --------------------------------------
12 # Usage: dns_geoscaling_add _acme-challenge.subdomain.domain.com "XyZ123..."
14 dns_geoscaling_add
() {
17 _info
"Using DNS-01 Geoscaling DNS2 hook"
19 GEOSCALING_Username
="${GEOSCALING_Username:-$(_readaccountconf_mutable GEOSCALING_Username)}"
20 GEOSCALING_Password
="${GEOSCALING_Password:-$(_readaccountconf_mutable GEOSCALING_Password)}"
21 if [ -z "$GEOSCALING_Username" ] ||
[ -z "$GEOSCALING_Password" ]; then
24 _err
"No auth details provided. Please set user credentials using the \$GEOSCALING_Username and \$GEOSCALING_Password environment variables."
27 _saveaccountconf_mutable GEOSCALING_Username
"${GEOSCALING_Username}"
28 _saveaccountconf_mutable GEOSCALING_Password
"${GEOSCALING_Password}"
30 # Fills in the $zone_id and $zone_name
31 find_zone
"${full_domain}" ||
return 1
32 _debug
"Zone id '${zone_id}' will be used."
34 # We're logged in here
36 # we should add ${full_domain} minus the trailing ${zone_name}
38 prefix
=$
(echo "${full_domain}" |
sed "s|\\.${zone_name}\$||")
40 body
="id=${zone_id}&name=${prefix}&type=TXT&content=${txt_value}&ttl=300&prio=0"
42 do_post
"$body" "https://www.geoscaling.com/dns2/ajax/add_record.php"
44 if [ "${exit_code}" -eq 0 ]; then
45 _info
"TXT record added successfully."
47 _err
"Couldn't add the TXT record."
53 #-- dns_geoscaling_rm() - Remove TXT record ------------------------------------
54 # Usage: dns_geoscaling_rm _acme-challenge.subdomain.domain.com "XyZ123..."
59 _info
"Cleaning up after DNS-01 Geoscaling DNS2 hook"
61 GEOSCALING_Username
="${GEOSCALING_Username:-$(_readaccountconf_mutable GEOSCALING_Username)}"
62 GEOSCALING_Password
="${GEOSCALING_Password:-$(_readaccountconf_mutable GEOSCALING_Password)}"
63 if [ -z "$GEOSCALING_Username" ] ||
[ -z "$GEOSCALING_Password" ]; then
66 _err
"No auth details provided. Please set user credentials using the \$GEOSCALING_Username and \$GEOSCALING_Password environment variables."
69 _saveaccountconf_mutable GEOSCALING_Username
"${GEOSCALING_Username}"
70 _saveaccountconf_mutable GEOSCALING_Password
"${GEOSCALING_Password}"
72 # fills in the $zone_id
73 find_zone
"${full_domain}" ||
return 1
74 _debug
"Zone id '${zone_id}' will be used."
76 # Here we're logged in
77 # Find the record id to clean
80 response
=$
(do_get
"https://www.geoscaling.com/dns2/index.php?module=domain&id=${zone_id}")
81 _debug2
"response" "$response"
83 table
="$(echo "${response}" | tr -d '\n' | sed 's|.*<div class="box
"><div class="boxtitle
">Basic Records</div><div class="boxtext
"><table|<table|; s|</table>.*|</table>|')"
84 _debug2 table
"${table}"
85 names
=$
(echo "${table}" | _egrep_o
'id="[0-9]+\.name">[^<]*</td>' |
sed 's|</td>||; s|.*>||')
86 ids
=$
(echo "${table}" | _egrep_o
'id="[0-9]+\.name">[^<]*</td>' |
sed 's|\.name">.*||; s|id="||')
87 types
=$
(echo "${table}" | _egrep_o
'id="[0-9]+\.type">[^<]*</td>' |
sed 's|</td>||; s|.*>||')
88 values
=$
(echo "${table}" | _egrep_o
'id="[0-9]+\.content">[^<]*</td>' |
sed 's|</td>||; s|.*>||')
90 _debug2 names
"${names}"
92 _debug2 types
"${types}"
93 _debug2 values
"${values}"
95 # look for line whose name is ${full_domain}, whose type is TXT, and whose value is ${txt_value}
96 line_num
="$(echo "${values}" | grep -F -n -- "${txt_value}" | _head_n 1 | cut -d ':' -f 1)"
97 _debug2 line_num
"${line_num}"
99 if [ -n "$line_num" ]; then
100 type=$
(echo "${types}" |
sed -n "${line_num}p")
101 name
=$
(echo "${names}" |
sed -n "${line_num}p")
102 id
=$
(echo "${ids}" |
sed -n "${line_num}p")
107 _debug2 full_domain
"$full_domain"
109 if [ "${type}" = "TXT" ] && [ "${name}" = "${full_domain}" ]; then
114 if [ "${found_id}" = "" ]; then
115 _err
"Can not find record id."
120 body
="id=${zone_id}&record_id=${found_id}"
121 response
=$
(do_post
"$body" "https://www.geoscaling.com/dns2/ajax/delete_record.php")
123 if [ "$exit_code" -eq 0 ]; then
124 _info
"Record removed successfully."
126 _err
"Could not clean (remove) up the record. Please go to Geoscaling administration interface and clean it by hand."
129 return "${exit_code}"
132 ########################## PRIVATE FUNCTIONS ###########################
136 export _H1
="Cookie: $geoscaling_phpsessid_cookie"
143 export _H1
="Cookie: $geoscaling_phpsessid_cookie"
144 _post
"${_body}" "${_url}"
149 _info
"Logging in..."
151 username_encoded
="$(printf "%s
" "${GEOSCALING_Username}" | _url_encode)"
152 password_encoded
="$(printf "%s
" "${GEOSCALING_Password}" | _url_encode)"
153 body
="username=${username_encoded}&password=${password_encoded}"
155 response
=$
(_post
"$body" "https://www.geoscaling.com/dns2/index.php?module=auth")
156 _debug2 response
"${response}"
158 #retcode=$(grep '^HTTP[^ ]*' "${HTTP_HEADER}" | _head_n 1 | _egrep_o '[0-9]+$')
159 retcode
=$
(grep '^HTTP[^ ]*' "${HTTP_HEADER}" | _head_n
1 | cut
-d ' ' -f 2)
161 if [ "$retcode" != "302" ]; then
162 _err
"Geoscaling login failed for user ${GEOSCALING_Username}. Check ${HTTP_HEADER} file"
166 geoscaling_phpsessid_cookie
="$(grep -i '^set-cookie:' "${HTTP_HEADER}" | _egrep_o 'PHPSESSID=[^;]*;' | tr -d ';')"
173 response
="$(do_get "https
://www.geoscaling.com
/dns
2/index.php?module
=auth
")"
174 _debug2 response
"$response"
185 response
="$(do_get "https
://www.geoscaling.com
/dns
2/index.php?module
=domains
")"
187 table
="$(echo "${response}" | tr -d '\n' | sed 's|.*<div class="box
"><div class="boxtitle
">Your domains</div><div class="boxtext
"><table|<table|; s|</table>.*|</table>|')"
188 _debug2 table
"${table}"
189 zone_names
="$(echo "${table}" | _egrep_o '<b>[^<]*</b>' | sed 's|<b>||;s|</b>||')"
190 _debug2 _matches
"${zone_names}"
191 # Zone names and zone IDs are in same order
192 zone_ids
=$
(echo "${table}" | _egrep_o
'<a href=.index\.php\?module=domain&id=[0-9]+. onclick="javascript:show_loader\(\);">' |
sed 's|.*id=||;s|. .*||')
194 _debug2
"These are the zones on this Geoscaling account:"
195 _debug2
"zone_names" "${zone_names}"
196 _debug2
"And these are their respective IDs:"
197 _debug2
"zone_ids" "${zone_ids}"
198 if [ -z "${zone_names}" ] ||
[ -z "${zone_ids}" ]; then
199 _err
"Can not get zone names or IDs."
202 # Walk through all possible zone names
205 attempted_zone
=$
(echo "${domain}" | cut
-d .
-f ${strip_counter}-)
207 # All possible zone names have been tried
208 if [ -z "${attempted_zone}" ]; then
209 _err
"No zone for domain '${domain}' found."
213 _debug
"Looking for zone '${attempted_zone}'"
215 line_num
="$(echo "${zone_names}" | grep -n "^
${attempted_zone}\$
" | _head_n 1 | cut -d : -f 1)"
216 _debug2 line_num
"${line_num}"
217 if [ "$line_num" ]; then
218 zone_id
=$
(echo "${zone_ids}" |
sed -n "${line_num}p")
219 zone_name
=$
(echo "${zone_names}" |
sed -n "${line_num}p")
220 if [ -z "${zone_id}" ]; then
221 _err
"Can not find zone id."
224 _debug
"Found relevant zone '${attempted_zone}' with id '${zone_id}' - will be used for domain '${domain}'."
228 _debug
"Zone '${attempted_zone}' doesn't exist, let's try a less specific zone."
229 strip_counter
=$
(_math
"${strip_counter}" + 1)