new pdns-search.sh
This commit is contained in:
parent
6d40482100
commit
cd39bfc95b
61
bin/pdns-search.sh
Executable file
61
bin/pdns-search.sh
Executable file
|
@ -0,0 +1,61 @@
|
|||
#!/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()
|
||||
{
|
||||
thisfilename=$(basename -- "$0")
|
||||
echo "$thisfilename"
|
||||
echo "Search data in Zones, Comments and RRSets."
|
||||
echo ""
|
||||
echo "usage: $thisfilename -q <query> [-e <max>] [-o <object>] [-c] [-h]"
|
||||
echo ""
|
||||
echo " -h Print this help."
|
||||
echo " -q <query> The string to search for."
|
||||
echo " -e <max> Maximum number of entries to return."
|
||||
echo " -o <object> Type of data to search for, one of 'all' (default), 'zone', 'record', 'comment'."
|
||||
echo " -c Output in csv format instead of columns."
|
||||
}
|
||||
|
||||
pdns:getoptions "$@"
|
||||
|
||||
# check for query
|
||||
if [[ -z $query ]]; then
|
||||
echo "query is required"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ -n $max ]]; then
|
||||
query="$query&max=$max"
|
||||
fi
|
||||
|
||||
if [[ -n $object ]]; then
|
||||
query="$query&object_type=$object"
|
||||
fi
|
||||
|
||||
tmpfile=$(mktemp)
|
||||
|
||||
# export zone and check http status
|
||||
zone_status=$(/usr/bin/curl --silent --output "$tmpfile" --write-out "%{http_code}" -H "X-API-Key: $api_key" $api_base_url/search-data?q=$query)
|
||||
|
||||
if [[ $zone_status = 200 ]]; then
|
||||
if [[ -n $csv ]]; then
|
||||
# csv output
|
||||
dasel -r json -w csv -f $tmpfile|sed -e 's/"""/"/g'
|
||||
else
|
||||
# column output
|
||||
dasel -r json -w csv -f $tmpfile|sed -e 's/"""/"/g'|column -t -s ','
|
||||
fi
|
||||
elif [[ $zone_status = 404 ]]; then
|
||||
echo 404 Not Found, $zone does not exist
|
||||
else
|
||||
echo Unexecpted http response checking for existence of zone $zone: $zone_status
|
||||
fi
|
||||
|
||||
rm $tmpfile
|
Loading…
Reference in New Issue
Block a user