2019-12-29 10:59:28 +01:00
|
|
|
#!/usr/bin/env sh
|
2018-03-09 16:29:47 +01:00
|
|
|
########################################################################
|
|
|
|
# All-inkl Kasserver hook script for acme.sh
|
|
|
|
#
|
|
|
|
# Environment variables:
|
|
|
|
#
|
|
|
|
# - $KAS_Login (Kasserver API login name)
|
|
|
|
# - $KAS_Authtype (Kasserver API auth type. Default: sha1)
|
|
|
|
# - $KAS_Authdata (Kasserver API auth data.)
|
|
|
|
#
|
|
|
|
# Author: Martin Kammerlander, Phlegx Systems OG <martin.kammerlander@phlegx.com>
|
2020-01-15 13:56:01 +01:00
|
|
|
# Updated by: Marc-Oliver Lange <git@die-lang.es>
|
2018-03-09 16:29:47 +01:00
|
|
|
# Credits: Inspired by dns_he.sh. Thanks a lot man!
|
2018-03-09 16:33:35 +01:00
|
|
|
# Git repo: https://github.com/phlegx/acme.sh
|
2018-03-09 16:29:47 +01:00
|
|
|
# TODO: Better Error handling
|
2019-12-28 11:58:21 +01:00
|
|
|
########################################################################
|
2018-03-09 16:29:47 +01:00
|
|
|
KAS_Api="https://kasapi.kasserver.com/dokumentation/formular.php"
|
2020-01-15 13:56:01 +01:00
|
|
|
######## Public functions #####################
|
|
|
|
dns_kas_add() {
|
2018-03-16 15:49:40 +01:00
|
|
|
_fulldomain=$1
|
|
|
|
_txtvalue=$2
|
2018-03-09 16:29:47 +01:00
|
|
|
_info "Using DNS-01 All-inkl/Kasserver hook"
|
2020-01-15 13:56:01 +01:00
|
|
|
_info "Adding $_fulldomain DNS TXT entry on All-inkl/Kasserver"
|
2020-01-02 17:10:36 +01:00
|
|
|
_info "Check and Save Props"
|
2018-03-09 16:29:47 +01:00
|
|
|
_check_and_save
|
2020-01-02 17:10:36 +01:00
|
|
|
_info "Checking Zone and Record_Name"
|
2019-12-28 11:58:21 +01:00
|
|
|
_get_zone_and_record_name "$_fulldomain"
|
2020-01-02 17:10:36 +01:00
|
|
|
_info "Getting Record ID"
|
2018-03-09 16:29:47 +01:00
|
|
|
_get_record_id
|
|
|
|
|
2018-03-16 14:54:08 +01:00
|
|
|
_info "Creating TXT DNS record"
|
2018-03-09 16:29:47 +01:00
|
|
|
params="?kas_login=$KAS_Login"
|
|
|
|
params="$params&kas_auth_type=$KAS_Authtype"
|
|
|
|
params="$params&kas_auth_data=$KAS_Authdata"
|
|
|
|
params="$params&var1=record_name"
|
|
|
|
params="$params&wert1=$_record_name"
|
|
|
|
params="$params&var2=record_type"
|
|
|
|
params="$params&wert2=TXT"
|
|
|
|
params="$params&var3=record_data"
|
2018-03-16 15:49:40 +01:00
|
|
|
params="$params&wert3=$_txtvalue"
|
2018-03-09 16:29:47 +01:00
|
|
|
params="$params&var4=record_aux"
|
|
|
|
params="$params&wert4=0"
|
2018-03-16 14:54:08 +01:00
|
|
|
params="$params&kas_action=add_dns_settings"
|
|
|
|
params="$params&var5=zone_host"
|
|
|
|
params="$params&wert5=$_zone"
|
2018-08-02 16:20:48 +02:00
|
|
|
_debug2 "Wait for 10 seconds by default before calling KAS API."
|
2020-01-23 19:20:44 +01:00
|
|
|
_sleep 10
|
2018-03-09 16:29:47 +01:00
|
|
|
response="$(_get "$KAS_Api$params")"
|
|
|
|
_debug2 "response" "$response"
|
|
|
|
|
|
|
|
if ! _contains "$response" "TRUE"; then
|
|
|
|
_err "An unkown error occurred, please check manually."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_kas_rm() {
|
2018-03-16 15:49:40 +01:00
|
|
|
_fulldomain=$1
|
|
|
|
_txtvalue=$2
|
2018-03-09 16:29:47 +01:00
|
|
|
_info "Using DNS-01 All-inkl/Kasserver hook"
|
|
|
|
_info "Cleaning up after All-inkl/Kasserver hook"
|
2018-03-16 15:49:40 +01:00
|
|
|
_info "Removing $_fulldomain DNS TXT entry on All-inkl/Kasserver"
|
2020-01-15 17:48:30 +01:00
|
|
|
|
2020-01-02 17:10:36 +01:00
|
|
|
_info "Check and Save Props"
|
2018-03-09 16:29:47 +01:00
|
|
|
_check_and_save
|
2020-01-02 17:10:36 +01:00
|
|
|
_info "Checking Zone and Record_Name"
|
2019-12-28 11:58:21 +01:00
|
|
|
_get_zone_and_record_name "$_fulldomain"
|
2020-01-02 17:10:36 +01:00
|
|
|
_info "Getting Record ID"
|
2018-03-09 16:29:47 +01:00
|
|
|
_get_record_id
|
2020-01-15 17:48:30 +01:00
|
|
|
|
2019-11-29 22:22:26 +01:00
|
|
|
# If there is a record_id, delete the entry
|
2018-03-09 16:29:47 +01:00
|
|
|
if [ -n "$_record_id" ]; then
|
|
|
|
params="?kas_login=$KAS_Login"
|
|
|
|
params="$params&kas_auth_type=$KAS_Authtype"
|
|
|
|
params="$params&kas_auth_data=$KAS_Authdata"
|
|
|
|
params="$params&kas_action=delete_dns_settings"
|
2019-11-29 22:22:26 +01:00
|
|
|
|
2019-12-12 16:23:42 +01:00
|
|
|
for i in $_record_id; do
|
2019-06-05 11:38:41 +02:00
|
|
|
params2="$params&var1=record_id"
|
|
|
|
params2="$params2&wert1=$i"
|
|
|
|
_debug2 "Wait for 10 seconds by default before calling KAS API."
|
2020-01-23 19:20:44 +01:00
|
|
|
_sleep 10
|
2019-06-05 11:38:41 +02:00
|
|
|
response="$(_get "$KAS_Api$params2")"
|
|
|
|
_debug2 "response" "$response"
|
|
|
|
if ! _contains "$response" "TRUE"; then
|
|
|
|
_err "Either the txt record is not found or another error occurred, please check manually."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
done
|
2018-03-09 16:29:47 +01:00
|
|
|
else # Cannot delete or unkown error
|
|
|
|
_err "No record_id found that can be deleted. Please check manually."
|
|
|
|
return 1
|
|
|
|
fi
|
2019-11-29 22:46:44 +01:00
|
|
|
return 0
|
2018-03-09 16:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
########################## PRIVATE FUNCTIONS ###########################
|
|
|
|
|
|
|
|
# Checks for the ENV variables and saves them
|
|
|
|
_check_and_save() {
|
|
|
|
KAS_Login="${KAS_Login:-$(_readaccountconf_mutable KAS_Login)}"
|
|
|
|
KAS_Authtype="${KAS_Authtype:-$(_readaccountconf_mutable KAS_Authtype)}"
|
|
|
|
KAS_Authdata="${KAS_Authdata:-$(_readaccountconf_mutable KAS_Authdata)}"
|
|
|
|
|
|
|
|
if [ -z "$KAS_Login" ] || [ -z "$KAS_Authtype" ] || [ -z "$KAS_Authdata" ]; then
|
|
|
|
KAS_Login=
|
|
|
|
KAS_Authtype=
|
|
|
|
KAS_Authdata=
|
|
|
|
_err "No auth details provided. Please set user credentials using the \$KAS_Login, \$KAS_Authtype, and \$KAS_Authdata environment variables."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
_saveaccountconf_mutable KAS_Login "$KAS_Login"
|
|
|
|
_saveaccountconf_mutable KAS_Authtype "$KAS_Authtype"
|
|
|
|
_saveaccountconf_mutable KAS_Authdata "$KAS_Authdata"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2019-12-28 11:58:21 +01:00
|
|
|
# Gets back the base domain/zone and record name.
|
2018-03-09 16:29:47 +01:00
|
|
|
# See: https://github.com/Neilpang/acme.sh/wiki/DNS-API-Dev-Guide
|
2019-12-28 23:42:46 +01:00
|
|
|
_get_zone_and_record_name() {
|
2020-01-15 17:48:30 +01:00
|
|
|
params="?kas_login=$KAS_Login"
|
2020-01-02 17:10:36 +01:00
|
|
|
params="?kas_login=$KAS_Login"
|
|
|
|
params="$params&kas_auth_type=$KAS_Authtype"
|
|
|
|
params="$params&kas_auth_data=$KAS_Authdata"
|
|
|
|
params="$params&kas_action=get_domains"
|
|
|
|
|
|
|
|
_debug2 "Wait for 10 seconds by default before calling KAS API."
|
2020-01-23 19:20:44 +01:00
|
|
|
_sleep 10
|
2020-01-02 17:10:36 +01:00
|
|
|
response="$(_get "$KAS_Api$params")"
|
|
|
|
_debug2 "response" "$response"
|
2020-01-15 13:56:01 +01:00
|
|
|
_zonen="$(echo "$response" | tr -d "\n\r" | tr -d " " | tr '[]' '<>' | sed "s/=>Array/\n=> Array/g" | tr ' ' '\n' | grep "domain_name" | tr '<' '\n' | grep "domain_name" | sed "s/domain_name>=>//g")"
|
2019-12-28 11:58:21 +01:00
|
|
|
_domain="$1"
|
2020-01-15 13:56:01 +01:00
|
|
|
_temp_domain="$(echo "$1" | sed 's/\.$//')"
|
2019-12-28 11:58:21 +01:00
|
|
|
_rootzone="$_domain"
|
|
|
|
for i in $_zonen; do
|
|
|
|
l1=${#_rootzone}
|
|
|
|
l2=${#i}
|
|
|
|
if _endswith "$_domain" "$i" && [ "$l1" -ge "$l2" ]; then
|
|
|
|
_rootzone="$i"
|
|
|
|
fi
|
|
|
|
done
|
2020-01-02 17:10:36 +01:00
|
|
|
_zone="${_rootzone}."
|
2020-01-15 13:56:01 +01:00
|
|
|
_temp_record_name="$(echo "$_temp_domain" | sed "s/$_rootzone//g")"
|
|
|
|
_record_name="$(echo "$_temp_record_name" | sed 's/\.$//')"
|
2020-01-02 17:10:36 +01:00
|
|
|
_debug2 "Zone:" "$_zone"
|
|
|
|
_debug2 "Domain:" "$_domain"
|
|
|
|
_debug2 "Record_Name:" "$_record_name"
|
2018-03-16 15:02:47 +01:00
|
|
|
return 0
|
2018-03-09 16:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Retrieve the DNS record ID
|
|
|
|
_get_record_id() {
|
|
|
|
params="?kas_login=$KAS_Login"
|
|
|
|
params="$params&kas_auth_type=$KAS_Authtype"
|
|
|
|
params="$params&kas_auth_data=$KAS_Authdata"
|
|
|
|
params="$params&kas_action=get_dns_settings"
|
|
|
|
params="$params&var1=zone_host"
|
|
|
|
params="$params&wert1=$_zone"
|
|
|
|
|
2018-08-02 16:20:48 +02:00
|
|
|
_debug2 "Wait for 10 seconds by default before calling KAS API."
|
2020-01-23 19:20:44 +01:00
|
|
|
_sleep 10
|
2018-03-09 16:29:47 +01:00
|
|
|
response="$(_get "$KAS_Api$params")"
|
|
|
|
_debug2 "response" "$response"
|
2020-01-02 17:10:36 +01:00
|
|
|
_record_id="$(echo "$response" | tr -d "\n\r" | tr -d " " | tr '[]' '<>' | sed "s/=>Array/\n=> Array/g" | tr ' ' '\n' | grep "=>$_record_name<" | grep '>TXT<' | tr '<' '\n' | grep record_id | sed "s/record_id>=>//g")"
|
2018-03-09 16:29:47 +01:00
|
|
|
_debug2 _record_id "$_record_id"
|
|
|
|
return 0
|
2019-11-29 22:22:26 +01:00
|
|
|
}
|