This repository was archived by the owner on Aug 1, 2025. It is now read-only.
Whitelist 2.0 - A major update #158
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Whitelist 2.0 - A major update
It's been a long time since this project got an update. I've been inactive on GitHub for some time but I will address the issues and PR as soon as possible.
whitelist.py
The project is rewritten in Python and has many features that are requested by the Pi-hole users. Pi-hole 5.0 introduced databases. New version of Pi-hole migrated list storage from individual files in
/etc/pihole
to a new gravity database in the same directory calledgravity.db
.This allows control over enabling and disabling items in the lists, and even the ability to add comments to remind you why you black/whitelisted something!
The script will check for the Pi-hole path, read/write permission before proceeding further and checks whether the Pi-hole uses database or not i.e; it checks the Pi-hole version. The script is backward compatible. Now all the domain has a comment section that provides some useful info about it.
The comment field has a unique string -
qjz9zk
to uniquely identify the domains added by this script so the user can remove the domains without affecting other whitelisted sites.uninstall.py
As mentioned earlier, the unique string (
qjz9zk
) will come in handy while removing the domains from the database. It uses LIKE operator of the sqlite to match the wildcard string present in the comment section.SELECT * FROM domainlist WHERE type = 0 AND comment LIKE '%qjz9zk%'
This statement will remove the domain only if it is present in the exact whitelist section and having the string qjz9zk.
Domains in the regex list will not be removed by this script.
The older version of the Pi-hole uses a simple text file to store the entries. In this case the script will match the domains present in your Pi-hole to the domains present in the GitHub repo and removes them accordingly.
Usage
Take a backup of your Pi-hole. If anyone wants to test the scripts make sure you have the latest version of python3 and have proper permission to execute the script. I have checked these scripts from Pi-hole 3.3 to Pi-hole 5.x and Docker version.
sudo python3 whitelist.py
Contributing to the project:
If you find any bugs or improve the code, please create a PR on the development branch
Reference
https://www.sqlitetutorial.net/
https://docs.pi-hole.net/
Thanks to @mmotti https://github.com/mmotti/pihole-regex for his regex scripts.
#151
#138
#142
#147