|
|
|
@ -23,28 +23,42 @@ dns_czechia_add() { |
|
|
|
_cz=$(printf "%s" "$_current_zone" | _lower_case | sed 's/ //g') |
|
|
|
_tk=$(printf "%s" "$CZ_AuthorizationToken" | sed 's/ //g') |
|
|
|
if [ -z "$_cz" ] || [ -z "$_tk" ]; then |
|
|
|
_err "Missing zone or AuthorizationToken (CZ_Zones/CZ_AuthorizationToken)." |
|
|
|
_err "Missing zone or Token." |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
_url="$CZ_API_BASE/api/DNS/$_cz/TXT" |
|
|
|
_fd=$(printf "%s" "$fulldomain" | _lower_case | sed 's/\.$//') |
|
|
|
|
|
|
|
# Robustní určení hostname - pokud se shoduje se zónou, použije @ |
|
|
|
if [ "$_fd" = "$_cz" ]; then |
|
|
|
_h="@" |
|
|
|
else |
|
|
|
_h=$(printf "%s" "$_fd" | sed "s/\.$_cz$//") |
|
|
|
[ "$_h" = "$_fd" ] && _h="@" |
|
|
|
fi |
|
|
|
# Pojistka: hostName nesmí být nikdy prázdný řetězec |
|
|
|
[ -z "$_h" ] && _h="@" |
|
|
|
|
|
|
|
_info "Adding TXT record for $_h in zone $_cz" |
|
|
|
_h_esc=$(printf "%s" "$_h" | sed 's/\\/\\\\/g; s/"/\\"/g') |
|
|
|
_txt_esc=$(printf "%s" "$txtvalue" | sed 's/\\/\\\\/g; s/"/\\"/g') |
|
|
|
_body="{\"hostName\":\"$_h_esc\",\"text\":\"$_txt_esc\",\"ttl\":60,\"publishZone\":1}" |
|
|
|
export _H1="Content-Type: application/json" |
|
|
|
export _H2="AuthorizationToken: $_tk" |
|
|
|
|
|
|
|
if ! _res="$(_post "$_body" "$_url" "" "POST")"; then |
|
|
|
_err "API request failed." |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
|
|
|
|
# Ignorujeme chybu, pokud záznam již existuje (časté při testech) |
|
|
|
if _contains "$_res" "already exists"; then |
|
|
|
_info "Record already exists, skipping." |
|
|
|
return 0 |
|
|
|
fi |
|
|
|
|
|
|
|
if _contains "$_res" "\"status\":4" || _contains "$_res" "\"status\":5" || _contains "$_res" "\"errors\""; then |
|
|
|
_err "API error details: $_res" |
|
|
|
_err "API error: $_res" |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
return 0 |
|
|
|
@ -64,12 +78,16 @@ dns_czechia_rm() { |
|
|
|
_h="@" |
|
|
|
else |
|
|
|
_h=$(printf "%s" "$_fd" | sed "s/\.$_cz$//") |
|
|
|
[ "$_h" = "$_fd" ] && _h="@" |
|
|
|
fi |
|
|
|
[ -z "$_h" ] && _h="@" |
|
|
|
|
|
|
|
_h_esc=$(printf "%s" "$_h" | sed 's/\\/\\\\/g; s/"/\\"/g') |
|
|
|
_txt_esc=$(printf "%s" "$txtvalue" | sed 's/\\/\\\\/g; s/"/\\"/g') |
|
|
|
_body="{\"hostName\":\"$_h_esc\",\"text\":\"$_txt_esc\",\"ttl\":60,\"publishZone\":1}" |
|
|
|
export _H1="Content-Type: application/json" |
|
|
|
export _H2="AuthorizationToken: $_tk" |
|
|
|
# Při mazání ignorujeme výsledek (pokud neexistuje, je to v pořádku) |
|
|
|
_post "$_body" "$_url" "" "DELETE" >/dev/null |
|
|
|
return 0 |
|
|
|
} |
|
|
|
|