Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ERROR]: Unable to parse results from queryads.php: Unhandled error message () #2195

Closed
3 tasks done
silv3rr opened this issue May 28, 2018 · 48 comments
Closed
3 tasks done
Labels
Submitter Attention Required Need action from submitter to continue triage: Issue User Filled out Issue Template

Comments

@silv3rr
Copy link

silv3rr commented May 28, 2018

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:

$queryAds = file("http://127.0.0.1/admin/scripts/pi-hole/php/queryads.php?domain=$serverName&bp", FILE_IGNORE_NEW_LINES);

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

@AzureMarker
Copy link
Contributor

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.

@silv3rr
Copy link
Author

silv3rr commented May 30, 2018

@Mcat12 I did not delete anything, I just opened a new issue. Anyways, I edited and molded issue to template.

@dschaper dschaper added the triage: Issue User Filled out Issue Template label May 30, 2018
@AzureMarker
Copy link
Contributor

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.

@silv3rr
Copy link
Author

silv3rr commented Jun 1, 2018

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:

  • open source code file in github web interface as usual
  • click line number and create new issue
  • no template

@bolausson
Copy link
Contributor

bolausson commented Jun 11, 2018

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

@AzureMarker
Copy link
Contributor

If a blocked domain is resolved to the IPv6 address of the Pi-hole, does the block page work?

@bolausson
Copy link
Contributor

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

@silv3rr
Copy link
Author

silv3rr commented Jun 21, 2018

@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);
...

@silv3rr
Copy link
Author

silv3rr commented Jun 21, 2018

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).

@dschaper
Copy link
Member

@silv3rr Do you want to open a Pull Request with your code additions?

@dschaper dschaper added the Submitter Attention Required Need action from submitter to continue label Jul 10, 2018
@silv3rr
Copy link
Author

silv3rr commented Jul 12, 2018

@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) ?

@dschaper
Copy link
Member

We'd welcome the Pull Request if you'd like to set one up.

@dschaper dschaper removed the Submitter Attention Required Need action from submitter to continue label Jul 12, 2018
@Sh4d1
Copy link
Contributor

Sh4d1 commented Aug 21, 2018

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>%

@DrMacinyasha
Copy link

DrMacinyasha commented Aug 27, 2018

@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 $serverName there instead of the IP address.

@Sh4d1
Copy link
Contributor

Sh4d1 commented Sep 3, 2018

@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 :)

@rolsch
Copy link

rolsch commented Nov 4, 2018

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...

@freemann
Copy link

@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.

@rolsch
Copy link

rolsch commented Nov 12, 2018

Manually :-)
After an pihole -up i change the lighttpd config to port 81 and restart.
The apache2 runs at port 80/443...

@melroy89
Copy link

melroy89 commented Jan 3, 2019

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.

@dschaper
Copy link
Member

dschaper commented Mar 7, 2019

Please open a new issue.

@mingaldrichgan
Copy link

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).

@MichaIng
Copy link
Contributor

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.

@mfigrs
Copy link

mfigrs commented Apr 25, 2019

I've just encountered this issue.

My setup:

  • pihole in docker container (with macvlan driver and its own IP) on Synology DS.
  • port forward on router - from port 88 external to port 80 internal

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?

@unitpas
Copy link

unitpas commented Apr 25, 2019

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

@unitpas
Copy link

unitpas commented May 7, 2019

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

@mschoettle
Copy link
Contributor

This issue can occur in two ways:

  1. changing the port
  2. changing the host from pi.hole to something else

In 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.

@corbolais
Copy link

corbolais commented Feb 8, 2020

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

@pgporada
Copy link

I can confirm that @unitpas simple fix works for me on a raspberry pi.

mschoettle added a commit to mschoettle/pi-hole that referenced this issue Apr 10, 2020
… and/or hostname.

See issues pi-hole#2195 and pi-hole#2720.

Signed-off-by: Matthias Schoettle <git@mattsch.com>
@rvs007
Copy link

rvs007 commented Apr 20, 2020

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.

@akeyx
Copy link

akeyx commented Apr 22, 2020

As per pi-hole/docker-pi-hole#224 (comment)
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.

@pralor-bot
Copy link

This issue has been mentioned on Pi-hole Userspace. There might be relevant details there:

https://discourse.pi-hole.net/t/failed-cors-null-vs-192-168-1-9-dns-somesecretname-nl-pi-hole-localhost/37746/10

@wmarler
Copy link

wmarler commented Apr 18, 2021

This issue gets stickier when you've:

  1. not installed lighttpd, but set up apache instead
  2. configured the Admin-LTE pages to be served via a vhost, e.g. 'pihole.mydomain.com'
  3. setup letsencrypt certificates and are redirecting http to https

I started poking when I got the following log entry in my apache log whean I loaded https://pihole.mydomain.com/pihole/index.php

[Sat Apr 17 23:59:20.554071 2021] [php7:warn] [pid 1654310] [client 10.100.1.199:34506] PHP Warning: file(http://127.0.0.1:443/admin/scripts/pi-hole/php/queryads.php?domain=pihole.mydomain.com&amp;bp): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request\r\n in /var/www/pihole/pihole/index.php on line 172

Replacing the static http://127.0.0.1 with https://pihole.mydomain.com makes the page load, but styling and javascript wouldn't load. I got this in the apache logs: [Sun Apr 18 00:45:42.131151 2021] [core:info] [pid 3062177] [client 10.100.1199.20:34906] AH00128: File does not exist: /var/www/dns/pihole/pihole/blockingpage.css, referer: https://pihole.wmarler.com/pihole/index.php

The issue isn't so much with the "/var/www/dns/" as it is with the "pihole/pihole/blockingpage.css'. Changing line 267 of pihole/index.php to href="/pihole/blockingpage.css" fixed that. Is that safe? There were a few other src/href links I changed to absolute links from relative ones to make the page load.

I'm thinking .... this might be an unsupported use case : )

@calvinthefreak
Copy link

Problem is still persistant... the Problem is, that some browsers like Firefox give errorpages in the Beta for using HTTP (Like the warn for unsigned SSL)
I am using Nginx-Reverseproxy in front, and want to use SSL in my network. So no little Kiddie in my network could intercept the request like a charm...

@MichaIng
Copy link
Contributor

MichaIng commented Jul 16, 2021

Probably it's better to query the database directly instead of doing an API request, which should also be faster: https://github.com/pi-hole/pi-hole/blob/8660459/advanced/index.php#L167-L172

But as far as I can think of now, the browser or proxy shouldn't play a role here as the request is done by the PHP server and not the browser, isn't it? 🤔
The issue most likely is when the webserver redirects this request to HTTPS, which does not work with a plain IP. It would be possible to configure the webserver to serve plain HTTP requests for local requests only, which should solve the issue. But better indeed to not rely on a plain HTTP requests at all (code-wise).

For the issue with the blockingpage.css you mean this line?
https://github.com/obones/pi-hole/blob/85cf988/advanced/index.php#L233
I'm currently not sure whether this needs to be a full URL, when used as blocking page. But actually the parent request is done to the Pi-hole server already, so it should be fine to use regular absolute file paths there. But someone needs to verify as we might miss something. And might not be worth to do something about it anymore, as of: #3910

@calvinthefreak
Copy link

@MichaIng First Problem here is:
Request is done http in the backend inside the "Backbone"
but the server still thinks, that the request, like @silv3rr did wrote the Server still thinks, that its port 443....
Well, that will not work.

So, little hacketty spaghetti and the nginx Proxy simulates "http" request to hostname "[ip of container]"
Seems about to be right, but still... I need to rewrite / to /admin/ because otherways pihole thinks, the domain, which isn't blocked is blocked.

Here for Anybody interested:
(done with nginxproxymanager)
grafik

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Please comment or update this issue or it will be closed in 5 days.

@github-actions github-actions bot added the Submitter Attention Required Need action from submitter to continue label Jan 11, 2022
@LuckyTurtleDev
Copy link

I still hit the issue at the latest docker image.
Maybe it should be reopen.

@yubiuser
Copy link
Member

@Lukas1818 Please open a new issue at https://github.com/pi-hole/docker-pi-hole

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Submitter Attention Required Need action from submitter to continue triage: Issue User Filled out Issue Template
Projects
None yet
Development

No branches or pull requests