acme.sh/dnsapi/dns_nm.sh

88 lines
2.5 KiB
Bash
Raw Normal View History

2020-03-07 13:55:09 +00:00
#!/usr/bin/env sh
########################################################################
# https://namemaster.de hook script for acme.sh
#
# Environment variables:
#
# - $NM_user (your namemaster.de API username)
# - $NM_md5 (your namemaster.de API password_as_md5hash)
#
# Author: Thilo Gass <thilo.gass@gmail.com>
# Git repo: https://github.com/ThiloGa/acme.sh
#-- dns_nm_add() - Add TXT record --------------------------------------
# Usage: dns_nm_add _acme-challenge.subdomain.domain.com "XyZ123..."
dns_nm_add() {
fulldomain=$1
txt_value=$2
_info "Using DNS-01 namemaster hook"
2020-03-07 13:55:09 +00:00
NM_user="${NM_user:-$(_readaccountconf_mutable NM_user)}"
NM_md5="${NM_md5:-$(_readaccountconf_mutable NM_md5)}"
if [ -z "$NM_user" ] || [ -z "$NM_md5" ]; then
NM_user=""
NM_md5=""
_err "No auth details provided. Please set user credentials using the \$NM_user and \$NM_md5 environment variables."
2020-03-07 13:55:09 +00:00
return 1
fi
#save the api user and md5 password to the account conf file.
_debug "Save user and hash"
_saveaccountconf_mutable NM_user "$NM_user"
_saveaccountconf_mutable NM_md5 "$NM_md5"
zone="$(echo "$fulldomain" | _egrep_o "[^.]+.[^.]+$")"
2020-03-07 13:55:09 +00:00
get="https://namemaster.de/api/api.php?User=$NM_user&Password=$NM_md5&Antwort=csv&Int=0&Typ=ACME&Zone=$zone&hostname=$fulldomain&TXT=$txt_value&Action=Auto&Lifetime=3600"
if ! erg="$(_get "$get")"; then
_err "error Deleting $zone TXT: $txt_value"
return 1
2020-03-07 13:55:09 +00:00
fi
if _contains "$erg" "Success"; then
_info "Success, TXT Added, OK"
else
2020-03-07 14:45:41 +00:00
_err "error Adding $zone TXT: $txt_value erg: $erg"
2020-03-07 13:55:09 +00:00
return 1
fi
2020-03-07 14:33:21 +00:00
_debug "ok Auto $zone TXT: $txt_value erg: $erg"
2020-03-07 13:55:09 +00:00
return 0
2020-03-07 20:11:08 +00:00
2020-03-07 13:55:09 +00:00
}
dns_nm_rm() {
fulldomain=$1
txt_value=$2
2020-03-07 13:55:09 +00:00
NM_user="${NM_user:-$(_readaccountconf_mutable NM_user)}"
NM_md5="${NM_md5:-$(_readaccountconf_mutable NM_md5)}"
if [ -z "$NM_user" ] || [ -z "$NM_md5" ]; then
NM_user=""
NM_md5=""
_err "No auth details provided. Please set user credentials using the \$NM_user and \$NM_md5 environment variables."
2020-03-07 13:55:09 +00:00
return 1
fi
zone="$(echo "$fulldomain" | _egrep_o "[^.]+.[^.]+$")"
2020-03-07 13:55:09 +00:00
get="https://namemaster.de/api/api.php?User=$NM_user&Password=$NM_md5&Antwort=csv&Int=0&Typ=TXT&Zone=$zone&hostname=$fulldomain&TXT=$txt_value&Action=Delete_IN&TTL=0"
2020-03-07 15:00:52 +00:00
if ! erg="$(_get "$get")"; then
2020-03-07 14:45:41 +00:00
_err "error Deleting $zone TXT: $txt_value"
2020-03-07 13:55:09 +00:00
return 1
fi
if _contains "$erg" "Success"; then
_info "Success, TXT removed, OK"
else
2020-03-07 14:33:21 +00:00
_err "error Auto $zone TXT: $txt_value erg: $erg"
return 1
fi
2020-03-07 13:55:09 +00:00
2020-03-07 14:33:21 +00:00
_debug "ok Auto $zone TXT: $txt_value erg: $erg"
return 0
2020-03-07 13:55:09 +00:00
}