Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/pi-hole/pi-hole.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'advanced/Scripts/webpage.sh')
-rwxr-xr-xadvanced/Scripts/webpage.sh95
1 files changed, 81 insertions, 14 deletions
diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh
index a518a428..1f7cc728 100755
--- a/advanced/Scripts/webpage.sh
+++ b/advanced/Scripts/webpage.sh
@@ -10,17 +10,22 @@
# This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license.
-readonly setupVars="/etc/pihole/setupVars.conf"
readonly dnsmasqconfig="/etc/dnsmasq.d/01-pihole.conf"
readonly dhcpconfig="/etc/dnsmasq.d/02-pihole-dhcp.conf"
readonly FTLconf="/etc/pihole/pihole-FTL.conf"
# 03 -> wildcards
readonly dhcpstaticconfig="/etc/dnsmasq.d/04-pihole-static-dhcp.conf"
-readonly PI_HOLE_BIN_DIR="/usr/local/bin"
readonly dnscustomfile="/etc/pihole/custom.list"
+readonly dnscustomcnamefile="/etc/dnsmasq.d/05-pihole-custom-cname.conf"
readonly gravityDBfile="/etc/pihole/gravity.db"
+# Source install script for ${setupVars}, ${PI_HOLE_BIN_DIR} and valid_ip()
+readonly PI_HOLE_FILES_DIR="/etc/.pihole"
+# shellcheck disable=SC2034 # used in basic-install
+PH_TEST="true"
+source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
+
coltable="/opt/pihole/COL_TABLE"
if [[ -f ${coltable} ]]; then
source ${coltable}
@@ -209,8 +214,34 @@ 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"
+
+ # 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
+
+ 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
@@ -225,7 +256,16 @@ SetDNSServers() {
IFS=',' read -r -a array <<< "${args[2]}"
for index in "${!array[@]}"
do
- add_setting "PIHOLE_DNS_$((index+1))" "${array[index]}"
+ # Replace possible "\#" by "#". This fixes AdminLTE#1427
+ local ip
+ ip="${array[index]//\\#/#}"
+
+ if valid_ip "${ip}" || valid_ip6 "${ip}" ; then
+ add_setting "PIHOLE_DNS_$((index+1))" "${ip}"
+ else
+ echo -e " ${CROSS} Invalid IP has been passed"
+ exit 1
+ fi
done
if [[ "${args[3]}" == "domain-needed" ]]; then
@@ -246,16 +286,13 @@ 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"
fi
ProcessDNSSettings
@@ -400,6 +437,10 @@ SetWebUILayout() {
change_setting "WEBUIBOXEDLAYOUT" "${args[2]}"
}
+SetWebUITheme() {
+ change_setting "WEBTHEME" "${args[2]}"
+}
+
CheckUrl(){
local regex
# Check for characters NOT allowed in URLs
@@ -595,6 +636,7 @@ SetPrivacyLevel() {
# Set privacy level. Minimum is 0, maximum is 4
if [ "${args[2]}" -ge 0 ] && [ "${args[2]}" -le 4 ]; then
changeFTLsetting "PRIVACYLEVEL" "${args[2]}"
+ pihole restartdns reload-lists
fi
}
@@ -620,6 +662,28 @@ RemoveCustomDNSAddress() {
RestartDNS
}
+AddCustomCNAMERecord() {
+ echo -e " ${TICK} Adding custom CNAME record..."
+
+ domain="${args[2]}"
+ target="${args[3]}"
+ echo "cname=${domain},${target}" >> "${dnscustomcnamefile}"
+
+ # Restart dnsmasq to load new custom CNAME records
+ RestartDNS
+}
+
+RemoveCustomCNAMERecord() {
+ echo -e " ${TICK} Removing custom CNAME record..."
+
+ domain="${args[2]}"
+ target="${args[3]}"
+ sed -i "/cname=${domain},${target}/d" "${dnscustomcnamefile}"
+
+ # Restart dnsmasq to update removed custom CNAME records
+ RestartDNS
+}
+
main() {
args=("$@")
@@ -638,6 +702,7 @@ main() {
"enabledhcp" ) EnableDHCP;;
"disabledhcp" ) DisableDHCP;;
"layout" ) SetWebUILayout;;
+ "theme" ) SetWebUITheme;;
"-h" | "--help" ) helpFunc;;
"privacymode" ) SetPrivacyMode;;
"resolve" ) ResolutionSettings;;
@@ -652,6 +717,8 @@ main() {
"-l" | "privacylevel" ) SetPrivacyLevel;;
"addcustomdns" ) AddCustomDNSAddress;;
"removecustomdns" ) RemoveCustomDNSAddress;;
+ "addcustomcname" ) AddCustomCNAMERecord;;
+ "removecustomcname" ) RemoveCustomCNAMERecord;;
* ) helpFunc;;
esac