Roll back merge #1417 (#1494)

pull/1388/merge
WaLLy3K 7 years ago committed by DL6ER
parent d913534793
commit 2b8a8b03a8

@ -80,49 +80,66 @@ updateGravityFunc() {
exit 0 exit 0
} }
scanList() { scanList(){
domain="${1}" domain="${1}"
list="${2}" list="${2}"
method="${3}" method="${3}"
if [[ ${method} == "-exact" ]] ; then
grep -i -E "(^|\s)${domain}($|\s)" "${list}"
else
grep -i "${domain}" "${list}"
fi
}
if [[ "${method}" == "-exact" ]]; then processWildcards() {
grep -i -E -l "(^|\s|\/)${domain}($|\s|\/)" ${list} 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 else
grep -i "${domain}" ${list} ar="${array[$j]}.${ar}"
fi fi
done
echo "${ar}"
done
} }
queryFunc() { queryFunc() {
domain="${2}"
method="${3}" method="${3}"
lists=( /etc/pihole/list.* /etc/pihole/blacklist.txt)
# If domain contains non ASCII characters, convert domain to punycode if python exists for list in ${lists[@]}; do
# Cr: https://serverfault.com/a/335079 if [ -e "${list}" ]; then
if [[ -z "${2}" ]]; then result=$(scanList ${domain} ${list} ${method})
echo "::: No domain specified" # Remove empty lines before couting number of results
exit 1 count=$(sed '/^\s*$/d' <<< "$result" | wc -l)
elif [[ "${2}" = *[![:ascii:]]* ]]; then echo "::: ${list} (${count} results)"
[[ "$(which python)" ]] && domain=$(python -c 'import sys;print sys.argv[1].decode("utf-8").encode("idna")' "${2}") if [[ ${count} > 0 ]]; then
echo "${result}"
fi
echo ""
else else
domain="${2}" echo "::: ${list} does not exist"
echo ""
fi fi
done
# Scan Whitelist, Blacklist and Wildcards # Scan for possible wildcard matches
lists="/etc/pihole/whitelist.txt /etc/pihole/blacklist.txt $wildcardlist" if [ -e "${wildcardlist}" ]; then
result=$(scanList ${domain} "${lists}" ${method}) local wildcards=($(processWildcards "${domain}"))
if [[ -n "$result" ]]; then for domain in ${wildcards[@]}; do
echo "$result" result=$(scanList "\/${domain}\/" ${wildcardlist})
[[ ! -t 1 ]] && exit 0 # Remove empty lines before couting number of results
count=$(sed '/^\s*$/d' <<< "$result" | wc -l)
if [[ ${count} > 0 ]]; then
echo "::: Wildcard blocking ${domain} (${count} results)"
echo "${result}"
echo ""
fi fi
done
# Scan Domains lists
result=$(scanList ${domain} "/etc/pihole/*.domains" ${method})
if [[ -n "$result" ]]; then
sort -t . -k 2 -g <<< "$result"
else
[ -n "$method" ] && exact="exact "
echo "::: No ${exact}results found for ${domain}"
fi fi
exit 0 exit 0
} }

Loading…
Cancel
Save