mirror of
https://github.com/acmesh-official/acme.sh.git
synced 2025-04-29 22:52:43 +00:00
Add _rm by quering the recordId
This commit is contained in:
parent
89b7e8f5da
commit
04e72dcfed
@ -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"
|
#Hosttech_Key="asdfasdfawefasdfawefasdafe"
|
||||||
|
|
||||||
@ -19,9 +27,6 @@ dns_hosttech_add() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#save the api key and email to the account conf file.
|
|
||||||
_saveaccountconf_mutable Hosttech_Key "$Hosttech_Key"
|
|
||||||
|
|
||||||
_debug "First detect the root zone"
|
_debug "First detect the root zone"
|
||||||
if ! _get_root "$fulldomain"; then
|
if ! _get_root "$fulldomain"; then
|
||||||
_err "invalid domain"
|
_err "invalid domain"
|
||||||
@ -33,10 +38,6 @@ dns_hosttech_add() {
|
|||||||
_info "Adding record"
|
_info "Adding record"
|
||||||
if _hosttech_rest POST "zones/$_domain/records" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"text\":\"$txtvalue\",\"ttl\":600}"; then
|
if _hosttech_rest POST "zones/$_domain/records" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"text\":\"$txtvalue\",\"ttl\":600}"; then
|
||||||
if _contains "$_response" "$_sub_domain"; 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"
|
_info "Added, OK"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
@ -58,24 +59,30 @@ dns_hosttech_rm() {
|
|||||||
if [ -z "$Hosttech_Key" ]; then
|
if [ -z "$Hosttech_Key" ]; then
|
||||||
Hosttech_Key=""
|
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.hosttech.nl/mijn_hosttech"
|
_err "You can get yours from You can get yours from https://www.myhosttech.eu/user/dns/api"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_debug "First detect the root zone"
|
_debug "First detect the zoneid"
|
||||||
if ! _get_root "$fulldomain"; then
|
if ! _get_zoneid "$fulldomain"; then
|
||||||
_err "invalid domain"
|
_err "invalid zoneid"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_debug _sub_domain "$_sub_domain"
|
_debug _sub_domain "$_sub_domain"
|
||||||
_debug _domain "$_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"
|
_debug "Removing txt record"
|
||||||
delRecordID="$(_readaccountconf "recordID")"
|
_hosttech_rest DELETE "zones/$_domain/records/$_recordid"
|
||||||
_hosttech_rest DELETE "zones/$_domain/records/$delRecordID"
|
|
||||||
|
|
||||||
_clearaccountconf recordID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#################### Private functions below ##################################
|
#################### Private functions below ##################################
|
||||||
@ -85,7 +92,7 @@ dns_hosttech_rm() {
|
|||||||
# _domain=domain.com
|
# _domain=domain.com
|
||||||
_get_root() {
|
_get_root() {
|
||||||
domain=$1
|
domain=$1
|
||||||
i=2
|
i=1
|
||||||
p=1
|
p=1
|
||||||
while true; do
|
while true; do
|
||||||
_domain=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
_domain=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
||||||
@ -97,7 +104,7 @@ _get_root() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if _hosttech_rest GET "zones?query=${_domain}"; then
|
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
|
return 0
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@ -109,6 +116,62 @@ _get_root() {
|
|||||||
return 1
|
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() {
|
_hosttech_rest() {
|
||||||
m=$1
|
m=$1
|
||||||
ep="$2"
|
ep="$2"
|
||||||
@ -132,4 +195,4 @@ _hosttech_rest() {
|
|||||||
|
|
||||||
_debug2 response "$_response"
|
_debug2 response "$_response"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user