From b825b70db0c607b1be1ac2d431bcd87d40955c68 Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 11:00:04 +0200 Subject: [PATCH 01/15] Create dns_wts.sh --- dnsapi/dns_wts.sh | 1 + 1 file changed, 1 insertion(+) create mode 100644 dnsapi/dns_wts.sh diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/dnsapi/dns_wts.sh @@ -0,0 +1 @@ + From 287381c210209530c3794856b408303ac44acd12 Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 11:04:37 +0200 Subject: [PATCH 02/15] Update dns_wts.sh --- dnsapi/dns_wts.sh | 156 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh index 8b137891..5ef60f8f 100644 --- a/dnsapi/dns_wts.sh +++ b/dnsapi/dns_wts.sh @@ -1 +1,157 @@ +#!/usr/bin/env sh +# shellcheck disable=SC2034 +dns_wts_info='Wärner Technologie Services +Site: Waerner-TechServices.de +Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_wts +Options: + WTS_API_Token API Token +Issues: github.com/acmesh-official/acme.sh/issues/4419 +Author: Lukas Wärner (CEO) +' +WTS_API="https://wts-api.de/hosting/domain" + +######## Public functions ###################### + +#Usage: dns_wts_add _acme-challenge.domain.waerner-techservices.de "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" +dns_wts_add() { + fulldomain=$1 + txtvalue=$2 + + WTS_API_Token="${WTS_API_Token:-$(_readaccountconf_mutable WTS_API_Token)}" + if [ -z "$WTS_API_Token" ]; then + _err "You must export variable: WTS_API_Token" + _err "The API Key for your WTS account is necessary." + _err "You can look it up in your WTS account." + return 1 + fi + + # Now save the credentials. + _saveaccountconf_mutable WTS_API_Token "$WTS_API_Token" + + if ! _get_root "$fulldomain"; then + _err "invalid domain" "$fulldomain" + return 1 + fi + _debug _sub_domain "$_sub_domain" + _debug _domain "$_domain" + + # convert to lower case + _domain="$(echo "$_domain" | _lower_case)" + _sub_domain="$(echo "$_sub_domain" | _lower_case)" + # Now add the TXT record + _info "Trying to add TXT record" + if _WTS_rest "POST" "add_record=$_domain&praefix=$_sub_domain&type=TXT&content=$txtvalue"; then + _info "TXT record has been successfully added." + return 0 + else + _err "Errors happened during adding the TXT record, response=$_response" + return 1 + fi + +} + +#Usage: fulldomain txtvalue +#Usage: dns_wts_rm _acme-challenge.domain.waerner-techservices.de "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" +#Remove the txt record after validation. +dns_wts_rm() { + fulldomain=$1 + txtvalue=$2 + + WTS_API_Token="${WTS_API_Token:-$(_readaccountconf_mutable WTS_API_Token)}" + if [ -z "$WTS_API_Token" ]; then + _err "You must export variable: WTS_API_Token" + _err "The API Key for your WTS account is necessary." + _err "You can look it up in your WTS account." + return 1 + fi + + if ! _get_root "$fulldomain"; then + _err "invalid domain" "$fulldomain" + return 1 + fi + _debug _sub_domain "$_sub_domain" + _debug _domain "$_domain" + + # convert to lower case + _domain="$(echo "$_domain" | _lower_case)" + _sub_domain="$(echo "$_sub_domain" | _lower_case)" + # Now delete the TXT record + _info "Trying to delete TXT record" + if _WTS_rest "DELETE" "del_record=$_domain&praefix=$_sub_domain&type=TXT&content=$txtvalue"; then + _info "TXT record has been successfully deleted." + return 0 + else + _err "Errors happened during deleting the TXT record, response=$_response" + return 1 + fi + +} + +#################### Private functions below ################################## +#_acme-challenge.www.domain.com +#returns +# _sub_domain=_acme-challenge.www +# _domain=domain.com +_get_root() { + domain="$1" + i=1 + p=1 + + _WTS_get "get_domains" + domain_data=$_response + + while true; do + h=$(printf "%s" "$domain" | cut -d . -f "$i"-100) + if [ -z "$h" ]; then + #not valid + return 1 + fi + + #if _contains "$domain_data" "\""$h"\"\:"; then + if _contains "$domain_data" "\"""$h""\"\:"; then + _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-"$p") + _domain="$h" + return 0 + fi + p=$i + i=$(_math "$i" + 1) + done + return 1 +} + +#send get request to api +# $1 has to set the api-function +_WTS_get() { + url="$WTS_API?$1" + export _H1="Authorization: Bearer $WTS_API_Token" + + _response=$(_get "$url") + _response="$(echo "$_response" | _normalizeJson)" + + if _contains "$_response" "429 Too Many Requests"; then + _info "API throttled, sleeping to reset the limit" + _sleep 10 + _response=$(_get "$url") + _response="$(echo "$_response" | _normalizeJson)" + fi +} + +_WTS_rest() { + url="$WTS_API" + export _H1="Authorization: Bearer $WTS_API_Token" + export _H2="Content-Type: application/x-www-form-urlencoded" + _response=$(_post "$2" "$url" "" "$1") + + if _contains "$_response" "429 Too Many Requests"; then + _info "API throttled, sleeping to reset the limit" + _sleep 10 + _response=$(_post "$2" "$url" "" "$1") + fi + + if ! _contains "$_response" "\"info\":\"success\""; then + return 1 + fi + _debug2 response "$_response" + return 0 +} From 1483ecb69f42b8cc51fcdce40503db11b63d1951 Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 12:43:38 +0200 Subject: [PATCH 03/15] Update dns_wts.sh Fully integrated new WTS-API for updating dns-records. --- dnsapi/dns_wts.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh index 5ef60f8f..fd10332d 100644 --- a/dnsapi/dns_wts.sh +++ b/dnsapi/dns_wts.sh @@ -13,6 +13,8 @@ WTS_API="https://wts-api.de/hosting/domain" ######## Public functions ###################### +TMP_RecordID=0 # Temporary Id of the creazed record will be safed here. + #Usage: dns_wts_add _acme-challenge.domain.waerner-techservices.de "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" dns_wts_add() { fulldomain=$1 @@ -41,7 +43,8 @@ dns_wts_add() { _sub_domain="$(echo "$_sub_domain" | _lower_case)" # Now add the TXT record _info "Trying to add TXT record" - if _WTS_rest "POST" "add_record=$_domain&praefix=$_sub_domain&type=TXT&content=$txtvalue"; then + # if _WTS_rest "POST" "add_record=$_domain&praefix=$_sub_domain&type=TXT&content=$txtvalue"; then + if _WTS_rest "POST" "/$_domain/records/add/txt/$_sub_domain/$txtvalue?WTS-API-Token=$WTS_API_Token"; then _info "TXT record has been successfully added." return 0 else @@ -78,7 +81,7 @@ dns_wts_rm() { _sub_domain="$(echo "$_sub_domain" | _lower_case)" # Now delete the TXT record _info "Trying to delete TXT record" - if _WTS_rest "DELETE" "del_record=$_domain&praefix=$_sub_domain&type=TXT&content=$txtvalue"; then + if _WTS_rest "DELETE" "/$_domain/records/remove/$TMP_RecordID?WTS-API-Token=$WTS_API_Token"; then _info "TXT record has been successfully deleted." return 0 else From f459849452a9fc182024c5ab4c9a3cd0d8e6bda4 Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 12:56:54 +0200 Subject: [PATCH 04/15] Update dns_wts.sh --- dnsapi/dns_wts.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh index fd10332d..5ee5fe75 100644 --- a/dnsapi/dns_wts.sh +++ b/dnsapi/dns_wts.sh @@ -5,7 +5,7 @@ Site: Waerner-TechServices.de Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_wts Options: WTS_API_Token API Token -Issues: github.com/acmesh-official/acme.sh/issues/4419 +Issues: github.com/acmesh-official/acme.sh/issues/6372 Author: Lukas Wärner (CEO) ' @@ -41,17 +41,20 @@ dns_wts_add() { # convert to lower case _domain="$(echo "$_domain" | _lower_case)" _sub_domain="$(echo "$_sub_domain" | _lower_case)" + # Now add the TXT record _info "Trying to add TXT record" - # if _WTS_rest "POST" "add_record=$_domain&praefix=$_sub_domain&type=TXT&content=$txtvalue"; then if _WTS_rest "POST" "/$_domain/records/add/txt/$_sub_domain/$txtvalue?WTS-API-Token=$WTS_API_Token"; then _info "TXT record has been successfully added." + TMP_RecordID="$(echo "$_response" | _egrep_o '"record_id"[[:space:]]*:[[:space:]]*"[^"]+"' | cut -d ':' -f2 | tr -d ' "')" + _debug "Saved TMP_RecordID=$TMP_RecordID" return 0 else _err "Errors happened during adding the TXT record, response=$_response" return 1 fi + } #Usage: fulldomain txtvalue @@ -85,8 +88,12 @@ dns_wts_rm() { _info "TXT record has been successfully deleted." return 0 else - _err "Errors happened during deleting the TXT record, response=$_response" - return 1 + if $WTS_API_Token == 0: + _err "Errors happened during deleting the TXT record, because the temporary record-id from creation is not set." + return 1 + else: + _err "Errors happened during deleting the TXT record, response=$_response" + return 1 fi } From 2a62f8af8ff3a24ae6a8d9a3e71eafc0698405c5 Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 13:33:40 +0200 Subject: [PATCH 05/15] Update dns_wts.sh --- dnsapi/dns_wts.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh index 5ee5fe75..d7fb4551 100644 --- a/dnsapi/dns_wts.sh +++ b/dnsapi/dns_wts.sh @@ -88,12 +88,13 @@ dns_wts_rm() { _info "TXT record has been successfully deleted." return 0 else - if $WTS_API_Token == 0: + if [ -z "$TMP_RecordID" ]; then _err "Errors happened during deleting the TXT record, because the temporary record-id from creation is not set." return 1 else: _err "Errors happened during deleting the TXT record, response=$_response" return 1 + fi fi } From 99c4296404d648be1648071b0cdaf67ccbc58364 Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 14:11:08 +0200 Subject: [PATCH 06/15] Update dns_wts.sh Resolving errors while updating records. --- dnsapi/dns_wts.sh | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh index d7fb4551..f23feef4 100644 --- a/dnsapi/dns_wts.sh +++ b/dnsapi/dns_wts.sh @@ -10,7 +10,6 @@ Author: Lukas Wärner (CEO) ' WTS_API="https://wts-api.de/hosting/domain" - ######## Public functions ###################### TMP_RecordID=0 # Temporary Id of the creazed record will be safed here. @@ -109,7 +108,9 @@ _get_root() { i=1 p=1 - _WTS_get "get_domains" + WTS_API_Token="${WTS_API_Token:-$(_readaccountconf_mutable WTS_API_Token)}" + + _WTS_get "list?WTS-API-Token=$WTS_API_Token" domain_data=$_response while true; do @@ -134,7 +135,7 @@ _get_root() { #send get request to api # $1 has to set the api-function _WTS_get() { - url="$WTS_API?$1" + url="$WTS_API/$1" export _H1="Authorization: Bearer $WTS_API_Token" _response=$(_get "$url") @@ -152,15 +153,40 @@ _WTS_rest() { url="$WTS_API" export _H1="Authorization: Bearer $WTS_API_Token" export _H2="Content-Type: application/x-www-form-urlencoded" - _response=$(_post "$2" "$url" "" "$1") + + + method="$1" + path="$2" + full_url="$WTS_API$path" + + export _H1="Authorization: Bearer $WTS_API_Token" + export _H2="Content-Type: application/x-www-form-urlencoded" + + if [ "$method" = "POST" ]; then + _response=$(_post "" "$full_url") + elif [ "$method" = "DELETE" ]; then + _response=$(_post "" "$full_url" "" "DELETE") + else + _response=$(_get "$full_url") + fi if _contains "$_response" "429 Too Many Requests"; then _info "API throttled, sleeping to reset the limit" _sleep 10 - _response=$(_post "$2" "$url" "" "$1") + if [ "$method" = "POST" ]; then + _response=$(_post "" "$full_url") + elif [ "$method" = "DELETE" ]; then + _response=$(_post "" "$full_url" "" "DELETE") + else + _response=$(_get "$full_url") + fi fi - if ! _contains "$_response" "\"info\":\"success\""; then + _debug2 response "$_response" + echo "$_response" | grep -q "\"info\":\"success\"" + + + if ! _contains "$_response" "\"success\":\True"; then return 1 fi _debug2 response "$_response" From c443f45142732a71449630a1f493ef69e40fdec1 Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 15:27:04 +0200 Subject: [PATCH 07/15] Update dns_wts.sh Saving the TMP_RecordID in a TMP-File. --- dnsapi/dns_wts.sh | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh index f23feef4..a06e19ee 100644 --- a/dnsapi/dns_wts.sh +++ b/dnsapi/dns_wts.sh @@ -12,7 +12,11 @@ Author: Lukas Wärner (CEO) WTS_API="https://wts-api.de/hosting/domain" ######## Public functions ###################### -TMP_RecordID=0 # Temporary Id of the creazed record will be safed here. +# TMP_RecordID=0 # Temporary Id of the creazed record will be safed here. + +TMP_DIR="/tmp/acme-wts" +mkdir -p "$TMP_DIR" +TMP_RECORD_FILE="$TMP_DIR/${fulldomain//\*/_}.record_id" #Usage: dns_wts_add _acme-challenge.domain.waerner-techservices.de "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" dns_wts_add() { @@ -45,8 +49,14 @@ dns_wts_add() { _info "Trying to add TXT record" if _WTS_rest "POST" "/$_domain/records/add/txt/$_sub_domain/$txtvalue?WTS-API-Token=$WTS_API_Token"; then _info "TXT record has been successfully added." - TMP_RecordID="$(echo "$_response" | _egrep_o '"record_id"[[:space:]]*:[[:space:]]*"[^"]+"' | cut -d ':' -f2 | tr -d ' "')" - _debug "Saved TMP_RecordID=$TMP_RecordID" + # export TMP_RecordID="$(echo "$_response" | _egrep_o '"record_id"[[:space:]]*:[[:space:]]*[0-9]+' | cut -d ':' -f2 | tr -d ' ')" + TMP_RecordID="$(echo "$_response" | _egrep_o '"record_id"[[:space:]]*:[[:space:]]*[0-9]+' | cut -d ':' -f2 | tr -d ' ')" + TMP_RECORD_FILE="/tmp/acme-wts/${fulldomain//\*/_}.record_id" + mkdir -p /tmp/acme-wts + echo "$TMP_RecordID" > "$TMP_RECORD_FILE" + _info "Saved TMP_RecordID=$TMP_RecordID to $TMP_RECORD_FILE" + + return 0 else _err "Errors happened during adding the TXT record, response=$_response" @@ -83,6 +93,27 @@ dns_wts_rm() { _sub_domain="$(echo "$_sub_domain" | _lower_case)" # Now delete the TXT record _info "Trying to delete TXT record" + + TMP_RECORD_FILE="/tmp/acme-wts/${fulldomain//\*/_}.record_id" + + if [ -f "$TMP_RECORD_FILE" ]; then + TMP_RecordID="$(cat "$TMP_RECORD_FILE")" + rm -f "$TMP_RECORD_FILE" + _debug "Loaded TMP_RecordID=$TMP_RecordID from $TMP_RECORD_FILE" + else + _err "TMP_RecordID file not found for domain $fulldomain" + return 1 + fi + + + + if [ -z "$TMP_RecordID" ]; then + _err "TMP_RecordID not found. Cannot delete record." + return 1 + fi + + _info "Using TMP_RecordID: $TMP_RecordID" + if _WTS_rest "DELETE" "/$_domain/records/remove/$TMP_RecordID?WTS-API-Token=$WTS_API_Token"; then _info "TXT record has been successfully deleted." return 0 @@ -186,7 +217,11 @@ _WTS_rest() { echo "$_response" | grep -q "\"info\":\"success\"" - if ! _contains "$_response" "\"success\":\True"; then + if _contains "$_response" '"error_desc":"Error while deleting dns-record."'; then + return 1 + fi + + if ! _contains "$_response" '"success":true'; then return 1 fi _debug2 response "$_response" From 5f0841a643383152c384c57aab4752bf0de1e138 Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 19:07:43 +0200 Subject: [PATCH 08/15] Update dns_wts.sh --- dnsapi/dns_wts.sh | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh index a06e19ee..609f573b 100644 --- a/dnsapi/dns_wts.sh +++ b/dnsapi/dns_wts.sh @@ -51,10 +51,11 @@ dns_wts_add() { _info "TXT record has been successfully added." # export TMP_RecordID="$(echo "$_response" | _egrep_o '"record_id"[[:space:]]*:[[:space:]]*[0-9]+' | cut -d ':' -f2 | tr -d ' ')" TMP_RecordID="$(echo "$_response" | _egrep_o '"record_id"[[:space:]]*:[[:space:]]*[0-9]+' | cut -d ':' -f2 | tr -d ' ')" - TMP_RECORD_FILE="/tmp/acme-wts/${fulldomain//\*/_}.record_id" - mkdir -p /tmp/acme-wts - echo "$TMP_RecordID" > "$TMP_RECORD_FILE" - _info "Saved TMP_RecordID=$TMP_RecordID to $TMP_RECORD_FILE" + # TMP_RECORD_FILE="/tmp/acme-wts/${fulldomain//\*/_}.record_id" + # mkdir -p /tmp/acme-wts + # echo "$TMP_RecordID" > "$TMP_RECORD_FILE" + _saveaccountconf_mutable "_WTS_RecordID_$fulldomain" "$TMP_RecordID" + _info "Saved TMP_RecordID=$TMP_RecordID" return 0 @@ -94,18 +95,18 @@ dns_wts_rm() { # Now delete the TXT record _info "Trying to delete TXT record" - TMP_RECORD_FILE="/tmp/acme-wts/${fulldomain//\*/_}.record_id" - - if [ -f "$TMP_RECORD_FILE" ]; then - TMP_RecordID="$(cat "$TMP_RECORD_FILE")" - rm -f "$TMP_RECORD_FILE" - _debug "Loaded TMP_RecordID=$TMP_RecordID from $TMP_RECORD_FILE" - else - _err "TMP_RecordID file not found for domain $fulldomain" - return 1 - fi + # TMP_RECORD_FILE="/tmp/acme-wts/${fulldomain//\*/_}.record_id" + # if [ -f "$TMP_RECORD_FILE" ]; then + # TMP_RecordID="$(cat "$TMP_RECORD_FILE")" + # rm -f "$TMP_RECORD_FILE" + # _debug "Loaded TMP_RecordID=$TMP_RecordID from $TMP_RECORD_FILE" + # else + # _err "TMP_RecordID file not found for domain $fulldomain" + # return 1 + # fi + TMP_RecordID="$(_readaccountconf_mutable "_WTS_RecordID_$fulldomain")" if [ -z "$TMP_RecordID" ]; then _err "TMP_RecordID not found. Cannot delete record." From f8eccefad418cfde97b972aadb13bd3a07a9b678 Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 19:17:35 +0200 Subject: [PATCH 09/15] Update dns_wts.sh --- dnsapi/dns_wts.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh index 609f573b..1a253566 100644 --- a/dnsapi/dns_wts.sh +++ b/dnsapi/dns_wts.sh @@ -54,7 +54,9 @@ dns_wts_add() { # TMP_RECORD_FILE="/tmp/acme-wts/${fulldomain//\*/_}.record_id" # mkdir -p /tmp/acme-wts # echo "$TMP_RecordID" > "$TMP_RECORD_FILE" - _saveaccountconf_mutable "_WTS_RecordID_$fulldomain" "$TMP_RecordID" + clean_domain="${fulldomain//\*/_wildcard_}" + _saveaccountconf_mutable "_WTS_RecordID_$clean_domain" "$TMP_RecordID" + _info "Saved TMP_RecordID=$TMP_RecordID" @@ -106,7 +108,8 @@ dns_wts_rm() { # return 1 # fi - TMP_RecordID="$(_readaccountconf_mutable "_WTS_RecordID_$fulldomain")" + clean_domain="${fulldomain//\*/_wildcard_}" + TMP_RecordID="$(_readaccountconf_mutable "_WTS_RecordID_$clean_domain")" if [ -z "$TMP_RecordID" ]; then _err "TMP_RecordID not found. Cannot delete record." From 141287fe2110c31210fcc9540b1b37b539499bc0 Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 19:18:02 +0200 Subject: [PATCH 10/15] Update dns_wts.sh --- dnsapi/dns_wts.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh index 1a253566..b76de4a6 100644 --- a/dnsapi/dns_wts.sh +++ b/dnsapi/dns_wts.sh @@ -14,9 +14,9 @@ WTS_API="https://wts-api.de/hosting/domain" # TMP_RecordID=0 # Temporary Id of the creazed record will be safed here. -TMP_DIR="/tmp/acme-wts" -mkdir -p "$TMP_DIR" -TMP_RECORD_FILE="$TMP_DIR/${fulldomain//\*/_}.record_id" +# TMP_DIR="/tmp/acme-wts" +# mkdir -p "$TMP_DIR" +# TMP_RECORD_FILE="$TMP_DIR/${fulldomain//\*/_}.record_id" #Usage: dns_wts_add _acme-challenge.domain.waerner-techservices.de "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" dns_wts_add() { From e016f5d037965c6d5b14b0d005952edfd8f00060 Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 19:45:58 +0200 Subject: [PATCH 11/15] Update dns_wts.sh --- dnsapi/dns_wts.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh index b76de4a6..c2aaf2c0 100644 --- a/dnsapi/dns_wts.sh +++ b/dnsapi/dns_wts.sh @@ -55,7 +55,7 @@ dns_wts_add() { # mkdir -p /tmp/acme-wts # echo "$TMP_RecordID" > "$TMP_RECORD_FILE" clean_domain="${fulldomain//\*/_wildcard_}" - _saveaccountconf_mutable "_WTS_RecordID_$clean_domain" "$TMP_RecordID" + _saveaccountconf_mutable "_WTS_RecordID" "$TMP_RecordID" _info "Saved TMP_RecordID=$TMP_RecordID" @@ -109,7 +109,7 @@ dns_wts_rm() { # fi clean_domain="${fulldomain//\*/_wildcard_}" - TMP_RecordID="$(_readaccountconf_mutable "_WTS_RecordID_$clean_domain")" + TMP_RecordID="$(_readaccountconf_mutable "_WTS_RecordID")" if [ -z "$TMP_RecordID" ]; then _err "TMP_RecordID not found. Cannot delete record." From 0016fe2e13f2a87efcab9bc2f6602c5972430fa3 Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 20:23:09 +0200 Subject: [PATCH 12/15] Update dns_wts.sh --- dnsapi/dns_wts.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh index c2aaf2c0..66f53b55 100644 --- a/dnsapi/dns_wts.sh +++ b/dnsapi/dns_wts.sh @@ -1,5 +1,4 @@ -#!/usr/bin/env sh -# shellcheck disable=SC2034 +#!/bin/bash dns_wts_info='Wärner Technologie Services Site: Waerner-TechServices.de Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_wts From b5124582ff72e2a69d1b97a41623f976fed47e4b Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 20:27:28 +0200 Subject: [PATCH 13/15] Update dns_wts.sh --- dnsapi/dns_wts.sh | 94 +++++++++++------------------------------------ 1 file changed, 22 insertions(+), 72 deletions(-) diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh index 66f53b55..1cabaae4 100644 --- a/dnsapi/dns_wts.sh +++ b/dnsapi/dns_wts.sh @@ -1,4 +1,5 @@ -#!/bin/bash +#!/bin/bash + dns_wts_info='Wärner Technologie Services Site: Waerner-TechServices.de Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_wts @@ -9,15 +10,10 @@ Author: Lukas Wärner (CEO) ' WTS_API="https://wts-api.de/hosting/domain" + ######## Public functions ###################### -# TMP_RecordID=0 # Temporary Id of the creazed record will be safed here. - -# TMP_DIR="/tmp/acme-wts" -# mkdir -p "$TMP_DIR" -# TMP_RECORD_FILE="$TMP_DIR/${fulldomain//\*/_}.record_id" - -#Usage: dns_wts_add _acme-challenge.domain.waerner-techservices.de "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" +# Add TXT record dns_wts_add() { fulldomain=$1 txtvalue=$2 @@ -30,47 +26,36 @@ dns_wts_add() { return 1 fi - # Now save the credentials. _saveaccountconf_mutable WTS_API_Token "$WTS_API_Token" if ! _get_root "$fulldomain"; then - _err "invalid domain" "$fulldomain" + _err "Invalid domain: $fulldomain" return 1 fi + _debug _sub_domain "$_sub_domain" _debug _domain "$_domain" - # convert to lower case _domain="$(echo "$_domain" | _lower_case)" _sub_domain="$(echo "$_sub_domain" | _lower_case)" - - # Now add the TXT record + _info "Trying to add TXT record" if _WTS_rest "POST" "/$_domain/records/add/txt/$_sub_domain/$txtvalue?WTS-API-Token=$WTS_API_Token"; then _info "TXT record has been successfully added." - # export TMP_RecordID="$(echo "$_response" | _egrep_o '"record_id"[[:space:]]*:[[:space:]]*[0-9]+' | cut -d ':' -f2 | tr -d ' ')" - TMP_RecordID="$(echo "$_response" | _egrep_o '"record_id"[[:space:]]*:[[:space:]]*[0-9]+' | cut -d ':' -f2 | tr -d ' ')" - # TMP_RECORD_FILE="/tmp/acme-wts/${fulldomain//\*/_}.record_id" - # mkdir -p /tmp/acme-wts - # echo "$TMP_RecordID" > "$TMP_RECORD_FILE" + + TMP_RecordID="$(echo "$_response" | _egrep_o '"record_id"[[:space:]]*:[[:space:]]*[0-9]+' | grep -o '[0-9]\+')" clean_domain="${fulldomain//\*/_wildcard_}" - _saveaccountconf_mutable "_WTS_RecordID" "$TMP_RecordID" - + + _saveaccountconf_mutable "SAVED__WTS_RecordID__$clean_domain" "$TMP_RecordID" _info "Saved TMP_RecordID=$TMP_RecordID" - - return 0 else _err "Errors happened during adding the TXT record, response=$_response" return 1 fi - - } -#Usage: fulldomain txtvalue -#Usage: dns_wts_rm _acme-challenge.domain.waerner-techservices.de "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" -#Remove the txt record after validation. +# Remove TXT record dns_wts_rm() { fulldomain=$1 txtvalue=$2 @@ -78,37 +63,24 @@ dns_wts_rm() { WTS_API_Token="${WTS_API_Token:-$(_readaccountconf_mutable WTS_API_Token)}" if [ -z "$WTS_API_Token" ]; then _err "You must export variable: WTS_API_Token" - _err "The API Key for your WTS account is necessary." - _err "You can look it up in your WTS account." return 1 fi if ! _get_root "$fulldomain"; then - _err "invalid domain" "$fulldomain" + _err "Invalid domain: $fulldomain" return 1 fi + _debug _sub_domain "$_sub_domain" _debug _domain "$_domain" - # convert to lower case _domain="$(echo "$_domain" | _lower_case)" _sub_domain="$(echo "$_sub_domain" | _lower_case)" - # Now delete the TXT record + _info "Trying to delete TXT record" - # TMP_RECORD_FILE="/tmp/acme-wts/${fulldomain//\*/_}.record_id" - - # if [ -f "$TMP_RECORD_FILE" ]; then - # TMP_RecordID="$(cat "$TMP_RECORD_FILE")" - # rm -f "$TMP_RECORD_FILE" - # _debug "Loaded TMP_RecordID=$TMP_RecordID from $TMP_RECORD_FILE" - # else - # _err "TMP_RecordID file not found for domain $fulldomain" - # return 1 - # fi - clean_domain="${fulldomain//\*/_wildcard_}" - TMP_RecordID="$(_readaccountconf_mutable "_WTS_RecordID")" + TMP_RecordID="$(_readaccountconf_mutable "SAVED__WTS_RecordID__$clean_domain")" if [ -z "$TMP_RecordID" ]; then _err "TMP_RecordID not found. Cannot delete record." @@ -121,22 +93,13 @@ dns_wts_rm() { _info "TXT record has been successfully deleted." return 0 else - if [ -z "$TMP_RecordID" ]; then - _err "Errors happened during deleting the TXT record, because the temporary record-id from creation is not set." - return 1 - else: - _err "Errors happened during deleting the TXT record, response=$_response" - return 1 - fi + _err "Errors happened during deleting the TXT record, response=$_response" + return 1 fi - } #################### Private functions below ################################## -#_acme-challenge.www.domain.com -#returns -# _sub_domain=_acme-challenge.www -# _domain=domain.com + _get_root() { domain="$1" i=1 @@ -150,11 +113,9 @@ _get_root() { while true; do h=$(printf "%s" "$domain" | cut -d . -f "$i"-100) if [ -z "$h" ]; then - #not valid return 1 fi - #if _contains "$domain_data" "\""$h"\"\:"; then if _contains "$domain_data" "\"""$h""\"\:"; then _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-"$p") _domain="$h" @@ -166,8 +127,7 @@ _get_root() { return 1 } -#send get request to api -# $1 has to set the api-function +# Send GET request _WTS_get() { url="$WTS_API/$1" export _H1="Authorization: Bearer $WTS_API_Token" @@ -183,12 +143,8 @@ _WTS_get() { fi } +# REST request _WTS_rest() { - url="$WTS_API" - export _H1="Authorization: Bearer $WTS_API_Token" - export _H2="Content-Type: application/x-www-form-urlencoded" - - method="$1" path="$2" full_url="$WTS_API$path" @@ -217,16 +173,10 @@ _WTS_rest() { fi _debug2 response "$_response" - echo "$_response" | grep -q "\"info\":\"success\"" - if _contains "$_response" '"error_desc":"Error while deleting dns-record."'; then return 1 fi - if ! _contains "$_response" '"success":true'; then - return 1 - fi - _debug2 response "$_response" - return 0 + echo "$_response" | grep -q "\"success\":true" } From 9b139d0321f0686df5f24081ccc2639c73f4457f Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 20:30:12 +0200 Subject: [PATCH 14/15] Update dns_wts.sh --- dnsapi/dns_wts.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh index 1cabaae4..697987c1 100644 --- a/dnsapi/dns_wts.sh +++ b/dnsapi/dns_wts.sh @@ -1,4 +1,5 @@ #!/bin/bash +# shellcheck disable=SC2034 dns_wts_info='Wärner Technologie Services Site: Waerner-TechServices.de From 64773ae9d7cac19ef0b644b36242732dda7dc222 Mon Sep 17 00:00:00 2001 From: LukasWRN <127308232+LukasWRN@users.noreply.github.com> Date: Mon, 26 May 2025 20:49:33 +0200 Subject: [PATCH 15/15] Update dns_wts.sh --- dnsapi/dns_wts.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/dnsapi/dns_wts.sh b/dnsapi/dns_wts.sh index 697987c1..71d3731e 100644 --- a/dnsapi/dns_wts.sh +++ b/dnsapi/dns_wts.sh @@ -176,6 +176,7 @@ _WTS_rest() { _debug2 response "$_response" if _contains "$_response" '"error_desc":"Error while deleting dns-record."'; then + _err "Error while deleting dns-record" return 1 fi