Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Conversation

anudeepND
Copy link
Owner

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/piholeto a new gravity database in the same directory called gravity.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

@anudeepND anudeepND mentioned this pull request Aug 30, 2020
@anudeepND anudeepND merged commit b145db2 into master Aug 30, 2020
@anudeepND anudeepND deleted the whitelist-2.0 branch August 30, 2020 06:34

sqliteConnection.commit()

# total_changes is returning 2x the actual value. ¯\_(ツ)_/¯
Copy link
Contributor

@mwoolweaver mwoolweaver Sep 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit after some research:

why wouldn't you look for entries that you left a comment on when checking for the changes that have been made?

your not adding the domain if it's already been whitelisted right? and you aren't deleting from the database while adding it, right?

anudeepND added a commit that referenced this pull request Sep 2, 2020
remove error prone total_changes function introduced in #158
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Removing the whitelist Comments for Pi-hole v5 [request] add whitelist to to there own category when Pi-hole v5.0.
3 participants