Update dns_servercow.sh to support wildcard certs

Updated dns_servercow.sh to support txt records with multiple entries. This supports wildcard certificates that require txt records with the same name and different contents.
This commit is contained in:
anom-human 2021-03-11 20:25:49 +01:00 committed by Alexander Kulumbeg
parent 923eece3f5
commit 2cbf3f7e15

View File

@ -48,44 +48,44 @@ dns_servercow_add() {
_debug _sub_domain "$_sub_domain" _debug _sub_domain "$_sub_domain"
_debug _domain "$_domain" _debug _domain "$_domain"
# check whether a txt record already exists for the subdomain # check whether a txt record already exists for the subdomain
if printf -- "%s" "$response" | grep "{\"name\":\"$_sub_domain\",\"ttl\":20,\"type\":\"TXT\"" >/dev/null; then if printf -- "%s" "$response" | grep "{\"name\":\"$_sub_domain\",\"ttl\":20,\"type\":\"TXT\"" >/dev/null; then
_info "A txt record with the same name already exists." _info "A txt record with the same name already exists."
# trim the string on the left # trim the string on the left
txtvalue_old=${response#*{\"name\":\"$_sub_domain\",\"ttl\":20,\"type\":\"TXT\",\"content\":\"} txtvalue_old=${response#*{\"name\":\"$_sub_domain\",\"ttl\":20,\"type\":\"TXT\",\"content\":\"}
# trim the string on the right # trim the string on the right
txtvalue_old=${txtvalue_old%%\"*} txtvalue_old=${txtvalue_old%%\"*}
_debug txtvalue_old "$txtvalue_old" _debug txtvalue_old "$txtvalue_old"
_info "Add the new txtvalue to the existing txt record." _info "Add the new txtvalue to the existing txt record."
if _servercow_api POST "$_domain" "{\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":[\"$txtvalue\",\"$txtvalue_old\"],\"ttl\":20}"; then if _servercow_api POST "$_domain" "{\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":[\"$txtvalue\",\"$txtvalue_old\"],\"ttl\":20}"; then
if printf -- "%s" "$response" | grep "ok" >/dev/null; then if printf -- "%s" "$response" | grep "ok" >/dev/null; then
_info "Added additional txtvalue, OK" _info "Added additional txtvalue, OK"
return 0 return 0
else else
_err "add txt record error." _err "add txt record error."
return 1 return 1
fi
fi fi
_err "add txt record error." fi
return 1 _err "add txt record error."
else return 1
_info "There is no txt record with the name yet." else
if _servercow_api POST "$_domain" "{\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"ttl\":20}"; then _info "There is no txt record with the name yet."
if printf -- "%s" "$response" | grep "ok" >/dev/null; then if _servercow_api POST "$_domain" "{\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"ttl\":20}"; then
_info "Added, OK" if printf -- "%s" "$response" | grep "ok" >/dev/null; then
return 0 _info "Added, OK"
else return 0
_err "add txt record error." else
_err "add txt record error."
return 1 return 1
fi
fi fi
_err "add txt record error." fi
return 1 _err "add txt record error."
return 1
fi fi
return 1 return 1
} }