Unter OpenWRT kein =~; IP-Adressvalidierung korrigiert; Optionale Nutzung von rndc -> Vorteil: nur eine Zone wird neu geladen; Refaktoring
This commit is contained in:
parent
bc38442387
commit
038acaa2eb
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
DomainZone="50.10.in-addr.arpa."
|
DomainZone="50.10.in-addr.arpa."
|
||||||
ForwardZoneFiles=("/srv/fff-dns/db.fff.community")
|
ForwardZoneFiles=("/srv/fff-dns/db.fff.community")
|
||||||
|
@ -15,24 +15,27 @@ ReverseServerName=aquarius.gw.fff.community.
|
||||||
|
|
||||||
#################################################################
|
#################################################################
|
||||||
|
|
||||||
function dnsreload {
|
function GetZoneFileSerial() {
|
||||||
systemctl reload bind9
|
local FirstSOALineAndFollowing="/\S\+\s\+IN\s\+SOA\s/,\$!d;"
|
||||||
|
local RemoveComments=":a;s/;.*$//g;"
|
||||||
|
local EleminateLineBreaks=":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""$EleminateLineBreaks""$SearchPrintSerial" "$1")
|
||||||
|
echo "$serial"
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate_ip() {
|
function dnsreload {
|
||||||
local ip=$1
|
if [[ -n "$Usernc" ]]; then
|
||||||
local stat=1
|
rndc reload "$DomainZone" IN "icvpn-internal-view"
|
||||||
|
else
|
||||||
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
systemctl reload bind9
|
||||||
OIFS=$IFS
|
|
||||||
IFS='.'
|
|
||||||
ip=($ip)
|
|
||||||
IFS=$OIFS
|
|
||||||
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
|
|
||||||
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
|
|
||||||
stat=$?
|
|
||||||
fi
|
fi
|
||||||
return $stat
|
}
|
||||||
|
|
||||||
|
function validate_ipv4() {
|
||||||
|
[[ -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 $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,7 +45,7 @@ for ForwardZoneFile in "${ForwardZoneFiles[@]}"
|
||||||
do
|
do
|
||||||
ZoneName=$(sed -ne 's/\(\S\+\)\s\+IN\s\+SOA\s\+\S\+.*/\1/p' "$ForwardZoneFile")
|
ZoneName=$(sed -ne 's/\(\S\+\)\s\+IN\s\+SOA\s\+\S\+.*/\1/p' "$ForwardZoneFile")
|
||||||
named-compilezone -o "$TempDir/$ZoneName" $ZoneName $ForwardZoneFile >/dev/null 2>&1
|
named-compilezone -o "$TempDir/$ZoneName" $ZoneName $ForwardZoneFile >/dev/null 2>&1
|
||||||
serial=$(sed -e '/\S\+\s\+IN\s\+SOA\s/,$!d;:a;s/;.*$//g;:a;N;$!ba;s/\n//g;s/\S\+\s\+IN\s\+SOA\s\+\S\+\s\+\S\+\s\+(\?\s\+\([0-9]*\).*/\1/' "$TempDir/$ZoneName" )
|
serial="$(GetZoneFileSerial '$TempDir/$ZoneName')"
|
||||||
Serials+=( "$serial" )
|
Serials+=( "$serial" )
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -58,7 +61,7 @@ do
|
||||||
i=0
|
i=0
|
||||||
for IP in $IPs
|
for IP in $IPs
|
||||||
do
|
do
|
||||||
if validate_ip $IP
|
if validate_ipv4 $IP
|
||||||
then
|
then
|
||||||
echo $(echo $IP | awk 'BEGIN { FS = "." } ; { print $4 "." $3 "." $2 "." $1 }')".in-addr.arpa." $TTL IN PTR ${Hosts[$i]} >> "$TempDir/$DomainZone"
|
echo $(echo $IP | awk 'BEGIN { FS = "." } ; { print $4 "." $3 "." $2 "." $1 }')".in-addr.arpa." $TTL IN PTR ${Hosts[$i]} >> "$TempDir/$DomainZone"
|
||||||
fi
|
fi
|
||||||
|
@ -66,13 +69,13 @@ do
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -f $ReverseZoneFile ]; then
|
if [[ -f $ReverseZoneFile ]]; then
|
||||||
oldSerial=$(grep SOA $ReverseZoneFile | awk 'NR==1{print $7}')
|
oldSerial="$(GetZoneFileSerial '$ReverseZoneFile')"
|
||||||
else
|
else
|
||||||
oldSerial=0
|
oldSerial=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $serial -gt $oldSerial ]
|
if [[ $serial -gt $oldSerial ]]
|
||||||
then
|
then
|
||||||
named-compilezone -o $ReverseZoneFile $DomainZone "$TempDir/$DomainZone" >/dev/null 2>&1
|
named-compilezone -o $ReverseZoneFile $DomainZone "$TempDir/$DomainZone" >/dev/null 2>&1
|
||||||
dnsreload
|
dnsreload
|
||||||
|
|
Loading…
Reference in New Issue