This commit is contained in:
root 2024-02-02 00:55:45 +02:00
commit 8bf896a908
2 changed files with 50 additions and 0 deletions

45
dump-dns-cache.sh Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env bash
HOST="$1"
USERNAME="$2"
PASSWORD="$3"
FILTER="$4"
USE_RUBY="0"
if [ -z "${HOST}" ]
then
echo "Missing hostname"
exit 1
fi
if [ -z "${USERNAME}" ]
then
echo "Missing username"
exit 1
fi
if [ -z "${PASSWORD}" ]
then
echo "Missing password"
exit 1
fi
if [ -z "${FILTER}" ]
then
JQ_QUERY_TEMPLATE='.[]'
else
JQ_QUERY_TEMPLATE='.[] | select(.name|contains("###PATTERN###"))'
fi
QUERY='{".proplist": [".id","name","type","data","ttl"]}'
if [ "${USE_RUBY}" -gt "0" ]
then
JQ_QUERY=$( echo "${JQ_QUERY_TEMPLATE}" |ruby replace-str.rb "###PATTERN###" "${FILTER}" )
else
JQ_QUERY=$( echo "${JQ_QUERY_TEMPLATE}" | sed -e "s@###PATTERN###@${FILTER}@g" )
fi
curl -s -k -u "${USERNAME}:${PASSWORD}" "https://${HOST}/rest/ip/dns/cache/print" \
--data "${QUERY}" -H "content-type: application/json" | \
jq "${JQ_QUERY}"

5
replace-str.rb Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env ruby
while line = STDIN.gets
puts "#{line.chomp.gsub("#{ARGV[0]}","#{ARGV[1]}")}"
end