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 reading PiHole stats #317

Closed
AlexFullmoon opened this issue Oct 14, 2021 · 8 comments
Closed

Error reading PiHole stats #317

AlexFullmoon opened this issue Oct 14, 2021 · 8 comments

Comments

@AlexFullmoon
Copy link
Contributor

Pihole at https://dns.mydomain.tld/api.php returns valid-looking json:

{"domains_being_blocked":999385,"dns_queries_today":3187,"ads_blocked_today":66,"ads_percentage_today":2.070913,"unique_domains":779,"queries_forwarded":2418,"queries_cached":683,"clients_ever_seen":11,"unique_clients":11,"dns_queries_all_types":3187,"reply_NODATA":50,"reply_NXDOMAIN":13,"reply_CNAME":27,"reply_IP":42,"privacy_level":0,"status":"enabled","gravity_last_updated":{"file_exists":true,"absolute":1634201879,"relative":{"days":0,"hours":0,"minutes":39}}}

Yet homer/PiHole.vue fails with
SyntaxError: Unexpected token F in JSON at position 0 PiHole.vue:71

@sargonas
Copy link

If it helps you any, I just looked at my own, and it seems to be working fine, and from looking through the API JSON results, the format and data points haven't changed in a long time so in theory should still be parsing fine by default.

@AlexFullmoon
Copy link
Contributor Author

Ugh. As I suspect, its again something something CORS something misconfiguration headers.

Any advice on how to debug that?

@sargonas
Copy link

CORS issues are my bane as well debugging and I am afraid my knowledge on working around them is limited. I wonder though, are you using a reverse proxy internally for your hostnames? if so it may perhaps work better if you call the PiHole by it's IP address directly.

@AlexFullmoon
Copy link
Contributor Author

I wonder though, are you using a reverse proxy internally for your hostnames?

Sure I do, nginx (with wather limited configuration options). Calling through http://IP would cause mixed content error.

@sargonas
Copy link

sargonas commented Oct 17, 2021

I could easily have my web tools mixed up, but im pretty sure you can call http://IP:port i think, if that helps.

@mcclurec
Copy link
Contributor

mcclurec commented Nov 3, 2021

Likely related to this PR cc @bastienwirtz we should finalize on a fetch mixin pattern and get it merged

@ellisdickinson46
Copy link

ellisdickinson46 commented Dec 7, 2021

For anyone needing to diagnose this CORS issue, this thread may solve part of the problem temporarily: https://discourse.pi-hole.net/t/add-domain-to-authorized-hostnames-permanently/32007/2.

To summarise, you can modify, the $AUTHORISED_HOSTNAMES declaration in the auth.php file of pihole found at /path-to-pihole/admin/scripts/pi-hole/php/auth.php to include the domain or IP of your homer instance. Do note this will likely need updating every time you update Pi-hole. Additionally because of the use of credentials when fetching data, you will also need to set the Access-Control-Allow-Credentials to true, this header should be set on your proxy.

As for the SyntaxError you will see, after some poking, it is the beginning of an error from Pi-hole that reads:
"Failed CORS: [browser_origin] vs [authorised_hostnames]", this is likely caused by CORS headers being set on your proxy instead of on your Pi-hole instance itself. Changing it to be on Pi-hole fixed this problem for me.

Edit: Fixed Typos

@bastienwirtz
Copy link
Owner

Hi there !

CORS related issues are now documented here (feel free to add information if needed) and I finished to add the support for the useCredential option. It should help!

I'm closing this issue as every info are available to solve the PiHole CORS issue. Feel free to reopen if needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants