51 lines
1.7 KiB
Bash
Executable File
51 lines
1.7 KiB
Bash
Executable File
#!/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 "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)."
|
|
}
|
|
|
|
pdns: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
|
|
# remove header row
|
|
SEARCH=("${SEARCH[@]:1}")
|
|
# check each row to verify data and output zone (domain) if it validates
|
|
for ROW in "${SEARCH[@]}"; 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
|