mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-26 14:50:17 +00:00
pihole command: read values from pihole-FTL instead of setupvars.conf
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
parent
dbc6b814b2
commit
2784b267ec
2 changed files with 12 additions and 25 deletions
|
@ -153,7 +153,7 @@ getFTLPID() {
|
||||||
# Example getFTLConfigValue dns.piholePTR
|
# Example getFTLConfigValue dns.piholePTR
|
||||||
#######################
|
#######################
|
||||||
getFTLConfigValue(){
|
getFTLConfigValue(){
|
||||||
pihole-FTL --config "${1}"
|
pihole-FTL --config -q "${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
|
@ -166,5 +166,5 @@ getFTLConfigValue(){
|
||||||
# setFTLConfigValue dnsmasq.upstreams '[ "8.8.8.8" , "8.8.4.4" ]'
|
# setFTLConfigValue dnsmasq.upstreams '[ "8.8.8.8" , "8.8.4.4" ]'
|
||||||
#######################
|
#######################
|
||||||
setFTLConfigValue(){
|
setFTLConfigValue(){
|
||||||
pihole-FTL --config "${1}" "${2}"
|
pihole-FTL --config "${1}" "${2}" >/dev/null
|
||||||
}
|
}
|
||||||
|
|
33
pihole
33
pihole
|
@ -11,10 +11,9 @@
|
||||||
|
|
||||||
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||||
|
|
||||||
# setupVars and PI_HOLE_BIN_DIR are not readonly here because in some functions (checkout),
|
# PI_HOLE_BIN_DIR is not readonly here because in some functions (checkout),
|
||||||
# they might get set again when the installer is sourced. This causes an
|
# they might get set again when the installer is sourced. This causes an
|
||||||
# error due to modifying a readonly variable.
|
# error due to modifying a readonly variable.
|
||||||
setupVars="/etc/pihole/setupVars.conf"
|
|
||||||
PI_HOLE_BIN_DIR="/usr/local/bin"
|
PI_HOLE_BIN_DIR="/usr/local/bin"
|
||||||
|
|
||||||
readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
||||||
|
@ -193,7 +192,7 @@ Time:
|
||||||
|
|
||||||
elif [[ "${1}" == "0" ]]; then
|
elif [[ "${1}" == "0" ]]; then
|
||||||
# Disable Pi-hole
|
# Disable Pi-hole
|
||||||
if grep -cq "BLOCKING_ENABLED=false" "${setupVars}"; then
|
if ! getFTLConfigValue dns.blocking.active; then
|
||||||
echo -e " ${INFO} Blocking already disabled, nothing to do"
|
echo -e " ${INFO} Blocking already disabled, nothing to do"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -233,19 +232,19 @@ Time:
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local str="Pi-hole Disabled"
|
local str="Pi-hole Disabled"
|
||||||
addOrEditKeyValPair "${setupVars}" "BLOCKING_ENABLED" "false"
|
setFTLConfigValue dns.blocking.active false
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Enable Pi-hole
|
# Enable Pi-hole
|
||||||
killall -q pihole-reenable
|
killall -q pihole-reenable
|
||||||
if grep -cq "BLOCKING_ENABLED=true" "${setupVars}"; then
|
if getFTLConfigValue dns.blocking.active; then
|
||||||
echo -e " ${INFO} Blocking already enabled, nothing to do"
|
echo -e " ${INFO} Blocking already enabled, nothing to do"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
echo -e " ${INFO} Enabling blocking"
|
echo -e " ${INFO} Enabling blocking"
|
||||||
local str="Pi-hole Enabled"
|
local str="Pi-hole Enabled"
|
||||||
|
|
||||||
addOrEditKeyValPair "${setupVars}" "BLOCKING_ENABLED" "true"
|
setFTLConfigValue dns.blocking.active true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
restartDNS reload-lists
|
restartDNS reload-lists
|
||||||
|
@ -267,8 +266,7 @@ Options:
|
||||||
exit 0
|
exit 0
|
||||||
elif [[ "${1}" == "off" ]]; then
|
elif [[ "${1}" == "off" ]]; then
|
||||||
# Disable logging
|
# Disable logging
|
||||||
removeKey /etc/dnsmasq.d/01-pihole.conf "log-queries"
|
setFTLConfigValue dns.queryLogging false
|
||||||
addOrEditKeyValPair "${setupVars}" "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
|
||||||
|
@ -277,8 +275,7 @@ Options:
|
||||||
local str="Logging has been disabled!"
|
local str="Logging has been disabled!"
|
||||||
elif [[ "${1}" == "on" ]]; then
|
elif [[ "${1}" == "on" ]]; then
|
||||||
# Enable logging
|
# Enable logging
|
||||||
addKey /etc/dnsmasq.d/01-pihole.conf "log-queries"
|
setFTLConfigValue dns.queryLogging true
|
||||||
addOrEditKeyValPair "${setupVars}" "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
|
||||||
|
@ -354,26 +351,16 @@ statusFunc() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Determine if Pi-hole's blocking is enabled
|
# Determine if Pi-hole's blocking is enabled
|
||||||
if grep -q "BLOCKING_ENABLED=false" /etc/pihole/setupVars.conf; then
|
if getFTLConfigValue dns.blocking.active; then
|
||||||
# A config is commented out
|
|
||||||
case "${1}" in
|
|
||||||
"web") echo 0;;
|
|
||||||
*) echo -e " ${CROSS} Pi-hole blocking is disabled";;
|
|
||||||
esac
|
|
||||||
elif grep -q "BLOCKING_ENABLED=true" /etc/pihole/setupVars.conf; then
|
|
||||||
# Configs are set
|
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
"web") echo "$port";;
|
"web") echo "$port";;
|
||||||
*) echo -e " ${TICK} Pi-hole blocking is enabled";;
|
*) echo -e " ${TICK} Pi-hole blocking is enabled";;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
# No configs were found
|
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
"web") echo -2;;
|
"web") echo 0;;
|
||||||
*) echo -e " ${INFO} Pi-hole blocking will be enabled";;
|
*) echo -e " ${CROSS} Pi-hole blocking is disabled";;
|
||||||
esac
|
esac
|
||||||
# Enable blocking
|
|
||||||
"${PI_HOLE_BIN_DIR}"/pihole enable
|
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue