powerdns-tools/sbin/pdns-zone-asc.sh

68 lines
2.1 KiB
Bash
Raw Normal View History

2024-02-12 10:47:34 -08:00
#!/bin/bash
#
# pdns-tools
# https://git.stack-source.com/msb/pdns-tools
# Copyright (c) 2024 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# load include file
source $(dirname $0)/pdns.sh
help()
{
echo "Associate zone in DNS with this server."
echo ""
echo "usage: $thisfilename -z <zone> [-x] [-h]"
echo ""
echo " -h Print this help."
echo " -z <zone> Zone (domain name) to associate."
echo " -x Execute (force) - don't prompt for confirmation."
}
pdns:getoptions "$@"
# check for zone
if [[ -z $zone ]]; then
echo "zone is required"
exit
fi
# check if zone already assocated with this server
zone_associated=$(/usr/local/bin/vdns-zone-ext.sh -z $zone)
if [[ $zone_associated = "true" ]]; then
echo "Zone $zone already associated with this server."
exit
fi
# make sure zone exists in DNS
zone_exists=$(/usr/local/sbin/pdns-zone-ext.sh -z $zone)
if [[ $zone_exists = "true" ]]; then
# check if zone is already associated with any (a different) server
SEARCH=($(/usr/local/sbin/pdns-search.sh -q hostname=*/$zone -c))
# check for header row output, this indicates one or more results were found
if [[ "${SEARCH[0]}" = "content,name,object_type,type,zone,zone_id" ]]; then
if [[ -z $execute ]]; then
existing=$(echo ${SEARCH[1]}|cut -d , -f 1|cut -d = -f 2 |cut -d / -f 1)
echo Zone $zone is currently associated with server $existing
if pdns::yesno "Change $zone association to this server ($hostname)?"; then
# return newline
echo
else
echo
echo "Update canceled, zone association for $zone unchanged."
exit
fi
fi
fi
# get current SOA
soa=$(/usr/local/sbin/pdns-zone-exp.sh -z stack-source.com -c|grep ',SOA,'|cut -d , -f 5)
# get/set account
if [[ -z $account ]]; then
account=$hostname
fi
pdns-rr-rep.sh -z $zone -n $zone -t SOA -r "$soa" -w "hostname=$hostname/$zone" -a $account
else
echo "Zone $zone does not exist in DNS."
exit
fi