diff options
author | Mcat12 <newtoncat12@yahoo.com> | 2017-01-29 03:19:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-29 03:19:18 +0300 |
commit | 8cb4304c13c35d6183e60db7afcd82c01923558c (patch) | |
tree | 112cde007d44a1f144f6fc8e8c4aeaf7ba561e54 /pihole | |
parent | 47196d86adbdead18faf3a0c17d3ccc5b457da6d (diff) | |
parent | 0375a3caa393b5492a90d4449b5b8191d6f225e8 (diff) |
Merge pull request #1158 from pi-hole/developmentv2.12
[RELEASE] Pi-hole Core 2.12
Diffstat (limited to 'pihole')
-rwxr-xr-x | pihole | 53 |
1 files changed, 43 insertions, 10 deletions
@@ -11,6 +11,7 @@ # (at your option) any later version. PI_HOLE_SCRIPT_DIR="/opt/pihole" +readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then if [ -x "$(command -v sudo)" ];then @@ -38,6 +39,11 @@ blacklistFunc() { exit 0 } +wildcardFunc() { + "${PI_HOLE_SCRIPT_DIR}"/list.sh "$@" + exit 0 +} + debugFunc() { "${PI_HOLE_SCRIPT_DIR}"/piholeDebug.sh exit 0 @@ -63,11 +69,6 @@ updateGravityFunc() { exit 0 } -setupLCDFunction() { - "${PI_HOLE_SCRIPT_DIR}"/setupLCD.sh - exit 0 -} - scanList(){ domain="${1}" list="${2}" @@ -79,19 +80,52 @@ scanList(){ fi } +processWildcards() { + IFS="." read -r -a array <<< "${1}" + for (( i=${#array[@]}-1; i>=0; i-- )); do + ar="" + for (( j=${#array[@]}-1; j>${#array[@]}-i-2; j-- )); do + if [[ $j == $((${#array[@]}-1)) ]]; then + ar="${array[$j]}" + else + ar="${array[$j]}.${ar}" + fi + done + echo "${ar}" + done +} + queryFunc() { domain="${2}" method="${3}" lists=( /etc/pihole/list.* /etc/pihole/blacklist.txt) for list in ${lists[@]}; do - result=$(scanList ${domain} ${list} ${method}) + if [ -e "${list}" ]; then + result=$(scanList ${domain} ${list} ${method}) + # Remove empty lines before couting number of results + count=$(sed '/^\s*$/d' <<< "$result" | wc -l) + echo "::: ${list} (${count} results)" + if [[ ${count} > 0 ]]; then + echo "${result}" + fi + echo "" + else + echo "::: ${list} does not exist" + echo "" + fi + done + + # Scan for possible wildcard matches + local wildcards=($(processWildcards "${domain}")) + for domain in ${wildcards[@]}; do + result=$(scanList "\/${domain}\/" ${wildcardlist}) # Remove empty lines before couting number of results count=$(sed '/^\s*$/d' <<< "$result" | wc -l) - echo "::: ${list} (${count} results)" if [[ ${count} > 0 ]]; then + echo "::: Wildcard blocking ${domain} (${count} results)" echo "${result}" + echo "" fi - echo "" done exit 0 } @@ -248,7 +282,6 @@ helpFunc() { ::: -up, updatePihole Update Pi-hole ::: -r, reconfigure Reconfigure or Repair Pi-hole ::: -g, updateGravity Update the list of ad-serving domains -::: -s, setupLCD Automatically configures the Pi to use the 2.8 LCD screen to display stats on it ::: -c, chronometer Calculates stats and displays to an LCD ::: -h, help Show this help dialog ::: -v, version Show current versions @@ -275,12 +308,12 @@ fi case "${1}" in "-w" | "whitelist" ) whitelistFunc "$@";; "-b" | "blacklist" ) blacklistFunc "$@";; + "-wild" | "wildcard" ) wildcardFunc "$@";; "-d" | "debug" ) debugFunc;; "-f" | "flush" ) flushFunc;; "-up" | "updatePihole" ) updatePiholeFunc;; "-r" | "reconfigure" ) reconfigurePiholeFunc;; "-g" | "updateGravity" ) updateGravityFunc "$@";; - "-s" | "setupLCD" ) setupLCDFunction;; "-c" | "chronometer" ) chronometerFunc "$@";; "-h" | "help" ) helpFunc;; "-v" | "version" ) versionFunc "$@";; |