2 ########################################################################
3 # All-inkl Kasserver hook script for acme.sh
5 # Environment variables:
7 # - $KAS_Login (Kasserver API login name)
8 # - $KAS_Authtype (Kasserver API auth type. Default: plain)
9 # - $KAS_Authdata (Kasserver API auth data.)
11 # Last update: squared GmbH <github@squaredgmbh.de>
13 # - dns_he.sh. Thanks a lot man!
14 # - Martin Kammerlander, Phlegx Systems OG <martin.kammerlander@phlegx.com>
15 # - Marc-Oliver Lange <git@die-lang.es>
16 # - https://github.com/o1oo11oo/kasapi.sh
17 ########################################################################
18 KAS_Api_GET
="$(_get "https
://kasapi.kasserver.com
/soap
/wsdl
/KasApi.wsdl
")"
19 KAS_Api
="$(echo "$KAS_Api_GET" | tr -d ' ' | grep -i "<soap
:addresslocation
=" | sed "s
/='/\n/g" | grep -i "http" | sed "s/'\
/>//g
")"
20 _info
"[KAS] -> API URL $KAS_Api"
22 KAS_Auth_GET
="$(_get "https
://kasapi.kasserver.com
/soap
/wsdl
/KasAuth.wsdl
")"
23 KAS_Auth
="$(echo "$KAS_Auth_GET" | tr -d ' ' | grep -i "<soap
:addresslocation
=" | sed "s
/='/\n/g" | grep -i "http" | sed "s/'\
/>//g
")"
24 _info
"[KAS] -> AUTH URL $KAS_Auth"
26 KAS_default_ratelimit
=5 # TODO - Every response delivers a ratelimit (seconds) where KASAPI is blocking a request.
28 ######## Public functions #####################
33 _info
"[KAS] -> Using DNS-01 All-inkl/Kasserver hook"
34 _info
"[KAS] -> Check and Save Props"
37 _info
"[KAS] -> Adding $_fulldomain DNS TXT entry on all-inkl.com/Kasserver"
38 _info
"[KAS] -> Retriving Credential Token"
41 _info
"[KAS] -> Checking Zone and Record_Name"
42 _get_zone_and_record_name
"$_fulldomain"
44 _info
"[KAS] -> Checking for existing Record entries"
47 # If there is a record_id, delete the entry
48 if [ -n "$_record_id" ]; then
49 _info
"[KAS] -> Existing records found. Now deleting old entries"
50 for i
in $_record_id; do
51 _delete_RecordByID
"$i"
54 _info
"[KAS] -> No record found."
57 _info
"[KAS] -> Creating TXT DNS record"
58 action
="add_dns_settings"
59 kasReqParam
="\"record_name\":\"$_record_name\""
60 kasReqParam
="$kasReqParam,\"record_type\":\"TXT\""
61 kasReqParam
="$kasReqParam,\"record_data\":\"$_txtvalue\""
62 kasReqParam
="$kasReqParam,\"record_aux\":\"0\""
63 kasReqParam
="$kasReqParam,\"zone_host\":\"$_zone\""
64 response
="$(_callAPI "$action" "$kasReqParam")"
65 _debug2
"[KAS] -> Response" "$response"
67 if [ -z "$response" ]; then
68 _info
"[KAS] -> Response was empty, please check manually."
70 elif _contains
"$response" "<SOAP-ENV:Fault>"; then
71 faultstring
="$(echo "$response" | tr -d '\n\r' | sed "s
/<faultstring
>/\n=> /g
" | sed "s
/<\
/faultstring
>/\n/g
" | grep "=>" | sed "s
/=> //g
")"
72 case "${faultstring}" in
73 "record_already_exists")
74 _info
"[KAS] -> The record already exists, which must not be a problem. Please check manually."
77 _err
"[KAS] -> An error =>$faultstring<= occurred, please check manually."
81 elif ! _contains
"$response" "<item><key xsi:type=\"xsd:string\">ReturnString</key><value xsi:type=\"xsd:string\">TRUE</value></item>"; then
82 _err
"[KAS] -> An unknown error occurred, please check manually."
92 _info
"[KAS] -> Using DNS-01 All-inkl/Kasserver hook"
93 _info
"[KAS] -> Check and Save Props"
96 _info
"[KAS] -> Cleaning up after All-inkl/Kasserver hook"
97 _info
"[KAS] -> Removing $_fulldomain DNS TXT entry on All-inkl/Kasserver"
98 _info
"[KAS] -> Retriving Credential Token"
101 _info
"[KAS] -> Checking Zone and Record_Name"
102 _get_zone_and_record_name
"$_fulldomain"
104 _info
"[KAS] -> Getting Record ID"
107 _info
"[KAS] -> Removing entries with ID: $_record_id"
108 # If there is a record_id, delete the entry
109 if [ -n "$_record_id" ]; then
110 for i
in $_record_id; do
111 _delete_RecordByID
"$i"
113 else # Cannot delete or unkown error
114 _info
"[KAS] -> No record_id found that can be deleted. Please check manually."
119 ########################## PRIVATE FUNCTIONS ###########################
121 _delete_RecordByID
() {
123 action
="delete_dns_settings"
124 kasReqParam
="\"record_id\":\"$recId\""
125 response
="$(_callAPI "$action" "$kasReqParam")"
126 _debug2
"[KAS] -> Response" "$response"
128 if [ -z "$response" ]; then
129 _info
"[KAS] -> Response was empty, please check manually."
131 elif _contains
"$response" "<SOAP-ENV:Fault>"; then
132 faultstring
="$(echo "$response" | tr -d '\n\r' | sed "s
/<faultstring
>/\n=> /g
" | sed "s
/<\
/faultstring
>/\n/g
" | grep "=>" | sed "s
/=> //g
")"
133 case "${faultstring}" in
134 "record_id_not_found")
135 _info
"[KAS] -> The record was not found, which perhaps is not a problem. Please check manually."
138 _err
"[KAS] -> An error =>$faultstring<= occurred, please check manually."
142 elif ! _contains
"$response" "<item><key xsi:type=\"xsd:string\">ReturnString</key><value xsi:type=\"xsd:string\">TRUE</value></item>"; then
143 _err
"[KAS] -> An unknown error occurred, please check manually."
147 # Checks for the ENV variables and saves them
149 KAS_Login
="${KAS_Login:-$(_readaccountconf_mutable KAS_Login)}"
150 KAS_Authtype
="${KAS_Authtype:-$(_readaccountconf_mutable KAS_Authtype)}"
151 KAS_Authdata
="${KAS_Authdata:-$(_readaccountconf_mutable KAS_Authdata)}"
153 if [ -z "$KAS_Login" ] ||
[ -z "$KAS_Authtype" ] ||
[ -z "$KAS_Authdata" ]; then
157 _err
"[KAS] -> No auth details provided. Please set user credentials using the \$KAS_Login, \$KAS_Authtype, and \$KAS_Authdata environment variables."
160 _saveaccountconf_mutable KAS_Login
"$KAS_Login"
161 _saveaccountconf_mutable KAS_Authtype
"$KAS_Authtype"
162 _saveaccountconf_mutable KAS_Authdata
"$KAS_Authdata"
166 # Gets back the base domain/zone and record name.
167 # See: https://github.com/Neilpang/acme.sh/wiki/DNS-API-Dev-Guide
168 _get_zone_and_record_name
() {
170 response
="$(_callAPI "$action")"
171 _debug2
"[KAS] -> Response" "$response"
173 if [ -z "$response" ]; then
174 _info
"[KAS] -> Response was empty, please check manually."
176 elif _contains
"$response" "<SOAP-ENV:Fault>"; then
177 faultstring
="$(echo "$response" | tr -d '\n\r' | sed "s
/<faultstring
>/\n=> /g
" | sed "s
/<\
/faultstring
>/\n/g
" | grep "=>" | sed "s
/=> //g
")"
178 _err
"[KAS] -> Either no domains were found or another error =>$faultstring<= occurred, please check manually."
182 zonen
="$(echo "$response" | sed 's/<item>/\n/g' | sed -r 's/(.*<key xsi:type="xsd
:string
">domain_name<\/key><value xsi:type="xsd
:string
">)(.*)(<\/value.*)/\2/' | sed '/^</d')"
184 temp_domain
="$(echo "$1" | sed 's/\.$//')"
189 if _endswith
"$domain" "$i" && [ "$l1" -ge "$l2" ]; then
194 temp_record_name
="$(echo "$temp_domain" | sed "s
/$rootzone//g
")"
195 _record_name
="$(echo "$temp_record_name" | sed 's/\.$//')"
196 _debug
"[KAS] -> Zone:" "$_zone"
197 _debug
"[KAS] -> Domain:" "$domain"
198 _debug
"[KAS] -> Record_Name:" "$_record_name"
202 # Retrieve the DNS record ID
204 action
="get_dns_settings"
205 kasReqParam
="\"zone_host\":\"$_zone\""
206 response
="$(_callAPI "$action" "$kasReqParam")"
207 _debug2
"[KAS] -> Response" "$response"
209 if [ -z "$response" ]; then
210 _info
"[KAS] -> Response was empty, please check manually."
212 elif _contains
"$response" "<SOAP-ENV:Fault>"; then
213 faultstring
="$(echo "$response" | tr -d '\n\r' | sed "s
/<faultstring
>/\n=> /g
" | sed "s
/<\
/faultstring
>/\n/g
" | grep "=>" | sed "s
/=> //g
")"
214 _err
"[KAS] -> Either no domains were found or another error =>$faultstring<= occurred, please check manually."
218 _record_id
="$(echo "$response" | tr -d '\n\r' | sed "s
/<item xsi
:type=\"ns2
:Map
\">/\n/g
" | grep -i "$_record_name" | grep -i ">TXT
<" | sed "s
/<item
><key xsi
:type=\"xsd
:string
\">record_id
<\
/key
><value xsi
:type=\"xsd
:string
\">/=>/g
" | grep -i "$_txtvalue" | sed "s
/<\
/value
><\
/item
>/\n/g
" | grep "=>" | sed "s
/=>//g
")"
219 _debug
"[KAS] -> Record Id: " "$_record_id"
223 # Retrieve credential token
224 _get_credential_token
() {
225 baseParamAuth
="\"kas_login\":\"$KAS_Login\""
226 baseParamAuth
="$baseParamAuth,\"kas_auth_type\":\"$KAS_Authtype\""
227 baseParamAuth
="$baseParamAuth,\"kas_auth_data\":\"$KAS_Authdata\""
228 baseParamAuth
="$baseParamAuth,\"session_lifetime\":600"
229 baseParamAuth
="$baseParamAuth,\"session_update_lifetime\":\"Y\""
231 data
='<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:xmethodsKasApiAuthentication" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:KasAuth><Params xsi:type="xsd:string">{'
232 data
="$data$baseParamAuth}</Params></ns1:KasAuth></SOAP-ENV:Body></SOAP-ENV:Envelope>"
234 _debug
"[KAS] -> Be friendly and wait $KAS_default_ratelimit seconds by default before calling KAS API."
235 _sleep
$KAS_default_ratelimit
237 contentType
="text/xml"
238 export _H1
="SOAPAction: urn:xmethodsKasApiAuthentication#KasAuth"
239 response
="$(_post "$data" "$KAS_Auth" "" "POST
" "$contentType")"
240 _debug2
"[KAS] -> Response" "$response"
242 if [ -z "$response" ]; then
243 _info
"[KAS] -> Response was empty, please check manually."
245 elif _contains
"$response" "<SOAP-ENV:Fault>"; then
246 faultstring
="$(echo "$response" | tr -d '\n\r' | sed "s
/<faultstring
>/\n=> /g
" | sed "s
/<\
/faultstring
>/\n/g
" | grep "=>" | sed "s
/=> //g
")"
247 _err
"[KAS] -> Could not retrieve login token or antoher error =>$faultstring<= occurred, please check manually."
251 _credential_token
="$(echo "$response" | tr '\n' ' ' | sed 's/.*return xsi:type="xsd
:string
">\(.*\)<\/return>/\1/' | sed 's/<\/ns1:KasAuthResponse\(.*\)Envelope>.*//')"
252 _debug
"[KAS] -> Credential Token: " "$_credential_token"
260 baseParamAuth
="\"kas_login\":\"$KAS_Login\""
261 baseParamAuth
="$baseParamAuth,\"kas_auth_type\":\"session\""
262 baseParamAuth
="$baseParamAuth,\"kas_auth_data\":\"$_credential_token\""
264 data
='<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:xmethodsKasApi" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:KasApi><Params xsi:type="xsd:string">{'
265 data
="$data$baseParamAuth,\"kas_action\":\"$kasaction\""
266 if [ -n "$kasReqParams" ]; then
267 data
="$data,\"KasRequestParams\":{$kasReqParams}"
269 data
="$data}</Params></ns1:KasApi></SOAP-ENV:Body></SOAP-ENV:Envelope>"
271 _debug2
"[KAS] -> Request" "$data"
273 _debug
"[KAS] -> Be friendly and wait $KAS_default_ratelimit seconds by default before calling KAS API."
274 _sleep
$KAS_default_ratelimit
276 contentType
="text/xml"
277 export _H1
="SOAPAction: urn:xmethodsKasApi#KasApi"
278 response
="$(_post "$data" "$KAS_Api" "" "POST
" "$contentType")"
279 _debug2
"[KAS] -> Response" "$response"