vdns-stack/bin/vdns-zone-lst.sh

53 lines
1.8 KiB
Bash
Raw Permalink Normal View History

2024-02-22 15:02:16 -08:00
#!/bin/bash
#
# vdns-stack
# https://git.stack-source.com/msb/vdns-stack
# 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)/vdns.sh
help()
{
echo "List Zones exists that are in DNS and associated with this server."
echo ""
echo "usage: $thisfilename [-q <query>] [-h]"
echo ""
echo " -h Print this help."
echo " -q <query> Optional search term."
echo " Can be a domain, or a partial string with * for wildcard."
echo " If using wildcard put the query in single quotes. e.g.:"
echo " $thisfilename (returns all domains)."
echo " $thisfilename -q example.com (returns domain example.com, if found)."
echo " $thisfilename -q '*example*' (returns any domain with example as part of the name)."
}
vdns:getoptions "$@"
if [[ -z $query ]]; then
query=*
fi
SEARCH=($(/usr/local/sbin/pdns-search.sh -q hostname=$hostname/$query -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
# sort results
readarray -td '' SORTED < <(printf '%s\0' "${SEARCH[@]}" | sort -z)
# echo header and remove header row
echo zone
# check each row to verify data and output zone (domain) if it validates
for ROW in "${SORTED[@]}"; do
# turn row into array
readarray -d , -t row_array < <(echo $ROW)
# get zone, strip ending dot
zone=$(sed 's/.$//' <<< "${row_array[4]}")
# compare row to expected/valid result
if [[ $ROW = "hostname=$hostname/$zone,$zone.,comment,SOA,$zone.,$zone." ]]; then
# got a match
echo $zone
fi
done
fi