mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 10:43:55 +00:00
Replace value for BLOCKING_ENABLED (and QUERY_LOGGING, for consistency) and if value that we are trying to replace does not exist, add it to the end of the file.
Co-authored-by: MichaIng <micha@dietpi.com> Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
parent
e80a7731c9
commit
1dd9d55d82
1 changed files with 14 additions and 4 deletions
18
pihole
18
pihole
|
@ -170,6 +170,16 @@ restartDNS() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addOrEditKeyValPair() {
|
||||||
|
local key="${1}"
|
||||||
|
local value="${2}"
|
||||||
|
if grep -q "^${key}=" "${setupVars}"; then
|
||||||
|
sed -i "/^${key}=/c\\${key}=${value}" "${setupVars}"
|
||||||
|
else
|
||||||
|
echo "${key}=${value}" >> "${setupVars}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
piholeEnable() {
|
piholeEnable() {
|
||||||
if [[ "${2}" == "-h" ]] || [[ "${2}" == "--help" ]]; then
|
if [[ "${2}" == "-h" ]] || [[ "${2}" == "--help" ]]; then
|
||||||
echo "Usage: pihole disable [time]
|
echo "Usage: pihole disable [time]
|
||||||
|
@ -223,7 +233,7 @@ Time:
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local str="Pi-hole Disabled"
|
local str="Pi-hole Disabled"
|
||||||
sed -i "s/^BLOCKING_ENABLED=true/BLOCKING_ENABLED=false/" "${setupVars}"
|
addOrEditKeyValPair "BLOCKING_ENABLED" "false"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Enable Pi-hole
|
# Enable Pi-hole
|
||||||
|
@ -235,7 +245,7 @@ Time:
|
||||||
echo -e " ${INFO} Enabling blocking"
|
echo -e " ${INFO} Enabling blocking"
|
||||||
local str="Pi-hole Enabled"
|
local str="Pi-hole Enabled"
|
||||||
|
|
||||||
sed -i "s/^BLOCKING_ENABLED=false/BLOCKING_ENABLED=true/" "${setupVars}"
|
addOrEditKeyValPair "BLOCKING_ENABLED" "true"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
restartDNS reload-lists
|
restartDNS reload-lists
|
||||||
|
@ -258,7 +268,7 @@ Options:
|
||||||
elif [[ "${1}" == "off" ]]; then
|
elif [[ "${1}" == "off" ]]; then
|
||||||
# Disable logging
|
# Disable logging
|
||||||
sed -i 's/^log-queries/#log-queries/' /etc/dnsmasq.d/01-pihole.conf
|
sed -i 's/^log-queries/#log-queries/' /etc/dnsmasq.d/01-pihole.conf
|
||||||
sed -i 's/^QUERY_LOGGING=true/QUERY_LOGGING=false/' /etc/pihole/setupVars.conf
|
addOrEditKeyValPair "QUERY_LOGGING" "false"
|
||||||
if [[ "${2}" != "noflush" ]]; then
|
if [[ "${2}" != "noflush" ]]; then
|
||||||
# Flush logs
|
# Flush logs
|
||||||
"${PI_HOLE_BIN_DIR}"/pihole -f
|
"${PI_HOLE_BIN_DIR}"/pihole -f
|
||||||
|
@ -268,7 +278,7 @@ Options:
|
||||||
elif [[ "${1}" == "on" ]]; then
|
elif [[ "${1}" == "on" ]]; then
|
||||||
# Enable logging
|
# Enable logging
|
||||||
sed -i 's/^#log-queries/log-queries/' /etc/dnsmasq.d/01-pihole.conf
|
sed -i 's/^#log-queries/log-queries/' /etc/dnsmasq.d/01-pihole.conf
|
||||||
sed -i 's/^QUERY_LOGGING=false/QUERY_LOGGING=true/' /etc/pihole/setupVars.conf
|
addOrEditKeyValPair "QUERY_LOGGING" "true"
|
||||||
echo -e " ${INFO} Enabling logging..."
|
echo -e " ${INFO} Enabling logging..."
|
||||||
local str="Logging has been enabled!"
|
local str="Logging has been enabled!"
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue