- Some minor fixes on script 'bind_change_ip.sh'.
- Redesign script 'bind_change_ttl.sh'. - Redesign script 'bind_set_ttl_to_default.sh'.
This commit is contained in:
parent
bbb8c5a023
commit
af94d5de33
@ -687,8 +687,6 @@ while IFS='' read -r _line || [[ -n $_line ]] ; do
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if $_set_ipv6 ; then
|
if $_set_ipv6 ; then
|
||||||
if $(grep -q -e "$IPv6_ADDRESS_OLD" "$zone_file") ; then
|
if $(grep -q -e "$IPv6_ADDRESS_OLD" "$zone_file") ; then
|
||||||
if [ ${#zonefiles_arr[@]} -eq 0 ] ; then
|
if [ ${#zonefiles_arr[@]} -eq 0 ] ; then
|
||||||
@ -713,12 +711,9 @@ echo ""
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for zone_file in ${zonefiles_arr[@]} ; do
|
for zone_file in ${zonefiles_arr[@]} ; do
|
||||||
|
|
||||||
echo -e "\tconverting $zone_file.."
|
echo -e "\tEditing \033[1m$zone_file\033[m .."
|
||||||
|
|
||||||
## - calculate new serial
|
## - calculate new serial
|
||||||
## -
|
## -
|
||||||
@ -777,7 +772,7 @@ for zone_file in ${zonefiles_arr[@]} ; do
|
|||||||
|
|
||||||
if $_replaced_ipv6 && $IGNORE_ALT_HOSTNAMES ; then
|
if $_replaced_ipv6 && $IGNORE_ALT_HOSTNAMES ; then
|
||||||
echononl "\t Setting back hostnames containing \"-alt\".."
|
echononl "\t Setting back hostnames containing \"-alt\".."
|
||||||
perl -i -n -p -e "s#^(.+(-alt).*)\s+IN\s+A\s+$IPv6_ADDRESS_NEW#\1 IN A $IPv6_ADDRESS_OLD#" $zone_file > /dev/null 2>&1
|
perl -i -n -p -e "s#^(.+(-alt).*)\s+IN\s+AAAA\s+$IPv6_ADDRESS_NEW#\1 IN AAAA $IPv6_ADDRESS_OLD#" $zone_file > /dev/null 2>&1
|
||||||
if [ "$?" = "0" ]; then
|
if [ "$?" = "0" ]; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
|
@ -1,20 +1,29 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
## --- Variables (default Values)
|
|
||||||
## ---
|
working_dir="$(dirname $(realpath $0))"
|
||||||
_zone_file_dir=/etc/bind/master
|
conf_file="${working_dir}/conf/bind.conf"
|
||||||
#_zone_file_dir=/root/tmp/master
|
|
||||||
|
log_file="$(mktemp)"
|
||||||
|
|
||||||
|
backup_date="$(date +%Y-%m-%d-%H%M)"
|
||||||
|
|
||||||
_serial_new=`date +%Y%m%d01`
|
_serial_new=`date +%Y%m%d01`
|
||||||
|
|
||||||
_zone_file_suffix=zone
|
|
||||||
|
|
||||||
## ---
|
#---------------------------------------
|
||||||
## --- End: Variables (default Values)
|
#-----------------------------
|
||||||
|
# Base Function(s)
|
||||||
|
#-----------------------------
|
||||||
|
#---------------------------------------
|
||||||
|
|
||||||
|
clean_up() {
|
||||||
|
|
||||||
|
# Perform program exit housekeeping
|
||||||
|
rm $log_file
|
||||||
|
exit $1
|
||||||
|
}
|
||||||
|
|
||||||
## --- some functions
|
|
||||||
## ---
|
|
||||||
echononl(){
|
echononl(){
|
||||||
echo X\\c > /tmp/shprompt$$
|
echo X\\c > /tmp/shprompt$$
|
||||||
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
|
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
|
||||||
@ -31,7 +40,7 @@ fatal(){
|
|||||||
echo ""
|
echo ""
|
||||||
echo -e "\t\033[31m\033[1mScript is canceled\033[m\033[m"
|
echo -e "\t\033[31m\033[1mScript is canceled\033[m\033[m"
|
||||||
echo ""
|
echo ""
|
||||||
exit 1
|
clean_up 1
|
||||||
}
|
}
|
||||||
|
|
||||||
warn (){
|
warn (){
|
||||||
@ -61,6 +70,9 @@ error(){
|
|||||||
echo_ok() {
|
echo_ok() {
|
||||||
echo -e "\033[75G[ \033[32mok\033[m ]"
|
echo -e "\033[75G[ \033[32mok\033[m ]"
|
||||||
}
|
}
|
||||||
|
echo_done() {
|
||||||
|
echo -e "\033[75G[ \033[32mdone\033[m ]"
|
||||||
|
}
|
||||||
echo_failed(){
|
echo_failed(){
|
||||||
echo -e "\033[75G[ \033[1;31mfailed\033[m ]"
|
echo -e "\033[75G[ \033[1;31mfailed\033[m ]"
|
||||||
}
|
}
|
||||||
@ -110,8 +122,71 @@ is_valid_ipv6() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## ---
|
trap clean_up SIGHUP SIGINT SIGTERM
|
||||||
## --- END: functions
|
|
||||||
|
|
||||||
|
|
||||||
|
#---------------------------------------
|
||||||
|
#-----------------------------
|
||||||
|
# Setting Defaults
|
||||||
|
#-----------------------------
|
||||||
|
#---------------------------------------
|
||||||
|
|
||||||
|
DEFAULT_CONF_FILE_DIR="/etc/bind"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---------------------------------------
|
||||||
|
#-----------------------------
|
||||||
|
# Load default values from bind.conf
|
||||||
|
#
|
||||||
|
# Overwrites the settings above
|
||||||
|
#
|
||||||
|
#-----------------------------
|
||||||
|
#---------------------------------------
|
||||||
|
|
||||||
|
#clear
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echononl " Loading default Configuration values from $(basename ${conf_file}).."
|
||||||
|
if [[ ! -f "$conf_file" ]]; then
|
||||||
|
echo_skipped
|
||||||
|
else
|
||||||
|
source "${conf_file}" > $log_file 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
fatal "$(cat $log_file)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -n "$CONF_FILE_DIR" ]] && DEFAULT_CONF_FILE_DIR="$CONF_FILE_DIR"
|
||||||
|
|
||||||
|
if [[ -n "$ZONE_FILE_MASTER_DIR" ]] ; then
|
||||||
|
DEFAULT_ZONE_FILE_MASTER_DIR="$ZONE_FILE_MASTER_DIR"
|
||||||
|
else
|
||||||
|
DEFAULT_ZONE_FILE_MASTER_DIR="${DEFAULT_CONF_FILE_DIR}/master"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$ZONE_FILE_SLAVE_DIR" ]] ; then
|
||||||
|
DEFAULT_ZONE_FILE_SLAVE_DIR="$ZONE_FILE_SLAVE_DIR"
|
||||||
|
else
|
||||||
|
DEFAULT_ZONE_FILE_SLAVE_DIR="${DEFAULT_CONF_FILE_DIR}/slave"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$ZONE_FILE_SUFFIX" ]] ; then
|
||||||
|
DEFAULT_ZONE_FILE_SUFFIX="$ZONE_FILE_SUFFIX"
|
||||||
|
else
|
||||||
|
DEFAULT_ZONE_FILE_SUFFIX='zone'
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$ZONES_DECLARATION_FILE" ]] ; then
|
||||||
|
DEFAULT_ZONES_DECLARATION_FILE="$ZONES_DECLARATION_FILE"
|
||||||
|
else
|
||||||
|
DEFAULT_ZONES_DECLARATION_FILE="${CONF_FILE_DIR}/named.conf.local"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\033[32m--\033[m"
|
echo -e "\033[32m--\033[m"
|
||||||
@ -182,9 +257,15 @@ while [ "X$IPv6_ADDRESS" = "X" ]; do
|
|||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
if ! $_set_ipv6 && ! $_set_ipv4 ; then
|
||||||
|
fatal "No IP-Adresses given to change TTL for.."
|
||||||
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\033[32m--\033[m"
|
echo -e "\033[32m--\033[m"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
echo "Insert New TTL for the given IP-Address(es)"
|
echo "Insert New TTL for the given IP-Address(es)"
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "[ \033[33mTIP\033[m ]: Choose a extraordinary Number (like 363 or 181), so you can"
|
echo -e "[ \033[33mTIP\033[m ]: Choose a extraordinary Number (like 363 or 181), so you can"
|
||||||
@ -212,44 +293,6 @@ while [ "X$TTL" = "X" ]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[32m--\033[m"
|
|
||||||
echo ""
|
|
||||||
echo "Insert the directory, where your zone-files resides."
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
ZONE_FILE_DIR=
|
|
||||||
while [ "X$ZONE_FILE_DIR" = "X" ]; do
|
|
||||||
echononl "Zone File Directory [$_zone_file_dir]: "
|
|
||||||
read ZONE_FILE_DIR
|
|
||||||
if [ "X$ZONE_FILE_DIR" = "X" ]; then
|
|
||||||
ZONE_FILE_DIR=$_zone_file_dir
|
|
||||||
fi
|
|
||||||
if [ ! -d $ZONE_FILE_DIR ]; then
|
|
||||||
echo -e "\n\tDirectory \033[33m\033[1m$ZONE_FILE_DIR\033[m does NOT exist!\n"
|
|
||||||
ZONE_FILE_DIR=
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[32m--\033[m"
|
|
||||||
echo ""
|
|
||||||
echo "Insert the file-suffix of thr zone-files"
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
ZONE_FILE_SUFFIX=
|
|
||||||
echononl "Suffix of Zone Files [$_zone_file_suffix]: "
|
|
||||||
read ZONE_FILE_SUFFIX
|
|
||||||
if [ "X$ZONE_FILE_SUFFIX" = "X" ]; then
|
|
||||||
ZONE_FILE_SUFFIX=$_zone_file_suffix
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
if ! $_set_ipv6 && ! $_set_ipv4 ; then
|
|
||||||
fatal "No IP-Adresses given to change TTL for.."
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\033[32m--\033[m"
|
echo -e "\033[32m--\033[m"
|
||||||
echo ""
|
echo ""
|
||||||
@ -277,6 +320,100 @@ while [ "$OK" != "yes" -o "$OK" != "no" ] ; do
|
|||||||
done
|
done
|
||||||
[[ $OK = "yes" ]] && IGNORE_ALT_HOSTNAMES=true
|
[[ $OK = "yes" ]] && IGNORE_ALT_HOSTNAMES=true
|
||||||
|
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[32m--\033[m"
|
||||||
|
echo "Common parameters"
|
||||||
|
echo -e "\033[32m--\033[m"
|
||||||
|
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Insert directory containing the bind configuration files."
|
||||||
|
echo ""
|
||||||
|
CONF_FILE_DIR=""
|
||||||
|
if [[ -n "$DEFAULT_CONF_FILE_DIR" ]] ; then
|
||||||
|
echononl "Bind Configuration Directory [${DEFAULT_CONF_FILE_DIR}]: "
|
||||||
|
read CONF_FILE_DIR
|
||||||
|
if [[ "X$CONF_FILE_DIR" = "X" ]]; then
|
||||||
|
CONF_FILE_DIR="$DEFAULT_CONF_FILE_DIR"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echononl "Bind Configuration Directory: "
|
||||||
|
read CONF_FILE_DIR
|
||||||
|
while [ "X$CONF_FILE_DIR" = "X" ] ; do
|
||||||
|
echo -e "\n\t\033[33m\033[1mSetting 'Bind Configuration Directory' is required!\033[m\n"
|
||||||
|
echononl "Bind Configuration Directory: "
|
||||||
|
read CONF_FILE_DIR
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -n "$ZONES_DECLARATION_FILE" ]] || DEFAULT_ZONES_DECLARATION_FILE="${CONF_FILE_DIR}/named.conf.local"
|
||||||
|
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[32m--\033[m"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Insert zones declaration file."
|
||||||
|
echo ""
|
||||||
|
ZONES_DECLARATION_FILE=""
|
||||||
|
if [[ -n "$DEFAULT_ZONES_DECLARATION_FILE" ]] ; then
|
||||||
|
echononl "Zones Declaration File [${DEFAULT_ZONES_DECLARATION_FILE}]: "
|
||||||
|
read ZONES_DECLARATION_FILE
|
||||||
|
if [[ "X$ZONES_DECLARATION_FILE" = "X" ]]; then
|
||||||
|
ZONES_DECLARATION_FILE="$DEFAULT_ZONES_DECLARATION_FILE"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echononl "Zones Declaration File: "
|
||||||
|
read ZONES_DECLARATION_FILE
|
||||||
|
while [ "X$ZONES_DECLARATION_FILE" = "X" ] ; do
|
||||||
|
echo -e "\n\t\033[33m\033[1mSetting 'Zones Declaration File' is required!\033[m\n"
|
||||||
|
echononl "Zones Declaration File: "
|
||||||
|
read ZONES_DECLARATION_FILE
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[32m--\033[m"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Insert the directory, where your zone-files resides."
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
ZONE_FILE_MASTER_DIR=""
|
||||||
|
if [[ -n "$DEFAULT_ZONE_FILE_MASTER_DIR" ]] ; then
|
||||||
|
echononl "Zone File Directory (master) [${DEFAULT_ZONE_FILE_MASTER_DIR}]: "
|
||||||
|
read ZONE_FILE_MASTER_DIR
|
||||||
|
if [[ "X$ZONE_FILE_MASTER_DIR" = "X" ]]; then
|
||||||
|
ZONE_FILE_MASTER_DIR="$DEFAULT_ZONE_FILE_MASTER_DIR"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echononl "Zone File Directory (master): "
|
||||||
|
read ZONE_FILE_MASTER_DIR
|
||||||
|
while [ "X$ZONE_FILE_MASTER_DIR" = "X" ] ; do
|
||||||
|
echo -e "\n\t\033[33m\033[1mSetting 'Zone File Directory (master)' is required!\033[m\n"
|
||||||
|
echononl "Zone File Directory (master): "
|
||||||
|
read ZONE_FILE_MASTER_DIR
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
#echo ""
|
||||||
|
#echo -e "\033[32m--\033[m"
|
||||||
|
#
|
||||||
|
#echo ""
|
||||||
|
#echo "Insert the file-suffix of thr zone-files"
|
||||||
|
#echo ""
|
||||||
|
#echo ""
|
||||||
|
#ZONE_FILE_SUFFIX=
|
||||||
|
#echononl "Suffix of Zone Files [$_zone_file_suffix]: "
|
||||||
|
#read ZONE_FILE_SUFFIX
|
||||||
|
#if [ "X$ZONE_FILE_SUFFIX" = "X" ]; then
|
||||||
|
# ZONE_FILE_SUFFIX=$_zone_file_suffix
|
||||||
|
#fi
|
||||||
|
|
||||||
|
|
||||||
clear
|
clear
|
||||||
echo ""
|
echo ""
|
||||||
echo ""
|
echo ""
|
||||||
@ -299,8 +436,10 @@ echo "New TTL...........................: $TTL"
|
|||||||
echo ""
|
echo ""
|
||||||
echo "Ignore hostnames containing \"-alt\": $IGNORE_ALT_HOSTNAMES"
|
echo "Ignore hostnames containing \"-alt\": $IGNORE_ALT_HOSTNAMES"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Zone File Directory...............: $ZONE_FILE_DIR"
|
echo "Bind Configuration Directory......: $CONF_FILE_DIR"
|
||||||
echo "Zone File Suffix..................: $ZONE_FILE_SUFFIX"
|
echo "Zones Declaration File............: $ZONES_DECLARATION_FILE"
|
||||||
|
echo "Zone File Directory...............: $ZONE_FILE_MASTER_DIR"
|
||||||
|
#echo "Zone File Suffix..................: $ZONE_FILE_SUFFIX"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
OK=
|
OK=
|
||||||
@ -324,64 +463,166 @@ done
|
|||||||
[[ $OK = "yes" ]] || fatal Repeat execution with different parameters
|
[[ $OK = "yes" ]] || fatal Repeat execution with different parameters
|
||||||
|
|
||||||
|
|
||||||
cp -a $ZONE_FILE_DIR ${ZONE_FILE_DIR}.BAK-`date +%Y-%m-%d-%H%M`
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echononl "\tBackup directory '${ZONE_FILE_MASTER_DIR}'.."
|
||||||
|
cp -a "${ZONE_FILE_MASTER_DIR}" "${ZONE_FILE_MASTER_DIR}.${backup_date}" > $log_file 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
fatal "$(cat $log_file)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echononl "\tCreate array of given IPv4 addresses"
|
||||||
ipv4_addresses_arr=()
|
ipv4_addresses_arr=()
|
||||||
for _ipv4_address in $IPv4_ADDRESS ; do
|
for _ipv4_address in $IPv4_ADDRESS ; do
|
||||||
containsElement "$_ipv4_address" "${ipv4_addresses_arr[@]}" && continue
|
containsElement "$_ipv4_address" "${ipv4_addresses_arr[@]}" && continue
|
||||||
ipv4_addresses_arr+=("$_ipv4_address")
|
ipv4_addresses_arr+=("$_ipv4_address")
|
||||||
done
|
done
|
||||||
|
echo_done
|
||||||
|
|
||||||
|
echononl "\tCreate array of given IPv6 addresses"
|
||||||
ipv6_addresses_arr=()
|
ipv6_addresses_arr=()
|
||||||
for _ipv6_address in $IPv6_ADDRESS ; do
|
for _ipv6_address in $IPv6_ADDRESS ; do
|
||||||
containsElement "$_ipv6_address" "${ipv6_addresses_arr[@]}" && continue
|
containsElement "$_ipv6_address" "${ipv6_addresses_arr[@]}" && continue
|
||||||
ipv6_addresses_arr+=("$_ipv6_address")
|
ipv6_addresses_arr+=("$_ipv6_address")
|
||||||
done
|
done
|
||||||
|
echo_done
|
||||||
|
|
||||||
|
#zonefiles_arr=()
|
||||||
|
#if $_set_ipv4 ; then
|
||||||
|
# for _ipv4_address in ${ipv4_addresses_arr[@]} ; do
|
||||||
|
# _zone_files_ipv4=`grep -l -e "$_ipv4_address" ${ZONE_FILE_DIR}/*.$ZONE_FILE_SUFFIX`
|
||||||
|
# if [ ${#zonefiles_arr[@]} -eq 0 ] ; then
|
||||||
|
# for _zone_file in $_zone_files_ipv4 ; do
|
||||||
|
# zonefiles_arr+=("$_zone_file")
|
||||||
|
# done
|
||||||
|
# else
|
||||||
|
# for _zone_file in $_zone_files_ipv4 ; do
|
||||||
|
# containsElement "$_zone_file" "${zonefiles_arr[@]}" && continue
|
||||||
|
# zonefiles_arr+=("$_zone_file")
|
||||||
|
# done
|
||||||
|
# fi
|
||||||
|
# done
|
||||||
|
#fi
|
||||||
|
#
|
||||||
|
#if $_set_ipv6 ; then
|
||||||
|
# for _ipv6_address in "${ipv6_addresses_arr[@]}" ; do
|
||||||
|
# _zone_files_ipv6=`grep -l -e "$_ipv6_address" ${ZONE_FILE_DIR}/*.$ZONE_FILE_SUFFIX`
|
||||||
|
# if [ ${#zonefiles_arr[@]} -eq 0 ] ; then
|
||||||
|
# for _zone_file in $_zone_files_ipv6 ; do
|
||||||
|
# zonefiles_arr+=("$_zone_file")
|
||||||
|
# done
|
||||||
|
# else
|
||||||
|
# for _zone_file in $_zone_files_ipv6 ; do
|
||||||
|
# containsElement "$_zone_file" ${zonefiles_arr[@]} && continue
|
||||||
|
# zonefiles_arr+=("$_zone_file")
|
||||||
|
# done
|
||||||
|
# fi
|
||||||
|
# done
|
||||||
|
#fi
|
||||||
|
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[37m\033[1mDetermine zone files conatining ip-adressse for which TTL time is requested to change..\033[m"
|
||||||
|
|
||||||
|
_found=false
|
||||||
|
_is_master=false
|
||||||
zonefiles_arr=()
|
zonefiles_arr=()
|
||||||
if $_set_ipv4 ; then
|
zone_file=""
|
||||||
for _ipv4_address in ${ipv4_addresses_arr[@]} ; do
|
regex_master="type[[:space:]]+master"
|
||||||
_zone_files_ipv4=`grep -l -e "$_ipv4_address" ${ZONE_FILE_DIR}/*.$ZONE_FILE_SUFFIX`
|
regex_file="^[[:space:]]*file"
|
||||||
if [ ${#zonefiles_arr[@]} -eq 0 ] ; then
|
while IFS='' read -r _line || [[ -n $_line ]] ; do
|
||||||
for _zone_file in $_zone_files_ipv4 ; do
|
|
||||||
zonefiles_arr+=("$_zone_file")
|
|
||||||
done
|
|
||||||
else
|
|
||||||
for _zone_file in $_zone_files_ipv4 ; do
|
|
||||||
containsElement "$_zone_file" "${zonefiles_arr[@]}" && continue
|
|
||||||
zonefiles_arr+=("$_zone_file")
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if $_set_ipv6 ; then
|
if [[ $_line =~ ^[[:space:]]*zone[[:space:]]+ ]]; then
|
||||||
for _ipv6_address in "${ipv6_addresses_arr[@]}" ; do
|
_found=true
|
||||||
_zone_files_ipv6=`grep -l -e "$_ipv6_address" ${ZONE_FILE_DIR}/*.$ZONE_FILE_SUFFIX`
|
#zone="$(echo $_line | awk '{print$2}')"
|
||||||
if [ ${#zonefiles_arr[@]} -eq 0 ] ; then
|
#shopt -s extglob
|
||||||
for _zone_file in $_zone_files_ipv6 ; do
|
#if [[ $zone =~ \; ]]; then
|
||||||
zonefiles_arr+=("$_zone_file")
|
# zone=${zone%%*(\;)}
|
||||||
done
|
#fi
|
||||||
else
|
#if [[ $zone =~ ^\" ]]; then
|
||||||
for _zone_file in $_zone_files_ipv6 ; do
|
# zone=${zone##*(\")}
|
||||||
containsElement "$_zone_file" ${zonefiles_arr[@]} && continue
|
# zone=${zone%%*(\")}
|
||||||
zonefiles_arr+=("$_zone_file")
|
#fi
|
||||||
done
|
#shopt -u extglob
|
||||||
|
fi
|
||||||
|
if $_found ; then
|
||||||
|
if [[ $_line =~ $regex_file ]]; then
|
||||||
|
zone_file=$(echo $_line | awk '{print$2}')
|
||||||
|
shopt -s extglob
|
||||||
|
if [[ $zone_file =~ \; ]]; then
|
||||||
|
zone_file=${zone_file%%*(\;)}
|
||||||
|
fi
|
||||||
|
if [[ $zone_file =~ ^\" ]]; then
|
||||||
|
zone_file=${zone_file##*(\")}
|
||||||
|
zone_file=${zone_file%%*(\")}
|
||||||
|
fi
|
||||||
|
shopt -u extglob
|
||||||
fi
|
fi
|
||||||
done
|
if [[ $_line =~ $regex_master ]]; then
|
||||||
fi
|
_is_master=true
|
||||||
|
fi
|
||||||
|
if [[ "$_line" =~ ^[[:space:]]*\}[[:space:]]*\; ]]; then
|
||||||
|
if $_is_master && [[ -n "$zone_file" ]]; then
|
||||||
|
|
||||||
|
|
||||||
|
if $_set_ipv4 ; then
|
||||||
|
|
||||||
|
for _ipv4_address in "${ipv4_addresses_arr[@]}" ; do
|
||||||
|
if $(grep -q -E "IN\s+A\s+$_ipv4_address" "$zone_file") ; then
|
||||||
|
if [ ${#zonefiles_arr[@]} -eq 0 ] ; then
|
||||||
|
zonefiles_arr+=("$zone_file")
|
||||||
|
else
|
||||||
|
if ! containsElement "$zone_file" "${zonefiles_arr[@]}" ; then
|
||||||
|
zonefiles_arr+=("$zone_file")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $_set_ipv6 ; then
|
||||||
|
|
||||||
|
for _ipv6_address in "${ipv6_addresses_arr[@]}" ; do
|
||||||
|
if $(grep -q -E "IN\s+AAAA\s+$_ipv6_address" "$zone_file") > /dev/null 2>&1 ; then
|
||||||
|
if [ ${#zonefiles_arr[@]} -eq 0 ] ; then
|
||||||
|
zonefiles_arr+=("$zone_file")
|
||||||
|
else
|
||||||
|
if ! containsElement "$zone_file" "${zonefiles_arr[@]}" ; then
|
||||||
|
zonefiles_arr+=("$zone_file")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
_is_master=false
|
||||||
|
_found=false
|
||||||
|
zone_file=""
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done < "$ZONES_DECLARATION_FILE"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
|
||||||
#for _val in "${zonefiles_arr[@]}" ; do
|
#for _val in "${zonefiles_arr[@]}" ; do
|
||||||
# echo
|
# echo
|
||||||
# echo -e "$_val"
|
# echo -e "$_val"
|
||||||
#done
|
#done
|
||||||
#
|
#
|
||||||
#exit
|
#clean_up 0
|
||||||
|
|
||||||
|
|
||||||
for zone_file in ${zonefiles_arr[@]} ; do
|
for zone_file in ${zonefiles_arr[@]} ; do
|
||||||
|
|
||||||
echo -e "\n\tconverting $zone_file .."
|
echo -e "\n\tEditing \033[37m\033[1m$zone_file\033[m .."
|
||||||
|
|
||||||
_replaced=false
|
_replaced=false
|
||||||
|
|
||||||
@ -395,7 +636,7 @@ for zone_file in ${zonefiles_arr[@]} ; do
|
|||||||
if $_set_ipv4 ; then
|
if $_set_ipv4 ; then
|
||||||
|
|
||||||
for _ipv4_address in "${ipv4_addresses_arr[@]}" ; do
|
for _ipv4_address in "${ipv4_addresses_arr[@]}" ; do
|
||||||
if grep -e "IN\s*A\s*$_ipv4_address" $zone_file > /dev/null 2>&1 ; then
|
if $(grep -q -E "IN\s+A\s+$_ipv4_address" "$zone_file") ; then
|
||||||
|
|
||||||
## - setze neue ttl für ipv4 address
|
## - setze neue ttl für ipv4 address
|
||||||
## -
|
## -
|
||||||
@ -434,7 +675,7 @@ for zone_file in ${zonefiles_arr[@]} ; do
|
|||||||
if $_set_ipv6 ; then
|
if $_set_ipv6 ; then
|
||||||
|
|
||||||
for _ipv6_address in "${ipv6_addresses_arr[@]}" ; do
|
for _ipv6_address in "${ipv6_addresses_arr[@]}" ; do
|
||||||
if grep -e "IN\s*AAAA\s*$_ipv6_address" $zone_file > /dev/null 2>&1 ; then
|
if $(grep -q -E "IN\s+AAAA\s+$_ipv6_address" "$zone_file") > /dev/null 2>&1 ; then
|
||||||
|
|
||||||
## - setze neue ttl für ipv6 address
|
## - setze neue ttl für ipv6 address
|
||||||
## -
|
## -
|
||||||
@ -457,7 +698,7 @@ for zone_file in ${zonefiles_arr[@]} ; do
|
|||||||
fi
|
fi
|
||||||
if $_replaced && $IGNORE_ALT_HOSTNAMES ; then
|
if $_replaced && $IGNORE_ALT_HOSTNAMES ; then
|
||||||
echononl "\t Setting back hostnames containing \"-alt\".."
|
echononl "\t Setting back hostnames containing \"-alt\".."
|
||||||
perl -i -n -p -e "s#^(.+(-alt).*)\s+$TTL\s+IN\s+AAAA\s+$_ipv6_address#\1 IN A $_ipv6_address#" $zone_file > /dev/null 2>&1
|
perl -i -n -p -e "s#^(.+(-alt).*)\s+$TTL\s+IN\s+AAAA\s+$_ipv6_address#\1 IN AAAA $_ipv6_address#" $zone_file > /dev/null 2>&1
|
||||||
if [ "$?" = "0" ]; then
|
if [ "$?" = "0" ]; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
@ -488,5 +729,20 @@ for zone_file in ${zonefiles_arr[@]} ; do
|
|||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
echo
|
|
||||||
exit
|
if [[ -d "${ZONE_FILE_MASTER_DIR}.${backup_date}" ]] ; then
|
||||||
|
diff -Nur "${ZONE_FILE_MASTER_DIR}" "${ZONE_FILE_MASTER_DIR}.${backup_date}" > /dev/null 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
info "No zone file has changed.\n\t Removing previously created backup"
|
||||||
|
echononl "\tDelete '${ZONE_FILE_MASTER_DIR}.${backup_date}'.."
|
||||||
|
rm -rf "${ZONE_FILE_MASTER_DIR}.${backup_date}" > $log_file 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
clean_up 0
|
||||||
|
@ -1,20 +1,29 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
|
||||||
## --- Variables (default Values)
|
working_dir="$(dirname $(realpath $0))"
|
||||||
## ---
|
conf_file="${working_dir}/conf/bind.conf"
|
||||||
#_zone_file_dir=/etc/bind/master
|
|
||||||
_zone_file_dir=/root/tmp/master
|
log_file="$(mktemp)"
|
||||||
|
|
||||||
|
backup_date="$(date +%Y-%m-%d-%H%M)"
|
||||||
|
|
||||||
_serial_new=`date +%Y%m%d01`
|
_serial_new=`date +%Y%m%d01`
|
||||||
|
|
||||||
_zone_file_suffix=zone
|
|
||||||
## ---
|
|
||||||
## --- End: Variables (default Values)
|
|
||||||
|
|
||||||
|
#---------------------------------------
|
||||||
|
#-----------------------------
|
||||||
|
# Base Function(s)
|
||||||
|
#-----------------------------
|
||||||
|
#---------------------------------------
|
||||||
|
|
||||||
|
clean_up() {
|
||||||
|
|
||||||
|
# Perform program exit housekeeping
|
||||||
|
rm $log_file
|
||||||
|
exit $1
|
||||||
|
}
|
||||||
|
|
||||||
## --- some functions
|
|
||||||
## ---
|
|
||||||
echononl(){
|
echononl(){
|
||||||
echo X\\c > /tmp/shprompt$$
|
echo X\\c > /tmp/shprompt$$
|
||||||
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
|
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
|
||||||
@ -31,7 +40,7 @@ fatal(){
|
|||||||
echo ""
|
echo ""
|
||||||
echo -e "\t\033[31m\033[1mScript is canceled\033[m\033[m"
|
echo -e "\t\033[31m\033[1mScript is canceled\033[m\033[m"
|
||||||
echo ""
|
echo ""
|
||||||
exit 1
|
clean_up 1
|
||||||
}
|
}
|
||||||
|
|
||||||
warn (){
|
warn (){
|
||||||
@ -61,6 +70,9 @@ error(){
|
|||||||
echo_ok() {
|
echo_ok() {
|
||||||
echo -e "\033[75G[ \033[32mok\033[m ]"
|
echo -e "\033[75G[ \033[32mok\033[m ]"
|
||||||
}
|
}
|
||||||
|
echo_done() {
|
||||||
|
echo -e "\033[75G[ \033[32mdone\033[m ]"
|
||||||
|
}
|
||||||
echo_failed(){
|
echo_failed(){
|
||||||
echo -e "\033[75G[ \033[1;31mfailed\033[m ]"
|
echo -e "\033[75G[ \033[1;31mfailed\033[m ]"
|
||||||
}
|
}
|
||||||
@ -110,8 +122,71 @@ is_valid_ipv6() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## ---
|
trap clean_up SIGHUP SIGINT SIGTERM
|
||||||
## --- END: functions
|
|
||||||
|
|
||||||
|
|
||||||
|
#---------------------------------------
|
||||||
|
#-----------------------------
|
||||||
|
# Setting Defaults
|
||||||
|
#-----------------------------
|
||||||
|
#---------------------------------------
|
||||||
|
|
||||||
|
DEFAULT_CONF_FILE_DIR="/etc/bind"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---------------------------------------
|
||||||
|
#-----------------------------
|
||||||
|
# Load default values from bind.conf
|
||||||
|
#
|
||||||
|
# Overwrites the settings above
|
||||||
|
#
|
||||||
|
#-----------------------------
|
||||||
|
#---------------------------------------
|
||||||
|
|
||||||
|
#clear
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echononl " Loading default Configuration values from $(basename ${conf_file}).."
|
||||||
|
if [[ ! -f "$conf_file" ]]; then
|
||||||
|
echo_skipped
|
||||||
|
else
|
||||||
|
source "${conf_file}" > $log_file 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
fatal "$(cat $log_file)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -n "$CONF_FILE_DIR" ]] && DEFAULT_CONF_FILE_DIR="$CONF_FILE_DIR"
|
||||||
|
|
||||||
|
if [[ -n "$ZONE_FILE_MASTER_DIR" ]] ; then
|
||||||
|
DEFAULT_ZONE_FILE_MASTER_DIR="$ZONE_FILE_MASTER_DIR"
|
||||||
|
else
|
||||||
|
DEFAULT_ZONE_FILE_MASTER_DIR="${DEFAULT_CONF_FILE_DIR}/master"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$ZONE_FILE_SLAVE_DIR" ]] ; then
|
||||||
|
DEFAULT_ZONE_FILE_SLAVE_DIR="$ZONE_FILE_SLAVE_DIR"
|
||||||
|
else
|
||||||
|
DEFAULT_ZONE_FILE_SLAVE_DIR="${DEFAULT_CONF_FILE_DIR}/slave"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$ZONE_FILE_SUFFIX" ]] ; then
|
||||||
|
DEFAULT_ZONE_FILE_SUFFIX="$ZONE_FILE_SUFFIX"
|
||||||
|
else
|
||||||
|
DEFAULT_ZONE_FILE_SUFFIX='zone'
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$ZONES_DECLARATION_FILE" ]] ; then
|
||||||
|
DEFAULT_ZONES_DECLARATION_FILE="$ZONES_DECLARATION_FILE"
|
||||||
|
else
|
||||||
|
DEFAULT_ZONES_DECLARATION_FILE="${CONF_FILE_DIR}/named.conf.local"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\033[32m--\033[m"
|
echo -e "\033[32m--\033[m"
|
||||||
@ -178,44 +253,90 @@ while [ "X$IPv6_ADDRESS" = "X" ]; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if ! $_set_ipv6 && ! $_set_ipv4 ; then
|
||||||
|
fatal "No IP-Adresses given for changing their TTL to the zone-file default.."
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[32m--\033[m"
|
||||||
|
echo "Common parameters"
|
||||||
|
echo -e "\033[32m--\033[m"
|
||||||
|
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Insert directory containing the bind configuration files."
|
||||||
|
echo ""
|
||||||
|
CONF_FILE_DIR=""
|
||||||
|
if [[ -n "$DEFAULT_CONF_FILE_DIR" ]] ; then
|
||||||
|
echononl "Bind Configuration Directory [${DEFAULT_CONF_FILE_DIR}]: "
|
||||||
|
read CONF_FILE_DIR
|
||||||
|
if [[ "X$CONF_FILE_DIR" = "X" ]]; then
|
||||||
|
CONF_FILE_DIR="$DEFAULT_CONF_FILE_DIR"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echononl "Bind Configuration Directory: "
|
||||||
|
read CONF_FILE_DIR
|
||||||
|
while [ "X$CONF_FILE_DIR" = "X" ] ; do
|
||||||
|
echo -e "\n\t\033[33m\033[1mSetting 'Bind Configuration Directory' is required!\033[m\n"
|
||||||
|
echononl "Bind Configuration Directory: "
|
||||||
|
read CONF_FILE_DIR
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -n "$ZONES_DECLARATION_FILE" ]] || DEFAULT_ZONES_DECLARATION_FILE="${CONF_FILE_DIR}/named.conf.local"
|
||||||
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\033[32m--\033[m"
|
echo -e "\033[32m--\033[m"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Insert zones declaration file."
|
||||||
|
echo ""
|
||||||
|
ZONES_DECLARATION_FILE=""
|
||||||
|
if [[ -n "$DEFAULT_ZONES_DECLARATION_FILE" ]] ; then
|
||||||
|
echononl "Zones Declaration File [${DEFAULT_ZONES_DECLARATION_FILE}]: "
|
||||||
|
read ZONES_DECLARATION_FILE
|
||||||
|
if [[ "X$ZONES_DECLARATION_FILE" = "X" ]]; then
|
||||||
|
ZONES_DECLARATION_FILE="$DEFAULT_ZONES_DECLARATION_FILE"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echononl "Zones Declaration File: "
|
||||||
|
read ZONES_DECLARATION_FILE
|
||||||
|
while [ "X$ZONES_DECLARATION_FILE" = "X" ] ; do
|
||||||
|
echo -e "\n\t\033[33m\033[1mSetting 'Zones Declaration File' is required!\033[m\n"
|
||||||
|
echononl "Zones Declaration File: "
|
||||||
|
read ZONES_DECLARATION_FILE
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[32m--\033[m"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Insert the directory, where your zone-files resides."
|
echo "Insert the directory, where your zone-files resides."
|
||||||
echo ""
|
echo ""
|
||||||
echo ""
|
echo ""
|
||||||
ZONE_FILE_DIR=
|
ZONE_FILE_MASTER_DIR=""
|
||||||
while [ "X$ZONE_FILE_DIR" = "X" ]; do
|
if [[ -n "$DEFAULT_ZONE_FILE_MASTER_DIR" ]] ; then
|
||||||
echononl "Zone File Directory [$_zone_file_dir]: "
|
echononl "Zone File Directory (master) [${DEFAULT_ZONE_FILE_MASTER_DIR}]: "
|
||||||
read ZONE_FILE_DIR
|
read ZONE_FILE_MASTER_DIR
|
||||||
if [ "X$ZONE_FILE_DIR" = "X" ]; then
|
if [[ "X$ZONE_FILE_MASTER_DIR" = "X" ]]; then
|
||||||
ZONE_FILE_DIR=$_zone_file_dir
|
ZONE_FILE_MASTER_DIR="$DEFAULT_ZONE_FILE_MASTER_DIR"
|
||||||
fi
|
fi
|
||||||
if [ ! -d $ZONE_FILE_DIR ]; then
|
else
|
||||||
echo -e "\n\tDirectory \033[33m\033[1m$ZONE_FILE_DIR\033[m does NOT exist!\n"
|
echononl "Zone File Directory (master): "
|
||||||
ZONE_FILE_DIR=
|
read ZONE_FILE_MASTER_DIR
|
||||||
fi
|
while [ "X$ZONE_FILE_MASTER_DIR" = "X" ] ; do
|
||||||
done
|
echo -e "\n\t\033[33m\033[1mSetting 'Zone File Directory (master)' is required!\033[m\n"
|
||||||
|
echononl "Zone File Directory (master): "
|
||||||
echo ""
|
read ZONE_FILE_MASTER_DIR
|
||||||
echo -e "\033[32m--\033[m"
|
done
|
||||||
echo ""
|
|
||||||
echo "Insert the file-suffix of thr zone-files"
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
ZONE_FILE_SUFFIX=
|
|
||||||
echononl "Suffix of Zone Files [$_zone_file_suffix]: "
|
|
||||||
read ZONE_FILE_SUFFIX
|
|
||||||
if [ "X$ZONE_FILE_SUFFIX" = "X" ]; then
|
|
||||||
ZONE_FILE_SUFFIX=$_zone_file_suffix
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if ! $_set_ipv6 && ! $_set_ipv4 ; then
|
|
||||||
fatal "No IP-Adresses given for changing their TTL to the zone-file default.."
|
|
||||||
fi
|
|
||||||
|
|
||||||
clear
|
clear
|
||||||
echo ""
|
echo ""
|
||||||
echo ""
|
echo ""
|
||||||
@ -236,8 +357,10 @@ fi
|
|||||||
echo ""
|
echo ""
|
||||||
echo "New TTL...........................: Zonefile default"
|
echo "New TTL...........................: Zonefile default"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Zone File Directory...............: $ZONE_FILE_DIR"
|
echo "Bind Configuration Directory......: $CONF_FILE_DIR"
|
||||||
echo "Zone File Suffix..................: $ZONE_FILE_SUFFIX"
|
echo "Zones Declaration File............: $ZONES_DECLARATION_FILE"
|
||||||
|
echo "Zone File Directory...............: $ZONE_FILE_MASTER_DIR"
|
||||||
|
#echo "Zone File Suffix..................: $ZONE_FILE_SUFFIX"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
OK=
|
OK=
|
||||||
@ -262,57 +385,114 @@ done
|
|||||||
[[ $OK = "yes" ]] || fatal Repeat execution with different parameters
|
[[ $OK = "yes" ]] || fatal Repeat execution with different parameters
|
||||||
|
|
||||||
|
|
||||||
cp -a $ZONE_FILE_DIR ${ZONE_FILE_DIR}.BAK-`date +%Y-%m-%d-%H%M`
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echononl "\tBackup directory '${ZONE_FILE_MASTER_DIR}'.."
|
||||||
|
cp -a "${ZONE_FILE_MASTER_DIR}" "${ZONE_FILE_MASTER_DIR}.${backup_date}" > $log_file 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
fatal "$(cat $log_file)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echononl "\tCreate array of given IPv4 addresses"
|
||||||
ipv4_addresses_arr=()
|
ipv4_addresses_arr=()
|
||||||
for _ipv4_address in $IPv4_ADDRESS ; do
|
for _ipv4_address in $IPv4_ADDRESS ; do
|
||||||
containsElement "$_ipv4_address" "${ipv4_addresses_arr[@]}" && continue
|
containsElement "$_ipv4_address" "${ipv4_addresses_arr[@]}" && continue
|
||||||
ipv4_addresses_arr+=("$_ipv4_address")
|
ipv4_addresses_arr+=("$_ipv4_address")
|
||||||
done
|
done
|
||||||
|
echo_done
|
||||||
|
|
||||||
|
echononl "\tCreate array of given IPv6 addresses"
|
||||||
ipv6_addresses_arr=()
|
ipv6_addresses_arr=()
|
||||||
for _ipv6_address in $IPv6_ADDRESS ; do
|
for _ipv6_address in $IPv6_ADDRESS ; do
|
||||||
containsElement "$_ipv6_address" "${ipv6_addresses_arr[@]}" && continue
|
containsElement "$_ipv6_address" "${ipv6_addresses_arr[@]}" && continue
|
||||||
ipv6_addresses_arr+=("$_ipv6_address")
|
ipv6_addresses_arr+=("$_ipv6_address")
|
||||||
done
|
done
|
||||||
|
echo_done
|
||||||
|
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[37m\033[1mDetermine zone files conatining ip-adressse for which TTL time is requested to change..\033[m"
|
||||||
|
|
||||||
|
_found=false
|
||||||
|
_is_master=false
|
||||||
zonefiles_arr=()
|
zonefiles_arr=()
|
||||||
if $_set_ipv4 ; then
|
zone_file=""
|
||||||
for _ipv4_address in "${ipv4_addresses_arr[@]}" ; do
|
regex_master="type[[:space:]]+master"
|
||||||
_zone_files_ipv4=`grep -l -e "$_ipv4_address" ${ZONE_FILE_DIR}/*.$ZONE_FILE_SUFFIX`
|
regex_file="^[[:space:]]*file"
|
||||||
if [ ${#zonefiles_arr[@]} -eq 0 ] ; then
|
while IFS='' read -r _line || [[ -n $_line ]] ; do
|
||||||
for _zone_file in "$_zone_files_ipv4" ; do
|
|
||||||
zonefiles_arr+=("$_zone_file")
|
|
||||||
done
|
|
||||||
else
|
|
||||||
for _zone_file in "$_zone_files_ipv4" ; do
|
|
||||||
containsElement "$_zone_file" "${zonefiles_arr[@]}" && continue
|
|
||||||
zonefiles_arr+=("$_zone_file")
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if $_set_ipv6 ; then
|
if [[ $_line =~ ^[[:space:]]*zone[[:space:]]+ ]]; then
|
||||||
for _ipv6_address in "${ipv6_addresses_arr[@]}" ; do
|
_found=true
|
||||||
_zone_files_ipv6=`grep -l -e "$_ipv6_address" ${ZONE_FILE_DIR}/*.$ZONE_FILE_SUFFIX`
|
fi
|
||||||
if [ ${#zonefiles_arr[@]} -eq 0 ] ; then
|
if $_found ; then
|
||||||
for _zone_file in "$_zone_files_ipv6" ; do
|
if [[ $_line =~ $regex_file ]]; then
|
||||||
zonefiles_arr+=("$_zone_file")
|
zone_file=$(echo $_line | awk '{print$2}')
|
||||||
done
|
shopt -s extglob
|
||||||
else
|
if [[ $zone_file =~ \; ]]; then
|
||||||
for _zone_file in "$_zone_files_ipv6" ; do
|
zone_file=${zone_file%%*(\;)}
|
||||||
containsElement "$_zone_file" "${zonefiles_arr[@]}" && continue
|
fi
|
||||||
zonefiles_arr+=("$_zone_file")
|
if [[ $zone_file =~ ^\" ]]; then
|
||||||
done
|
zone_file=${zone_file##*(\")}
|
||||||
|
zone_file=${zone_file%%*(\")}
|
||||||
|
fi
|
||||||
|
shopt -u extglob
|
||||||
fi
|
fi
|
||||||
done
|
if [[ $_line =~ $regex_master ]]; then
|
||||||
fi
|
_is_master=true
|
||||||
|
fi
|
||||||
|
if [[ "$_line" =~ ^[[:space:]]*\}[[:space:]]*\; ]]; then
|
||||||
|
if $_is_master && [[ -n "$zone_file" ]]; then
|
||||||
|
|
||||||
|
|
||||||
|
if $_set_ipv4 ; then
|
||||||
|
|
||||||
|
for _ipv4_address in "${ipv4_addresses_arr[@]}" ; do
|
||||||
|
if $(grep -q -E "IN\s+A\s+$_ipv4_address" "$zone_file") ; then
|
||||||
|
if [ ${#zonefiles_arr[@]} -eq 0 ] ; then
|
||||||
|
zonefiles_arr+=("$zone_file")
|
||||||
|
else
|
||||||
|
if ! containsElement "$zone_file" "${zonefiles_arr[@]}" ; then
|
||||||
|
zonefiles_arr+=("$zone_file")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $_set_ipv6 ; then
|
||||||
|
|
||||||
|
for _ipv6_address in "${ipv6_addresses_arr[@]}" ; do
|
||||||
|
if $(grep -q -E "IN\s+AAAA\s+$_ipv6_address" "$zone_file") > /dev/null 2>&1 ; then
|
||||||
|
if [ ${#zonefiles_arr[@]} -eq 0 ] ; then
|
||||||
|
zonefiles_arr+=("$zone_file")
|
||||||
|
else
|
||||||
|
if ! containsElement "$zone_file" "${zonefiles_arr[@]}" ; then
|
||||||
|
zonefiles_arr+=("$zone_file")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
_is_master=false
|
||||||
|
_found=false
|
||||||
|
zone_file=""
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done < "$ZONES_DECLARATION_FILE"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
|
||||||
for zone_file in ${zonefiles_arr[@]} ; do
|
for zone_file in ${zonefiles_arr[@]} ; do
|
||||||
|
|
||||||
echo -e "\n\tconverting $zone_file .."
|
echo -e "\n\tEditing \033[37m\033[1m$zone_file\033[m .."
|
||||||
|
|
||||||
_replaced=false
|
_replaced=false
|
||||||
|
|
||||||
@ -326,14 +506,14 @@ for zone_file in ${zonefiles_arr[@]} ; do
|
|||||||
if $_set_ipv4 ; then
|
if $_set_ipv4 ; then
|
||||||
|
|
||||||
for _ipv4_address in "${ipv4_addresses_arr[@]}" ; do
|
for _ipv4_address in "${ipv4_addresses_arr[@]}" ; do
|
||||||
if grep -e "IN\s*A\s*$_ipv4_address" $zone_file > /dev/null 2>&1 ; then
|
if $(grep -q -E "IN\s+A\s+$_ipv4_address" "$zone_file") ; then
|
||||||
|
|
||||||
## - setze neue ttl für ipv4 address
|
## - setze neue ttl für ipv4 address
|
||||||
## -
|
## -
|
||||||
echononl "\t Set TTL to the zonfile default for IPv4 address $_ipv4_address .."
|
echononl "\t Set TTL to the zonfile default for IPv4 address $_ipv4_address .."
|
||||||
|
|
||||||
if grep -e "\s*[0-9][0-9]\s*IN\s*A\s*$_ipv4_address" $zone_file > /dev/null 2>&1 ; then
|
if grep -e "\s*[0-9][0-9]\s*IN\s*A\s*$_ipv4_address" $zone_file > /dev/null 2>&1 ; then
|
||||||
perl -i -n -p -e "s/^(.+\s+)[0-9]{2,}(\s+IN\s+A\s+$_ipv4_address)/\1\2/" $zone_file
|
perl -i -n -p -e "s/^(.+\s+)[0-9]{2,}\s+(IN\s+A\s+$_ipv4_address)/\1\2/" $zone_file
|
||||||
if [ "$?" = "0" ]; then
|
if [ "$?" = "0" ]; then
|
||||||
echo_ok
|
echo_ok
|
||||||
_replaced=true
|
_replaced=true
|
||||||
@ -352,14 +532,14 @@ for zone_file in ${zonefiles_arr[@]} ; do
|
|||||||
if $_set_ipv6 ; then
|
if $_set_ipv6 ; then
|
||||||
|
|
||||||
for _ipv6_address in "${ipv6_addresses_arr[@]}" ; do
|
for _ipv6_address in "${ipv6_addresses_arr[@]}" ; do
|
||||||
if grep -e "IN\s*AAAA\s*$_ipv6_address" $zone_file > /dev/null 2>&1 ; then
|
if $(grep -q -E "IN\s+AAAA\s+$_ipv6_address" "$zone_file") > /dev/null 2>&1 ; then
|
||||||
|
|
||||||
## - setze neue ttl für ipv6 address
|
## - setze neue ttl für ipv6 address
|
||||||
## -
|
## -
|
||||||
echononl "\t Set TTL to the zonfile default for IPv6 address $_ipv6_address .."
|
echononl "\t Set TTL to the zonfile default for IPv6 address $_ipv6_address .."
|
||||||
|
|
||||||
if grep -e "\s*[0-9][0-9]\s*IN\s*AAAA\s*$_ipv6_address" $zone_file > /dev/null 2>&1 ; then
|
if grep -e "\s*[0-9][0-9]\s*IN\s*AAAA\s*$_ipv6_address" $zone_file > /dev/null 2>&1 ; then
|
||||||
perl -i -n -p -e "s/^(.+\s+)[0-9]{2,}(\s+IN\s+AAAA\s+$_ipv6_address)/\1\2/" $zone_file
|
perl -i -n -p -e "s/^(.+\s+)[0-9]{2,}\s+(IN\s+AAAA\s+$_ipv6_address)/\1\2/" $zone_file
|
||||||
if [ "$?" = "0" ]; then
|
if [ "$?" = "0" ]; then
|
||||||
echo_ok
|
echo_ok
|
||||||
_replaced=true
|
_replaced=true
|
||||||
@ -393,5 +573,20 @@ for zone_file in ${zonefiles_arr[@]} ; do
|
|||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
echo
|
|
||||||
exit
|
if [[ -d "${ZONE_FILE_MASTER_DIR}.${backup_date}" ]] ; then
|
||||||
|
diff -Nur "${ZONE_FILE_MASTER_DIR}" "${ZONE_FILE_MASTER_DIR}.${backup_date}" > /dev/null 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
info "No zone file has changed.\n\t Removing previously created backup"
|
||||||
|
echononl "\tDelete '${ZONE_FILE_MASTER_DIR}.${backup_date}'.."
|
||||||
|
rm -rf "${ZONE_FILE_MASTER_DIR}.${backup_date}" > $log_file 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
clean_up 0
|
||||||
|
Loading…
Reference in New Issue
Block a user