add new bin/vdns-zone-def.sh

This commit is contained in:
Matthew Saunders Brown 2024-02-12 10:47:14 -08:00
parent debeb16646
commit 0a347a35cf

60
bin/vdns-zone-def.sh Executable file
View File

@ -0,0 +1,60 @@
#!/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 /usr/local/sbin/pdns.sh
help()
{
echo "Show default records for given domain."
echo ""
echo "usage: $thisfilename -z <zone> [-c] [-h]"
echo ""
echo " -h Print this help."
echo " -z <zone> Zone (domain name) to display default records for."
echo " -c Output in csv format instead of columns."
}
pdns:getoptions "$@"
# check for zone
if [[ -z $zone ]]; then
echo "zone is required"
exit 1
fi
output="name,type,content"
# add SOA to output
output="$output\n$zone,SOA,$zone_default_ns $zone_defaults_mbox $serial $zone_defaults_refresh $zone_defaults_retry $zone_defaults_expire $zone_defaults_minimum"
# add each additiona record to output
for record in "${default_records[@]}"; do
# replace @ with zone
record=$(echo ${record} | sed -e "s/@/$zone/g")
# turn record row info in to array
orig_ifs="$IFS"
IFS='|'
read -r -a recordArray <<< "$record"
IFS="$orig_ifs"
# extract record info from array
rr_name=${recordArray[0]}
rr_type=${recordArray[1]}
rr_content=${recordArray[2]}
if [[ $rr_type = TXT ]]; then
rr_content="\"$rr_content\""
fi
output="$output\n$rr_name,$rr_type,$rr_content"
done
if [[ $csv ]]; then
echo -e $output
else
echo -e $output | column -t -s ,
fi