From 90a5a13197d9cb43d1f2daea39693a0e312d02cf Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 8 Apr 2020 15:35:07 +0200 Subject: [PATCH 1/5] Convert CONDITIONAL_FORWARDING to REV_SERVER settings. Try to detect intended CIDR range automatically. Signed-off-by: DL6ER --- advanced/Scripts/webpage.sh | 56 +++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f0f8bc31..41e52747 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -210,8 +210,42 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 fi if [[ "${CONDITIONAL_FORWARDING}" == true ]]; then - add_dnsmasq_setting "server=/${CONDITIONAL_FORWARDING_DOMAIN}/${CONDITIONAL_FORWARDING_IP}" - add_dnsmasq_setting "server=/${CONDITIONAL_FORWARDING_REVERSE}/${CONDITIONAL_FORWARDING_IP}" + # Convert legacy "conditional forwarding" to rev-server configuration + REV_SERVER=true + add_setting "REV_SERVER" "true" + + REV_SERVER_DOMAIN="${CONDITIONAL_FORWARDING_DOMAIN}" + add_setting "REV_SERVER_DOMAIN" "${REV_SERVER_DOMAIN}" + + REV_SERVER_TARGET="${CONDITIONAL_FORWARDING_IP}" + add_setting "REV_SERVER_TARGET" "${REV_SERVER_TARGET}" + + # Remove obsolete settings from setupVars.conf + delete_setting "CONDITIONAL_FORWARDING" + delete_setting "CONDITIONAL_FORWARDING_REVERSE" + delete_setting "CONDITIONAL_FORWARDING_DOMAIN" + delete_setting "CONDITIONAL_FORWARDING_IP" + + # Try to detect intended CIDR by analyzing the target + if [[ "${REV_SERVER_TARGET}" =~ 10\..* ]]; then + # Private network, Class A (RFC 1597 + RFC 1918) + REV_SERVER_CIDR="10.0.0.0/8" + elif [[ "${REV_SERVER_TARGET}" =~ 192\.168\..* ]]; then + # Private network, Class C (RFC 1597 + RFC 1918) + REV_SERVER_CIDR="192.168.0.0/16" + else + # Something else. The user will have to adapt this + # as we cannot know how large their subnet is + REV_SERVER_CIDR="${REV_SERVER_TARGET}/32" + fi + add_setting "REV_SERVER_CIDR" "${REV_SERVER_CIDR}" + fi + + if [[ "${REV_SERVER}" == true ]]; then + add_dnsmasq_setting "rev-server=${REV_SERVER_CIDR},${REV_SERVER_TARGET}" + if [ -n "${REV_SERVER_DOMAIN}" ]; then + add_dnsmasq_setting "server=/${REV_SERVER_DOMAIN}/${REV_SERVER_TARGET}" + fi fi # Prevent Firefox from automatically switching over to DNS-over-HTTPS @@ -247,16 +281,16 @@ SetDNSServers() { change_setting "DNSSEC" "false" fi - if [[ "${args[6]}" == "conditional_forwarding" ]]; then - change_setting "CONDITIONAL_FORWARDING" "true" - change_setting "CONDITIONAL_FORWARDING_IP" "${args[7]}" - change_setting "CONDITIONAL_FORWARDING_DOMAIN" "${args[8]}" - change_setting "CONDITIONAL_FORWARDING_REVERSE" "${args[9]}" + if [[ "${args[6]}" == "rev-server" ]]; then + change_setting "REV_SERVER" "true" + change_setting "REV_SERVER_CIDR" "${args[7]}" + change_setting "REV_SERVER_TARGET" "${args[8]}" + change_setting "REV_SERVER_DOMAIN" "${args[9]}" else - change_setting "CONDITIONAL_FORWARDING" "false" - delete_setting "CONDITIONAL_FORWARDING_IP" - delete_setting "CONDITIONAL_FORWARDING_DOMAIN" - delete_setting "CONDITIONAL_FORWARDING_REVERSE" + change_setting "REV_SERVER" "false" + delete_setting "REV_SERVER_CIDR" + delete_setting "REV_SERVER_TARGET" + delete_setting "REV_SERVER_DOMAIN" fi ProcessDNSSettings From 4130af0aab17689c7295dbe90d1188fefd02874c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 9 Apr 2020 09:05:43 +0200 Subject: [PATCH 2/5] Retain rev-server settings when the feature gets disabled. Signed-off-by: DL6ER --- advanced/Scripts/webpage.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 41e52747..5e63f0cf 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -288,9 +288,6 @@ SetDNSServers() { change_setting "REV_SERVER_DOMAIN" "${args[9]}" else change_setting "REV_SERVER" "false" - delete_setting "REV_SERVER_CIDR" - delete_setting "REV_SERVER_TARGET" - delete_setting "REV_SERVER_DOMAIN" fi ProcessDNSSettings From 093054a1eb6bfc82968ab0c36f0dfc737514599b Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 9 Apr 2020 09:38:24 +0200 Subject: [PATCH 3/5] Automatically convert legacy IP range to Class C network Signed-off-by: DL6ER --- advanced/Scripts/webpage.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 5e63f0cf..d5bf46a4 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -231,12 +231,12 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 # Private network, Class A (RFC 1597 + RFC 1918) REV_SERVER_CIDR="10.0.0.0/8" elif [[ "${REV_SERVER_TARGET}" =~ 192\.168\..* ]]; then - # Private network, Class C (RFC 1597 + RFC 1918) + # Private network, Class B (RFC 1597 + RFC 1918) REV_SERVER_CIDR="192.168.0.0/16" else - # Something else. The user will have to adapt this - # as we cannot know how large their subnet is - REV_SERVER_CIDR="${REV_SERVER_TARGET}/32" + # Something else, convert to /24 subnet (preserves legacy behavior) + # This sed converts "192.168.1.2" to "192.168.1.0/24" + REV_SERVER_CIDR="$(sed "s+\\.[0-9]*$+\\.0/24+" <<< "${REV_SERVER_TARGET}")" fi add_setting "REV_SERVER_CIDR" "${REV_SERVER_CIDR}" fi From 6160eb689462b435b6d6bfd9320b47b7c92cfc49 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 4 Jun 2020 09:22:40 +0200 Subject: [PATCH 4/5] This regex is too complex for bash's own replacement. Add ignore for the shellcheck rule. Signed-off-by: DL6ER --- advanced/Scripts/webpage.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f53b58cc..98e4620c 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -236,6 +236,7 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 else # Something else, convert to /24 subnet (preserves legacy behavior) # This sed converts "192.168.1.2" to "192.168.1.0/24" + # shellcheck disable=2001 REV_SERVER_CIDR="$(sed "s+\\.[0-9]*$+\\.0/24+" <<< "${REV_SERVER_TARGET}")" fi add_setting "REV_SERVER_CIDR" "${REV_SERVER_CIDR}" From 9bf0f2a161d166fb3e98c79936f75cf6427e4fd9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 21 Jun 2020 21:47:30 +0200 Subject: [PATCH 5/5] Reduce handholding when trying to foresee the intentions of the user. The code does now preserve legacy behavior and users can open up the subnet manually if they like. Signed-off-by: DL6ER --- advanced/Scripts/webpage.sh | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 98e4620c..ca8d8e20 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -226,19 +226,10 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 delete_setting "CONDITIONAL_FORWARDING_DOMAIN" delete_setting "CONDITIONAL_FORWARDING_IP" - # Try to detect intended CIDR by analyzing the target - if [[ "${REV_SERVER_TARGET}" =~ 10\..* ]]; then - # Private network, Class A (RFC 1597 + RFC 1918) - REV_SERVER_CIDR="10.0.0.0/8" - elif [[ "${REV_SERVER_TARGET}" =~ 192\.168\..* ]]; then - # Private network, Class B (RFC 1597 + RFC 1918) - REV_SERVER_CIDR="192.168.0.0/16" - else - # Something else, convert to /24 subnet (preserves legacy behavior) - # This sed converts "192.168.1.2" to "192.168.1.0/24" - # shellcheck disable=2001 - REV_SERVER_CIDR="$(sed "s+\\.[0-9]*$+\\.0/24+" <<< "${REV_SERVER_TARGET}")" - fi + # Convert existing input to /24 subnet (preserves legacy behavior) + # This sed converts "192.168.1.2" to "192.168.1.0/24" + # shellcheck disable=2001 + REV_SERVER_CIDR="$(sed "s+\\.[0-9]*$+\\.0/24+" <<< "${REV_SERVER_TARGET}")" add_setting "REV_SERVER_CIDR" "${REV_SERVER_CIDR}" fi