2020-12-24 11:03:25 +01:00
|
|
|
#!/usr/bin/env sh
|
2023-11-18 17:57:12 +01:00
|
|
|
# shellcheck disable=SC2034
|
|
|
|
dns_ionos_info='IONOS.de
|
|
|
|
Site: IONOS.de
|
|
|
|
Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_ionos
|
|
|
|
Options:
|
|
|
|
IONOS_PREFIX Prefix
|
|
|
|
IONOS_SECRET Secret
|
|
|
|
Issues: github.com/acmesh-official/acme.sh/issues/3379
|
|
|
|
'
|
2020-12-24 11:03:25 +01:00
|
|
|
|
|
|
|
IONOS_API="https://api.hosting.ionos.com/dns"
|
|
|
|
IONOS_ROUTE_ZONES="/v1/zones"
|
|
|
|
|
2020-12-24 13:06:07 +01:00
|
|
|
IONOS_TXT_TTL=60 # minimum accepted by API
|
2020-12-24 11:03:25 +01:00
|
|
|
IONOS_TXT_PRIO=10
|
|
|
|
|
|
|
|
dns_ionos_add() {
|
|
|
|
fulldomain=$1
|
|
|
|
txtvalue=$2
|
|
|
|
|
2021-01-18 14:35:08 +01:00
|
|
|
if ! _ionos_init; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2021-02-23 19:49:58 +01:00
|
|
|
_body="[{\"name\":\"$_sub_domain.$_domain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"ttl\":$IONOS_TXT_TTL,\"prio\":$IONOS_TXT_PRIO,\"disabled\":false}]"
|
2021-01-18 14:35:08 +01:00
|
|
|
|
2022-05-22 13:24:18 +02:00
|
|
|
if _ionos_rest POST "$IONOS_ROUTE_ZONES/$_zone_id/records" "$_body" && [ "$_code" = "201" ]; then
|
2020-12-24 13:06:07 +01:00
|
|
|
_info "TXT record has been created successfully."
|
2020-12-24 11:03:25 +01:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_ionos_rm() {
|
|
|
|
fulldomain=$1
|
|
|
|
txtvalue=$2
|
|
|
|
|
2021-01-18 14:35:08 +01:00
|
|
|
if ! _ionos_init; then
|
|
|
|
return 1
|
|
|
|
fi
|
2020-12-24 11:03:25 +01:00
|
|
|
|
2021-01-18 14:35:08 +01:00
|
|
|
if ! _ionos_get_record "$fulldomain" "$_zone_id" "$txtvalue"; then
|
2020-12-24 11:03:25 +01:00
|
|
|
_err "Could not find _acme-challenge TXT record."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2022-05-22 13:24:18 +02:00
|
|
|
if _ionos_rest DELETE "$IONOS_ROUTE_ZONES/$_zone_id/records/$_record_id" && [ "$_code" = "200" ]; then
|
2020-12-24 13:06:07 +01:00
|
|
|
_info "TXT record has been deleted successfully."
|
2020-12-24 11:03:25 +01:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
_ionos_init() {
|
|
|
|
IONOS_PREFIX="${IONOS_PREFIX:-$(_readaccountconf_mutable IONOS_PREFIX)}"
|
|
|
|
IONOS_SECRET="${IONOS_SECRET:-$(_readaccountconf_mutable IONOS_SECRET)}"
|
2020-12-24 13:06:07 +01:00
|
|
|
|
2020-12-24 11:03:25 +01:00
|
|
|
if [ -z "$IONOS_PREFIX" ] || [ -z "$IONOS_SECRET" ]; then
|
|
|
|
_err "You didn't specify an IONOS api prefix and secret yet."
|
|
|
|
_err "Read https://beta.developer.hosting.ionos.de/docs/getstarted to learn how to get a prefix and secret."
|
|
|
|
_err ""
|
|
|
|
_err "Then set them before calling acme.sh:"
|
|
|
|
_err "\$ export IONOS_PREFIX=\"...\""
|
|
|
|
_err "\$ export IONOS_SECRET=\"...\""
|
|
|
|
_err "\$ acme.sh --issue -d ... --dns dns_ionos"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
_saveaccountconf_mutable IONOS_PREFIX "$IONOS_PREFIX"
|
|
|
|
_saveaccountconf_mutable IONOS_SECRET "$IONOS_SECRET"
|
|
|
|
|
|
|
|
if ! _get_root "$fulldomain"; then
|
|
|
|
_err "Cannot find this domain in your IONOS account."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
_get_root() {
|
|
|
|
domain=$1
|
2021-01-21 16:10:10 +01:00
|
|
|
i=1
|
2020-12-24 11:03:25 +01:00
|
|
|
p=1
|
|
|
|
|
|
|
|
if _ionos_rest GET "$IONOS_ROUTE_ZONES"; then
|
2022-05-22 13:24:18 +02:00
|
|
|
_response="$(echo "$_response" | tr -d "\n")"
|
2020-12-24 11:03:25 +01:00
|
|
|
|
|
|
|
while true; do
|
2024-10-13 17:41:22 +02:00
|
|
|
h=$(printf "%s" "$domain" | cut -d . -f "$i"-100)
|
2020-12-24 11:03:25 +01:00
|
|
|
if [ -z "$h" ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2022-05-22 13:24:18 +02:00
|
|
|
_zone="$(echo "$_response" | _egrep_o "\"name\":\"$h\".*\}")"
|
2020-12-24 11:03:25 +01:00
|
|
|
if [ "$_zone" ]; then
|
2021-01-20 21:08:58 +01:00
|
|
|
_zone_id=$(printf "%s\n" "$_zone" | _egrep_o "\"id\":\"[a-fA-F0-9\-]*\"" | _head_n 1 | cut -d : -f 2 | tr -d '\"')
|
2020-12-24 11:03:25 +01:00
|
|
|
if [ "$_zone_id" ]; then
|
2024-10-13 17:41:22 +02:00
|
|
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-"$p")
|
2020-12-24 11:03:25 +01:00
|
|
|
_domain=$h
|
|
|
|
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
p=$i
|
|
|
|
i=$(_math "$i" + 1)
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
_ionos_get_record() {
|
|
|
|
fulldomain=$1
|
|
|
|
zone_id=$2
|
2021-01-18 14:35:08 +01:00
|
|
|
txtrecord=$3
|
2020-12-24 11:03:25 +01:00
|
|
|
|
|
|
|
if _ionos_rest GET "$IONOS_ROUTE_ZONES/$zone_id?recordName=$fulldomain&recordType=TXT"; then
|
2022-05-22 13:24:18 +02:00
|
|
|
_response="$(echo "$_response" | tr -d "\n")"
|
2020-12-24 11:03:25 +01:00
|
|
|
|
2022-05-22 13:24:18 +02:00
|
|
|
_record="$(echo "$_response" | _egrep_o "\"name\":\"$fulldomain\"[^\}]*\"type\":\"TXT\"[^\}]*\"content\":\"\\\\\"$txtrecord\\\\\"\".*\}")"
|
2020-12-24 11:03:25 +01:00
|
|
|
if [ "$_record" ]; then
|
2021-01-20 21:08:58 +01:00
|
|
|
_record_id=$(printf "%s\n" "$_record" | _egrep_o "\"id\":\"[a-fA-F0-9\-]*\"" | _head_n 1 | cut -d : -f 2 | tr -d '\"')
|
2020-12-24 13:06:07 +01:00
|
|
|
|
|
|
|
return 0
|
2020-12-24 11:03:25 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
_ionos_rest() {
|
|
|
|
method="$1"
|
|
|
|
route="$2"
|
|
|
|
data="$3"
|
|
|
|
|
|
|
|
IONOS_API_KEY="$(printf "%s.%s" "$IONOS_PREFIX" "$IONOS_SECRET")"
|
|
|
|
|
|
|
|
export _H1="X-API-Key: $IONOS_API_KEY"
|
|
|
|
|
2022-05-22 13:24:18 +02:00
|
|
|
# clear headers
|
|
|
|
: >"$HTTP_HEADER"
|
|
|
|
|
2020-12-24 11:03:25 +01:00
|
|
|
if [ "$method" != "GET" ]; then
|
|
|
|
export _H2="Accept: application/json"
|
|
|
|
export _H3="Content-Type: application/json"
|
|
|
|
|
2022-05-22 13:24:18 +02:00
|
|
|
_response="$(_post "$data" "$IONOS_API$route" "" "$method" "application/json")"
|
2020-12-24 11:03:25 +01:00
|
|
|
else
|
|
|
|
export _H2="Accept: */*"
|
2021-05-25 15:57:15 +02:00
|
|
|
export _H3=
|
2022-05-22 13:24:18 +02:00
|
|
|
|
|
|
|
_response="$(_get "$IONOS_API$route")"
|
2020-12-24 11:03:25 +01:00
|
|
|
fi
|
|
|
|
|
2022-05-22 13:24:18 +02:00
|
|
|
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")"
|
|
|
|
|
2020-12-24 11:03:25 +01:00
|
|
|
if [ "$?" != "0" ]; then
|
2022-05-22 13:24:18 +02:00
|
|
|
_err "Error $route: $_response"
|
2020-12-24 11:03:25 +01:00
|
|
|
return 1
|
|
|
|
fi
|
2022-05-22 13:24:18 +02:00
|
|
|
|
|
|
|
_debug2 "_response" "$_response"
|
|
|
|
_debug2 "_code" "$_code"
|
2020-12-24 11:03:25 +01:00
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|