-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds dynamic helper to add text (TXT) DNS resource records
- Loading branch information
1 parent
4b82baa
commit 2673a7f
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/bash | ||
# | ||
# dyn_txt <dns fqdn> <text for text record> | ||
# Sends DNS updates for TXT Resource Records | ||
# where <dns fqdn> is the full dns name at which to place the record | ||
# where <text for text record is the full text contents in double quotes if content is to contain spaces> | ||
# | ||
# | ||
#------------------------------------------------------------------------------ | ||
|
||
|
||
# load helpful functions | ||
for i in functions/*.sh | ||
do | ||
. ${i} | ||
[[ -n ${DEBUG_SET_VARS} ]] && echo "Sourced ${PWD}/$i ..." | ||
done | ||
|
||
set_vars $* | ||
|
||
#------------------------------------------------------------------------------ | ||
|
||
# define default update add | ||
NSUPDATE_ACTION=${NSUPDATE_ACTION:-"add"} | ||
NSUPDATE_TTL="60" | ||
|
||
NSUPDATE_AUTH_SIG0_KEY_FQDN=${NSUPDATE_AUTH_SIG0_KEY_FQDN:-${NEW_FQDN}} | ||
[[ -n ${DEBUG} ]] && echo "DEBUG: NSUPDATE_AUTH_SIG0_KEY_FQDN='${NSUPDATE_AUTH_SIG0_KEY_FQDN}'" | ||
|
||
# split NEW_FQDN into DNS ZONE & SUBLABEL | ||
ZONE=$(get_soa "${NEW_FQDN}") | ||
[[ ! -n ${ZONE} ]] && echo "Could not find SOA in FQDN '${NEW_FQDN}'" && exit 1 | ||
NEW_SUBZONE=${NEW_FQDN%*${ZONE}} | ||
[[ -n ${NEW_SUBZONE} ]] && NEW_SUBZONE=${NEW_SUBZONE::-1} # if not null, remove trailing dot | ||
|
||
# recursively search keystore for most particular subdomain keypair under ZONE | ||
subdomain="${NSUPDATE_AUTH_SIG0_KEY_FQDN:-NEW_FQDN}" | ||
while [[ ! -n "${NSUPDATE_AUTH_SIG0_KEYID}" ]] && [[ "${subdomain}" == *"${ZONE}" ]] | ||
do | ||
# [[ -n ${DEBUG} ]] && echo "DEBUG: get_sig0_keyid NSUPDATE_AUTH_SIG0_KEYID '${subdomain}' '${NSUPDATE_SIG0_KEYPATH}'" | ||
get_sig0_keyid NSUPDATE_AUTH_SIG0_KEYID "${subdomain}" "${NSUPDATE_SIG0_KEYPATH}" | ||
[[ ! -n "${NSUPDATE_AUTH_SIG0_KEYID}" ]] && subdomain="${subdomain#*.}" | ||
done | ||
|
||
# loop over command line parameter (post getops()) for TXT records to add | ||
# for txt in ${CMDLINE_EXTRA_PARAMS}; do | ||
txt="${CMDLINE_EXTRA_PARAMS}" | ||
NSUPDATE_RRTYPE="TXT" | ||
NSUPDATE_ITEM_RR="${NSUPDATE_ITEM_RR}update ${NSUPDATE_ACTION} ${NEW_FQDN} ${NSUPDATE_TTL} ${NSUPDATE_RRTYPE} \"${txt}\"\n" | ||
# done | ||
|
||
# form nsupdate RR update statements | ||
case ${NSUPDATE_ACTION} in | ||
add) | ||
# NSUPDATE_PRECONDITION_SET="nxrrset" | ||
# NSUPDATE_PRECONDITION="prereq ${NSUPDATE_PRECONDITION_SET} ${word}._dns-sd._udp.${DNSSD_DOMAIN}. IN PTR" | ||
# NSUPDATE_ITEM_RR="update ${NSUPDATE_ACTION} ${word}._dns-sd._udp.${DNSSD_DOMAIN} ${NSUPDATE_TTL} PTR ${DNSSD_DOMAIN}." | ||
send_nsupdate "${NEW_FQDN}" "$(echo ${NSUPDATE_PRECONDITION};echo -e ${NSUPDATE_ITEM_RR})" "${subdomain}" | ||
;; | ||
delete) | ||
# NSUPDATE_PRECONDITION_SET="yxrrset" | ||
# NSUPDATE_PRECONDITION="prereq ${NSUPDATE_PRECONDITION_SET} ${word}._dns-sd._udp.${DNSSD_DOMAIN}. IN PTR" | ||
# NSUPDATE_ITEM_RR="update ${NSUPDATE_ACTION} ${word}._dns-sd._udp.${DNSSD_DOMAIN} ${NSUPDATE_TTL} PTR ${DNSSD_DOMAIN}." | ||
send_nsupdate "${NEW_FQDN}" "$(echo ${NSUPDATE_PRECONDITION};echo -e ${NSUPDATE_ITEM_RR})" "${subdomain}" | ||
;; | ||
*) | ||
# NSUPDATE_ACTION should default to "add" - should never get here | ||
echo "Error: NSUPDATE_ACTION is set to '${NSUPDATE_ACTION}', but must be set to 'add' or 'delete'." | ||
exit 1 | ||
;; | ||
esac | ||
|
||
|
||
DIG_QUERY_PARAM="@${ZONE_SOA_MASTER} +noall +answer +dnssec" | ||
echo "$( dig ${DIG_QUERY_PARAM} ${NEW_FQDN} TXT )" |