- Add script 'bind_get_zonefile_by_hostname.sh'.
- bind_get_domain_by_hostname.sh: some minor changes and bug fixes.
This commit is contained in:
@@ -28,12 +28,28 @@ usage() {
|
||||
|
||||
Usage: $(basename $0) [Options] <full-qualified-hostname>
|
||||
|
||||
Script checks if a given hostname is supported by this nameserver. Hostname can
|
||||
alos be a TLD name.
|
||||
Script checks if a given hostname is supported by this nameserver. The concerning
|
||||
zone will be printed out.
|
||||
|
||||
As result the Script returns the zone (domain) of the given hostname." In silent
|
||||
mode (-q), script returns an empty String, if the given hostname is not
|
||||
supported by this nameserver.
|
||||
If running in a terminal and not in silent mode (-q), the output is clearly
|
||||
arranged in a human readable way.
|
||||
|
||||
If not running in a terminal or silent mode (-q) is set, only the name of the
|
||||
zonefile will be printed out or an empty string, if the given hostname is
|
||||
not supported by this nameservice.
|
||||
|
||||
Parameter "check" can be used, to test whether this script is accessable (e.g. from a
|
||||
further script on a remote host). Nothing will be done, scripts returns '0'.
|
||||
|
||||
Return (Exit) Codes:
|
||||
success:
|
||||
0: hostname is supported
|
||||
error:
|
||||
10: Invalid hostname/domain given
|
||||
11: the given hostname is not supported by this nameserver
|
||||
12: given hostname is supported, but this nameserver is not the master of
|
||||
the concerning zone
|
||||
99: Fatal error
|
||||
|
||||
Options:
|
||||
|
||||
@@ -106,6 +122,10 @@ echo_skipped() {
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
trap clean_up SIGHUP SIGINT SIGTERM
|
||||
|
||||
|
||||
# - Test whether stdout (file descriptor 1) is a terminal or not (e.g. cron
|
||||
# - or if you pipe the output to some other program)
|
||||
#
|
||||
@@ -132,10 +152,18 @@ if [[ $# -ne 1 ]] ; then
|
||||
if $verbose ; then
|
||||
usage "wrong number of arguments"
|
||||
else
|
||||
clean_up 10
|
||||
clean_up 99
|
||||
fi
|
||||
fi
|
||||
|
||||
# - Parameter "check" can be used, to test whether this script
|
||||
# - is accessable (e.g. from a script on a remote host)
|
||||
# -
|
||||
if [[ "$1" = "check" ]]; then
|
||||
info "Script \033[1m$(basename $0)\033[m was successfully invoked, but its only a test."
|
||||
clean_up 0
|
||||
fi
|
||||
|
||||
hostname=$1
|
||||
|
||||
|
||||
@@ -143,7 +171,7 @@ $verbose && echo ""
|
||||
|
||||
if [[ -z "$hostname" ]] ; then
|
||||
error "No hostname/domain given!"
|
||||
clean_up 10
|
||||
clean_up 99
|
||||
fi
|
||||
|
||||
|
||||
@@ -187,7 +215,6 @@ fi
|
||||
$verbose && echo ""
|
||||
|
||||
|
||||
|
||||
# - Validate Syntax of given domain
|
||||
# -
|
||||
valid_domain_regex="^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$"
|
||||
@@ -206,28 +233,61 @@ else
|
||||
clean_up 10
|
||||
fi
|
||||
|
||||
|
||||
# - Is hostname supported by this nameserver?
|
||||
# -
|
||||
_failed=false
|
||||
_hostname=$(echo ${hostname//\./\\.})
|
||||
while ! grep -E "^\s*zone\s+\"?$_hostname" $ZONES_DECLARATION_FILE > /dev/null 2>&1 ; do
|
||||
hostname=${hostname#*.}
|
||||
_hostname=$(echo ${hostname//\./\\.})
|
||||
if [[ ! $_hostname =~ \. ]]; then
|
||||
zone=$hostname
|
||||
_zone=$(echo ${zone//\./\\.})
|
||||
while ! grep -E "^\s*zone\s+\"?$_zone" $ZONES_DECLARATION_FILE > /dev/null 2>&1 ; do
|
||||
zone=${zone#*.}
|
||||
_zone=$(echo ${zone//\./\\.})
|
||||
if [[ ! $_zone =~ \. ]]; then
|
||||
_failed=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if $_failed ; then
|
||||
$verbose && error "hostname \"$1\" not supported by this nameserver!"
|
||||
else
|
||||
domain=$hostname
|
||||
if $verbose ; then
|
||||
info "Hosted Zone: \033[1m${domain}\033[m"
|
||||
else
|
||||
echo "$domain"
|
||||
fi
|
||||
$verbose && error "hostname \"$hostname\" not supported by this nameserver!"
|
||||
clean_up 11
|
||||
fi
|
||||
|
||||
$verbose && echo
|
||||
# - Is this nameserver also the master?
|
||||
# -
|
||||
_found=false
|
||||
_found_zonefile=false
|
||||
_is_master=false
|
||||
zone_file=""
|
||||
regex_zone="^[[:space:]]*zone[[:space:]]+\"?$(echo ${zone//\./\\.})\""
|
||||
regex_file="^[[:space:]]*file"
|
||||
regex_master="type[[:space:]]+master"
|
||||
while IFS='' read -r line || [[ -n "$line" ]] ; do
|
||||
if [[ $line =~ $regex_zone ]]; then
|
||||
_found=true
|
||||
fi
|
||||
if $_found ; then
|
||||
if [[ $line =~ $regex_master ]]; then
|
||||
_is_master=true
|
||||
fi
|
||||
if [[ "$line" =~ ^[[:space:]]*\}[[:space:]]*\; ]]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done < $ZONES_DECLARATION_FILE
|
||||
|
||||
|
||||
if $_is_master ; then
|
||||
if $verbose ; then
|
||||
info "Hosted Zone: \033[1m${zone}\033[m"
|
||||
else
|
||||
echo "$zone"
|
||||
fi
|
||||
else
|
||||
$verbose && error "hostname \"$hostname\" is supported but this nameserver is not the master!"
|
||||
clean_up 12
|
||||
fi
|
||||
|
||||
$verbose && echo ""
|
||||
clean_up 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user