From 0a347a35cf3b35ca40710934282c2542f78dcdb2 Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Mon, 12 Feb 2024 10:47:14 -0800 Subject: [PATCH] add new bin/vdns-zone-def.sh --- bin/vdns-zone-def.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 bin/vdns-zone-def.sh diff --git a/bin/vdns-zone-def.sh b/bin/vdns-zone-def.sh new file mode 100755 index 0000000..c0ffc78 --- /dev/null +++ b/bin/vdns-zone-def.sh @@ -0,0 +1,60 @@ +#!/bin/bash +# +# pdns-tools +# https://git.stack-source.com/msb/pdns-tools +# Copyright (c) 2024 Matthew Saunders Brown +# 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 [-c] [-h]" + echo "" + echo " -h Print this help." + echo " -z 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