]> Frank Brehm's Git Trees - scripts/root-bin.git/commitdiff
Adding check-zones
authorroot Liz <root@nexunus.net>
Thu, 5 Jan 2017 16:00:45 +0000 (17:00 +0100)
committerroot Liz <root@nexunus.net>
Thu, 5 Jan 2017 16:00:45 +0000 (17:00 +0100)
check-zones [new file with mode: 0755]

diff --git a/check-zones b/check-zones
new file mode 100755 (executable)
index 0000000..cbc7f50
--- /dev/null
@@ -0,0 +1,123 @@
+#!/bin/bash
+
+set -e
+set -u
+
+# console colors:
+RED=""
+YELLOW=""
+GREEN=""
+BLUE=""
+NORMAL=""
+
+HAS_TTY='y'
+
+detect_color() {
+
+    local safe_term="${TERM//[^[:alnum:]]/?}"
+    local match_lhs=""
+    local use_color="false"
+    [[ -f ~/.dir_colors   ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
+    [[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
+    [[ -z ${match_lhs}    ]] \
+        && type -P dircolors >/dev/null \
+        && match_lhs=$(dircolors --print-database)
+    [[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color="true"
+
+    # console colors:
+    if [ "${use_color}" = "true" ] ; then
+        RED="\033[38;5;196m"
+        YELLOW="\033[38;5;226m"
+        GREEN="\033[38;5;46m"
+        BLUE="\033[38;5;27m"
+        NORMAL="\033[39m"
+    else
+        RED=""
+        YELLOW=""
+        GREEN=""
+        BLUE=""
+        NORMAL=""
+    fi
+
+    local my_tty=$(tty)
+    if [[ "${my_tty}" =~ 'not a tty' ]] ; then
+        my_tty='-'
+    fi
+
+    if [[ "${my_tty}" = '-' || "${safe_term}" = "dump" ]] ; then
+        HAS_TTY='n'
+    fi
+
+}
+detect_color
+
+
+BIND_DIR="/etc/bind"
+ZONES_DIR="${BIND_DIR}/zones"
+NAMED_PI_CONF="${BIND_DIR}/named-pri.conf"
+if [[ "$#" -gt "0" ]] ; then
+    NAMED_PI_CONF="$1"
+fi
+
+if [[ ! -f "${NAMED_PI_CONF}" ]] ; then
+    echo "File '${NAMED_PI_CONF}' not found." >&2
+    exit 4
+fi
+
+if [[ ! -d "${ZONES_DIR}" ]] ; then
+    echo "Directory '${ZONES_DIR}' not found." >&2
+    exit 5
+fi
+
+declare -a ZONES=()
+declare -A ZONE_FILES=()
+
+echo
+echo "===================================================================="
+echo -e "Checking Bind (named) ${GREEN}configuration${NORMAL} ..."
+named-checkconf
+
+for zone in $(cat "${NAMED_PI_CONF}" | \
+        egrep '^[[:space:]]*zone[[:space:]]' | \
+        sed -e 's/^[^"]*"//' -e 's/".*//' ) ; do
+
+    zone_type=$( cat "${NAMED_PI_CONF}" | \
+            egrep -w -A 5 "${zone}" | \
+            egrep -w 'type' | \
+            head -n 1 | \
+            sed -e 's/.*type[[:space:]]*//' -e 's/[[:space:]]*;.*//' | \
+            tr '[[:upper:]]' '[[:lower:]]' )
+    if [[ "${zone_type}" != 'master' ]] ; then
+        continue
+    fi
+
+    zone_file=$( cat "${NAMED_PI_CONF}" | \
+            egrep -w -A 5 "${zone}" | \
+            egrep -w 'file' | \
+            head -n 1 | \
+            sed -e 's/^[^"]*"//' -e 's/".*//' )
+
+    #echo "Found zone '${zone}', type '${zone_type}', zone file: '${zone_file}'."
+    ZONES+=("${zone}")
+    ZONE_FILES["${zone}"]="${zone_file}"
+done
+
+
+if [[ "${#ZONES[@]}" -lt "1" ]] ; then
+    echo "No zones to check found."
+    exit 0
+fi
+
+echo
+echo "===================================================================="
+echo "Checking primary zones:"
+for zone in "${ZONES[@]}" ; do
+    zone_file=${ZONE_FILES["${zone}"]}
+    echo
+    echo "-------------------------"
+    echo -e "Checking '${GREEN}${zone}${NORMAL}'       -> '${GREEN}${zone_file}${NORMAL}'"
+    named-checkzone "${zone}" "${zone_file}" || true
+done
+
+
+# vim: ts=4 et softtabstop=4 shiftwidth=4