forked from ph00lt0/blocklist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delist.sh
executable file
·62 lines (49 loc) · 2 KB
/
delist.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
read -p "Enter the domain that you want to delist:" domain
if [ "$domain" == "" ]; then
echo "No domain provided."
exit
else
if [ "$domain" == "v" ]; then
echo "Wrong paste command."
exit
fi
if [ "$domain" == "[A[A" ]; then
echo "syntax error [A[A."
exit
fi
read -p "Specify reason (required):" reason
if [ "$reason" == "" ]; then
echo "No reason provided."
exit
fi
declare blocklist="./blocklist.txt"
declare piholeBlocklist="./pihole-blocklist.txt"
declare rpzBlocklist="./rpz-blocklist.txt"
declare unboundBlocklist="./unbound-blocklist.txt"
declare domain=$(echo $domain | sed -E 's/^\s*.*:\/\///g') # remove any https:// or http://.
declare domain=$(echo $domain | sed 's:/*$::') # remove any trailing slash.
declare domain=$(echo $domain | sed 's/www.//g') # remove www. if present.
declare blocklistRule="||$domain^"
declare allowedRule="||$domain^\$badfilter"
declare piholeBlocklistRule="0.0.0.0 $domain"
declare rpzBlocklistRule="$domain CNAME ."
declare unboundBlocklistRule="local-zone: \"$domain.\" always_null"
# Only check for default blocklist as pihole list should contain same domains.
if grep -q $blocklistRule "$blocklist"; then
echo "checking for updates..."
git pull origin master && git pull github master
if grep -q $allowedRule "$blocklist"; then
echo "$domain rule delisted before you"
else
sed -i '' "s/$blocklistRule/$allowedRule # $reason/g" $blocklist
sed -i '' "s/$piholeBlocklistRule/! allow $domain reason: $reason/g" $piholeBlocklist
sed -i '' "s/$rpzBlocklistRule/; allow $domain reason: $reason/g" $rpzBlocklist
sed -i '' "s/$unboundBlocklistRule/# allow $domain reason: $reason/g" $unboundBlocklist
python3 ./ls-delete.py $domain
git commit -am "delisted $domain in blocklist" && git push origin master && git push github master
fi
else
echo "$domain domain not present"
fi
fi