diff --git a/advanced/01-pihole.conf b/advanced/01-pihole.conf index 8b772ae8..f7b78ab0 100644 --- a/advanced/01-pihole.conf +++ b/advanced/01-pihole.conf @@ -42,6 +42,6 @@ cache-size=10000 log-queries log-facility=/var/log/pihole.log -local-ttl=300 +local-ttl=2 log-async diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 86589083..a3f3261a 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -66,15 +66,15 @@ HandleOther() { domain="${1,,}" # Check validity of domain - validDomain=$(perl -lne 'print if /^((-|_)*[a-z\d]((-|_)*[a-z\d])*(-|_)*)(\.(-|_)*([a-z\d]((-|_)*[a-z\d])*))*$/' <<< "${domain}") # Valid chars check - validDomain=$(perl -lne 'print if /^.{1,253}$/' <<< "${validDomain}") # Overall length check - validDomain=$(perl -lne 'print if /^[^\.]{1,63}(\.[^\.]{1,63})*$/' <<< "${validDomain}") # Length of each label + if [[ "${#domain}" -le 253 ]]; then + validDomain=$(grep -P "^((-|_)*[a-z\d]((-|_)*[a-z\d])*(-|_)*)(\.(-|_)*([a-z\d]((-|_)*[a-z\d])*))*$" <<< "${domain}") # Valid chars check + validDomain=$(grep -P "^[^\.]{1,63}(\.[^\.]{1,63})*$" <<< "${validDomain}") # Length of each label + fi - if [[ -z "${validDomain}" ]]; then - echo -e " ${CROSS} $1 is not a valid argument or domain name!" - else - echo -e " ${TICK} $1 is a valid domain name!" + if [[ -n "${validDomain}" ]]; then domList=("${domList[@]}" ${validDomain}) + else + echo -e " ${CROSS} ${domain} is not a valid argument or domain name!" fi } @@ -107,6 +107,8 @@ AddDomain() { [[ "${list}" == "${wildcardlist}" ]] && listname="wildcard blacklist" if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then + [[ "${list}" == "${whitelist}" && -z "${type}" ]] && type="--whitelist-only" + [[ "${list}" == "${blacklist}" && -z "${type}" ]] && type="--blacklist-only" bool=true # Is the domain in the list we want to add it to? grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false @@ -129,7 +131,7 @@ AddDomain() { # Remove the /* from the end of the IP addresses IPV4_ADDRESS=${IPV4_ADDRESS%/*} IPV6_ADDRESS=${IPV6_ADDRESS%/*} - + [[ -z "${type}" ]] && type="--wildcard-only" bool=true # Is the domain in the list? grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false @@ -138,7 +140,7 @@ AddDomain() { if [[ "${verbose}" == true ]]; then echo -e " ${INFO} Adding $1 to wildcard blacklist..." fi - reload=true + reload="restart" echo "address=/$1/${IPV4_ADDRESS}" >> "${wildcardlist}" if [[ "${#IPV6_ADDRESS}" > 0 ]]; then echo "address=/$1/${IPV6_ADDRESS}" >> "${wildcardlist}" @@ -161,6 +163,8 @@ RemoveDomain() { if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then bool=true + [[ "${list}" == "${whitelist}" && -z "${type}" ]] && type="--whitelist-only" + [[ "${list}" == "${blacklist}" && -z "${type}" ]] && type="--blacklist-only" # Is it in the list? Logic follows that if its whitelisted it should not be blacklisted and vice versa grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false if [[ "${bool}" == true ]]; then @@ -175,6 +179,7 @@ RemoveDomain() { fi fi elif [[ "${list}" == "${wildcardlist}" ]]; then + [[ -z "${type}" ]] && type="--wildcard-only" bool=true # Is it in the list? grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false @@ -192,12 +197,10 @@ RemoveDomain() { fi } +# Update Gravity Reload() { - # Reload hosts file echo "" - echo -e " ${INFO} Updating gravity..." - echo "" - pihole -g -sd + pihole -g --skip-download "${type:-}" } Displaylist() { @@ -243,6 +246,7 @@ fi PoplistFile -if ${reload}; then - Reload +if [[ "${reload}" != false ]]; then + # Ensure that "restart" is used for Wildcard updates + Reload "${reload}" fi diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index fbba3f74..b0957ab4 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -1,4 +1,6 @@ #!/usr/bin/env bash +# shellcheck disable=SC1090 + # 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. @@ -30,6 +32,7 @@ Options: -f, fahrenheit Set Fahrenheit as preferred temperature unit -k, kelvin Set Kelvin as preferred temperature unit -r, hostrecord Add a name to the DNS associated to an IPv4/IPv6 address + -e, email Set an administrative contact address for the Block Page -h, --help Show this help dialog -i, interface Specify dnsmasq's interface listening behavior Add '-h' for more info on interface usage" @@ -226,20 +229,7 @@ Reboot() { } RestartDNS() { - local str="Restarting DNS service" - [[ -t 1 ]] && echo -ne " ${INFO} ${str}" - if command -v systemctl &> /dev/null; then - output=$( { systemctl restart dnsmasq; } 2>&1 ) - else - output=$( { service dnsmasq restart; } 2>&1 ) - fi - - if [[ -z "${output}" ]]; then - [[ -t 1 ]] && echo -e "${OVER} ${TICK} ${str}" - else - [[ ! -t 1 ]] && OVER="" - echo -e "${OVER} ${CROSS} ${output}" - fi + /usr/local/bin/pihole restartdns } SetQueryLogOptions() { @@ -427,6 +417,27 @@ Options: RestartDNS } +SetAdminEmail() { + if [[ "${1}" == *"-h"* ]]; then + echo "Usage: pihole -a email
+Example: 'pihole -a email admin@address.com' +Set an administrative contact address for the Block Page + +Options: + \"\" Empty: Remove admin contact + -h, --help Show this help dialog" + exit 0 + fi + + if [[ -n "${args[2]}" ]]; then + change_setting "ADMIN_EMAIL" "${args[2]}" + echo -e " ${TICK} Setting admin contact to ${args[2]}" + else + change_setting "ADMIN_EMAIL" "" + echo -e " ${TICK} Removing admin contact" + fi +} + SetListeningMode() { source "${setupVars}" @@ -497,6 +508,7 @@ main() { "addstaticdhcp" ) AddDHCPStaticAddress;; "removestaticdhcp" ) RemoveDHCPStaticAddress;; "-r" | "hostrecord" ) SetHostRecord "$3";; + "-e" | "email" ) SetAdminEmail "$3";; "-i" | "interface" ) SetListeningMode "$@";; "-t" | "teleporter" ) Teleporter;; "adlist" ) CustomizeAdLists;; diff --git a/advanced/blockingpage.css b/advanced/blockingpage.css index cf379eea..e74844d1 100644 --- a/advanced/blockingpage.css +++ b/advanced/blockingpage.css @@ -228,7 +228,6 @@ header #bpAlt label { .aboutImg { background: url("/admin/img/logo.svg") no-repeat center; background-size: 90px 90px; - border: 3px solid rgba(255,255,255,0.2); height: 90px; margin: 0 auto; padding: 2px; diff --git a/advanced/index.js b/advanced/index.js deleted file mode 100644 index 9e153e96..00000000 --- a/advanced/index.js +++ /dev/null @@ -1 +0,0 @@ -var x = "" diff --git a/advanced/index.php b/advanced/index.php index a44423e3..5c2f250d 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -9,32 +9,30 @@ // Sanitise HTTP_HOST output $serverName = htmlspecialchars($_SERVER["HTTP_HOST"]); +if (!is_file("/etc/pihole/setupVars.conf")) + die("[ERROR] File not found:/etc/pihole/setupVars.conf
");
+
// Get values from setupVars.conf
-if (is_file("/etc/pihole/setupVars.conf")) {
- $setupVars = parse_ini_file("/etc/pihole/setupVars.conf");
- $svFQDN = $setupVars["FQDN"];
- $svPasswd = !empty($setupVars["WEBPASSWORD"]);
- $svEmail = (!empty($setupVars["ADMIN_EMAIL"]) && filter_var($setupVars["ADMIN_EMAIL"], FILTER_VALIDATE_EMAIL)) ? $setupVars["ADMIN_EMAIL"] : "";
- unset($setupVars);
-} else {
- die("[ERROR] File not found: /etc/pihole/setupVars.conf
");
-}
+$setupVars = parse_ini_file("/etc/pihole/setupVars.conf");
+$svPasswd = !empty($setupVars["WEBPASSWORD"]);
+$svEmail = (!empty($setupVars["ADMIN_EMAIL"]) && filter_var($setupVars["ADMIN_EMAIL"], FILTER_VALIDATE_EMAIL)) ? $setupVars["ADMIN_EMAIL"] : "";
+unset($setupVars);
// Set landing page location, found within /var/www/html/
$landPage = "../landing.php";
-// Set empty array for hostnames to be accepted as self address for splash page
+// Define array for hostnames to be accepted as self address for splash page
$authorizedHosts = [];
-
-// Append FQDN to $authorizedHosts
-if (!empty($svFQDN)) array_push($authorizedHosts, $svFQDN);
-
-// Append virtual hostname to $authorizedHosts
-if (!empty($_SERVER["VIRTUAL_HOST"])) {
+if (!empty($_SERVER["FQDN"])) {
+ // If setenv.add-environment = ("fqdn" => "true") is configured in lighttpd,
+ // append $serverName to $authorizedHosts
+ array_push($authorizedHosts, $serverName);
+} else if (!empty($_SERVER["VIRTUAL_HOST"])) {
+ // Append virtual hostname to $authorizedHosts
array_push($authorizedHosts, $_SERVER["VIRTUAL_HOST"]);
}
-// Set which extension types render as Block Page (Including "" for index.wxyz)
+// Set which extension types render as Block Page (Including "" for index.ext)
$validExtTypes = array("asp", "htm", "html", "php", "rss", "xml", "");
// Get extension of current URL
@@ -56,8 +54,9 @@ function setHeader($type = "x") {
if (isset($type) && $type === "js") header("Content-Type: application/javascript");
}
-// Determine block page redirect type
+// Determine block page type
if ($serverName === "pi.hole") {
+ // Redirect to Web Interface
exit(header("Location: /admin"));
} elseif (filter_var($serverName, FILTER_VALIDATE_IP) || in_array($serverName, $authorizedHosts)) {
// Set Splash Page output
@@ -68,21 +67,28 @@ if ($serverName === "pi.hole") {