From 4bc0628358e48770e8bc56d44af93282dc6d6e47 Mon Sep 17 00:00:00 2001 From: baerengraben Date: Sat, 18 Nov 2023 00:30:47 +0100 Subject: [PATCH 1/9] Create dns_hosttech.sh Add hosttech API support --- dnsapi/dns_hosttech.sh | 135 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 dnsapi/dns_hosttech.sh diff --git a/dnsapi/dns_hosttech.sh b/dnsapi/dns_hosttech.sh new file mode 100644 index 00000000..85ed1d0a --- /dev/null +++ b/dnsapi/dns_hosttech.sh @@ -0,0 +1,135 @@ +#!/usr/bin/bash + +#Hosttech_Key="abcdefg" + +Hosttech_Api="https://api.ns1.hosttech.eu/api/user/v1" + +######## Public functions ##################### + +#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" +dns_hosttech_add() { + fulldomain=$1 + txtvalue=$2 + + Hosttech_Key="${Hosttech_Key:-$(_readaccountconf_mutable Hosttech_Key)}" + if [ -z "$Hosttech_Key" ]; then + Hosttech_Key="" + _err "You didn't specify a Hosttech api key." + _err "You can get yours from https://www.myhosttech.eu/user/dns/api" + return 1 + fi + + #save the api key and email to the account conf file. + _saveaccountconf_mutable Hosttech_Key "$Hosttech_Key" + + _debug "First detect the root zone" + if ! _get_root "$fulldomain"; then + _err "invalid domain" + return 1 + fi + _debug _sub_domain "$_sub_domain" + _debug _domain "$_domain" + + _info "Adding record" + if _hosttech_rest POST "zones/$_domain/records" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"text\":\"$txtvalue\",\"ttl\":600}"; then + if _contains "$_response" "$_sub_domain"; then + _debug recordID "$(echo "$_response" | grep -o '"id":[^"]*' | grep -Po "\d+")" + + #save the created recordID to the account conf file, so we can read it back for deleting in dns_hosttech_rm. + _saveaccountconf recordID "$(echo "$_response" | grep -o '"id":[^"]*' | grep -Po "\d+")" + _info "Added, OK" + return 0 + else + _err "Add txt record error." + return 1 + fi + fi + _err "Add txt record error." + return 1 + +} + +#fulldomain txtvalue +dns_hosttech_rm() { + fulldomain=$1 + txtvalue=$2 + + Hosttech_Key="${Hosttech_Key:-$(_readaccountconf_mutable Hosttech_Key)}" + if [ -z "$Hosttech_Key" ]; then + Hosttech_Key="" + _err "You didn't specify a Hosttech api key." + _err "You can get yours from https://www.hosttech.nl/mijn_hosttech" + return 1 + fi + + _debug "First detect the root zone" + if ! _get_root "$fulldomain"; then + _err "invalid domain" + return 1 + fi + + _debug _sub_domain "$_sub_domain" + _debug _domain "$_domain" + + _debug "Removing txt record" + delRecordID="$(_readaccountconf "recordID")" + _hosttech_rest DELETE "zones/$_domain/records/$delRecordID" + + _clearaccountconf recordID +} + +#################### Private functions below ################################## +#_acme-challenge.www.domain.com +#returns +# _sub_domain=_acme-challenge.www +# _domain=domain.com +_get_root() { + domain=$1 + i=2 + p=1 + while true; do + _domain=$(printf "%s" "$domain" | cut -d . -f $i-100) + _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) + _debug _domain "$_domain" + if [ -z "$_domain" ]; then + #not valid + return 1 + fi + + if _hosttech_rest GET "zones?query=${_domain}"; then + if [ "$(echo "$_response" | grep -o '"name":"[^"]*' | cut -d'"' -f4)" = "${_domain}" ]; then + return 0 + fi + else + return 1 + fi + p=$i + i=$(_math "$i" + 1) + done + return 1 +} + +_hosttech_rest() { + m=$1 + ep="$2" + data="$3" + _debug "$ep" + + export _H1="Authorization: Bearer $Hosttech_Key" + export _H2="accept: application/json" + export _H3="Content-Type: application/json" + + _debug data "$data" + _response="$(_post "$data" "$Hosttech_Api/$ep" "" "$m")" + + _code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")" + _debug "http response code $_code" + + if [ "$?" != "0" ]; then + _err "error $ep" + return 1 + fi + + _debug2 response "$_response" + return 0 +} From 912307ebb5293e08e55be8ee5fcd662789f344d5 Mon Sep 17 00:00:00 2001 From: baerengraben Date: Sat, 18 Nov 2023 00:43:56 +0100 Subject: [PATCH 2/9] Update dns_hosttech.sh --- dnsapi/dns_hosttech.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsapi/dns_hosttech.sh b/dnsapi/dns_hosttech.sh index 85ed1d0a..976db3c3 100644 --- a/dnsapi/dns_hosttech.sh +++ b/dnsapi/dns_hosttech.sh @@ -1,6 +1,6 @@ #!/usr/bin/bash -#Hosttech_Key="abcdefg" +#Hosttech_Key="abcdefghuhu" Hosttech_Api="https://api.ns1.hosttech.eu/api/user/v1" From aa560bd09785790dbeb711a077ef2a10d6294598 Mon Sep 17 00:00:00 2001 From: baerengraben Date: Sat, 18 Nov 2023 12:58:16 +0100 Subject: [PATCH 3/9] Update dns_hosttech.sh --- dnsapi/dns_hosttech.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dnsapi/dns_hosttech.sh b/dnsapi/dns_hosttech.sh index 976db3c3..bba8cfc8 100644 --- a/dnsapi/dns_hosttech.sh +++ b/dnsapi/dns_hosttech.sh @@ -1,7 +1,6 @@ #!/usr/bin/bash #Hosttech_Key="abcdefghuhu" - Hosttech_Api="https://api.ns1.hosttech.eu/api/user/v1" ######## Public functions ##################### @@ -34,8 +33,6 @@ dns_hosttech_add() { if _hosttech_rest POST "zones/$_domain/records" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"text\":\"$txtvalue\",\"ttl\":600}"; then if _contains "$_response" "$_sub_domain"; then _debug recordID "$(echo "$_response" | grep -o '"id":[^"]*' | grep -Po "\d+")" - - #save the created recordID to the account conf file, so we can read it back for deleting in dns_hosttech_rm. _saveaccountconf recordID "$(echo "$_response" | grep -o '"id":[^"]*' | grep -Po "\d+")" _info "Added, OK" return 0 @@ -46,7 +43,6 @@ dns_hosttech_add() { fi _err "Add txt record error." return 1 - } #fulldomain txtvalue From 91cb32eaeb337ac4ab123a7a07a6e3605321a7b2 Mon Sep 17 00:00:00 2001 From: baerengraben Date: Sat, 18 Nov 2023 13:15:24 +0100 Subject: [PATCH 4/9] Update dns_hosttech.sh --- dnsapi/dns_hosttech.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dnsapi/dns_hosttech.sh b/dnsapi/dns_hosttech.sh index bba8cfc8..10902c31 100644 --- a/dnsapi/dns_hosttech.sh +++ b/dnsapi/dns_hosttech.sh @@ -44,13 +44,12 @@ dns_hosttech_add() { _err "Add txt record error." return 1 } - -#fulldomain txtvalue + dns_hosttech_rm() { fulldomain=$1 txtvalue=$2 - Hosttech_Key="${Hosttech_Key:-$(_readaccountconf_mutable Hosttech_Key)}" + if [ -z "$Hosttech_Key" ]; then Hosttech_Key="" _err "You didn't specify a Hosttech api key." From 7c95ae4f967c02403e27081ac642b6f57bf6e6be Mon Sep 17 00:00:00 2001 From: baerengraben Date: Sat, 18 Nov 2023 13:22:06 +0100 Subject: [PATCH 5/9] Update dns_hosttech.sh --- dnsapi/dns_hosttech.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dnsapi/dns_hosttech.sh b/dnsapi/dns_hosttech.sh index 10902c31..069566b5 100644 --- a/dnsapi/dns_hosttech.sh +++ b/dnsapi/dns_hosttech.sh @@ -1,6 +1,7 @@ #!/usr/bin/bash -#Hosttech_Key="abcdefghuhu" +#Hosttech_Key="asdfasdfawefasdfawefasdafe" + Hosttech_Api="https://api.ns1.hosttech.eu/api/user/v1" ######## Public functions ##################### @@ -29,10 +30,12 @@ dns_hosttech_add() { _debug _sub_domain "$_sub_domain" _debug _domain "$_domain" - _info "Adding record" + _info "Adding record" if _hosttech_rest POST "zones/$_domain/records" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"text\":\"$txtvalue\",\"ttl\":600}"; then if _contains "$_response" "$_sub_domain"; then _debug recordID "$(echo "$_response" | grep -o '"id":[^"]*' | grep -Po "\d+")" + + #save the created recordID to the account conf file, so we can read it back for deleting in dns_hosttech_rm. _saveaccountconf recordID "$(echo "$_response" | grep -o '"id":[^"]*' | grep -Po "\d+")" _info "Added, OK" return 0 @@ -43,13 +46,15 @@ dns_hosttech_add() { fi _err "Add txt record error." return 1 + } +#fulldomain txtvalue dns_hosttech_rm() { fulldomain=$1 txtvalue=$2 + Hosttech_Key="${Hosttech_Key:-$(_readaccountconf_mutable Hosttech_Key)}" - if [ -z "$Hosttech_Key" ]; then Hosttech_Key="" _err "You didn't specify a Hosttech api key." From 25d2828cf7ec0cdcec135da7e7471715bd3c546c Mon Sep 17 00:00:00 2001 From: baerengraben Date: Sat, 18 Nov 2023 13:58:55 +0100 Subject: [PATCH 6/9] Update dns_hosttech.sh From 49e391555f4edbd02886ee44379a6a70e1a2f80d Mon Sep 17 00:00:00 2001 From: baerengraben Date: Sat, 18 Nov 2023 14:01:31 +0100 Subject: [PATCH 7/9] Update dns_hosttech.sh --- dnsapi/dns_hosttech.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsapi/dns_hosttech.sh b/dnsapi/dns_hosttech.sh index 069566b5..05d9c898 100644 --- a/dnsapi/dns_hosttech.sh +++ b/dnsapi/dns_hosttech.sh @@ -14,7 +14,7 @@ dns_hosttech_add() { Hosttech_Key="${Hosttech_Key:-$(_readaccountconf_mutable Hosttech_Key)}" if [ -z "$Hosttech_Key" ]; then Hosttech_Key="" - _err "You didn't specify a Hosttech api key." + _err "You didn't specify a Hosttech api key" _err "You can get yours from https://www.myhosttech.eu/user/dns/api" return 1 fi From 04e72dcfedcb01300a3a4872d91d72523bb2ea1e Mon Sep 17 00:00:00 2001 From: baerengraben Date: Thu, 23 Jan 2025 18:25:46 +0000 Subject: [PATCH 8/9] Add _rm by quering the recordId --- dnsapi/dns_hosttech.sh | 101 +++++++++++++++++++++++++++++++++-------- 1 file changed, 82 insertions(+), 19 deletions(-) diff --git a/dnsapi/dns_hosttech.sh b/dnsapi/dns_hosttech.sh index 05d9c898..11185c82 100644 --- a/dnsapi/dns_hosttech.sh +++ b/dnsapi/dns_hosttech.sh @@ -1,4 +1,12 @@ -#!/usr/bin/bash +#!/usr/bin/env sh +# shellcheck disable=SC2034 +dns_hosttech_info='hosttech.eu +Site: hosttech.eu +Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_hosttech +Options: + Hosttech_Key API Key +Issues: github.com/acmesh-official/acme.sh/issues/4900 +' #Hosttech_Key="asdfasdfawefasdfawefasdafe" @@ -19,9 +27,6 @@ dns_hosttech_add() { return 1 fi - #save the api key and email to the account conf file. - _saveaccountconf_mutable Hosttech_Key "$Hosttech_Key" - _debug "First detect the root zone" if ! _get_root "$fulldomain"; then _err "invalid domain" @@ -33,10 +38,6 @@ dns_hosttech_add() { _info "Adding record" if _hosttech_rest POST "zones/$_domain/records" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"text\":\"$txtvalue\",\"ttl\":600}"; then if _contains "$_response" "$_sub_domain"; then - _debug recordID "$(echo "$_response" | grep -o '"id":[^"]*' | grep -Po "\d+")" - - #save the created recordID to the account conf file, so we can read it back for deleting in dns_hosttech_rm. - _saveaccountconf recordID "$(echo "$_response" | grep -o '"id":[^"]*' | grep -Po "\d+")" _info "Added, OK" return 0 else @@ -58,24 +59,30 @@ dns_hosttech_rm() { if [ -z "$Hosttech_Key" ]; then Hosttech_Key="" _err "You didn't specify a Hosttech api key." - _err "You can get yours from https://www.hosttech.nl/mijn_hosttech" + _err "You can get yours from You can get yours from https://www.myhosttech.eu/user/dns/api" return 1 fi - _debug "First detect the root zone" - if ! _get_root "$fulldomain"; then - _err "invalid domain" + _debug "First detect the zoneid" + if ! _get_zoneid "$fulldomain"; then + _err "invalid zoneid" return 1 fi _debug _sub_domain "$_sub_domain" _debug _domain "$_domain" + _debug _zoneid "$_zoneid" + _debug _txtvalue "${txtvalue}" + + _debug "Second detect the recordid" + if ! _get_recordid "$_domain" "$_sub_domain" "${txtvalue}"; then + _err "invalid recordid" + return 1 + fi + _debug _recordid "$_recordid" _debug "Removing txt record" - delRecordID="$(_readaccountconf "recordID")" - _hosttech_rest DELETE "zones/$_domain/records/$delRecordID" - - _clearaccountconf recordID + _hosttech_rest DELETE "zones/$_domain/records/$_recordid" } #################### Private functions below ################################## @@ -85,7 +92,7 @@ dns_hosttech_rm() { # _domain=domain.com _get_root() { domain=$1 - i=2 + i=1 p=1 while true; do _domain=$(printf "%s" "$domain" | cut -d . -f $i-100) @@ -97,7 +104,7 @@ _get_root() { fi if _hosttech_rest GET "zones?query=${_domain}"; then - if [ "$(echo "$_response" | grep -o '"name":"[^"]*' | cut -d'"' -f4)" = "${_domain}" ]; then + if [ "$(echo "$_response" | _egrep_o '"name":"[^"]*' | cut -d'"' -f4)" = "${_domain}" ]; then return 0 fi else @@ -109,6 +116,62 @@ _get_root() { return 1 } +_get_zoneid() { + domain=$1 + i=1 + p=1 + while true; do + _domain=$(printf "%s" "$domain" | cut -d . -f $i-100) + _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) + _debug _domain "$_domain" + if [ -z "$_domain" ]; then + #not valid + return 1 + fi + + if _hosttech_rest GET "zones?query=${_domain}"; then + if [ "$(echo "$_response" | _egrep_o '"name":"[^"]*' | cut -d'"' -f4)" = "${_domain}" ]; then + # Get the id of the zone in question + _zoneid="$(echo "$_response" | _egrep_o '"id":[0-9]*' | cut -d':' -f2)" + if [ -z "$_zoneid" ]; then + return 1 + fi + return 0 + fi + else + return 1 + fi + p=$i + i=$(_math "$i" + 1) + done + return 1 +} + +_get_recordid() { + domainid=$1 + subdomain=$2 + txtvalue=$3 + + # Get all dns records for the domainname + if _hosttech_rest GET "zones/$_zoneid/records"; then + if ! _contains "$_response" '"id"'; then + _debug "No records in dns" + return 1 + fi + if ! _contains "$_response" '\"name\":\"'$subdomain'\"'; then + _debug "Record does not exist" + return 1 + fi + # Get the id of the record in question + _recordid=$(printf "%s" "$_response" | _egrep_o "[^{]*\"name\":\"$subdomain\"[^}]*" | _egrep_o "[^{]*\"text\":\"$txtvalue\"[^}]*" | _egrep_o "\"id\":[0-9]+" | cut -d : -f 2) + if [ -z "$_recordid" ]; then + return 1 + fi + return 0 + fi + return 0 +} + _hosttech_rest() { m=$1 ep="$2" @@ -132,4 +195,4 @@ _hosttech_rest() { _debug2 response "$_response" return 0 -} +} \ No newline at end of file From 24d36b7340d6b82ea69e7c6d3349bcc5a0fe1f80 Mon Sep 17 00:00:00 2001 From: baerengraben Date: Thu, 23 Jan 2025 19:04:59 +0000 Subject: [PATCH 9/9] ShellCheck and shfmt correction --- dnsapi/dns_hosttech.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dnsapi/dns_hosttech.sh b/dnsapi/dns_hosttech.sh index 11185c82..8e5c3e19 100644 --- a/dnsapi/dns_hosttech.sh +++ b/dnsapi/dns_hosttech.sh @@ -95,8 +95,8 @@ _get_root() { i=1 p=1 while true; do - _domain=$(printf "%s" "$domain" | cut -d . -f $i-100) - _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) + _domain=$(printf "%s" "$domain" | cut -d . -f "$i"-100) + _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-"$p") _debug _domain "$_domain" if [ -z "$_domain" ]; then #not valid @@ -121,8 +121,8 @@ _get_zoneid() { i=1 p=1 while true; do - _domain=$(printf "%s" "$domain" | cut -d . -f $i-100) - _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) + _domain=$(printf "%s" "$domain" | cut -d . -f "$i"-100) + _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-"$p") _debug _domain "$_domain" if [ -z "$_domain" ]; then #not valid @@ -158,7 +158,7 @@ _get_recordid() { _debug "No records in dns" return 1 fi - if ! _contains "$_response" '\"name\":\"'$subdomain'\"'; then + if ! _contains "$_response" '\"name\":\"'"$subdomain"'\"'; then _debug "Record does not exist" return 1 fi @@ -195,4 +195,4 @@ _hosttech_rest() { _debug2 response "$_response" return 0 -} \ No newline at end of file +}