Some improvements to index.php

Hey there,

First time user of Pi-hole here. Got it running on my Ubiquiti CloudKey following this guide over the weekend. Thanks for the great work!

Two issues I've noticed:

  • As the default HTTP port on a CloudKey is in use by UniFi, the guide included instructions to make lighttpd listen on port 81. I think index.php can be made more robust by adding the port number to the $queryAds array URL (near line 138): $queryAds = file("http://127.0.0.1:{$_SERVER['SERVER_PORT']}/admin/scripts/pi-hole/php/queryads.php?domain=$serverName&bp", FILE_IGNORE_NEW_LINES);
  • I understand that the Pi-hole admin console is supposed to be accessible at http://pi.hole & http://pi-hole/admin when running as DNS server, or http://[ip-address]/admin. When I visit http://[ip-address]/ though, I get an error like this: [ERROR]: Unable to parse results from queryads.php: Unhandled error message (Invalid domain!) If that URL serves no other purpose, changing the conditions (near line 60) to redirect to the admin console would make things more user-friendly: if ($serverName === "pi.hole" || $serverName === $_SERVER['SERVER_ADDR'] || $serverName === "pi.hole:".$_SERVER['SERVER_PORT'] || $serverName === $_SERVER['SERVER_ADDR'].":".$_SERVER['SERVER_PORT']) {

Pardon me for reporting this here rather than sending a PR, GitHub doesn't quite agree with me. Please also let me know if this has any unintended consequences I'm unaware of, as I am new to the code base. Thank you!

I disabled CloudKey's nginx listener and allocated port 80 to Pi-hole and just saw the page that is supposed to be displayed when visiting the ip address without /admin as well as the blocking page.

Looks like it is going to be a fair bit more work to get Pi-hole's pages working properly on a non-standard port.

It may be possible to split eth0 into a virtual interface eth0.1

That might eliminate the port 80/81 issue

1 Like

Thank you! This, I think, is the most elegant solution.

I had gone ahead and created server blocks in nginx to show CloudKey's landing page or Pi-hole based on the host header before I saw your reply.