2019-09-04 18:15:10 +02:00
|
|
|
#!/bin/sh
|
2021-07-08 00:39:48 +02:00
|
|
|
# SPDX-License-Identifier: GPL-3.0
|
|
|
|
#
|
|
|
|
# freifunk-franken dns-scipts (c) 2016 mayosemmel
|
|
|
|
# (c) 2020-2021 Fabian Bläse
|
2023-02-13 01:11:31 +01:00
|
|
|
# (c) 2021-2023 Blackyfff
|
2019-09-04 18:15:10 +02:00
|
|
|
|
|
|
|
# exit script when command fails
|
|
|
|
set -e
|
|
|
|
|
2023-02-13 01:11:31 +01:00
|
|
|
export DNSSCRIPT_VERSION="0.9.5"
|
2021-07-26 19:23:34 +02:00
|
|
|
|
2021-07-10 01:13:29 +02:00
|
|
|
. /etc/ffdns/community.conf
|
|
|
|
. /etc/ffdns/local.conf
|
2021-01-04 20:53:39 +01:00
|
|
|
|
2021-07-10 01:13:29 +02:00
|
|
|
export DNSSCRIPT_CONTACT_EMAIL
|
|
|
|
export DNSSCRIPT_SERVER_NAME
|
|
|
|
export DNSSCRIPT_BIND_RELOAD_VER
|
2023-04-02 03:25:21 +02:00
|
|
|
DNSSCRIPT_DNSSECPolicy="$DNSSECPolicy"
|
|
|
|
export DNSSCRIPT_DNSSECPolicy
|
|
|
|
DNSSCRIPT_TEMP_FOLDER="$TempFolder"
|
|
|
|
export DNSSCRIPT_TEMP_FOLDER
|
2021-01-21 19:21:25 +01:00
|
|
|
|
2021-07-10 01:13:29 +02:00
|
|
|
cd /usr/lib/ffdns/
|
2021-01-14 20:46:10 +01:00
|
|
|
. ./dns-functions.sh
|
2021-08-30 03:10:13 +02:00
|
|
|
. ./update-dns-functions.sh
|
2021-01-04 20:53:39 +01:00
|
|
|
|
2021-07-10 01:20:50 +02:00
|
|
|
MasterDomain="$CommunityDomain"
|
|
|
|
[ -z "$SubCommunityDomain" ] || MasterDomain="$SubCommunityDomain"".""$MasterDomain"
|
|
|
|
if [ -n "$CommunityExternPrefix" ];then
|
|
|
|
MasterExternDomain="$CommunityExternPrefix"".""$CommunityDomain"
|
|
|
|
[ -z "$SubCommunityDomain" ] || MasterExternDomain="$SubCommunityDomain"".""$MasterExternDomain"
|
|
|
|
fi
|
|
|
|
|
2021-10-13 01:09:49 +02:00
|
|
|
FirstInternalView="$( echo "$InternalViews" | sed -e 's/\s.*//')"
|
2021-07-10 01:13:29 +02:00
|
|
|
# ForwardZones: "<Zone>/<Zonendatei>" ; optionaly multiple " ""<ZoneX>/<ZonendateiX>" no spaces in full filename
|
2021-08-30 03:10:13 +02:00
|
|
|
ForwardZones="$MasterDomain""/""$ZoneFilesFolder""db.""$FirstInternalView"".""$MasterDomain"
|
2023-04-02 03:25:21 +02:00
|
|
|
[ -n "$DNSSCRIPT_DNSSECPolicy" ] || DNSSECKeyFolder=""
|
2021-03-10 00:02:15 +01:00
|
|
|
|
2021-08-30 03:10:13 +02:00
|
|
|
SetupCache
|
2021-02-08 01:34:03 +01:00
|
|
|
|
2023-04-02 03:25:21 +02:00
|
|
|
CachedMasterFile="$DNSSCRIPT_TEMP_FOLDER""cache/db.""$MasterDomain"
|
2021-03-10 00:02:15 +01:00
|
|
|
PreFetchMasterSerial="$(GetZoneFileSerial "$CachedMasterFile")"
|
2021-08-30 03:10:13 +02:00
|
|
|
GetMasterFile
|
2021-03-10 00:02:15 +01:00
|
|
|
PostFetchMasterSerial="$(GetZoneFileSerial "$CachedMasterFile")"
|
2019-09-04 18:15:10 +02:00
|
|
|
|
2021-08-30 03:10:13 +02:00
|
|
|
ServeMasterZone="$(DoServeMasterZone)"
|
2021-07-23 00:14:10 +02:00
|
|
|
|
2021-08-30 03:10:13 +02:00
|
|
|
if [ -n "$ServeMasterZone" ] || [ -n "$(DoServeOnlyExternZone)" ]; then
|
|
|
|
RemoveDNSSECKeysFromCacheFile
|
|
|
|
|
|
|
|
if [ -n "$ServeMasterZone" ]; then
|
|
|
|
MasterFile="$ZoneFilesFolder""db.""$FirstInternalView"".""$MasterDomain"
|
|
|
|
FileForExternGeneration="$MasterFile"
|
|
|
|
else
|
|
|
|
FileForExternGeneration="$CachedMasterFile"
|
2021-07-23 00:14:10 +02:00
|
|
|
fi
|
2023-02-13 01:11:31 +01:00
|
|
|
|
2021-03-10 00:02:15 +01:00
|
|
|
if [ -n "$ExternalView" ]; then
|
2021-07-10 01:20:50 +02:00
|
|
|
ExternFile="$ZoneFilesFolder""db.""$ExternalView"".""$MasterDomain"
|
2021-03-10 00:02:15 +01:00
|
|
|
else
|
2021-07-23 00:14:10 +02:00
|
|
|
ExternFile="$ZoneFilesFolder""db.extern.""$MasterDomain"
|
2021-02-08 01:34:03 +01:00
|
|
|
fi
|
2021-03-10 00:02:15 +01:00
|
|
|
|
2021-08-30 21:57:28 +02:00
|
|
|
SerialIntern="$(UpdateMasterZone)"
|
2021-02-08 01:34:03 +01:00
|
|
|
|
2021-07-23 00:14:10 +02:00
|
|
|
InternalZoneFile="$FileForExternGeneration"
|
|
|
|
ExternalZoneFile="$ExternFile"
|
|
|
|
InternalDomain="$MasterDomain"
|
|
|
|
ExternDomain="$MasterExternDomain"
|
|
|
|
UpdateExternal
|
2021-02-08 01:34:03 +01:00
|
|
|
fi
|
2019-09-04 18:15:10 +02:00
|
|
|
|
2021-03-10 00:02:15 +01:00
|
|
|
if [ -z "$MasterFile" ]; then
|
2021-08-30 03:10:13 +02:00
|
|
|
MasterFile="$ZoneFilesFolder""db.""$FirstInternalView"".""$MasterDomain"
|
2021-03-10 00:02:15 +01:00
|
|
|
cp -f "$CachedMasterFile" "$MasterFile"
|
|
|
|
fi
|
|
|
|
|
2021-08-30 03:10:13 +02:00
|
|
|
UpdateReverseZones "$CommunitySubnets" "$ForwardZones" "$RemoteLocation"
|
2021-07-23 00:14:10 +02:00
|
|
|
|
2021-01-14 20:46:10 +01:00
|
|
|
# set shorter TTL for Hoods
|
|
|
|
TTLReReExMi="420 360 180 1800 360"
|
|
|
|
|
2021-07-10 01:20:50 +02:00
|
|
|
Hoods="$(GetOwnHoods "$MasterDomain" "$MasterFile")"
|
2021-07-23 00:14:10 +02:00
|
|
|
DNSSECKeyFolder=""
|
2021-01-14 20:46:10 +01:00
|
|
|
for Hood in $Hoods; do
|
2021-07-10 01:20:50 +02:00
|
|
|
HoodDomain="${Hood%%\#*}"".""$MasterDomain"
|
2021-01-14 20:46:10 +01:00
|
|
|
Subnets="$(echo "${Hood#*\#}" | sed -e 's/#/ /g')"
|
2021-08-30 03:10:13 +02:00
|
|
|
HoodZoneFile="$ZoneFilesFolder""db.""$FirstInternalView"".""$HoodDomain"
|
2021-01-14 20:46:10 +01:00
|
|
|
if [ ! -f "$HoodZoneFile" ]; then
|
2021-01-19 17:49:06 +01:00
|
|
|
{
|
|
|
|
echo "\$TTL ${TTLReReExMi%% *}"
|
2021-06-27 22:51:24 +02:00
|
|
|
echo "@ IN SOA $DNSSCRIPT_SERVER_NAME""."" $DNSSCRIPT_CONTACT_EMAIL ("
|
|
|
|
echo " 1 ; Serial"
|
|
|
|
echo " ""$(echo "$TTLReReExMi" | awk '{print $2}')"" ; Refresh"
|
|
|
|
echo " ""$(echo "$TTLReReExMi" | awk '{print $3}')"" ; Retry"
|
|
|
|
echo " ""$(echo "$TTLReReExMi" | awk '{print $4}')"" ; Expire"
|
|
|
|
echo " ""$(echo "$TTLReReExMi" | awk '{print $5}')"" ) ; Negative Cache TTL"
|
2021-01-21 19:21:25 +01:00
|
|
|
echo ";"
|
2021-08-30 03:10:13 +02:00
|
|
|
echo "@ IN NS ""$DNSSCRIPT_SERVER_NAME""."""
|
2021-07-10 01:20:50 +02:00
|
|
|
GetOwnGlueRecords "$MasterDomain" "$HoodDomain" "$MasterFile"
|
2021-01-21 19:21:25 +01:00
|
|
|
echo ";"
|
2021-01-19 17:49:06 +01:00
|
|
|
} > "$HoodZoneFile"
|
2021-01-14 20:46:10 +01:00
|
|
|
fi
|
2023-04-02 03:25:21 +02:00
|
|
|
ZoneTempFolder="$DNSSCRIPT_TEMP_FOLDER""cache/"
|
2021-07-23 00:14:10 +02:00
|
|
|
./update-hoodzone.sh "$HoodZoneFile" "$HoodDomain" "$Subnets" "$InternalViews" "$ZoneTempFolder" "$ZoneFilesFolder"
|
|
|
|
|
2023-04-02 03:25:21 +02:00
|
|
|
InsertZoneToViews "$InternalViews" "$ZoneFilesFolder" "$HoodDomain" "$HoodZoneFile" "/etc/ffdns/"
|
2021-01-15 17:12:33 +01:00
|
|
|
|
2021-01-21 19:21:25 +01:00
|
|
|
HoodForwardZones="$ForwardZones $HoodDomain""/""$HoodZoneFile"
|
2021-08-31 01:09:09 +02:00
|
|
|
UpdateReverseZones "$Subnets" "$HoodForwardZones"
|
2021-08-30 03:10:13 +02:00
|
|
|
|
2021-07-10 01:20:50 +02:00
|
|
|
if [ -n "$MasterExternDomain" ]; then
|
|
|
|
HoodExternDomain="${Hood%%\#*}"".""$MasterExternDomain"
|
2021-02-08 21:23:15 +01:00
|
|
|
else
|
|
|
|
HoodExternDomain=""
|
|
|
|
fi
|
2021-06-27 22:51:24 +02:00
|
|
|
|
|
|
|
if [ -n "$ExternalView" ]; then
|
2021-07-23 00:14:10 +02:00
|
|
|
ExternFile="$ZoneFilesFolder""db.""$ExternalView"".""$HoodDomain"
|
2021-06-27 22:51:24 +02:00
|
|
|
elif [ -n "$HoodExternDomain" ]; then
|
|
|
|
ExternFile="$ZoneFilesFolder""db.""$HoodExternDomain"
|
|
|
|
else
|
|
|
|
ExternFile=""
|
|
|
|
fi
|
2021-02-08 01:34:03 +01:00
|
|
|
|
2021-06-27 22:51:24 +02:00
|
|
|
if [ -n "$ExternFile" ]; then
|
2021-07-23 00:14:10 +02:00
|
|
|
InternalZoneFile="$HoodZoneFile"
|
|
|
|
ExternalZoneFile="$ExternFile"
|
|
|
|
InternalDomain="$HoodDomain"
|
|
|
|
ExternDomain="$HoodExternDomain"
|
|
|
|
SerialIntern="$(GetZoneFileSerial "$InternalZoneFile")"
|
|
|
|
UpdateExternal
|
2021-02-08 01:34:03 +01:00
|
|
|
fi
|
2021-01-15 17:12:33 +01:00
|
|
|
done
|
|
|
|
|
2021-02-08 01:34:03 +01:00
|
|
|
ReConfigBind=0
|
2021-01-15 17:12:33 +01:00
|
|
|
UpdateBindConfig() {
|
2021-01-19 17:49:06 +01:00
|
|
|
if [ -f "$1" ] && ! cmp -s "$1" "$2"; then
|
|
|
|
mv "$1" "$2"
|
2021-02-08 01:34:03 +01:00
|
|
|
ReConfigBind=1
|
2021-01-15 17:12:33 +01:00
|
|
|
else
|
2021-01-19 17:49:06 +01:00
|
|
|
rm -f "$1"
|
2021-01-04 20:53:39 +01:00
|
|
|
fi
|
2021-01-15 17:12:33 +01:00
|
|
|
}
|
|
|
|
|
2021-02-08 01:34:03 +01:00
|
|
|
for IView in $InternalViews; do
|
2023-04-02 03:25:21 +02:00
|
|
|
UpdateBindConfig "$DNSSCRIPT_TEMP_FOLDER""$IView"".conf" "$GeneratedIncludeFileFolder""$IView"".conf"
|
2021-02-08 01:34:03 +01:00
|
|
|
done
|
2021-06-27 22:51:24 +02:00
|
|
|
if [ -n "$ExternalView" ]; then
|
2023-04-02 03:25:21 +02:00
|
|
|
UpdateBindConfig "$DNSSCRIPT_TEMP_FOLDER""$ExternalView"".conf" "$GeneratedIncludeFileFolder""$ExternalView"".conf"
|
2021-06-27 22:51:24 +02:00
|
|
|
fi
|
2021-01-15 17:12:33 +01:00
|
|
|
|
2021-02-08 01:34:03 +01:00
|
|
|
if [ $ReConfigBind -ne 0 ] || [ -f "/tmp/dnsscript-forcereconf" ]; then
|
2021-01-19 17:49:06 +01:00
|
|
|
if [ $((DNSSCRIPT_BIND_RELOAD_VER)) -eq 0 ]; then
|
2021-01-15 17:12:33 +01:00
|
|
|
systemctl restart bind9
|
2021-01-19 17:49:06 +01:00
|
|
|
elif [ $((DNSSCRIPT_BIND_RELOAD_VER)) -eq 1 ]; then
|
2021-01-15 17:12:33 +01:00
|
|
|
rndc reconfig
|
2021-01-19 20:24:33 +01:00
|
|
|
elif [ $((DNSSCRIPT_BIND_RELOAD_VER)) -eq 2 ]; then
|
2021-01-15 17:12:33 +01:00
|
|
|
/etc/init.d/named restart
|
|
|
|
fi
|
2021-01-21 19:21:25 +01:00
|
|
|
rm -f "/tmp/dnsscript-forcereconf"
|
|
|
|
fi
|