81 lines
2.3 KiB
Bash
Executable File
81 lines
2.3 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
DomainZone="50.10.in-addr.arpa."
|
|
ForwardZoneFiles="/srv/fff-dns/db.fff.community"
|
|
ReverseZoneFile="/var/lib/bind/db.50.10"
|
|
#Temporäres Verzeichnis - muss pro Zone exclusiv sein!
|
|
TempDir="/tmp/50.10.in-addr.arpa"
|
|
TTL=3600
|
|
refresh=2000
|
|
retry=6400
|
|
expire=2419200
|
|
minimum=86400
|
|
ContactEMail=franken.freifunk.net.
|
|
ReverseServerName=aquarius.gw.fff.community.
|
|
|
|
#################################################################
|
|
|
|
function GetZoneFileSerial() {
|
|
local FirstSOALineAndFollowing="^/\S\+\s\+IN\s\+SOA\s/,\$!d;"
|
|
local RemoveComments=":a;s/;.*$//g;"
|
|
local RemoveLineBreaks=":a;N;\$!ba;s/\n//g;"
|
|
local SearchPrintSerial="s/^\S\+\s\+IN\s\+SOA\s\+\S\+\s\+\S\+\s\+(\?\s\+\([0-9]*\).*/\1/"
|
|
|
|
local Serial=$(sed -e "$FirstSOALineAndFollowing""$RemoveComments""$RemoveLineBreaks""$SearchPrintSerial" "$1")
|
|
echo "$Serial"
|
|
}
|
|
|
|
function DNSReload {
|
|
if [[ -n "$Usernc" ]]; then
|
|
rndc reload "$DomainZone" IN "icvpn-internal-view"
|
|
else
|
|
systemctl reload bind9
|
|
fi
|
|
}
|
|
|
|
function ValidateIPv4() {
|
|
[[ -n "$(echo "$1" | sed -e '/^\(\(25[0-5]\|\(2[0-4]\|1[0-9]\|[1-9]\)\?[0-9]\)\.\)\{0,3\}\(25[0-5]\|\(2[0-4]\|1[0-9]\|[1-9]\)\?[0-9]\)$/!d')" ]]
|
|
return $?
|
|
}
|
|
|
|
|
|
mkdir -p $TempDir
|
|
|
|
for ForwardZoneFile in $ForwardZoneFiles
|
|
do
|
|
ZoneName="$DomainZone" #$(sed -ne 's/\(\S\+\)\s\+IN\s\+SOA\s\+\S\+.*/\1/p' "$ForwardZoneFile")
|
|
named-checkzone -o "$TempDir/$ZoneName" -D $ZoneName $ForwardZoneFile >/dev/null 2>&1
|
|
Serial=$(GetZoneFileSerial "$TempDir/$ZoneName")
|
|
NewSerial=$((Serial+NewSerial))
|
|
done
|
|
|
|
echo "$DomainZone $TTL IN SOA $ReverseServerName $ContactEMail $Serial $refresh $retry $expire $minimum" > "$TempDir/$DomainZone"
|
|
echo "$DomainZone $TTL IN NS $ReverseServerName" >> "$TempDir/$DomainZone"
|
|
for ForwardZoneFile in $(ls $TempDir)
|
|
do
|
|
Hosts=($(cat "$TempDir/$ForwardZoneFile" | grep -v SOA | awk '{ print $1 }'))
|
|
IPs=$(cat "$TempDir/$ForwardZoneFile" | grep -v SOA | awk '{ print $5 }')
|
|
i=0
|
|
for IP in $IPs
|
|
do
|
|
if ValidateIPv4 $IP
|
|
then
|
|
echo $(echo $IP | awk 'BEGIN { FS = "." } ; { print $4 "." $3 "." $2 "." $1 }')".in-addr.arpa." $TTL IN PTR ${Hosts[$i]} >> "$TempDir/$DomainZone"
|
|
fi
|
|
i=$((i+1))
|
|
done
|
|
done
|
|
|
|
if [[ -f $ReverseZoneFile ]]; then
|
|
OldSerial="$(GetZoneFileSerial '$ReverseZoneFile')"
|
|
else
|
|
OldSerial=0
|
|
fi
|
|
|
|
if [[ $Serial -gt $OldSerial ]]
|
|
then
|
|
named-compilezone -o $ReverseZoneFile $DomainZone "$TempDir/$DomainZone" >/dev/null 2>&1
|
|
DNSReload
|
|
fi
|
|
rm -r $TempDir
|