#!/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 $(dirname $0)/pdns.sh help() { echo "Search data in Zones, Comments and RRSets." echo "" echo "usage: $thisfilename -q [-e ] [-o ] [-c] [-h]" echo "" echo " -h Print this help." echo " -q The string to search for." echo " -e Maximum number of entries to return (defaults to 100)." echo " -o 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 else echo Unexecpted http response seraching for $query: $zone_status fi rm $tmpfile