mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-23 21:30:17 +00:00
Add support for whitelist regex filter management via CLI.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
65fdbc85d5
commit
96031214c6
3 changed files with 41 additions and 3 deletions
|
@ -28,5 +28,34 @@ CREATE TRIGGER tr_regex_blacklist_update AFTER UPDATE ON regex_blacklist
|
|||
UPDATE regex_blacklist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain;
|
||||
END;
|
||||
|
||||
CREATE TABLE regex_whitelist
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
domain TEXT UNIQUE NOT NULL,
|
||||
enabled BOOLEAN NOT NULL DEFAULT 1,
|
||||
date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
||||
date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
||||
comment TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE regex_whitelist_by_group
|
||||
(
|
||||
regex_id INTEGER NOT NULL REFERENCES regex_whitelist (id),
|
||||
group_id INTEGER NOT NULL REFERENCES "group" (id),
|
||||
PRIMARY KEY (regex_id, group_id)
|
||||
);
|
||||
|
||||
CREATE VIEW vw_regex_whitelist AS SELECT DISTINCT domain
|
||||
FROM regex_whitelist
|
||||
LEFT JOIN regex_whitelist_by_group ON regex_whitelist_by_group.regex_id = regex_whitelist.id
|
||||
LEFT JOIN "group" ON "group".id = regex_whitelist_by_group.group_id
|
||||
WHERE regex_whitelist.enabled = 1 AND (regex_whitelist_by_group.group_id IS NULL OR "group".enabled = 1)
|
||||
ORDER BY regex_whitelist.id;
|
||||
|
||||
CREATE TRIGGER tr_regex_whitelist_update AFTER UPDATE ON regex_whitelist
|
||||
BEGIN
|
||||
UPDATE regex_whitelist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain;
|
||||
END;
|
||||
|
||||
|
||||
UPDATE info SET value = 3 WHERE property = 'version';
|
||||
|
|
|
@ -38,6 +38,9 @@ helpFunc() {
|
|||
elif [[ "${listType}" == "regex_blacklist" ]]; then
|
||||
param="-regex"
|
||||
type="regex blacklist filter"
|
||||
elif [[ "${listType}" == "regex_blacklist" ]]; then
|
||||
param="-whiteregex"
|
||||
type="regex whitelist filter"
|
||||
else
|
||||
param="b"
|
||||
type="blacklist"
|
||||
|
@ -89,8 +92,11 @@ HandleOther() {
|
|||
|
||||
ProcessDomainList() {
|
||||
if [[ "${listType}" == "regex_blacklist" ]]; then
|
||||
# Regex filter list
|
||||
# Regex black filter list
|
||||
listname="regex blacklist filters"
|
||||
elif [[ "${listType}" == "regex_whitelist" ]]; then
|
||||
# Regex white filter list
|
||||
listname="regex whitelist filters"
|
||||
else
|
||||
# Whitelist / Blacklist
|
||||
listname="${listType}"
|
||||
|
@ -106,7 +112,7 @@ ProcessDomainList() {
|
|||
# if delmode then remove from desired list but do not add to the other
|
||||
if ${addmode}; then
|
||||
AddDomain "${dom}" "${listType}"
|
||||
if [[ ! "${listType}" == "regex_blacklist" ]]; then
|
||||
if [[ ! "${listType}" == "regex_"*"list" ]]; then
|
||||
RemoveDomain "${dom}" "${listAlt}"
|
||||
fi
|
||||
else
|
||||
|
@ -173,7 +179,7 @@ Displaylist() {
|
|||
data="$(sqlite3 "${gravityDBfile}" "SELECT domain,enabled,date_modified FROM ${listType};" 2> /dev/null)"
|
||||
|
||||
if [[ -z $data ]]; then
|
||||
echo -e "Not showing empty ${listname}"
|
||||
echo -e "Not showing empty list"
|
||||
else
|
||||
echo -e "Displaying ${listname}:"
|
||||
count=1
|
||||
|
@ -217,6 +223,7 @@ for var in "$@"; do
|
|||
"-b" | "blacklist" ) listType="blacklist"; listAlt="whitelist";;
|
||||
"--wild" | "wildcard" ) listType="regex_blacklist"; wildcard=true;;
|
||||
"--regex" | "regex" ) listType="regex_blacklist";;
|
||||
"--whiteregex" | "whiteregex" ) listType="regex_whitelist";;
|
||||
"-nr"| "--noreload" ) reload=false;;
|
||||
"-d" | "--delmode" ) addmode=false;;
|
||||
"-q" | "--quiet" ) verbose=false;;
|
||||
|
|
2
pihole
2
pihole
|
@ -377,6 +377,7 @@ Whitelist/Blacklist Options:
|
|||
-b, blacklist Blacklist domain(s)
|
||||
--wild, wildcard Wildcard blacklist domain(s)
|
||||
--regex, regex Regex blacklist domains(s)
|
||||
--whiteregex Regex whitelist domains(s)
|
||||
Add '-h' for more info on whitelist/blacklist usage
|
||||
|
||||
Debugging Options:
|
||||
|
@ -438,6 +439,7 @@ case "${1}" in
|
|||
"-b" | "blacklist" ) listFunc "$@";;
|
||||
"--wild" | "wildcard" ) listFunc "$@";;
|
||||
"--regex" | "regex" ) listFunc "$@";;
|
||||
"--whiteregex" | "whiteregex" ) listFunc "$@";;
|
||||
"-d" | "debug" ) debugFunc "$@";;
|
||||
"-f" | "flush" ) flushFunc "$@";;
|
||||
"-up" | "updatePihole" ) updatePiholeFunc "$@";;
|
||||
|
|
Loading…
Reference in a new issue