Skip to content

A nice 404 page for pihole with an added automatic script that can be used to whitelist the domain with the click of a button.

License

Notifications You must be signed in to change notification settings

perspector/Pihole-404

Repository files navigation

Pihole-404

A nice custom 404 page for pihole with an added automatic script that can be used to whitelist the domain with the click of a button.

This is what your 404 page will look like. Of course, you can also customize it. Above: This is what your 404 page will look like! Of course, feel free to customize it.

Note: This is an unofficial third-party addon for your pi-hole.

Table of Contents

The Problem

  Setting up a Pihole is awesome and pretty easy. But what happens when a page you want to go to is blocked? You get a regular 404 error. And what if you want to go to the webpage? First, you have to go to your pihole's website. Then you have to login. Next, you need to go to whitelist and type in the domain. This works if the user is the administrator, but what if you don't know the password or a client has problems?

The Solution

  Pihole-404 to the rescue! This simple script will add a button that lets you email the admin. This email will be read by an automatic python script and the domain will be whitelisted! And on top of all that, it makes the 404 page look very nice!
  I used Email so it would be more secure, not just a command being executed by the website. Having a button to run any command on the pihole would be a vulnerability, so I decided email would be better.

Step 1: Install Pihole and Get it Working

To get your pihole up and running (haha), head over to https://github.com/pi-hole/pi-hole

Step 2: (Gmail users only) Enable Less Secure App Access and IMAP

  If you are using an email provider other than Gmail, skip to step 4.
If you are using Gmail, you need to enable less secure app access to your google account here. You also need to enable IMAP, if it is not already enabled here. Scroll down to IMAP Access and make sure Status is set to Enable IMAP. I am not sure about other providers as I have not tried them.

Step 3: (Gmail users who use 2FA only) Add an App Password to Use Instead of your Google Account Password

If using Gmail and you have 2 Facter Authentication setup, do these steps. Otherwise, skip to step 4

  1. Go to https://myaccount.google.com/
  2. On the left side, select 'Security'
  3. Scroll down to the 'Signing in to Google' section and select 'App Passwords'
  4. You will be asked to sign in. Sign in.
  5. Once you have signed in again, press the menu 'Select an App' and then press 'Other'. Make the name something memorable such as 'Pihole'.
  6. Click 'GENERATE'. Copy the 16 character password for later.

Step 4: Set up the Repo and Install

On the Raspberry Pi, Clone this repository:

git clone https://github.com/perspector/Pihole-404.git

Navigate to the project folder:

cd Pihole-404

or wherever the repo folder was installed if you installed it in a different location.
Run the installer script (as root):

sudo python3 install.py

When you are asked for a password, enter your email password. If you use Google/Gmail and have 2 Facter Authentication set up, paste the app password from earlier (Step 3) here using Ctrl + Shift + V
Test the script here: http://doubleclick.net
You should get a 404 page like the screenshot above.

Known Issues/Bugs

  The script only works for http websites, not https/tls 😢.
  When using SSH to access the Raspberry Pi, the email checker program may be stopped when exitting SSH.
If this happens, just log on to the Raspberry Pi through HDMI and a keyboard.
Then go to the folder you cloned this repo in using cd Type:

watch -n 10 python3 EmailChecker.py &

This will start the program in the background.
If you did not setup run on boot in the installer script, when you shutdown or restart, you also must run this command.
If the Raspberry Pi updates, you may need to run the installer script again.
The installer script should fix this.

Note: This script sets blocking mode to IP blocking. If you want to change this, just edit /etc/pihole/pihole-FTL.conf and set blocking mode to something else (anything other than IP will disable the 404 page). This is explained in depth here

Uninstalling

If you want to uninstall the programs and restore settings before the script was used, just use the following command:

sudo sh uninstall.sh

Please email me at [email protected] to tell me why you chose to uninstall the programs.

Customizing

You can always replace background.jpg with another file (must have same filename).
You can also replace foreground.png with another file (must also have the same filename).
The CustomBlockPage.php file can be changed to whatever you want (must also have the same filename).

Credits

If you find this repo useful, please ⭐ it and share it! If you have questions, just create an issue