In raising this issue, I confirm the following: {please fill the checkboxes, e.g: [X]}
How familiar are you with the the source code relevant to this issue?:
7
Expected behaviour:
"Website blocked" page
Actual behaviour:
[ERROR]: Unable to parse results from queryads.php: Unhandled error message ()
Steps to reproduce:
Goto blocked/blacklisted domain.
For me the error is caused by having lighttpd listening (server.bind) on a specific network interface alias, not localhost.
Debug token provided by uploading pihole -d log:
N/A
Troubleshooting undertaken, and/or other relevant information:
Saw this already mentioned by @Amunak in issue #2172. Actually diff problem than @KnightTim, so created new issue:
It's fixed by replacing 127.0.0.1 with the IP of that interfaces or using $_SERVER['SERVER_ADDR'] var like @Amunak said:
$serverAddr = htmlspecialchars($_SERVER['SERVER_ADDR']);
$queryAds = file("http://$serverAddr/admin/scripts/pi-hole/php/queryads.php?domain=$serverName&bp", FILE_IGNORE_NEW_LINES);
To be 100% safe perhaps add a check if that var doesn't exist to use http://pi.hole/admin/scripts/pi-hole/php/queryads.php instead
Please fill out the issue template (see here for the template you deleted).
We install lighttpd to use localhost, so this is not an issue with a normal install. However, I do see the issue.
@Mcat12 I did not delete anything, I just opened a new issue. Anyways, I edited and molded issue to template.
It appears that some mobile clients don't start with the template like the website does...
If you want you can make a PR to fix it, or we will.
Addendum: seems queryAds also doesn't work with IPv6 (same issue)
About the template: not sure if I was on mobile tbh, but generate a PR if you want to.
EDIT: fyi think I know what happened:
I have the same issue as described by @silv3rr
When I open the PiHole IPv6 address (http://[2003:5f....]) in my browser (Chrome on Windows 10) , I get:
[ERROR]: Unable to parse results from queryads.php: Unhandled error message (Invalid domain!)
Wheres when I use the IPv4 (http://10.0...) address, I get a nice Logo with the following text below:
Pi-hole: Your black hole for Internet advertisements
My PiHole is running on a Raspberry Pi 3 Model B with an up to date Rasbian.
Pi-hole Version v3.3.1
Web Interface Version v3.3
FTL Version v3.0
If a blocked domain is resolved to the IPv6 address of the Pi-hole, does the block page work?
I recently switched my router and IPv6 is not yet working, so I can't test it at the moment. I'll try it as soon as my IPv6 is working again.
Anyone else who could test it at the moment?
Cheers,
Bjoern
@Mcat12 nope:
# host pi.hole
pi.hole has address 192.168.0.254
pi.hole has IPv6 address 2001:fff:ffff:fff::1
# pihole -b example.com
[i] Adding example.com to blacklist...
[i] example.com does not exist in whitelist, no need to remove!
[i] example.com does not exist in wildcard blacklist, no need to remove!
[i] Using cached Event Horizon list...
[i] 130562 unique domains trapped in the Event Horizon
[i] Number of blacklisted domains: 6
[鉁揮 Parsing domains into hosts format
[鉁揮 Cleaning up stray matter
[鉁揮 Force-reloading DNS service
[鉁揮 DNS service is running
[鉁揮 Pi-hole blocking is Enabled
# host example.com
example.com has address 192.168.0.254
example.com has IPv6 address 2001:fff:ffff:fff::1
# curl -4 -s example.com|head
<!DOCTYPE html>
<!-- Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL. -->
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/> <meta name="robots" content="noindex,nofollow"/>
# curl -6 -s example.com
[ERROR]: Unable to parse results from <i>queryads.php</i>: <code>Unhandled error message (<code></code>)</code>
My kludge:
function queryAds($serverName) {
...
$serverAddr = htmlspecialchars($_SERVER['SERVER_ADDR']);
// ipv6 does not seem to work..
if (strpos($serverAddr, ':') !== false) {
echo ("<b>NOTICE:</b> Changing Server Address <code>$serverAddr</code> to <code>empty</code><br>");
$serverAddr = "";
}
if (empty($serverAddr)) {
$serverAddr = gethostbyname("pi.hole") ? "pi.hole" : "192.168.0.254";
echo ("<b>NOTICE:</b> Changed empty Server Address to <code>$serverAddr</code><br>");
}
$queryAds = file("http://$serverAddr/admin/scripts/pi-hole/php/queryads.php?domain=$serverName&bp", FILE_IGNORE_NEW_LINES);
...
Test with kludge enabled:
# curl -6 -s example.com|head
<b>NOTICE:</b> Changing Server Address <code>2001:fff:ffff:fff::1</code> to <code>empty</code><br><b>NOTICE:</b> Changed empty Server Address to <code>pi.hole</code><br><!DOCTYPE html>
<!-- Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL. -->
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/> <meta name="robots" content="noindex,nofollow"/>
Also http://[2001:fff:ffff:fff::1]/admin/ in browser does always work for me, without kludge (but not queryads).
@silv3rr Do you want to open a Pull Request with your code additions?
@dschaper That was just a quickfix with hardcoded ip and example to show the issue.
As a general fix it's probably best to get ip from setupVars.conf and reuse code from Dashboard's admin/settings.php:
https://github.com/pi-hole/AdminLTE/blob/e48aa295bd993a4a82bdabeb12a73e3123fc1559/settings.php#L80
So, combine $_SERVER['SERVER_ADDR'] and ipv4/6 from setupVars, then if we still don't have an address use 'pi.hole' as last fallback. That seems pretty robust.
If you want I can do the change (and create pull req) ?
We'd welcome the Pull Request if you'd like to set one up.
Any updates here ? Having the same issue as @bolausson :
$ curl -g -6 "[pi hole ipv6 address]"
[ERROR]: Unable to parse results from <i>queryads.php</
i>: <code>Unhandled error message (<code>Invalid domain
!</code>)</code>%
@Sh4d1 I found that the fix mentioned in #2172 fixed this issue for me:
In my case the same issue boils down to this line in index.php:
$queryAds = file("http://127.0.0.1/admin/scripts/pi-hole/php/queryads.php?domain=$serverName&bp", FILE_IGNORE_NEW_LINES);For whatever reason there's hardcoded IP address of the server even though there's almost no reason to do that, and it fucks with more complicated setups that don't pass everything to the pihole web interface. The fix, to me, was to just put
$serverNamethere instead of the IP address.
@DrMacinyasha I guess it's two different issues, one when trying to access the pi hole server, the second when trying to access a website. The PR #2388 fixes the server access :)
I have configure the lighttpd / pihole for tcp port 81 after the install,
so this hardcoded string take me in some trouble :-(
Port 80 is used for an apache2 / nextcloud b眉ndle (NextcloudPI).
So please make this string more dynamic in the next pihole versions - thanks.
The setup script should ask/check the lighttpd port and set the correct vars in the scripts...
@rolsch did you managed to fix it? If so, how did you fix? I'm experiencing the same error after reconfiguring to http_port <> 80.
Manually :-)
After an pihole -up i change the lighttpd config to port 81 and restart.
The apache2 runs at port 80/443...
Also note that I run Nginx on port 443 (using Let's Encrypt) together with a domain name. So uhh.. this should be config depended.
Please open a new issue.
I, too, was getting this error message instead of the splash page on nginx, and fixed it by adding the $serverName to the list of $authorizedHosts (see pull request).
Hey guys. We also got a report about this issue posted by OP and I am trying to replicate but can't. Tested on Lighttpd without setenv.add-environment = ("fqdn" => "true") and blocking page shows up fine. Tested access from another system on local network.
I could not identify any clear steps to replicate yet, besides the above. Also I am not quite sure what the FQDN parameter actually does, overriding somehow a check whether the request is coming from a FQDN or not? If so this doesn't sound like a reasonable "fix" at all. Instead of overriding parameters I suggest to handle the given ones as desired. But yeah, I do not really understand the issue here, so far 馃槈. If I can help with whatever testing, my machines are ready and can be configured with any webserver. Just need to know how to force the error in the first place.
@rolsch
Btw why bother with Lighttpd when using Apache anyway? Simple skip webserver install when being asked during Pi-hole installer, or run the script with --disable-install-webserver. Pi-hole runs fine on Apache + Nginx as well. Multiple webservers + custom posts might be a reason for errors in general, at least I would not rely on that everything uses the correct desired ports, e.g. when certain web application is doing some checks on itself and simply uses loopback IP/localhost on default HTTP(S) port.
I've just encountered this issue.
My setup:
After visiting mywebsite.com:88 I get this error. However, if I access pihole locally by typing the macvlan IP, all works fine.
Is this an issue with my setup, or is it a pihole issue?
docker exec -it
apt-get update
apt-get install nano
nano /var/www/html/pihole/index.php
change
$serverName = htmlspecialchars($_SERVER["HTTP_HOST"]);
with
$serverName = htmlspecialchars($_SERVER["SERVER_ADDR"]);
Ctrl+X to save
reload web page
Please open Docker issues in our Docker repository. https://github.com/pi-hole/docker-pi-hole
@dschaper
But the solution by @unitpas doesn't look like something docker specific. I'm no expert and not sure about the difference between those two variables (HTTP_HOST vs SERVER_ADDR), but perhaps one works more generic then the other one? At least the error reported here (not only in combination with docker) is related to this $serverName.
We have a number of different issues crossing over each other. There are docker issues (modifying a file in a docker container will be lost when the container is restarted) and AdminLTE issues (index.php is at https://github.com/pi-hole/AdminLTE/blob/master/index.php). If the proposed solution is AdminLTE related then there needs to be an issue opened in that repository to track it. If the issue is potentially created by docker or solved by docker image changes then the issues need to be opened there.
@dschaper
Most importantly, the solution by @unitpas works for me.
I am a newbie at this, but it doesn't seem to me that it is an "AdminLTE" issue. The "AdmnLTE" index.php does not look like the file I edited. Besides, I could not even see the welcome page, as that is where I got the error.
I also do not think it's a docker issue. Just a problem with $serverName - perhaps it could be an array of HTTP_HOST and SERVER_ADDR - so that it would work in both scenarios?
sorry newbie here, just set up pihole, and was wanted to access the webserver remotely so did a port map in my router.
But when I try to reach it from outside, it gives me this error
I installed ubuntu in a VM just to run pihole - no issues when I'm at home on my own network.
Is this is the same error or should I open a new thread?
TY
docker exec -it bash
apt-get update
apt-get install nanonano /var/www/html/pihole/index.php
change
$serverName = htmlspecialchars($_SERVER["HTTP_HOST"]);
with
$serverName = htmlspecialchars($_SERVER["SERVER_ADDR"]);Ctrl+X to save
reload web page
Worked.
Thanks for this.
To add more info though, I use a different port externally, to map port 80 internal. If I connect to the external IP directly with the different port, it throws that error, but if I edit and go directly to the dashboard link like this:
http://externalip:port/admin/index.php
There are no issues, works fine. Which I'm ok with (and would rather not make any changes from the stock installation).
What's the diff between HTTP_HOST and SERVER_ADDR in the code? Does one not handle things well? Sorry not a Linux guy...,
Cheers
@teredactle see https://www.php.net/manual/en/reserved.variables.server.php
SERVER_ADDR'
The IP address of the server under which the current script is executing.
'HTTP_HOST'
Contents of the Host: header from the current request, if there is one.
ok.... this tells me nothing, as I don't use Linux or code; I have no idea what these mean in this particular context, and why one would solve the issue over the other.
What is your question? The difference between the two? Without a more specific question, that is the best answer I can give.
SERVER_ADDR'
The IP address of the server under which the current script is executing.
@teredactle my solution works because the docker instance SERVER_ADDR is 127.0.0.1 same as the local host computer
This issue can occur in two ways:
pi.hole to something elseIn my case I have a reverse proxy so I wanted to use port 80 and lighttpd on another port.
There are a few changes in pihole/index.php that I did that solve part of this problem (changing the port and host). I am happy to create a pull request for this.
The other issue is this condition with the hard-coded host pi.hole to redirect to the admin page: https://github.com/pi-hole/pi-hole/blob/master/advanced/index.php#L53
I saw somewhere that this blocking page will disappear (correct me if I'm wrong) so this might not be a problem anymore.
TL;DR: umask issue. #2413 (curtesy of @DrGeoff) tipped me off: umask of 0077 lead to inaccessible /var/www/html/admin, /var/www/html/pihole permissions were fine, though!
Solution: Fix permissions of /var/www/html/admin/*.
Kept For Reference Only:
This happened when deploying pihole on a machine using sslh (both openvpn an httpd use port 80) and having
server.bind = "127.0.0.1"
server.port = 8080
in lighttpd.conf. Additionally, pihole is listening in on tun0, ip 10.x.x.1#53 with pihole-FTL equally listening in on tun0, ip 10.x.x.1 . Requests get forwarded to unbound, listening on 127.0.0.1#5353. A completely separate bind/named is listening on 127.0.0.1#53.
Replacing
$serverName = htmlspecialchars($_SERVER["HTTP_HOST"]);
by
$serverName = htmlspecialchars($_SERVER["SERVER_ADDR"]);
in /var/www/html/pihole/index.php as per @unitpas resolved this issue.
cheers
I can confirm that @unitpas simple fix works for me on a raspberry pi.
To add more info though, I use a different port externally, to map port 80 internal. If I connect to the external IP directly with the different port, it throws that error, but if I edit and go directly to the dashboard link like this:
http://externalip:port/admin/index.php
There are no issues, works fine. Which I'm ok with (and would rather not make any changes from the stock installation).
Thank you for this! I had the same problem where I was getting the error when trying to connect to the pihole admin page via a different external port that's forwarded to port 80 of the pihole IP. Just changing the URL to the above works without having to edit any pihole configuration files.
As per https://github.com/pi-hole/docker-pi-hole/issues/224#issuecomment-377669791
A fix for: [ERROR]: Unable to parse results from queryads.php
when running in a docker container is to add the VIRTUAL_HOST environment variable.
This will be dependent on the way you access the container but say if you've created a (nginx) proxy like eg:
server {
listen 80 default;
server_name pi.hole;
server_name pihole;
location / {
proxy_pass http://pi.hole:8180;
}
}
and pi.hole is in your docker host /etc/hosts like:
127.0.0.1 pi.hole
then you need this as the docker container environment variable:
VIRTUAL_HOST: pi.hole:8180
where 8180 is the docker exposed port.
This issue has been mentioned on Pi-hole Userspace. There might be relevant details there:
Most helpful comment
docker exec -it bash
apt-get update
apt-get install nano
nano /var/www/html/pihole/index.php
change
$serverName = htmlspecialchars($_SERVER["HTTP_HOST"]);
with
$serverName = htmlspecialchars($_SERVER["SERVER_ADDR"]);
Ctrl+X to save
reload web page