Comments (9)
I have been wanting to figure out a way to do this for a while, as a lot of people request it. However, this single-line command has gotten pretty complex and as it was a pull-request, I don't fully understand it. I see that you are trying to use a whitelist file to somehow remove the entries from the list.
Could you break down each pipe in the command and explain what each one does?
from pi-hole.
Well, initially I wanted to separate them into subsequent statements, but I then decided to avoid that because I wanted to limit the amount of writes to the SD card.
All I did was to insert the following into the pipe chain: cat - /usr/local/etc/whitelist.txt | sort | uniq -u
I did this just after a sanitized, uniq-ued, sorted list of addresses were generated, but before the DNS rules were generated.
This addition adds the whitelisted entries to the list ('-' is the list read from stdin), sorts it again, and uses uniq with the '-u' flag to remove all entries with duplicates (thus the whitelisted ones).
There are 2 problems with my current implementation:
- If the whitelist file does not exist, it will fail. This can be handled better with a check-and-read statement.
- The bigger problem is that if the addresses I have in the whitelist get removed from the blacklist, then my addition will actually add them again! There is an easy fix for this as well, use:
cat - /usr/local/etc/whitelist.txt /usr/local/etc/whitelist.txt | sort | uniq -u
(adding whitelist entries twice will ensure they are always removed, I'll update my original comment.)
No. 2) above can be done better with regular expressions/awk scripts, but I'm lazy... :)
from pi-hole.
ps: my whitelist.txt contains an address-per-line like so:
imgs.xkcd.com
c.xkcd.com
from pi-hole.
Interesting. I'll look at your code more deeply and see what I can figure out.
Why does the whitelist need to be in there twice? I also don't really get what the - is for.
The error check should be fairly simple:
if [[ -f /usr/local/etc/whitelist.txt ]];then
command to remove
else
echo "File does not exist"
fi
from pi-hole.
Yup, I forgot to mention (added the info too late) : In cat -
, the -
reads from stdin (thus from the pipe).
cat - whitelist.txt whitelist.txt
, will basically then combine the list from the pipe, with two copies from the whitelist.
And the reason the list is added twice, is for the eventuality that the address I whitelisted is removed from the blacklist site, then it prevents that code from actually adding it again.
This has to do with my 'hack' to get it working quickly: uniq
with the -u
parameter basically only returns the lines which it did not find duplicated.
from pi-hole.
What about something like this?
~$ cat adList.conf
0-29.com
0-2u.com
0-days.net
0-free-porn-0.com
0-pdf.com
0.asdzc123.info
0.channel15.facebook.com
0.datacollector.coin.scribol.com
0.doctoraedom.ru
0.doctoralduz.ru
~$ cat whitelist.txt
0-pdf.com
0.datacollector.coin.scribol.com
~$ grep -v -x -f whitelist.txt adList.conf
0-29.com
0-2u.com
0-days.net
0-free-porn-0.com
0.asdzc123.info
0.channel15.facebook.com
0.doctoraedom.ru
0.doctoralduz.ru
I'm not quite sure how to implement it into the command yet.
from pi-hole.
This is indeed simpler!
So instead of:
| cat - /usr/local/etc/whitelist.txt /usr/local/etc/whitelist.txt | sort | uniq -u |
Thus do the following:
| grep -v -x -f whitelist.txt |
from pi-hole.
Cool! I will work a little more logic in to check for the file and then update the script.
from pi-hole.
Just add a whitelist.txt file to your home folder with one domain per line.
from pi-hole.
Related Issues (20)
- Hostnames not resolving on Dashboard tab for ipv6 devices HOT 6
- Querylog All Queries Same Host Problem HOT 1
- V6/Does not block anymore HOT 7
- Restore does not include static dhcp leases without ip HOT 3
- Temperature keeps reverting to Celsius from Fahrenheit when updating HOT 27
- Ads Not Blocking Properly in Pi-hole Docker HOT 6
- dnsmasq: failed to create listening socket for port 53: Address already in use HOT 4
- Blank admin PHP pages caused by empty persistentlogintoken file (includes fix) HOT 1
- Installation fails HOT 1
- Install: Check for valid upstream DNS IP addresses excludes IPv6 HOT 4
- (development-v6) cannot update FTL on arm device HOT 1
- (development-v6) cannot update FTL on amd64 device HOT 4
- Intermittent issues using custom dns_records HOT 2
- In an LXC container, the website displays a ‘load average’ that is very different from top HOT 7
- FTL database shouldn't be readable by unprivileged users HOT 6
- Raspberry Pi 5 having trouble binding interfaces when using NetworkManager HOT 1
- Update of pi-hole not possible on Linuxmint 6 (Debian) HOT 2
- pihole -v shows update available but pihole -up doesn't HOT 6
- Default list author fine with breaking functionality -- suggest finding alternative HOT 4
- Dashboard hanging HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pi-hole.