Compare commits
52 Commits
master
...
developmen
Author | SHA1 | Date | |
---|---|---|---|
|
9356d7bbb1 | ||
|
29a867d5ae | ||
|
86dd612882 | ||
|
42d3368955 | ||
|
21ae81ffdb | ||
|
b33434d02a | ||
|
d3e94cbceb | ||
|
9b4f6c84cd | ||
|
4d31d5ee11 | ||
|
9878477896 | ||
|
c0a2ab7b77 | ||
|
30ba79f6a0 | ||
|
cd3c97f113 | ||
|
e4a1f3a175 | ||
|
6121c162ff | ||
|
0d74b27101 | ||
|
7fa8cdd03e | ||
|
fe9031b26f | ||
|
063f92f8f4 | ||
|
be6a73f102 | ||
|
69e4e9a2ae | ||
|
4230be0c80 | ||
|
efa99a177e | ||
|
5cebceadda | ||
|
722a716de3 | ||
|
614d18cd3d | ||
|
54ce8c2622 | ||
|
329c161054 | ||
|
f8e84b3c3f | ||
|
c9809371ab | ||
|
a48750e257 | ||
|
0d4c69cc6f | ||
|
479b2bc075 | ||
|
2ade05d60f | ||
|
59fc3804be | ||
|
48138d32b6 | ||
|
ff5e788889 | ||
|
ab7d83384f | ||
|
48136c5bbc | ||
|
0219e5dfe0 | ||
|
0631cb4984 | ||
|
40b96e673b | ||
|
36ca858668 | ||
|
16b732fe8a | ||
|
1bf2f8d0b7 | ||
|
c756bcb9d1 | ||
|
42424b515b | ||
|
bd956b5f16 | ||
|
9db19c5e96 | ||
|
91b4233d3a | ||
|
0b905c28c1 | ||
|
f4286a4d12 |
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -37,7 +37,7 @@ jobs:
|
||||
uses: actions/checkout@v2
|
||||
-
|
||||
name: Set up Python 3.8
|
||||
uses: actions/setup-python@v2
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: 3.8
|
||||
-
|
||||
|
@@ -161,4 +161,4 @@ Some notable features include:
|
||||
There are several ways to [access the dashboard](https://discourse.pi-hole.net/t/how-do-i-access-pi-holes-dashboard-admin-interface/3168):
|
||||
|
||||
1. `http://pi.hole/admin/` (when using Pi-hole as your DNS server)
|
||||
2. `http://<IP_ADDPRESS_OF_YOUR_PI_HOLE>/admin/`
|
||||
2. `http://<IP_ADDRESS_OF_YOUR_PI_HOLE>/admin/`
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# Determine if terminal is capable of showing colors
|
||||
if [[ -t 1 ]] && [[ $(tput colors) -ge 8 ]]; then
|
||||
if ([[ -t 1 ]] && [[ $(tput colors) -ge 8 ]]) || [[ "${WEBCALL}" ]]; then
|
||||
# Bold and underline may not show up on all clients
|
||||
# If something MUST be emphasized, use both
|
||||
COL_BOLD='[1m'
|
||||
|
@@ -906,9 +906,11 @@ dig_at() {
|
||||
# Removes all interfaces which are not UP
|
||||
# s/^[0-9]*: //g;
|
||||
# Removes interface index
|
||||
# s/@.*//g;
|
||||
# Removes everything after @ (if found)
|
||||
# s/: <.*//g;
|
||||
# Removes everything after the interface name
|
||||
interfaces="$(ip link show | sed "/ master /d;/UP/!d;s/^[0-9]*: //g;s/: <.*//g;")"
|
||||
interfaces="$(ip link show | sed "/ master /d;/UP/!d;s/^[0-9]*: //g;s/@.*//g;s/: <.*//g;")"
|
||||
|
||||
while IFS= read -r iface ; do
|
||||
# Get addresses of current interface
|
||||
@@ -1273,7 +1275,7 @@ show_clients() {
|
||||
}
|
||||
|
||||
show_messages() {
|
||||
show_FTL_db_entries "Pi-hole diagnosis messages" "SELECT id,datetime(timestamp,'unixepoch','localtime') timestamp,type,message,blob1,blob2,blob3,blob4,blob5 FROM message;" "4 19 20 60 20 20 20 20 20"
|
||||
show_FTL_db_entries "Pi-hole diagnosis messages" "SELECT count (message) as count, datetime(max(timestamp),'unixepoch','localtime') as 'last timestamp', type, message, blob1, blob2, blob3, blob4, blob5 FROM message GROUP BY type, message, blob1, blob2, blob3, blob4, blob5;" "6 19 20 60 20 20 20 20 20"
|
||||
}
|
||||
|
||||
analyze_gravity_list() {
|
||||
|
@@ -63,7 +63,7 @@ else
|
||||
fi
|
||||
fi
|
||||
# Delete most recent 24 hours from FTL's database, leave even older data intact (don't wipe out all history)
|
||||
deleted=$(pihole-FTL sqlite3 "${DBFILE}" "DELETE FROM queries WHERE timestamp >= strftime('%s','now')-86400; select changes() from queries limit 1")
|
||||
deleted=$(pihole-FTL sqlite3 "${DBFILE}" "DELETE FROM query_storage WHERE timestamp >= strftime('%s','now')-86400; select changes() from query_storage limit 1")
|
||||
|
||||
# Restart pihole-FTL to force reloading history
|
||||
sudo pihole restartdns
|
||||
|
@@ -64,8 +64,8 @@ Example: 'pihole -q -exact domain.com'
|
||||
Query the adlists for a specified domain
|
||||
|
||||
Options:
|
||||
-exact Search the block lists for exact domain matches
|
||||
-all Return all query matches within a block list
|
||||
-exact Search the adlists for exact domain matches
|
||||
-all Return all query matches within the adlists
|
||||
-h, --help Show this help dialog"
|
||||
exit 0
|
||||
fi
|
||||
@@ -210,7 +210,7 @@ mapfile -t results <<< "$(scanDatabaseTable "${domainQuery}" "gravity")"
|
||||
|
||||
# Handle notices
|
||||
if [[ -z "${wbMatch:-}" ]] && [[ -z "${wcMatch:-}" ]] && [[ -z "${results[*]}" ]]; then
|
||||
echo -e " ${INFO} No ${exact/t/t }results found for ${COL_BOLD}${domainQuery}${COL_NC} within the block lists"
|
||||
echo -e " ${INFO} No ${exact/t/t }results found for ${COL_BOLD}${domainQuery}${COL_NC} within the adlists"
|
||||
exit 0
|
||||
elif [[ -z "${results[*]}" ]]; then
|
||||
# Result found in WL/BL/Wildcards
|
||||
|
@@ -1,4 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env sh
|
||||
# shellcheck disable=SC3043 #https://github.com/koalaman/shellcheck/wiki/SC3043#exceptions
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||
# Network-wide ad blocking via your own hardware.
|
||||
@@ -15,21 +17,76 @@
|
||||
# - New functions must have a test added for them in test/test_any_utils.py
|
||||
|
||||
#######################
|
||||
# Takes three arguments key, value, and file.
|
||||
# Takes either
|
||||
# - Three arguments: file, key, and value.
|
||||
# - Two arguments: file, and key.
|
||||
#
|
||||
# Checks the target file for the existence of the key
|
||||
# - If it exists, it changes the value
|
||||
# - If it does not exist, it adds the value
|
||||
#
|
||||
# Example usage:
|
||||
# addOrEditKeyValuePair "BLOCKING_ENABLED" "true" "/etc/pihole/setupVars.conf"
|
||||
# addOrEditKeyValuePair "/etc/pihole/setupVars.conf" "BLOCKING_ENABLED" "true"
|
||||
#######################
|
||||
addOrEditKeyValPair() {
|
||||
local key="${1}"
|
||||
local value="${2}"
|
||||
local file="${3}"
|
||||
if grep -q "^${key}=" "${file}"; then
|
||||
sed -i "/^${key}=/c\\${key}=${value}" "${file}"
|
||||
local file="${1}"
|
||||
local key="${2}"
|
||||
local value="${3}"
|
||||
|
||||
if [ "${value}" != "" ]; then
|
||||
# value has a value, so it is a key-value pair
|
||||
if grep -q "^${key}=" "${file}"; then
|
||||
# Key already exists in file, modify the value
|
||||
sed -i "/^${key}=/c\\${key}=${value}" "${file}"
|
||||
else
|
||||
# Key does not already exist, add it and it's value
|
||||
echo "${key}=${value}" >> "${file}"
|
||||
fi
|
||||
else
|
||||
echo "${key}=${value}" >> "${file}"
|
||||
# value has no value, so it is just a key. Add it if it does not already exist
|
||||
if ! grep -q "^${key}" "${file}"; then
|
||||
# Key does not exist, add it.
|
||||
echo "${key}" >> "${file}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
#######################
|
||||
# Takes two arguments file, and key.
|
||||
# Deletes a key from target file
|
||||
#
|
||||
# Example usage:
|
||||
# removeKey "/etc/pihole/setupVars.conf" "PIHOLE_DNS_1"
|
||||
#######################
|
||||
removeKey() {
|
||||
local file="${1}"
|
||||
local key="${2}"
|
||||
sed -i "/^${key}/d" "${file}"
|
||||
}
|
||||
|
||||
#######################
|
||||
# returns FTL's current telnet API port
|
||||
#######################
|
||||
getFTLAPIPort(){
|
||||
local FTLCONFFILE="/etc/pihole/pihole-FTL.conf"
|
||||
local DEFAULT_PORT_FILE="/run/pihole-FTL.port"
|
||||
local DEFAULT_FTL_PORT=4711
|
||||
local PORTFILE
|
||||
local ftl_api_port
|
||||
|
||||
if [ -f "$FTLCONFFILE" ]; then
|
||||
# if PORTFILE is not set in pihole-FTL.conf, use the default path
|
||||
PORTFILE="$( (grep "^PORTFILE=" $FTLCONFFILE || echo "$DEFAULT_PORT_FILE") | cut -d"=" -f2-)"
|
||||
fi
|
||||
|
||||
if [ -s "$PORTFILE" ]; then
|
||||
# -s: FILE exists and has a size greater than zero
|
||||
ftl_api_port=$(cat "${PORTFILE}")
|
||||
# Exploit prevention: unset the variable if there is malicious content
|
||||
# Verify that the value read from the file is numeric
|
||||
expr "$ftl_api_port" : "[^[:digit:]]" > /dev/null && unset ftl_api_port
|
||||
fi
|
||||
|
||||
# echo the port found in the portfile or default to the default port
|
||||
echo "${ftl_api_port:=$DEFAULT_FTL_PORT}"
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1090
|
||||
# shellcheck disable=SC2154
|
||||
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||
@@ -26,6 +28,9 @@ readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
||||
PH_TEST="true"
|
||||
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
||||
|
||||
utilsfile="/opt/pihole/utils.sh"
|
||||
source "${utilsfile}"
|
||||
|
||||
coltable="/opt/pihole/COL_TABLE"
|
||||
if [[ -f ${coltable} ]]; then
|
||||
source ${coltable}
|
||||
@@ -51,41 +56,35 @@ Options:
|
||||
}
|
||||
|
||||
add_setting() {
|
||||
echo "${1}=${2}" >> "${setupVars}"
|
||||
addOrEditKeyValPair "${setupVars}" "${1}" "${2}"
|
||||
}
|
||||
|
||||
delete_setting() {
|
||||
sed -i "/^${1}/d" "${setupVars}"
|
||||
removeKey "${setupVars}" "${1}"
|
||||
}
|
||||
|
||||
change_setting() {
|
||||
delete_setting "${1}"
|
||||
add_setting "${1}" "${2}"
|
||||
addOrEditKeyValPair "${setupVars}" "${1}" "${2}"
|
||||
}
|
||||
|
||||
addFTLsetting() {
|
||||
echo "${1}=${2}" >> "${FTLconf}"
|
||||
addOrEditKeyValPair "${FTLconf}" "${1}" "${2}"
|
||||
}
|
||||
|
||||
deleteFTLsetting() {
|
||||
sed -i "/^${1}/d" "${FTLconf}"
|
||||
removeKey "${FTLconf}" "${1}"
|
||||
}
|
||||
|
||||
changeFTLsetting() {
|
||||
deleteFTLsetting "${1}"
|
||||
addFTLsetting "${1}" "${2}"
|
||||
addOrEditKeyValPair "${FTLconf}" "${1}" "${2}"
|
||||
}
|
||||
|
||||
add_dnsmasq_setting() {
|
||||
if [[ "${2}" != "" ]]; then
|
||||
echo "${1}=${2}" >> "${dnsmasqconfig}"
|
||||
else
|
||||
echo "${1}" >> "${dnsmasqconfig}"
|
||||
fi
|
||||
addOrEditKeyValPair "${dnsmasqconfig}" "${1}" "${2}"
|
||||
}
|
||||
|
||||
delete_dnsmasq_setting() {
|
||||
sed -i "/^${1}/d" "${dnsmasqconfig}"
|
||||
removeKey "${dnsmasqconfig}" "${1}"
|
||||
}
|
||||
|
||||
SetTemperatureUnit() {
|
||||
@@ -183,7 +182,7 @@ ProcessDNSSettings() {
|
||||
fi
|
||||
|
||||
delete_dnsmasq_setting "dnssec"
|
||||
delete_dnsmasq_setting "trust-anchor="
|
||||
delete_dnsmasq_setting "trust-anchor"
|
||||
|
||||
if [[ "${DNSSEC}" == true ]]; then
|
||||
echo "dnssec
|
||||
@@ -808,6 +807,23 @@ RemoveCustomCNAMERecord() {
|
||||
fi
|
||||
}
|
||||
|
||||
SetRateLimit() {
|
||||
local rate_limit_count rate_limit_interval reload
|
||||
rate_limit_count="${args[2]}"
|
||||
rate_limit_interval="${args[3]}"
|
||||
reload="${args[4]}"
|
||||
|
||||
# Set rate-limit setting inf valid
|
||||
if [ "${rate_limit_count}" -ge 0 ] && [ "${rate_limit_interval}" -ge 0 ]; then
|
||||
changeFTLsetting "RATE_LIMIT" "${rate_limit_count}/${rate_limit_interval}"
|
||||
fi
|
||||
|
||||
# Restart FTL to update rate-limit settings only if $reload not false
|
||||
if [[ ! $reload == "false" ]]; then
|
||||
RestartDNS
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
args=("$@")
|
||||
|
||||
@@ -841,6 +857,7 @@ main() {
|
||||
"removecustomdns" ) RemoveCustomDNSAddress;;
|
||||
"addcustomcname" ) AddCustomCNAMERecord;;
|
||||
"removecustomcname" ) RemoveCustomCNAMERecord;;
|
||||
"ratelimit" ) SetRateLimit;;
|
||||
* ) helpFunc;;
|
||||
esac
|
||||
|
||||
|
@@ -164,13 +164,35 @@ ini_set("default_socket_timeout", 3);
|
||||
function queryAds($serverName) {
|
||||
// Determine the time it takes while querying adlists
|
||||
$preQueryTime = microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"];
|
||||
|
||||
// Determine which protocol should be used
|
||||
$protocol = "http";
|
||||
if ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ||
|
||||
(isset($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] === 'https') ||
|
||||
(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')
|
||||
) {
|
||||
$protocol = "https";
|
||||
}
|
||||
|
||||
// Format the URL
|
||||
$queryAdsURL = sprintf(
|
||||
"http://127.0.0.1:%s/admin/scripts/pi-hole/php/queryads.php?domain=%s&bp",
|
||||
"%s://127.0.0.1:%s/admin/scripts/pi-hole/php/queryads.php?domain=%s&bp",
|
||||
$protocol,
|
||||
$_SERVER["SERVER_PORT"],
|
||||
$serverName
|
||||
);
|
||||
$queryAds = file($queryAdsURL, FILE_IGNORE_NEW_LINES);
|
||||
$queryAds = array_values(array_filter(preg_replace("/data:\s+/", "", $queryAds)));
|
||||
|
||||
// Request the file and receive the response
|
||||
$queryAdsFile = file($queryAdsURL, FILE_IGNORE_NEW_LINES);
|
||||
|
||||
// $queryAdsFile must be an array (to avoid PHP 8.0+ error)
|
||||
if (is_array($queryAdsFile)) {
|
||||
$queryAds = array_values(array_filter(preg_replace("/data:\s+/", "", $queryAdsFile)));
|
||||
} else {
|
||||
// if not an array, return an error message
|
||||
return array("0" => "error", "1" => "<br>(".gettype($queryAdsFile).")<br>".print_r($queryAdsFile, true));
|
||||
}
|
||||
|
||||
$queryTime = sprintf("%.0f", (microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"]) - $preQueryTime);
|
||||
|
||||
// Exception Handling
|
||||
|
@@ -36,6 +36,11 @@ server.port = 80
|
||||
accesslog.filename = "/var/log/lighttpd/access.log"
|
||||
accesslog.format = "%{%s}t|%V|%r|%s|%b"
|
||||
|
||||
# Allow streaming response
|
||||
# reference: https://redmine.lighttpd.net/projects/lighttpd/wiki/Server_stream-response-bodyDetails
|
||||
server.stream-response-body = 1
|
||||
#ssl.read-ahead = "disable"
|
||||
|
||||
index-file.names = ( "index.php", "index.html", "index.lighttpd.html" )
|
||||
url.access-deny = ( "~", ".inc", ".md", ".yml", ".ini" )
|
||||
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
|
||||
|
@@ -37,6 +37,11 @@ server.port = 80
|
||||
accesslog.filename = "/var/log/lighttpd/access.log"
|
||||
accesslog.format = "%{%s}t|%V|%r|%s|%b"
|
||||
|
||||
# Allow streaming response
|
||||
# reference: https://redmine.lighttpd.net/projects/lighttpd/wiki/Server_stream-response-bodyDetails
|
||||
server.stream-response-body = 1
|
||||
#ssl.read-ahead = "disable"
|
||||
|
||||
index-file.names = ( "index.php", "index.html", "index.lighttpd.html" )
|
||||
url.access-deny = ( "~", ".inc", ".md", ".yml", ".ini" )
|
||||
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
|
||||
|
@@ -259,6 +259,29 @@ os_check() {
|
||||
fi
|
||||
}
|
||||
|
||||
# This function waits for dpkg to unlock, which signals that the previous apt-get command has finished.
|
||||
test_dpkg_lock() {
|
||||
i=0
|
||||
printf " %b Waiting for package manager to finish (up to 30 seconds)\\n" "${INFO}"
|
||||
# fuser is a program to show which processes use the named files, sockets, or filesystems
|
||||
# So while the lock is held,
|
||||
while fuser /var/lib/dpkg/lock >/dev/null 2>&1
|
||||
do
|
||||
# we wait half a second,
|
||||
sleep 0.5
|
||||
# increase the iterator,
|
||||
((i=i+1))
|
||||
# exit if waiting for more then 30 seconds
|
||||
if [[ $i -gt 60 ]]; then
|
||||
printf " %b %bError: Could not verify package manager finished and released lock. %b\\n" "${CROSS}" "${COL_LIGHT_RED}" "${COL_NC}"
|
||||
printf " Attempt to install packages manually and retry.\\n"
|
||||
exit 1;
|
||||
fi
|
||||
done
|
||||
# and then report success once dpkg is unlocked.
|
||||
return 0
|
||||
}
|
||||
|
||||
# Compatibility
|
||||
package_manager_detect() {
|
||||
# First check to see if apt-get is installed.
|
||||
@@ -287,7 +310,7 @@ package_manager_detect() {
|
||||
# Packages required to run this install script (stored as an array)
|
||||
INSTALLER_DEPS=(git iproute2 whiptail ca-certificates)
|
||||
# Packages required to run Pi-hole (stored as an array)
|
||||
PIHOLE_DEPS=(cron curl iputils-ping psmisc sudo unzip idn2 libcap2-bin dns-root-data libcap2 netcat-openbsd)
|
||||
PIHOLE_DEPS=(cron curl iputils-ping psmisc sudo unzip idn2 libcap2-bin dns-root-data libcap2 netcat-openbsd procps)
|
||||
# Packages required for the Web admin interface (stored as an array)
|
||||
# It's useful to separate this from Pi-hole, since the two repos are also setup separately
|
||||
PIHOLE_WEB_DEPS=(lighttpd "${phpVer}-common" "${phpVer}-cgi" "${phpVer}-sqlite3" "${phpVer}-xml" "${phpVer}-intl")
|
||||
@@ -302,22 +325,6 @@ package_manager_detect() {
|
||||
# and config file
|
||||
LIGHTTPD_CFG="lighttpd.conf.debian"
|
||||
|
||||
# This function waits for dpkg to unlock, which signals that the previous apt-get command has finished.
|
||||
test_dpkg_lock() {
|
||||
i=0
|
||||
# fuser is a program to show which processes use the named files, sockets, or filesystems
|
||||
# So while the lock is held,
|
||||
while fuser /var/lib/dpkg/lock >/dev/null 2>&1
|
||||
do
|
||||
# we wait half a second,
|
||||
sleep 0.5
|
||||
# increase the iterator,
|
||||
((i=i+1))
|
||||
done
|
||||
# and then report success once dpkg is unlocked.
|
||||
return 0
|
||||
}
|
||||
|
||||
# If apt-get is not found, check for rpm.
|
||||
elif is_command rpm ; then
|
||||
# Then check if dnf or yum is the package manager
|
||||
|
@@ -11,10 +11,9 @@
|
||||
source "/opt/pihole/COL_TABLE"
|
||||
|
||||
while true; do
|
||||
read -rp " ${QST} Are you sure you would like to remove ${COL_WHITE}Pi-hole${COL_NC}? [y/N] " yn
|
||||
case ${yn} in
|
||||
read -rp " ${QST} Are you sure you would like to remove ${COL_WHITE}Pi-hole${COL_NC}? [y/N] " answer
|
||||
case ${answer} in
|
||||
[Yy]* ) break;;
|
||||
[Nn]* ) echo -e "${OVER} ${COL_LIGHT_GREEN}Uninstall has been canceled${COL_NC}"; exit 0;;
|
||||
* ) echo -e "${OVER} ${COL_LIGHT_GREEN}Uninstall has been canceled${COL_NC}"; exit 0;;
|
||||
esac
|
||||
done
|
||||
@@ -76,8 +75,8 @@ removeAndPurge() {
|
||||
for i in "${DEPS[@]}"; do
|
||||
if package_check "${i}" > /dev/null; then
|
||||
while true; do
|
||||
read -rp " ${QST} Do you wish to remove ${COL_WHITE}${i}${COL_NC} from your system? [Y/N] " yn
|
||||
case ${yn} in
|
||||
read -rp " ${QST} Do you wish to remove ${COL_WHITE}${i}${COL_NC} from your system? [Y/N] " answer
|
||||
case ${answer} in
|
||||
[Yy]* )
|
||||
echo -ne " ${INFO} Removing ${i}...";
|
||||
${SUDO} "${PKG_REMOVE[@]}" "${i}" &> /dev/null;
|
||||
@@ -215,8 +214,8 @@ while true; do
|
||||
echo -n "${i} "
|
||||
done
|
||||
echo "${COL_NC}"
|
||||
read -rp " ${QST} Do you wish to go through each dependency for removal? (Choosing No will leave all dependencies installed) [Y/n] " yn
|
||||
case ${yn} in
|
||||
read -rp " ${QST} Do you wish to go through each dependency for removal? (Choosing No will leave all dependencies installed) [Y/n] " answer
|
||||
case ${answer} in
|
||||
[Yy]* ) removeAndPurge; break;;
|
||||
[Nn]* ) removeNoPurge; break;;
|
||||
* ) removeAndPurge; break;;
|
||||
|
61
pihole
61
pihole
@@ -21,7 +21,7 @@ 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"
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
source "${utilsfile}"
|
||||
|
||||
webpageFunc() {
|
||||
@@ -226,7 +226,7 @@ Time:
|
||||
fi
|
||||
|
||||
local str="Pi-hole Disabled"
|
||||
addOrEditKeyValPair "BLOCKING_ENABLED" "false" "${setupVars}"
|
||||
addOrEditKeyValPair "${setupVars}" "BLOCKING_ENABLED" "false"
|
||||
fi
|
||||
else
|
||||
# Enable Pi-hole
|
||||
@@ -238,7 +238,7 @@ Time:
|
||||
echo -e " ${INFO} Enabling blocking"
|
||||
local str="Pi-hole Enabled"
|
||||
|
||||
addOrEditKeyValPair "BLOCKING_ENABLED" "true" "${setupVars}"
|
||||
addOrEditKeyValPair "${setupVars}" "BLOCKING_ENABLED" "true"
|
||||
fi
|
||||
|
||||
restartDNS reload-lists
|
||||
@@ -260,8 +260,8 @@ Options:
|
||||
exit 0
|
||||
elif [[ "${1}" == "off" ]]; then
|
||||
# Disable logging
|
||||
sed -i 's/^log-queries/#log-queries/' /etc/dnsmasq.d/01-pihole.conf
|
||||
addOrEditKeyValPair "QUERY_LOGGING" "false" "${setupVars}"
|
||||
addOrEditKeyValPair /etc/dnsmasq.d/01-pihole.conf "log-queries"
|
||||
addOrEditKeyValPair "${setupVars}" "QUERY_LOGGING" "false"
|
||||
if [[ "${2}" != "noflush" ]]; then
|
||||
# Flush logs
|
||||
"${PI_HOLE_BIN_DIR}"/pihole -f
|
||||
@@ -270,8 +270,8 @@ Options:
|
||||
local str="Logging has been disabled!"
|
||||
elif [[ "${1}" == "on" ]]; then
|
||||
# Enable logging
|
||||
sed -i 's/^#log-queries/log-queries/' /etc/dnsmasq.d/01-pihole.conf
|
||||
addOrEditKeyValPair "QUERY_LOGGING" "true" "${setupVars}"
|
||||
removeKey /etc/dnsmasq.d/01-pihole.conf "log-queries"
|
||||
addOrEditKeyValPair "${setupVars}" "QUERY_LOGGING" "true"
|
||||
echo -e " ${INFO} Enabling logging..."
|
||||
local str="Logging has been enabled!"
|
||||
else
|
||||
@@ -316,9 +316,10 @@ analyze_ports() {
|
||||
|
||||
statusFunc() {
|
||||
# Determine if there is pihole-FTL service is listening
|
||||
local listening pid port
|
||||
local pid port ftl_api_port
|
||||
|
||||
pid="$(getFTLPID)"
|
||||
ftl_api_port="$(getFTLAPIPort)"
|
||||
if [[ "$pid" -eq "-1" ]]; then
|
||||
case "${1}" in
|
||||
"web") echo "-1";;
|
||||
@@ -326,8 +327,8 @@ statusFunc() {
|
||||
esac
|
||||
return 0
|
||||
else
|
||||
#get the port pihole-FTL is listening on by using FTL's telnet API
|
||||
port="$(echo ">dns-port >quit" | nc 127.0.0.1 4711)"
|
||||
#get the DNS port pihole-FTL is listening on by using FTL's telnet API
|
||||
port="$(echo ">dns-port >quit" | nc 127.0.0.1 "$ftl_api_port")"
|
||||
if [[ "${port}" == "0" ]]; then
|
||||
case "${1}" in
|
||||
"web") echo "-1";;
|
||||
@@ -364,7 +365,7 @@ statusFunc() {
|
||||
# Enable blocking
|
||||
"${PI_HOLE_BIN_DIR}"/pihole enable
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
tailFunc() {
|
||||
@@ -495,8 +496,38 @@ if [[ $# = 0 ]]; then
|
||||
helpFunc
|
||||
fi
|
||||
|
||||
# functions that do not require sudo power
|
||||
case "${1}" in
|
||||
"-h" | "help" | "--help" ) helpFunc;;
|
||||
"-v" | "version" ) versionFunc "$@";;
|
||||
"-c" | "chronometer" ) chronometerFunc "$@";;
|
||||
"-q" | "query" ) queryFunc "$@";;
|
||||
"status" ) statusFunc "$2";;
|
||||
"-t" | "tail" ) tailFunc "$2";;
|
||||
"tricorder" ) tricorderFunc;;
|
||||
|
||||
# we need to add all arguments that require sudo power to not trigger the * argument
|
||||
"-w" | "whitelist" ) ;;
|
||||
"-b" | "blacklist" ) ;;
|
||||
"--wild" | "wildcard" ) ;;
|
||||
"--regex" | "regex" ) ;;
|
||||
"--white-regex" | "white-regex" ) ;;
|
||||
"--white-wild" | "white-wild" ) ;;
|
||||
"-f" | "flush" ) ;;
|
||||
"-up" | "updatePihole" ) ;;
|
||||
"-r" | "reconfigure" ) ;;
|
||||
"-g" | "updateGravity" ) ;;
|
||||
"-l" | "logging" ) ;;
|
||||
"uninstall" ) ;;
|
||||
"enable" ) ;;
|
||||
"disable" ) ;;
|
||||
"-d" | "debug" ) ;;
|
||||
"restartdns" ) ;;
|
||||
"-a" | "admin" ) ;;
|
||||
"checkout" ) ;;
|
||||
"updatechecker" ) ;;
|
||||
"arpflush" ) ;;
|
||||
* ) helpFunc;;
|
||||
esac
|
||||
|
||||
# Must be root to use this tool
|
||||
@@ -523,21 +554,13 @@ case "${1}" in
|
||||
"-up" | "updatePihole" ) updatePiholeFunc "$@";;
|
||||
"-r" | "reconfigure" ) reconfigurePiholeFunc;;
|
||||
"-g" | "updateGravity" ) updateGravityFunc "$@";;
|
||||
"-c" | "chronometer" ) chronometerFunc "$@";;
|
||||
"-h" | "help" ) helpFunc;;
|
||||
"-v" | "version" ) versionFunc "$@";;
|
||||
"-q" | "query" ) queryFunc "$@";;
|
||||
"-l" | "logging" ) piholeLogging "$@";;
|
||||
"uninstall" ) uninstallFunc;;
|
||||
"enable" ) piholeEnable 1;;
|
||||
"disable" ) piholeEnable 0 "$2";;
|
||||
"status" ) statusFunc "$2";;
|
||||
"restartdns" ) restartDNS "$2";;
|
||||
"-a" | "admin" ) webpageFunc "$@";;
|
||||
"-t" | "tail" ) tailFunc "$2";;
|
||||
"checkout" ) piholeCheckoutFunc "$@";;
|
||||
"tricorder" ) tricorderFunc;;
|
||||
"updatechecker" ) updateCheckFunc "$@";;
|
||||
"arpflush" ) arpFunc "$@";;
|
||||
* ) helpFunc;;
|
||||
esac
|
||||
|
@@ -1,4 +1,4 @@
|
||||
FROM buildpack-deps:hirsute-scm
|
||||
FROM buildpack-deps:impish-scm
|
||||
|
||||
ENV GITDIR /etc/.pihole
|
||||
ENV SCRIPTDIR /opt/pihole
|
||||
|
@@ -1,16 +1,56 @@
|
||||
def test_key_val_replacement_works(host):
|
||||
''' Confirms addOrEditKeyValPair provides the expected output '''
|
||||
host.run('''
|
||||
setupvars=./testoutput
|
||||
source /opt/pihole/utils.sh
|
||||
addOrEditKeyValPair "KEY_ONE" "value1" "./testoutput"
|
||||
addOrEditKeyValPair "KEY_TWO" "value2" "./testoutput"
|
||||
addOrEditKeyValPair "KEY_ONE" "value3" "./testoutput"
|
||||
addOrEditKeyValPair "KEY_FOUR" "value4" "./testoutput"
|
||||
cat ./testoutput
|
||||
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1"
|
||||
addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2"
|
||||
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value3"
|
||||
addOrEditKeyValPair "./testoutput" "KEY_FOUR" "value4"
|
||||
addOrEditKeyValPair "./testoutput" "KEY_FIVE_NO_VALUE"
|
||||
addOrEditKeyValPair "./testoutput" "KEY_FIVE_NO_VALUE"
|
||||
''')
|
||||
output = host.run('''
|
||||
cat ./testoutput
|
||||
''')
|
||||
expected_stdout = 'KEY_ONE=value3\nKEY_TWO=value2\nKEY_FOUR=value4\n'
|
||||
expected_stdout = 'KEY_ONE=value3\nKEY_TWO=value2\nKEY_FOUR=value4\nKEY_FIVE_NO_VALUE\n'
|
||||
assert expected_stdout == output.stdout
|
||||
|
||||
|
||||
def test_key_val_removal_works(host):
|
||||
''' Confirms removeKey provides the expected output '''
|
||||
host.run('''
|
||||
source /opt/pihole/utils.sh
|
||||
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1"
|
||||
addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2"
|
||||
addOrEditKeyValPair "./testoutput" "KEY_THREE" "value3"
|
||||
removeKey "./testoutput" "KEY_TWO"
|
||||
''')
|
||||
output = host.run('''
|
||||
cat ./testoutput
|
||||
''')
|
||||
expected_stdout = 'KEY_ONE=value1\nKEY_THREE=value3\n'
|
||||
assert expected_stdout == output.stdout
|
||||
|
||||
|
||||
def test_getFTLAPIPort_default(host):
|
||||
''' Confirms getFTLAPIPort returns the default API port '''
|
||||
output = host.run('''
|
||||
source /opt/pihole/utils.sh
|
||||
getFTLAPIPort
|
||||
''')
|
||||
expected_stdout = '4711\n'
|
||||
assert expected_stdout == output.stdout
|
||||
|
||||
|
||||
def test_getFTLAPIPort_custom(host):
|
||||
''' Confirms getFTLAPIPort returns a custom API port in a custom PORTFILE location '''
|
||||
host.run('''
|
||||
echo "PORTFILE=/tmp/port.file" > /etc/pihole/pihole-FTL.conf
|
||||
echo "1234" > /tmp/port.file
|
||||
''')
|
||||
output = host.run('''
|
||||
source /opt/pihole/utils.sh
|
||||
getFTLAPIPort
|
||||
''')
|
||||
expected_stdout = '1234\n'
|
||||
assert expected_stdout == output.stdout
|
||||
|
Reference in New Issue
Block a user