The Pi-hole blocks ads for your entire network and it does so without any attention from you. I get comments and emails every day of people saying that they like how well it works. This is nice because since I know that it is operational, I can work on fun, new features. I prefer to do things this way as there is no point in improving something that is already broken. So thankfully, the Pi-hole continues to run!
In this post, I will tell you about some back-end improvements and then I will be making a another post about something really fun that I have been working on for the front-end.
Debugging Using X-Headers
Prior to figuring it out, if you had the Pi-hole dashboard installed, you were not able to access it while connected to the Pi-hole because all requests–including the dashboard–would get redirected to a blank page.
I have now it setup so that you can run a curl command to see if everything is set up properly. Take a look at the commands below. First, I download the header of the dashboard to verify it is working, which the X-Pi-hole header confirms.
me@MacBookAir:~$ curl -I http://192.168.1.141/admin/index.php HTTP/1.1 200 OK X-Pi-hole: The Pi-hole Web interface is working! Content-type: text/html; charset=UTF-8 Date: Fri, 09 Oct 2015 22:16:55 GMT Server: lighttpd/1.4.35
Next, I download an ad-serving domain to verify the blank page gets downloaded and that the cache control is working. This time, the X-header has changed to show that the black hole is devouring advertisements. The cache-control part already existed since this was part of the original Pi-hole, but it’s nice to have anyway.
me@MacBookAir:~$ curl -I a-ads.com HTTP/1.1 200 OK X-Pi-hole: A black hole for Internet advertisements. Expires: Sat, 10 Oct 2015 22:16:58 GMT Cache-Control: max-age=86400 Content-Type: text/html Accept-Ranges: bytes ETag: "831319033" Last-Modified: Sat, 03 Oct 2015 16:56:15 GMT Content-Length: 49 Date: Fri, 09 Oct 2015 22:16:58 GMT Server: lighttpd/1.4.35
Another useful feature is to see an access log of what resources are requested by clients. Here is a snippet of a log. First, my own site was trying to track me via WordPress stats. Then, you can see my curl commands going through, and finally, me writing this post.
..... pixel.wp.com 192.168.1.134 - - [09/Oct/2015:22:10:57 +0000] "GET /g.gif?v=wpcom-no-pv&x_notes-menu-impressions=nonzeroasync-jetpack&baba=0.1243435454 HTTP/1.1" 200 49 "http://pi-hole.net/install-the-web-interface-on-an-existing-pi-hole/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.7424.55 Safari/375.36" 192.168.1.141 192.168.1.134 - - [09/Oct/2015:22:11:37 +0000] "HEAD /admin/index.php HTTP/1.1" 200 0 "-" "curl/7.43.0" 192.168.1.141 192.168.1.134 - - [09/Oct/2015:22:15:04 +0000] "HEAD / HTTP/1.1" 200 0 "-" "curl/7.43.0" pixel.wp.com 192.168.1.134 - - [09/Oct/2015:22:17:27 +0000] "GET /g.gif?v=wpcom-no-pv&x_notesmenu-impressions=zero-jetpack&baba=0.4221303828526288 HTTP/1.1" 200 49 "http://jacobsalmela.com/wp-admin/post-new.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.5.4123.15 Safari/537.36" .....
You can use the access log for debugging, trending, or… my next fun, front-end project. Here is a hint: