Browse Source

Dockerfile updated to install bind-tools (nsupdate). Added the possibility to specify a zone through NSUPDATE_ZONE variables when using dns_nsupdate.sh

pull/1808/head
Marco Spinosa 7 years ago
parent
commit
7c6f2c0f46
  1. 1
      Dockerfile
  2. 46
      dnsapi/dns_nsupdate.sh

1
Dockerfile

@ -6,6 +6,7 @@ RUN apk update -f \
coreutils \ coreutils \
curl \ curl \
socat \ socat \
bind-tools \
&& rm -rf /var/cache/apk/* && rm -rf /var/cache/apk/*
ENV LE_CONFIG_HOME /acme.sh ENV LE_CONFIG_HOME /acme.sh

46
dnsapi/dns_nsupdate.sh

@ -1,6 +1,9 @@
#!/usr/bin/env sh #!/usr/bin/env sh
######## Public functions ##################### ######## Public functions #####################
ECHO=$(command -v echo)
NSUPDATE=$(command -v nsupdate)
NSUPDATE_COMMANDS_FILE="/tmp/nsupdate"
#Usage: dns_nsupdate_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" #Usage: dns_nsupdate_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
dns_nsupdate_add() { dns_nsupdate_add() {
@ -13,17 +16,26 @@ dns_nsupdate_add() {
_saveaccountconf NSUPDATE_SERVER "${NSUPDATE_SERVER}" _saveaccountconf NSUPDATE_SERVER "${NSUPDATE_SERVER}"
_saveaccountconf NSUPDATE_SERVER_PORT "${NSUPDATE_SERVER_PORT}" _saveaccountconf NSUPDATE_SERVER_PORT "${NSUPDATE_SERVER_PORT}"
_saveaccountconf NSUPDATE_KEY "${NSUPDATE_KEY}" _saveaccountconf NSUPDATE_KEY "${NSUPDATE_KEY}"
if ! [ -z "$NSUPDATE_ZONE" ]; then
_saveaccountconf NSUPDATE_ZONE "${NSUPDATE_ZONE}"
fi
_info "adding ${fulldomain}. 60 in txt \"${txtvalue}\"" _info "adding ${fulldomain}. 60 in txt \"${txtvalue}\""
nsupdate -k "${NSUPDATE_KEY}" <<EOF
server ${NSUPDATE_SERVER} ${NSUPDATE_SERVER_PORT}
update add ${fulldomain}. 60 in txt "${txtvalue}"
send
EOF
if [ $? -ne 0 ]; then
$ECHO "server ${NSUPDATE_SERVER} ${NSUPDATE_SERVER_PORT}" > ${NSUPDATE_COMMANDS_FILE}
if ! [ -z "$NSUPDATE_ZONE" ]; then
$ECHO "zone ${NSUPDATE_ZONE}" >> ${NSUPDATE_COMMANDS_FILE}
fi
$ECHO "update add ${fulldomain}. 60 in txt \"${txtvalue}\"" >> ${NSUPDATE_COMMANDS_FILE}
$ECHO "send" >> ${NSUPDATE_COMMANDS_FILE}
_debug "$(cat ${NSUPDATE_COMMANDS_FILE})"
if ! $NSUPDATE -k "${NSUPDATE_KEY}" -v ${NSUPDATE_COMMANDS_FILE}; then
_err "error updating domain" _err "error updating domain"
rm ${NSUPDATE_COMMANDS_FILE}
return 1 return 1
fi fi
rm ${NSUPDATE_COMMANDS_FILE}
return 0 return 0
} }
@ -34,16 +46,22 @@ dns_nsupdate_rm() {
[ -n "${NSUPDATE_SERVER}" ] || NSUPDATE_SERVER="localhost" [ -n "${NSUPDATE_SERVER}" ] || NSUPDATE_SERVER="localhost"
[ -n "${NSUPDATE_SERVER_PORT}" ] || NSUPDATE_SERVER_PORT=53 [ -n "${NSUPDATE_SERVER_PORT}" ] || NSUPDATE_SERVER_PORT=53
_info "removing ${fulldomain}. txt" _info "removing ${fulldomain}. txt"
nsupdate -k "${NSUPDATE_KEY}" <<EOF
server ${NSUPDATE_SERVER} ${NSUPDATE_SERVER_PORT}
update delete ${fulldomain}. txt
send
EOF
if [ $? -ne 0 ]; then
$ECHO "server ${NSUPDATE_SERVER} ${NSUPDATE_SERVER_PORT}" > ${NSUPDATE_COMMANDS_FILE}
if ! [ -z "$NSUPDATE_ZONE" ]; then
$ECHO "zone ${NSUPDATE_ZONE}" >> ${NSUPDATE_COMMANDS_FILE}
fi
$ECHO "update delete ${fulldomain}. txt" >> ${NSUPDATE_COMMANDS_FILE}
$ECHO "send" >> ${NSUPDATE_COMMANDS_FILE}
_debug "$(cat ${NSUPDATE_COMMANDS_FILE})"
if ! $NSUPDATE -k "${NSUPDATE_KEY}" -v ${NSUPDATE_COMMANDS_FILE}; then
_err "error updating domain" _err "error updating domain"
rm ${NSUPDATE_COMMANDS_FILE}
return 1 return 1
fi fi
rm ${NSUPDATE_COMMANDS_FILE}
return 0 return 0
} }

Loading…
Cancel
Save