From 330fa156c7d6dacec282a4eb4e39933ef64164f8 Mon Sep 17 00:00:00 2001 From: Blackyfff Date: Sat, 10 Jul 2021 01:20:50 +0200 Subject: [PATCH] Re-add Support for subsequent subdomain Signed-off-by: Blackyfff --- etc/ffdns/local.conf | 7 ++++ usr/lib/ffdns/update-dns.sh | 66 ++++++++++++++++++++----------------- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/etc/ffdns/local.conf b/etc/ffdns/local.conf index 78e13c2..4b9e44d 100644 --- a/etc/ffdns/local.conf +++ b/etc/ffdns/local.conf @@ -7,6 +7,13 @@ DNSSCRIPT_CONTACT_EMAIL="" #DNSSCRIPT_SERVER_NAME="dns.herpf.fff.community" DNSSCRIPT_SERVER_NAME="" +### If you are a root for $CommunityDomain or a first level Hood: do not specify +### If serving a subsequent subdomain, specify Remote and all Subdomains excluding the own +### For example if you are serving ... then specify . +### master file in remote needs to be named: db... +#RemoteLocation="https://gw01.herpf.fff.community/ffdns/" +#SubCommunityDomain="herpf" + ZoneFilesFolder="/etc/bind/fff/" BindIncludeFileFolder="/etc/bind/" TempFolder="/tmp/ffdns/" diff --git a/usr/lib/ffdns/update-dns.sh b/usr/lib/ffdns/update-dns.sh index 056db4f..d2589ff 100644 --- a/usr/lib/ffdns/update-dns.sh +++ b/usr/lib/ffdns/update-dns.sh @@ -18,12 +18,18 @@ export DNSSCRIPT_BIND_RELOAD_VER cd /usr/lib/ffdns/ . ./dns-functions.sh +MasterDomain="$CommunityDomain" +[ -z "$SubCommunityDomain" ] || MasterDomain="$SubCommunityDomain"".""$MasterDomain" +if [ -n "$CommunityExternPrefix" ];then + MasterExternDomain="$CommunityExternPrefix"".""$CommunityDomain" + [ -z "$SubCommunityDomain" ] || MasterExternDomain="$SubCommunityDomain"".""$MasterExternDomain" +fi + FirstInternal="$( echo "$InternalViews" | sed -ne 's/^\(\S\+\)\s.*$/\1/p')" # ForwardZones: "/" ; optionaly multiple " ""/" no spaces in full filename -ForwardZones="$CommunityDomain""/""$ZoneFilesFolder""db.""$FirstInternal"".""$CommunityDomain" +ForwardZones="$MasterDomain""/""$ZoneFilesFolder""db.""$FirstInternal"".""$MasterDomain" BindIcvpnAclTmp="$TempFolder""icvpn-acl.conf" BindIcvpnAcl="$BindIncludeFileFolder""icvpn-acl.conf" -[ -z "$CommunityExternPrefix" ] || CommunityExternDomain="$CommunityExternPrefix"".""$CommunityDomain" [ -n "$DNSSECPolicy" ] || DNSSECKeyFolder="" mkdir -p "$TempFolder""cache" @@ -33,12 +39,12 @@ for IView in $InternalViews; do done rm -f "$TempFolder""$ExternalView"".conf" -CachedMasterFile="$TempFolder""cache/db.""$CommunityDomain" +CachedMasterFile="$TempFolder""cache/db.""$MasterDomain" PreFetchMasterSerial="$(GetZoneFileSerial "$CachedMasterFile")" -$(curl -s -S -f "$RemoteLocation""db.""$CommunityDomain" --output "$CachedMasterFile" && [ -f "$CachedMasterFile" ] && echo "" >> "$CachedMasterFile") +$(curl -s -S -f "$RemoteLocation""db.""$MasterDomain" --output "$CachedMasterFile" && [ -f "$CachedMasterFile" ] && echo "" >> "$CachedMasterFile") PostFetchMasterSerial="$(GetZoneFileSerial "$CachedMasterFile")" -ServeMasterZone="$( GetAllZoneNameservers "$CommunityDomain" "$CachedMasterFile" | awk '{for(i=NF;i>0;--i) if($i=="'"$DNSSCRIPT_SERVER_NAME"'") {printf 1}}')" -if [ -n "$CommunityExternDomain" ]; then +[ -n "$SubCommunityDomain" ] || ServeMasterZone="$( GetAllZoneNameservers "$MasterDomain" "$CachedMasterFile" | awk '{for(i=NF;i>0;--i) if($i=="'"$DNSSCRIPT_SERVER_NAME"'") {printf 1}}')" +if [ -n "$MasterExternDomain" ]; then if [ -n "$ServeMasterZone" ]; then ServeExtZone="1" else @@ -52,17 +58,17 @@ if [ -n "$ServeMasterZone" ] || [ -n "$ServeExtZone" ]; then sed -i -e '/^\s*_dnsseckeys\./d' "$CachedMasterFile" FileForExternGeneration="$CachedMasterFile" if [ -n "$ExternalView" ]; then - ExternFile="$ZoneFilesFolder""db.""$ExternalView"".""$CommunityDomain" + ExternFile="$ZoneFilesFolder""db.""$ExternalView"".""$MasterDomain" else - ExternFile="$ZoneFilesFolder""db.""$CommunityExternDomain" + ExternFile="$ZoneFilesFolder""db.""$MasterExternDomain" fi LocalMasterSerial=$((PostFetchMasterSerial)) if [ -n "$ServeMasterZone" ]; then - MasterFile="$ZoneFilesFolder""db.""$FirstInternal"".""$CommunityDomain" + MasterFile="$ZoneFilesFolder""db.""$FirstInternal"".""$MasterDomain" FileForExternGeneration="$MasterFile" - ZoneTempFolder="$TempFolder""cache/""$CommunityDomain""/" + ZoneTempFolder="$TempFolder""cache/""$MasterDomain""/" - UpdateMaster="$(UpdateDNSSECEntryCache "$CommunityDomain" "$ZoneTempFolder" "$CachedMasterFile" "$DNSSECKeyFolder")" + UpdateMaster="$(UpdateDNSSECEntryCache "$MasterDomain" "$ZoneTempFolder" "$CachedMasterFile" "$DNSSECKeyFolder")" if [ $((PostFetchMasterSerial)) -gt $((PreFetchMasterSerial)) ] || [ $UpdateMaster -ne 0 ]; then cp -f "$CachedMasterFile" "$CachedMasterFile""I" for KeyFile in "$ZoneTempFolder"*; do @@ -79,9 +85,9 @@ if [ -n "$ServeMasterZone" ] || [ -n "$ServeExtZone" ]; then LocalMasterSerial=$((PostFetchMasterSerial)) fi mv "$CachedMasterFile""I" "$MasterFile" - ReloadZone "$CommunityDomain" "$InternalViews" + ReloadZone "$MasterDomain" "$InternalViews" - InsertZoneToViews "$InternalViews" "$ZoneFilesFolder" "$CommunityDomain" "$MasterFile" "$TempFolder" "$DNSSECPolicy" + InsertZoneToViews "$InternalViews" "$ZoneFilesFolder" "$MasterDomain" "$MasterFile" "$TempFolder" "$DNSSECPolicy" fi for Subnet in $CommunitySubnets; do ReverseDomains="$(GetReverseDomains "$Subnet")" @@ -97,7 +103,7 @@ if [ -n "$ServeMasterZone" ] || [ -n "$ServeExtZone" ]; then done done if [ -n "$ExternalView" ]; then - InsertZoneToIncludeFile "$CommunityDomain" "$ExternFile" "$TempFolder""$ExternalView"".conf" "$DNSSECPolicy" + InsertZoneToIncludeFile "$MasterDomain" "$ExternFile" "$TempFolder""$ExternalView"".conf" "$DNSSECPolicy" fi fi @@ -109,13 +115,13 @@ if [ -n "$ServeMasterZone" ] || [ -n "$ServeExtZone" ]; then s/^[^;^@]*\s\+\([^;]*\)\s[Ii][Nn]\s\+[Ss][Oo][Aa]\s/@ \1 IN SOA /g' "$FileForExternGeneration" \ > "$ExternFile" UpdateExternView=1 - [ -z "$ExternalView" ] || ReloadZone "$CommunityExternDomain" "$ExternalView" + [ -z "$ExternalView" ] || ReloadZone "$MasterExternDomain" "$ExternalView" fi fi if [ -n "$ServeExtZone" ]; then - MasterExtDomainFile="$ZoneFilesFolder""db.""$FirstInternal"".""$CommunityExternDomain" - ZoneTempFolder="$TempFolder""cache/""$CommunityExternDomain""/" + MasterExtDomainFile="$ZoneFilesFolder""db.""$FirstInternal"".""$MasterExternDomain" + ZoneTempFolder="$TempFolder""cache/""$MasterExternDomain""/" cp -f "$ExternFile" "$CachedMasterFile""E" sed -i -e '/^\s*_dnsseckeys\./d' "$CachedMasterFile""E" [ -n "$(sed -e '/^\s*\(@\s\+\([0-9]*\s\)\?\s*[Ii][Nn]\s\+[Nn][Ss]\)\s/!d' "$CachedMasterFile""E")" ] || \ @@ -123,12 +129,12 @@ if [ -n "$ServeMasterZone" ] || [ -n "$ServeExtZone" ]; then sed -i -e 's/^\s*'"$CommunityExternPrefix"'\s/@ /g;/^\s*@\s\+[Ii][Nn]\s\+[Dd][Ss]\s/d' "$CachedMasterFile""E" - UpdateExternDomain="$(UpdateDNSSECEntryCache "$CommunityExternDomain" "$ZoneTempFolder" "$CachedMasterFile""E" "$DNSSECKeyFolder")" + UpdateExternDomain="$(UpdateDNSSECEntryCache "$MasterExternDomain" "$ZoneTempFolder" "$CachedMasterFile""E" "$DNSSECKeyFolder")" if [ $UpdateExternView -ne 0 ] || [ $UpdateExternDomain -ne 0 ]; then for KeyFile in "$ZoneTempFolder"*; do [ "$KeyFile" == "$ZoneTempFolder""*" ] || \ cat "$KeyFile" >> "$CachedMasterFile""E" - done + done LocalExtDomainMasterSerial="$(GetZoneFileSerial "$MasterExtDomainFile")" if [ $((LocalMasterSerial)) -le $((LocalExtDomainMasterSerial)) ]; then @@ -137,26 +143,26 @@ if [ -n "$ServeMasterZone" ] || [ -n "$ServeExtZone" ]; then sed -i -e 's/^\(\s*\S\+\s\+\([0-9]*\s\)\?\s*[Ii][Nn]\s\+[Ss][Oo][Aa]\s\+\S\+\s\+\S\+\s\+\)'"$LocalMasterSerial"'\(\s\+.*\)$/\1'"$LocalExtDomainMasterSerial"'\3/g' "$CachedMasterFile""E" fi mv "$CachedMasterFile""E" "$MasterExtDomainFile" - ReloadZone "$CommunityExternDomain" "$InternalViews" + ReloadZone "$MasterExternDomain" "$InternalViews" fi - InsertZoneToViews "$InternalViews" "$ZoneFilesFolder" "$CommunityExternDomain" "$MasterExtDomainFile" "$TempFolder" "$DNSSECPolicy" - InsertZoneToViews "$ExternalView" "$ZoneFilesFolder" "$CommunityExternDomain" "$MasterExtDomainFile" "$TempFolder" "$DNSSECPolicy" + InsertZoneToViews "$InternalViews" "$ZoneFilesFolder" "$MasterExternDomain" "$MasterExtDomainFile" "$TempFolder" "$DNSSECPolicy" + InsertZoneToViews "$ExternalView" "$ZoneFilesFolder" "$MasterExternDomain" "$MasterExtDomainFile" "$TempFolder" "$DNSSECPolicy" fi fi if [ -z "$MasterFile" ]; then - MasterFile="$ZoneFilesFolder""db.""$FirstInternal"".""$CommunityDomain" + MasterFile="$ZoneFilesFolder""db.""$FirstInternal"".""$MasterDomain" cp -f "$CachedMasterFile" "$MasterFile" fi # set shorter TTL for Hoods TTLReReExMi="420 360 180 1800 360" -Hoods="$(GetOwnHoods "$CommunityDomain" "$MasterFile")" +Hoods="$(GetOwnHoods "$MasterDomain" "$MasterFile")" for Hood in $Hoods; do - HoodDomain="${Hood%%\#*}"".""$CommunityDomain" + HoodDomain="${Hood%%\#*}"".""$MasterDomain" Subnets="$(echo "${Hood#*\#}" | sed -e 's/#/ /g')" HoodZoneFile="$ZoneFilesFolder""db.""$FirstInternal"".""$HoodDomain" if [ ! -f "$HoodZoneFile" ]; then @@ -170,7 +176,7 @@ for Hood in $Hoods; do echo " ""$(echo "$TTLReReExMi" | awk '{print $5}')"" ) ; Negative Cache TTL" echo ";" echo "@ IN NS $DNSSCRIPT_SERVER_NAME"".""" - GetOwnGlueRecords "$CommunityDomain" "$HoodDomain" "$MasterFile" + GetOwnGlueRecords "$MasterDomain" "$HoodDomain" "$MasterFile" echo ";" } > "$HoodZoneFile" fi @@ -187,8 +193,8 @@ for Hood in $Hoods; do done done done - if [ -n "$CommunityExternDomain" ]; then - HoodExternDomain="${Hood%%\#*}"".""$CommunityExternDomain" + if [ -n "$MasterExternDomain" ]; then + HoodExternDomain="${Hood%%\#*}"".""$MasterExternDomain" else HoodExternDomain="" fi @@ -209,8 +215,8 @@ for Hood in $Hoods; do InsertZoneToViews "$ExternalView" "$ZoneFilesFolder" "$HoodDomain" "$ExternFile" "$TempFolder" "$DNSSECPolicy" if [ -n "$HoodExternDomain" ]; then - InsertZoneToViews "$InternalViews" "$ZoneFilesFolder" "${Hood%%\#*}"".""$CommunityExternDomain" "$ExternFile" "$TempFolder" "$DNSSECPolicy" - InsertZoneToViews "$ExternalView" "$ZoneFilesFolder" "${Hood%%\#*}"".""$CommunityExternDomain" "$ExternFile" "$TempFolder" "$DNSSECPolicy" + InsertZoneToViews "$InternalViews" "$ZoneFilesFolder" "${Hood%%\#*}"".""$MasterExternDomain" "$ExternFile" "$TempFolder" "$DNSSECPolicy" + InsertZoneToViews "$ExternalView" "$ZoneFilesFolder" "${Hood%%\#*}"".""$MasterExternDomain" "$ExternFile" "$TempFolder" "$DNSSECPolicy" fi done