You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

108 lines
3.4 KiB

#!/usr/bin/env sh
# dns_czechia.sh - CZECHIA.COM/ZONER DNS API for acme.sh (DNS-01)
#
# Documentation: https://api.czechia.com/swagger/index.html
#
# Required environment variables:
# CZ_AuthorizationToken Your API token from CZECHIA.COM/Zoner administration.
# CZ_Zones Managed zones separated by comma or space (e.g. "example.com").
#
# Optional environment variables:
# CZ_API_BASE Defaults to https://api.czechia.com
dns_czechia_add() {
fulldomain="$1"
txtvalue="$2"
_czechia_load_conf || return 1
_current_zone=$(_czechia_pick_zone "$fulldomain")
if [ -z "$_current_zone" ]; then
_err "No matching zone found for $fulldomain. Please check CZ_Zones."
return 1
fi
_url="$CZ_API_BASE/api/DNS/$_current_zone/TXT"
# Normalize using acme.sh internal function - NO 'tr' used here
_fd=$(_lower_case "$fulldomain" | sed 's/\.$//')
_cz=$(_lower_case "$_current_zone")
# Calculate hostname
_h=$(printf "%s" "$_fd" | sed "s/\.$_cz//; s/$_cz//")
[ -z "$_h" ] && _h="@"
_body="{\"hostName\":\"$_h\",\"text\":\"$txtvalue\",\"ttl\":3600,\"publishZone\":1}"
_info "Adding TXT record"
export _H1="Content-Type: application/json"
export _H2="authorizationToken: $CZ_AuthorizationToken"
_res=$(_post "$_body" "$_url" "" "POST")
if _contains "$_res" "errors" || _contains "$_res" "400"; then
_err "API error: $_res"
return 1
fi
return 0
}
dns_czechia_rm() {
fulldomain="$1"
txtvalue="$2"
_czechia_load_conf || return 1
_current_zone=$(_czechia_pick_zone "$fulldomain")
[ -z "$_current_zone" ] && return 1
_url="$CZ_API_BASE/api/DNS/$_current_zone/TXT"
_fd=$(_lower_case "$fulldomain" | sed 's/\.$//')
_cz=$(_lower_case "$_current_zone")
_h=$(printf "%s" "$_fd" | sed "s/\.$_cz//; s/$_cz//")
[ -z "$_h" ] && _h="@"
_body="{\"hostName\":\"$_h\",\"text\":\"$txtvalue\",\"publishZone\":1}"
_info "Removing TXT record"
export _H1="Content-Type: application/json"
export _H2="authorizationToken: $CZ_AuthorizationToken"
_res=$(_post "$_body" "$_url" "" "DELETE")
return 0
}
########################################################################
# Private functions
########################################################################
_czechia_load_conf() {
CZ_AuthorizationToken="${CZ_AuthorizationToken:-$(_getaccountconf CZ_AuthorizationToken)}"
[ -z "$CZ_AuthorizationToken" ] && _err "Missing CZ_AuthorizationToken" && return 1
CZ_Zones="${CZ_Zones:-$(_getaccountconf CZ_Zones)}"
[ -z "$CZ_Zones" ] && _err "Missing CZ_Zones" && return 1
CZ_API_BASE="${CZ_API_BASE:-https://api.czechia.com}"
_saveaccountconf CZ_AuthorizationToken "$CZ_AuthorizationToken"
_saveaccountconf CZ_Zones "$CZ_Zones"
return 0
}
_czechia_pick_zone() {
_fulldomain="$1"
_fd=$(_lower_case "$_fulldomain" | sed 's/\.$//')
_best_zone=""
# Replace comma with space using sed (Docker safe)
_zones_space=$(printf "%s" "$CZ_Zones" | sed 's/,/ /g')
for _z in $_zones_space; do
# Remove spaces and trailing dot, then lowercase - NO 'tr' used here
_clean_z=$(_lower_case "$_z" | sed 's/ //g; s/\.$//')
[ -z "$_clean_z" ] && continue
case "$_fd" in
"$_clean_z" | *".$_clean_z")
# Compare length using native shell ${#var} - Docker/BusyBox safe
if [ ${#_clean_z} -gt ${#_best_zone} ]; then
_best_zone="$_clean_z"
fi
;;
esac
done
[ -n "$_best_zone" ] && printf "%s" "$_best_zone"
}