From 9938f8059ab32067572e180456b3ef145f04fbed Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Wed, 7 Feb 2024 12:10:18 -0800 Subject: [PATCH] add new vdns scripts, for sudo access --- bin/vdns-rr-del.sh | 29 +++++++++++++++++++++++++ bin/vdns-rr-rep.sh | 29 +++++++++++++++++++++++++ bin/vdns-zone-add.sh | 35 +++++++++++++++++++++++++++++++ bin/vdns-zone-del.sh | 29 +++++++++++++++++++++++++ bin/vdns-zone-exp.sh | 29 +++++++++++++++++++++++++ bin/vdns-zone-ext.sh | 38 +++++++++++++++++++++++++++++++++ bin/vdns-zone-lst.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 239 insertions(+) create mode 100755 bin/vdns-rr-del.sh create mode 100755 bin/vdns-rr-rep.sh create mode 100755 bin/vdns-zone-add.sh create mode 100755 bin/vdns-zone-del.sh create mode 100755 bin/vdns-zone-exp.sh create mode 100755 bin/vdns-zone-ext.sh create mode 100755 bin/vdns-zone-lst.sh diff --git a/bin/vdns-rr-del.sh b/bin/vdns-rr-del.sh new file mode 100755 index 0000000..fbfa61e --- /dev/null +++ b/bin/vdns-rr-del.sh @@ -0,0 +1,29 @@ +#!/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 /usr/local/sbin/pdns.sh + +help() +{ + /usr/local/sbin/pdns-rr-del.sh -p $thisfilename -h +} + +pdns:getoptions "$@" + +# check for zone +if [[ -z $zone ]]; then + echo "zone is required" + exit 1 +fi + +zone_exists=$(/usr/local/bin/vdns-zone-ext.sh -z $zone) +if [[ $zone_exists = "true" ]]; then + /usr/local/sbin/pdns-rr-del.sh $@ +else + echo Zone $zone not found. +fi diff --git a/bin/vdns-rr-rep.sh b/bin/vdns-rr-rep.sh new file mode 100755 index 0000000..9a32308 --- /dev/null +++ b/bin/vdns-rr-rep.sh @@ -0,0 +1,29 @@ +#!/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 /usr/local/sbin/pdns.sh + +help() +{ + /usr/local/sbin/pdns-rr-rep.sh -p $thisfilename -h +} + +pdns:getoptions "$@" + +# check for zone +if [[ -z $zone ]]; then + echo "zone is required" + exit 1 +fi + +zone_exists=$(/usr/local/bin/vdns-zone-ext.sh -z $zone) +if [[ $zone_exists = "true" ]]; then + /usr/local/sbin/pdns-rr-rep.sh $@ +else + echo Zone $zone not found. +fi diff --git a/bin/vdns-zone-add.sh b/bin/vdns-zone-add.sh new file mode 100755 index 0000000..1b8f444 --- /dev/null +++ b/bin/vdns-zone-add.sh @@ -0,0 +1,35 @@ +#!/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 /usr/local/sbin/pdns.sh + +help() +{ + echo "Add new zone to DNS" + echo "" + echo "usage: $thisfilename -z [-h]" + echo "" + echo " -h Print this help." + echo " -z Zone (domain name) to add." +} + +pdns:getoptions "$@" + +# check for zone +if [[ -z $zone ]]; then + echo "zone is required" + exit 1 +fi + +zone_exists=$(/usr/local/sbin/pdns-zone-ext.sh -z $zone) +if [[ $zone_exists = "true" ]]; then + echo Zone $zone already exists. + exit 1 +else + /usr/local/bin/pdns-zone-add.sh -z $zone -w hostname=$hostname/$zone +fi diff --git a/bin/vdns-zone-del.sh b/bin/vdns-zone-del.sh new file mode 100755 index 0000000..abea185 --- /dev/null +++ b/bin/vdns-zone-del.sh @@ -0,0 +1,29 @@ +#!/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 /usr/local/sbin/pdns.sh + +help() +{ + /usr/local/sbin/pdns-zone-del.sh -p $thisfilename -h +} + +pdns:getoptions "$@" + +# check for zone +if [[ -z $zone ]]; then + echo "zone is required" + exit 1 +fi + +zone_exists=$(/usr/local/bin/vdns-zone-ext.sh -z $zone) +if [[ $zone_exists = "true" ]]; then + /usr/local/sbin/pdns-zone-del.sh $@ +else + echo Zone $zone not found. +fi diff --git a/bin/vdns-zone-exp.sh b/bin/vdns-zone-exp.sh new file mode 100755 index 0000000..a178fbb --- /dev/null +++ b/bin/vdns-zone-exp.sh @@ -0,0 +1,29 @@ +#!/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 /usr/local/sbin/pdns.sh + +help() +{ + /usr/local/sbin/pdns-zone-exp.sh -p $thisfilename -h +} + +pdns:getoptions "$@" + +# check for zone +if [[ -z $zone ]]; then + echo "zone is required" + exit 1 +fi + +zone_exists=$(/usr/local/bin/vdns-zone-ext.sh -z $zone) +if [[ $zone_exists = "true" ]]; then + /usr/local/sbin/pdns-zone-exp.sh $@ +else + echo Zone $zone not found. +fi diff --git a/bin/vdns-zone-ext.sh b/bin/vdns-zone-ext.sh new file mode 100755 index 0000000..e5f5242 --- /dev/null +++ b/bin/vdns-zone-ext.sh @@ -0,0 +1,38 @@ +#!/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 /usr/local/sbin/pdns.sh + +help() +{ + echo "Check if Zone exists (and is associated with this server)." + echo "" + echo "usage: $thisfilename -z [-h]" + echo "" + echo " -h Print this help." + echo " -z Zone (domain name) check." +} + +pdns:getoptions "$@" + +# check for zone +if [[ -z $zone ]]; then + echo "zone is required" + exit 1 +fi + +SEARCH=($(/usr/local/bin/vdns-zone-lst.sh -q $zone)) +if [[ ${#SEARCH[@]} = 1 ]]; then + if [[ "${SEARCH[0]}" = $zone ]]; then + echo true + exit 0 + fi +fi + +echo false +exit 1 diff --git a/bin/vdns-zone-lst.sh b/bin/vdns-zone-lst.sh new file mode 100755 index 0000000..c42051c --- /dev/null +++ b/bin/vdns-zone-lst.sh @@ -0,0 +1,50 @@ +#!/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 /usr/local/sbin/pdns.sh + +help() +{ + echo "List Zones exists that are in DNS and associated with this server." + echo "" + echo "usage: $thisfilename [-q ] [-h]" + echo "" + echo " -h Print this help." + echo " -q 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