Emulate wildcard blacklisting via -wild and move regex to -regex
Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
This commit is contained in:
parent
61f0cbe10a
commit
c5bb404d6a
|
@ -17,6 +17,7 @@ readonly regexlist="/etc/pihole/regex.list"
|
|||
reload=false
|
||||
addmode=true
|
||||
verbose=true
|
||||
wildcard=false
|
||||
|
||||
domList=()
|
||||
|
||||
|
@ -68,7 +69,7 @@ HandleOther() {
|
|||
|
||||
# Check validity of domain (don't check for regex entries)
|
||||
if [[ "${#domain}" -le 253 ]]; then
|
||||
if [[ "${listMain}" == "${regexlist}" ]]; then
|
||||
if [[ "${listMain}" == "${regexlist}" && "${wildcard}" == false ]]; then
|
||||
validDomain="${domain}"
|
||||
else
|
||||
validDomain=$(grep -P "^((-|_)*[a-z\\d]((-|_)*[a-z\\d])*(-|_)*)(\\.(-|_)*([a-z\\d]((-|_)*[a-z\\d])*))*$" <<< "${domain}") # Valid chars check
|
||||
|
@ -135,6 +136,9 @@ AddDomain() {
|
|||
elif [[ "${list}" == "${regexlist}" ]]; then
|
||||
[[ -z "${type}" ]] && type="--wildcard-only"
|
||||
bool=true
|
||||
|
||||
[[ "${wildcard}" == true ]] && domain="((^)|(\\.))${domain}$"
|
||||
|
||||
# Is the domain in the list?
|
||||
# Search only for exactly matching lines
|
||||
grep -Fx "${domain}" "${regexlist}" > /dev/null 2>&1 || bool=false
|
||||
|
@ -179,6 +183,8 @@ RemoveDomain() {
|
|||
fi
|
||||
elif [[ "${list}" == "${regexlist}" ]]; then
|
||||
[[ -z "${type}" ]] && type="--wildcard-only"
|
||||
[[ "${wildcard}" == true ]] && domain="((^)|(\\.))${domain}$"
|
||||
|
||||
bool=true
|
||||
# Is it in the list?
|
||||
grep -Fx "${domain}" "${regexlist}" > /dev/null 2>&1 || bool=false
|
||||
|
@ -236,7 +242,8 @@ for var in "$@"; do
|
|||
case "${var}" in
|
||||
"-w" | "whitelist" ) listMain="${whitelist}"; listAlt="${blacklist}";;
|
||||
"-b" | "blacklist" ) listMain="${blacklist}"; listAlt="${whitelist}";;
|
||||
"-wild" | "wildcard" ) listMain="${regexlist}";;
|
||||
"-wild" | "wildcard" ) listMain="${regexlist}"; wildcard=true;;
|
||||
"-regex" | "regex" ) listMain="${regexlist}";;
|
||||
"-nr"| "--noreload" ) reload=false;;
|
||||
"-d" | "--delmode" ) addmode=false;;
|
||||
"-q" | "--quiet" ) verbose=false;;
|
||||
|
|
|
@ -5,7 +5,7 @@ Pi-hole : A black-hole for internet advertisements
|
|||
.br
|
||||
.SH "SYNOPSIS"
|
||||
|
||||
\fBpihole\fR (\fB-w\fR|\fB-b\fR|\fB-wild\fR) [options] domain(s)
|
||||
\fBpihole\fR (\fB-w\fR|\fB-b\fR|\fB-wild\fR|\fB-regex\fR) [options] domain(s)
|
||||
.br
|
||||
\fBpihole -a\fR \fB-p\fR password
|
||||
.br
|
||||
|
@ -68,7 +68,12 @@ Available commands and options:
|
|||
|
||||
\fB-wild, wildcard\fR [options] [<domain1> <domain2 ...>]
|
||||
.br
|
||||
Add or removes specified regex pattern to the regex blacklist
|
||||
Add or removes specified domain to the wildcard blacklist
|
||||
.br
|
||||
|
||||
\fB-regex, regex\fR [options] [<regex1> <regex2 ...>]
|
||||
.br
|
||||
Add or removes specified regex filter to the regex blacklist
|
||||
.br
|
||||
|
||||
(Whitelist/Blacklist manipulation options):
|
||||
|
@ -273,11 +278,15 @@ Some usage examples
|
|||
Whitelist/blacklist manipulation
|
||||
.br
|
||||
|
||||
\fBpihole -w iloveads.example.com\fR Add "iloveads.example.com" to whitelist
|
||||
\fBpihole -w iloveads.example.com\fR Add "iloveads.example.com" to whitelist
|
||||
.br
|
||||
\fBpihole -b -d noads.example.com\fR Remove "noads.example.com" from blacklist
|
||||
\fBpihole -b -d noads.example.com\fR Remove "noads.example.com" from blacklist
|
||||
.br
|
||||
\fBpihole -wild ^example.*$\fR Add "^example.*$" as a regex pattern - would block all domains starting with "example"
|
||||
\fBpihole -wild "^example.*$"\fR Add "^example.*$" as a regex pattern - would
|
||||
block all domains starting with "example"
|
||||
.br
|
||||
\fBpihole -regex "ad.*\.example\.com$"\fR Add "ad.*\.example\.com$" to the regex
|
||||
blacklist - would block all subdomains of example.com which start with "ad"
|
||||
.br
|
||||
|
||||
Changing the Web Interface password
|
||||
|
|
22
pihole
22
pihole
|
@ -33,17 +33,7 @@ webpageFunc() {
|
|||
exit 0
|
||||
}
|
||||
|
||||
whitelistFunc() {
|
||||
"${PI_HOLE_SCRIPT_DIR}"/list.sh "$@"
|
||||
exit 0
|
||||
}
|
||||
|
||||
blacklistFunc() {
|
||||
"${PI_HOLE_SCRIPT_DIR}"/list.sh "$@"
|
||||
exit 0
|
||||
}
|
||||
|
||||
wildcardFunc() {
|
||||
listFunc() {
|
||||
"${PI_HOLE_SCRIPT_DIR}"/list.sh "$@"
|
||||
exit 0
|
||||
}
|
||||
|
@ -403,7 +393,8 @@ Add '-h' after specific commands for more information on usage
|
|||
Whitelist/Blacklist Options:
|
||||
-w, whitelist Whitelist domain(s)
|
||||
-b, blacklist Blacklist domain(s)
|
||||
-wild, wildcard Regex blacklist domain(s)
|
||||
-wild, wildcard Wildcard blacklist domain(s)
|
||||
-regex, regex Regex blacklist domains(s)
|
||||
Add '-h' for more info on whitelist/blacklist usage
|
||||
|
||||
Debugging Options:
|
||||
|
@ -445,9 +436,10 @@ fi
|
|||
|
||||
# Handle redirecting to specific functions based on arguments
|
||||
case "${1}" in
|
||||
"-w" | "whitelist" ) whitelistFunc "$@";;
|
||||
"-b" | "blacklist" ) blacklistFunc "$@";;
|
||||
"-wild" | "wildcard" ) wildcardFunc "$@";;
|
||||
"-w" | "whitelist" ) listFunc "$@";;
|
||||
"-b" | "blacklist" ) listFunc "$@";;
|
||||
"-wild" | "wildcard" ) listFunc "$@";;
|
||||
"-regex" | "regex" ) listFunc "$@";;
|
||||
"-d" | "debug" ) debugFunc "$@";;
|
||||
"-f" | "flush" ) flushFunc "$@";;
|
||||
"-up" | "updatePihole" ) updatePiholeFunc "$@";;
|
||||
|
|
Loading…
Reference in New Issue