Split new function out into a separte utility script and add a test for it. Can be used in future to organise re/commonly-used code
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
21
pihole
21
pihole
@@ -21,6 +21,9 @@ readonly FTL_PID_FILE="/run/pihole-FTL.pid"
|
||||
readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
||||
source "${colfile}"
|
||||
|
||||
readonly utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
source "${utilsfile}"
|
||||
|
||||
webpageFunc() {
|
||||
source "${PI_HOLE_SCRIPT_DIR}/webpage.sh"
|
||||
main "$@"
|
||||
@@ -170,16 +173,6 @@ restartDNS() {
|
||||
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() {
|
||||
if [[ "${2}" == "-h" ]] || [[ "${2}" == "--help" ]]; then
|
||||
echo "Usage: pihole disable [time]
|
||||
@@ -233,7 +226,7 @@ Time:
|
||||
fi
|
||||
|
||||
local str="Pi-hole Disabled"
|
||||
addOrEditKeyValPair "BLOCKING_ENABLED" "false"
|
||||
addOrEditKeyValPair "BLOCKING_ENABLED" "false" "${setupVars}"
|
||||
fi
|
||||
else
|
||||
# Enable Pi-hole
|
||||
@@ -245,7 +238,7 @@ Time:
|
||||
echo -e " ${INFO} Enabling blocking"
|
||||
local str="Pi-hole Enabled"
|
||||
|
||||
addOrEditKeyValPair "BLOCKING_ENABLED" "true"
|
||||
addOrEditKeyValPair "BLOCKING_ENABLED" "true" "${setupVars}"
|
||||
fi
|
||||
|
||||
restartDNS reload-lists
|
||||
@@ -268,7 +261,7 @@ Options:
|
||||
elif [[ "${1}" == "off" ]]; then
|
||||
# Disable logging
|
||||
sed -i 's/^log-queries/#log-queries/' /etc/dnsmasq.d/01-pihole.conf
|
||||
addOrEditKeyValPair "QUERY_LOGGING" "false"
|
||||
addOrEditKeyValPair "QUERY_LOGGING" "false" "${setupVars}"
|
||||
if [[ "${2}" != "noflush" ]]; then
|
||||
# Flush logs
|
||||
"${PI_HOLE_BIN_DIR}"/pihole -f
|
||||
@@ -278,7 +271,7 @@ Options:
|
||||
elif [[ "${1}" == "on" ]]; then
|
||||
# Enable logging
|
||||
sed -i 's/^#log-queries/log-queries/' /etc/dnsmasq.d/01-pihole.conf
|
||||
addOrEditKeyValPair "QUERY_LOGGING" "true"
|
||||
addOrEditKeyValPair "QUERY_LOGGING" "true" "${setupVars}"
|
||||
echo -e " ${INFO} Enabling logging..."
|
||||
local str="Logging has been enabled!"
|
||||
else
|
||||
|
Reference in New Issue
Block a user