mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-24 13:50:17 +00:00
Add automated wildcard list -> regex filter conversion
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
d254d6075a
commit
bc705aac03
2 changed files with 26 additions and 9 deletions
18
advanced/Scripts/wildcard_regex_converter.sh
Normal file
18
advanced/Scripts/wildcard_regex_converter.sh
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
wildcardFile="/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
||||||
|
|
||||||
|
convert_wildcard_to_regex() {
|
||||||
|
if [ ! -f "${wildcardFile}" ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
local addrlines domains uniquedomains
|
||||||
|
# Obtain wildcard domains from old file
|
||||||
|
addrlines="$(grep -oE "/.*/" ${wildcardFile})"
|
||||||
|
# Strip "/" from domain names
|
||||||
|
domains="$(sed 's/\///g;' <<< "${addrlines}")"
|
||||||
|
# Remove repeated domains (may have been inserted two times due to A and AAAA blocking)
|
||||||
|
uniquedomains="$(uniq <<< "${domains}")"
|
||||||
|
# Automatically generate regex filters and remove old wildcards file
|
||||||
|
awk '{print "(^)|(\\.)"$0"$"}' <<< "${uniquedomains}" >> "${regexFile}" && rm "${wildcardFile}"
|
||||||
|
}
|
17
gravity.sh
17
gravity.sh
|
@ -15,6 +15,8 @@ export LC_ALL=C
|
||||||
|
|
||||||
coltable="/opt/pihole/COL_TABLE"
|
coltable="/opt/pihole/COL_TABLE"
|
||||||
source "${coltable}"
|
source "${coltable}"
|
||||||
|
regexconverter="/opt/pihole/wildcard_regex_converter.sh"
|
||||||
|
source "${regexconverter}"
|
||||||
|
|
||||||
basename="pihole"
|
basename="pihole"
|
||||||
PIHOLE_COMMAND="/usr/local/bin/${basename}"
|
PIHOLE_COMMAND="/usr/local/bin/${basename}"
|
||||||
|
@ -26,7 +28,7 @@ adListDefault="${piholeDir}/adlists.default"
|
||||||
|
|
||||||
whitelistFile="${piholeDir}/whitelist.txt"
|
whitelistFile="${piholeDir}/whitelist.txt"
|
||||||
blacklistFile="${piholeDir}/blacklist.txt"
|
blacklistFile="${piholeDir}/blacklist.txt"
|
||||||
wildcardFile="/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
regexFile="${piholeDir}/regex.list"
|
||||||
|
|
||||||
adList="${piholeDir}/gravity.list"
|
adList="${piholeDir}/gravity.list"
|
||||||
blackList="${piholeDir}/black.list"
|
blackList="${piholeDir}/black.list"
|
||||||
|
@ -453,7 +455,7 @@ gravity_Whitelist() {
|
||||||
echo -e "${OVER} ${INFO} ${str}"
|
echo -e "${OVER} ${INFO} ${str}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Output count of blacklisted domains and wildcards
|
# Output count of blacklisted domains and regex filters
|
||||||
gravity_ShowBlockCount() {
|
gravity_ShowBlockCount() {
|
||||||
local num
|
local num
|
||||||
|
|
||||||
|
@ -462,13 +464,9 @@ gravity_ShowBlockCount() {
|
||||||
echo -e " ${INFO} Number of blacklisted domains: ${num}"
|
echo -e " ${INFO} Number of blacklisted domains: ${num}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -f "${wildcardFile}" ]]; then
|
if [[ -f "${regexFile}" ]]; then
|
||||||
num=$(grep -c "^" "${wildcardFile}")
|
num=$(grep -c "^" "${regexFile}")
|
||||||
# If IPv4 and IPv6 is used, divide total wildcard count by 2
|
echo -e " ${INFO} Number of regex filters: ${num}"
|
||||||
if [[ -n "${IPV4_ADDRESS}" ]] && [[ -n "${IPV6_ADDRESS}" ]];then
|
|
||||||
num=$(( num/2 ))
|
|
||||||
fi
|
|
||||||
echo -e " ${INFO} Number of wildcard blocked domains: ${num}"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -646,6 +644,7 @@ if [[ "${skipDownload}" == false ]] || [[ "${listType}" == "whitelist" ]]; then
|
||||||
gravity_Whitelist
|
gravity_Whitelist
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
convert_wildcard_to_regex
|
||||||
gravity_ShowBlockCount
|
gravity_ShowBlockCount
|
||||||
|
|
||||||
# Perform when downloading blocklists, or modifying the white/blacklist (not wildcards)
|
# Perform when downloading blocklists, or modifying the white/blacklist (not wildcards)
|
||||||
|
|
Loading…
Reference in a new issue