Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/pi-hole/pi-hole.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Warner <me@adamwarner.co.uk>2019-11-30 16:13:26 +0300
committerAdam Warner <me@adamwarner.co.uk>2019-11-30 16:13:26 +0300
commitd0de5fda3086614b1f8266a9a4ed12f0b6ef9c97 (patch)
treec14286ff8970a7c8bb60ae69a82234745a06c3e4 /advanced
parenta1f120b2ff5fd7801202a481723c12871a8ab902 (diff)
Simplify removal of domain from one list when it is requested for another
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
Diffstat (limited to 'advanced')
-rwxr-xr-xadvanced/Scripts/list.sh36
1 files changed, 25 insertions, 11 deletions
diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh
index 483b7153..55272cde 100755
--- a/advanced/Scripts/list.sh
+++ b/advanced/Scripts/list.sh
@@ -39,6 +39,18 @@ getTypeID() {
fi
}
+getListnameFromType() {
+ if [[ "$1" == "0" ]]; then
+ echo "whitelist"
+ elif [[ "$1" == "1" ]]; then
+ echo "blacklist"
+ elif [[ "$1" == "2" ]]; then
+ echo "regex_whitelist"
+ elif [[ "$1" == "3" ]]; then
+ echo "regex_blacklist"
+ fi
+}
+
helpFunc() {
if [[ "${listType}" == "whitelist" ]]; then
param="w"
@@ -105,19 +117,15 @@ HandleOther() {
}
ProcessDomainList() {
- local is_regexlist
if [[ "${listType}" == "regex_blacklist" ]]; then
# Regex black filter list
listname="regex blacklist filters"
- is_regexlist=true
elif [[ "${listType}" == "regex_whitelist" ]]; then
# Regex white filter list
listname="regex whitelist filters"
- is_regexlist=true
else
# Whitelist / Blacklist
listname="${listType}"
- is_regexlist=false
fi
for dom in "${domList[@]}"; do
@@ -130,9 +138,6 @@ ProcessDomainList() {
# if delmode then remove from desired list but do not add to the other
if ${addmode}; then
AddDomain "${dom}" "${listType}"
- if ! ${is_regexlist}; then
- RemoveDomain "${dom}" "${listAlt}"
- fi
else
RemoveDomain "${dom}" "${listType}"
fi
@@ -140,18 +145,27 @@ ProcessDomainList() {
}
AddDomain() {
- local domain list num typeID
+ local domain list num currTypeID currListName typeID
# Use printf to escape domain. %q prints the argument in a form that can be reused as shell input
domain="$1"
list="$2"
typeID="$(getTypeID "${list}")"
# Is the domain in the list we want to add it to?
- num="$(sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM domainlist WHERE domain = '${domain}' AND type = ${typeID};")"
+ num="$(sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM domainlist WHERE domain = '${domain}';")"
if [[ "${num}" -ne 0 ]]; then
- if [[ "${verbose}" == true ]]; then
- echo -e " ${INFO} ${1} already exists in ${listname}, no need to add!"
+ currTypeID="$(sqlite3 "${gravityDBfile}" "SELECT type FROM domainlist WHERE domain = '${domain}';")"
+ if [[ "${currTypeID}" == "${typeID}" ]]; then
+ if [[ "${verbose}" == true ]]; then
+ echo -e " ${INFO} ${1} already exists in ${listname}, no need to add!"
+ fi
+ else
+ currListName="$(getListnameFromType "${currTypeID}")"
+ sqlite3 "${gravityDBfile}" "UPDATE domainlist SET type = ${typeID} WHERE domain='${domain}';"
+ if [[ "${verbose}" == true ]]; then
+ echo -e " ${INFO} ${1} already exists in ${currListName}, it has been updated to the requested list type."
+ fi
fi
return
fi