anudeepND / whitelist

A simple tool to add commonly white listed domains to your Pi-Hole setup.
MIT License
4.22k stars 282 forks source link

Whitelist 2.0 - A major update #158

Closed anudeepND closed 4 years ago

anudeepND commented 4 years ago

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