Compare commits
3 Commits
master
...
tweak/ensu
Author | SHA1 | Date | |
---|---|---|---|
|
3b6286e139 | ||
|
e1a128f833 | ||
|
69e55aff83 |
22
advanced/Scripts/utils.sh
Normal file
22
advanced/Scripts/utils.sh
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Pi-hole: A black hole for Internet advertisements
|
||||||
|
# (c) 2020 Pi-hole, LLC (https://pi-hole.net)
|
||||||
|
# Network-wide ad blocking via your own hardware.
|
||||||
|
#
|
||||||
|
# Controller for all pihole scripts and functions.
|
||||||
|
#
|
||||||
|
# This file is copyright under the latest version of the EUPL.
|
||||||
|
# Please see LICENSE file for your rights under this license.
|
||||||
|
|
||||||
|
# Ensure there is a newline at the end of the file passed as argument
|
||||||
|
ensure_newline() {
|
||||||
|
# Check if the last line of the passed file is empty, if not, append a newline
|
||||||
|
# to the file to ensure we can append new content safely using echo "" >>
|
||||||
|
# later on
|
||||||
|
[ -n "$(tail -c1 "${1}")" ] && printf '\n' >> "${1}"
|
||||||
|
# There was also the suggestion of using a sed-magic call here, however, this
|
||||||
|
# had the drawback to updating all the file timestamps whenever the sed was
|
||||||
|
# run. This solution only updates the timestamp when actually appending a
|
||||||
|
# newline
|
||||||
|
}
|
@@ -22,13 +22,21 @@ readonly gravityDBfile="/etc/pihole/gravity.db"
|
|||||||
|
|
||||||
# Source install script for ${setupVars}, ${PI_HOLE_BIN_DIR} and valid_ip()
|
# Source install script for ${setupVars}, ${PI_HOLE_BIN_DIR} and valid_ip()
|
||||||
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
||||||
|
setupVars=""
|
||||||
|
DHCP_IPv6=false
|
||||||
# shellcheck disable=SC2034 # used in basic-install
|
# shellcheck disable=SC2034 # used in basic-install
|
||||||
PH_TEST="true"
|
PH_TEST="true"
|
||||||
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
||||||
|
|
||||||
coltable="/opt/pihole/COL_TABLE"
|
# ensure_newline()
|
||||||
|
readonly utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||||
|
# shellcheck source=./utils.sh
|
||||||
|
source "${utilsfile}"
|
||||||
|
|
||||||
|
readonly coltable="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
||||||
if [[ -f ${coltable} ]]; then
|
if [[ -f ${coltable} ]]; then
|
||||||
source ${coltable}
|
# shellcheck source=./COL_TABLE
|
||||||
|
source "${coltable}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
helpFunc() {
|
helpFunc() {
|
||||||
@@ -49,6 +57,7 @@ Options:
|
|||||||
}
|
}
|
||||||
|
|
||||||
add_setting() {
|
add_setting() {
|
||||||
|
ensure_newline "${setupVars}"
|
||||||
echo "${1}=${2}" >> "${setupVars}"
|
echo "${1}=${2}" >> "${setupVars}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +71,7 @@ change_setting() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addFTLsetting() {
|
addFTLsetting() {
|
||||||
|
ensure_newline "${FTLconf}"
|
||||||
echo "${1}=${2}" >> "${FTLconf}"
|
echo "${1}=${2}" >> "${FTLconf}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +85,7 @@ changeFTLsetting() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
add_dnsmasq_setting() {
|
add_dnsmasq_setting() {
|
||||||
|
ensure_newline "${dnsmasqconfig}"
|
||||||
if [[ "${2}" != "" ]]; then
|
if [[ "${2}" != "" ]]; then
|
||||||
echo "${1}=${2}" >> "${dnsmasqconfig}"
|
echo "${1}=${2}" >> "${dnsmasqconfig}"
|
||||||
else
|
else
|
||||||
@@ -146,6 +157,7 @@ SetWebPassword() {
|
|||||||
ProcessDNSSettings() {
|
ProcessDNSSettings() {
|
||||||
source "${setupVars}"
|
source "${setupVars}"
|
||||||
|
|
||||||
|
ensure_newline "${dnsmasqconfig}"
|
||||||
delete_dnsmasq_setting "server"
|
delete_dnsmasq_setting "server"
|
||||||
|
|
||||||
COUNTER=1
|
COUNTER=1
|
||||||
@@ -392,6 +404,7 @@ ProcessDHCPSettings() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Write settings to file
|
# Write settings to file
|
||||||
|
# We do not need to ensure a newline here as the entire file is re-written
|
||||||
echo "###############################################################################
|
echo "###############################################################################
|
||||||
# DHCP SERVER CONFIG FILE AUTOMATICALLY POPULATED BY PI-HOLE WEB INTERFACE. #
|
# DHCP SERVER CONFIG FILE AUTOMATICALLY POPULATED BY PI-HOLE WEB INTERFACE. #
|
||||||
# ANY CHANGES MADE TO THIS FILE WILL BE LOST ON CHANGE #
|
# ANY CHANGES MADE TO THIS FILE WILL BE LOST ON CHANGE #
|
||||||
@@ -545,6 +558,7 @@ AddDHCPStaticAddress() {
|
|||||||
ip="${args[3]}"
|
ip="${args[3]}"
|
||||||
host="${args[4]}"
|
host="${args[4]}"
|
||||||
|
|
||||||
|
ensure_newline "${dhcpstaticconfig}"
|
||||||
if [[ "${ip}" == "noip" ]]; then
|
if [[ "${ip}" == "noip" ]]; then
|
||||||
# Static host name
|
# Static host name
|
||||||
echo "dhcp-host=${mac},${host}" >> "${dhcpstaticconfig}"
|
echo "dhcp-host=${mac},${host}" >> "${dhcpstaticconfig}"
|
||||||
@@ -689,6 +703,7 @@ AddCustomDNSAddress() {
|
|||||||
|
|
||||||
ip="${args[2]}"
|
ip="${args[2]}"
|
||||||
host="${args[3]}"
|
host="${args[3]}"
|
||||||
|
ensure_newline "${dnscustomfile}"
|
||||||
echo "${ip} ${host}" >> "${dnscustomfile}"
|
echo "${ip} ${host}" >> "${dnscustomfile}"
|
||||||
|
|
||||||
# Restart dnsmasq to load new custom DNS entries
|
# Restart dnsmasq to load new custom DNS entries
|
||||||
@@ -711,6 +726,7 @@ AddCustomCNAMERecord() {
|
|||||||
|
|
||||||
domain="${args[2]}"
|
domain="${args[2]}"
|
||||||
target="${args[3]}"
|
target="${args[3]}"
|
||||||
|
ensure_newline "${dnscustomcnamefile}"
|
||||||
echo "cname=${domain},${target}" >> "${dnscustomcnamefile}"
|
echo "cname=${domain},${target}" >> "${dnscustomcnamefile}"
|
||||||
|
|
||||||
# Restart dnsmasq to load new custom CNAME records
|
# Restart dnsmasq to load new custom CNAME records
|
||||||
|
25
pihole
25
pihole
@@ -18,9 +18,16 @@ 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"
|
||||||
|
# shellcheck source=./advanced/Scripts/COL_TABLE
|
||||||
source "${colfile}"
|
source "${colfile}"
|
||||||
|
|
||||||
|
# ensure_newline()
|
||||||
|
readonly utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||||
|
# shellcheck source=./advanced/Scripts/utils.sh
|
||||||
|
source "${utilsfile}"
|
||||||
|
|
||||||
webpageFunc() {
|
webpageFunc() {
|
||||||
|
# shellcheck source=./advanced/Scripts/webpage.sh
|
||||||
source "${PI_HOLE_SCRIPT_DIR}/webpage.sh"
|
source "${PI_HOLE_SCRIPT_DIR}/webpage.sh"
|
||||||
main "$@"
|
main "$@"
|
||||||
exit 0
|
exit 0
|
||||||
@@ -37,9 +44,13 @@ debugFunc() {
|
|||||||
|
|
||||||
# Pull off the `debug` leaving passed call augmentation flags in $1
|
# Pull off the `debug` leaving passed call augmentation flags in $1
|
||||||
shift
|
shift
|
||||||
|
# We do not want to be warned about implicit concatenation of array in [[ ]]
|
||||||
|
# as this is exactly what we want here
|
||||||
|
# shellcheck disable=SC2199
|
||||||
if [[ "$@" == *"-a"* ]]; then
|
if [[ "$@" == *"-a"* ]]; then
|
||||||
automated="true"
|
automated="true"
|
||||||
fi
|
fi
|
||||||
|
# shellcheck disable=SC2199
|
||||||
if [[ "$@" == *"-w"* ]]; then
|
if [[ "$@" == *"-w"* ]]; then
|
||||||
web="true"
|
web="true"
|
||||||
fi
|
fi
|
||||||
@@ -154,7 +165,7 @@ Time:
|
|||||||
echo -e " ${INFO} Blocking already disabled, nothing to do"
|
echo -e " ${INFO} Blocking already disabled, nothing to do"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
if [[ $# > 1 ]]; then
|
if [[ $# -gt 1 ]]; then
|
||||||
local error=false
|
local error=false
|
||||||
if [[ "${2}" == *"s" ]]; then
|
if [[ "${2}" == *"s" ]]; then
|
||||||
tt=${2%"s"}
|
tt=${2%"s"}
|
||||||
@@ -162,7 +173,7 @@ Time:
|
|||||||
local str="Disabling blocking for ${tt} seconds"
|
local str="Disabling blocking for ${tt} seconds"
|
||||||
echo -e " ${INFO} ${str}..."
|
echo -e " ${INFO} ${str}..."
|
||||||
local str="Blocking will be re-enabled in ${tt} seconds"
|
local str="Blocking will be re-enabled in ${tt} seconds"
|
||||||
nohup "${PI_HOLE_SCRIPT_DIR}"/pihole-reenable.sh ${tt} </dev/null &>/dev/null &
|
nohup "${PI_HOLE_SCRIPT_DIR}/pihole-reenable.sh" "${tt}" </dev/null &>/dev/null &
|
||||||
else
|
else
|
||||||
local error=true
|
local error=true
|
||||||
fi
|
fi
|
||||||
@@ -172,8 +183,8 @@ Time:
|
|||||||
local str="Disabling blocking for ${tt} minutes"
|
local str="Disabling blocking for ${tt} minutes"
|
||||||
echo -e " ${INFO} ${str}..."
|
echo -e " ${INFO} ${str}..."
|
||||||
local str="Blocking will be re-enabled in ${tt} minutes"
|
local str="Blocking will be re-enabled in ${tt} minutes"
|
||||||
tt=$((${tt}*60))
|
tt=$((tt*60))
|
||||||
nohup "${PI_HOLE_SCRIPT_DIR}"/pihole-reenable.sh ${tt} </dev/null &>/dev/null &
|
nohup "${PI_HOLE_SCRIPT_DIR}/pihole-reenable.sh" "${tt}" </dev/null &>/dev/null &
|
||||||
else
|
else
|
||||||
local error=true
|
local error=true
|
||||||
fi
|
fi
|
||||||
@@ -191,6 +202,7 @@ Time:
|
|||||||
|
|
||||||
local str="Pi-hole Disabled"
|
local str="Pi-hole Disabled"
|
||||||
sed -i "/BLOCKING_ENABLED=/d" "${setupVars}"
|
sed -i "/BLOCKING_ENABLED=/d" "${setupVars}"
|
||||||
|
ensure_newline "${setupVars}"
|
||||||
echo "BLOCKING_ENABLED=false" >> "${setupVars}"
|
echo "BLOCKING_ENABLED=false" >> "${setupVars}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -204,6 +216,7 @@ Time:
|
|||||||
local str="Pi-hole Enabled"
|
local str="Pi-hole Enabled"
|
||||||
|
|
||||||
sed -i "/BLOCKING_ENABLED=/d" "${setupVars}"
|
sed -i "/BLOCKING_ENABLED=/d" "${setupVars}"
|
||||||
|
ensure_newline "${setupVars}"
|
||||||
echo "BLOCKING_ENABLED=true" >> "${setupVars}"
|
echo "BLOCKING_ENABLED=true" >> "${setupVars}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -320,7 +333,8 @@ statusFunc() {
|
|||||||
|
|
||||||
tailFunc() {
|
tailFunc() {
|
||||||
# Warn user if Pi-hole's logging is disabled
|
# Warn user if Pi-hole's logging is disabled
|
||||||
local logging_enabled=$(grep -c "^log-queries" /etc/dnsmasq.d/01-pihole.conf)
|
local logging_enabled
|
||||||
|
logging_enabled=$(grep -c "^log-queries" /etc/dnsmasq.d/01-pihole.conf)
|
||||||
if [[ "${logging_enabled}" == "0" ]]; then
|
if [[ "${logging_enabled}" == "0" ]]; then
|
||||||
# No "log-queries" lines are found.
|
# No "log-queries" lines are found.
|
||||||
# Commented out lines (such as "#log-queries") are ignored
|
# Commented out lines (such as "#log-queries") are ignored
|
||||||
@@ -361,6 +375,7 @@ Branches:
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# shellcheck source=./advanced/Scripts/piholeCheckout.sh
|
||||||
source "${PI_HOLE_SCRIPT_DIR}"/piholeCheckout.sh
|
source "${PI_HOLE_SCRIPT_DIR}"/piholeCheckout.sh
|
||||||
shift
|
shift
|
||||||
checkout "$@"
|
checkout "$@"
|
||||||
|
Reference in New Issue
Block a user