|
|
@ -30,33 +30,6 @@ gravityDBfile="${GRAVITYDB}"
|
|
|
|
colfile="/opt/pihole/COL_TABLE"
|
|
|
|
colfile="/opt/pihole/COL_TABLE"
|
|
|
|
source "${colfile}"
|
|
|
|
source "${colfile}"
|
|
|
|
|
|
|
|
|
|
|
|
# Scan an array of files for matching strings
|
|
|
|
|
|
|
|
scanList(){
|
|
|
|
|
|
|
|
# Escape full stops
|
|
|
|
|
|
|
|
local domain="${1}" esc_domain="${1//./\\.}" lists="${2}" list_type="${3:-}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Prevent grep from printing file path
|
|
|
|
|
|
|
|
cd "$piholeDir" || exit 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Prevent grep -i matching slowly: https://bit.ly/2xFXtUX
|
|
|
|
|
|
|
|
export LC_CTYPE=C
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# /dev/null forces filename to be printed when only one list has been generated
|
|
|
|
|
|
|
|
case "${list_type}" in
|
|
|
|
|
|
|
|
"exact" ) grep -i -E -l "(^|(?<!#)\\s)${esc_domain}($|\\s|#)" ${lists} /dev/null 2>/dev/null;;
|
|
|
|
|
|
|
|
# Iterate through each regexp and check whether it matches the domainQuery
|
|
|
|
|
|
|
|
# If it does, print the matching regexp and continue looping
|
|
|
|
|
|
|
|
# Input 1 - regexps | Input 2 - domainQuery
|
|
|
|
|
|
|
|
"regex" )
|
|
|
|
|
|
|
|
for list in ${lists}; do
|
|
|
|
|
|
|
|
if [[ "${domain}" =~ ${list} ]]; then
|
|
|
|
|
|
|
|
printf "%b\n" "${list}";
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
done;;
|
|
|
|
|
|
|
|
* ) grep -i "${esc_domain}" ${lists} /dev/null 2>/dev/null;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [[ "${options}" == "-h" ]] || [[ "${options}" == "--help" ]]; then
|
|
|
|
if [[ "${options}" == "-h" ]] || [[ "${options}" == "--help" ]]; then
|
|
|
|
echo "Usage: pihole -q [option] <domain>
|
|
|
|
echo "Usage: pihole -q [option] <domain>
|
|
|
|
Example: 'pihole -q -exact domain.com'
|
|
|
|
Example: 'pihole -q -exact domain.com'
|
|
|
@ -84,15 +57,45 @@ options=$(sed -E 's/ ?-(all|exact) ?//g' <<< "${options}")
|
|
|
|
case "${options}" in
|
|
|
|
case "${options}" in
|
|
|
|
"" ) str="No domain specified";;
|
|
|
|
"" ) str="No domain specified";;
|
|
|
|
*" "* ) str="Unknown query option specified";;
|
|
|
|
*" "* ) str="Unknown query option specified";;
|
|
|
|
*[![:ascii:]]* ) domainQuery=$(idn2 "${options}");;
|
|
|
|
*[![:ascii:]]* ) rawDomainQuery=$(idn2 "${options}");;
|
|
|
|
* ) domainQuery="${options}";;
|
|
|
|
* ) rawDomainQuery="${options}";;
|
|
|
|
esac
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# convert the domain to lowercase
|
|
|
|
|
|
|
|
domainQuery=$(echo "${rawDomainQuery}" | tr '[:upper:]' '[:lower:]')
|
|
|
|
|
|
|
|
|
|
|
|
if [[ -n "${str:-}" ]]; then
|
|
|
|
if [[ -n "${str:-}" ]]; then
|
|
|
|
echo -e "${str}${COL_NC}\\nTry 'pihole -q --help' for more information."
|
|
|
|
echo -e "${str}${COL_NC}\\nTry 'pihole -q --help' for more information."
|
|
|
|
exit 1
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Scan an array of files for matching strings
|
|
|
|
|
|
|
|
scanList(){
|
|
|
|
|
|
|
|
# Escape full stops
|
|
|
|
|
|
|
|
local domain="${1}" esc_domain="${1//./\\.}" lists="${2}" list_type="${3:-}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Prevent grep from printing file path
|
|
|
|
|
|
|
|
cd "$piholeDir" || exit 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Prevent grep -i matching slowly: https://bit.ly/2xFXtUX
|
|
|
|
|
|
|
|
export LC_CTYPE=C
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# /dev/null forces filename to be printed when only one list has been generated
|
|
|
|
|
|
|
|
case "${list_type}" in
|
|
|
|
|
|
|
|
"exact" ) grep -i -E -l "(^|(?<!#)\\s)${esc_domain}($|\\s|#)" "${lists}" /dev/null 2>/dev/null;;
|
|
|
|
|
|
|
|
# Iterate through each regexp and check whether it matches the domainQuery
|
|
|
|
|
|
|
|
# If it does, print the matching regexp and continue looping
|
|
|
|
|
|
|
|
# Input 1 - regexps | Input 2 - domainQuery
|
|
|
|
|
|
|
|
"regex" )
|
|
|
|
|
|
|
|
for list in ${lists}; do
|
|
|
|
|
|
|
|
if [[ "${domain}" =~ ${list} ]]; then
|
|
|
|
|
|
|
|
printf "%b\n" "${list}";
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
done;;
|
|
|
|
|
|
|
|
* ) grep -i "${esc_domain}" "${lists}" /dev/null 2>/dev/null;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
scanDatabaseTable() {
|
|
|
|
scanDatabaseTable() {
|
|
|
|
local domain table list_type querystr result extra
|
|
|
|
local domain table list_type querystr result extra
|
|
|
|
domain="$(printf "%q" "${1}")"
|
|
|
|
domain="$(printf "%q" "${1}")"
|
|
|
|