hassio-addons / addon-pi-hole

Pi-hole - Home Assistant Community Add-ons
https://addons.community
MIT License
123 stars 39 forks source link

Unable to retrieve API token since v4.0.0 #99

Closed CodeFinder2 closed 4 years ago

CodeFinder2 commented 5 years ago

Problem/Motivation

I am using this switch to temporarily disable pihole blocking which uses curl and the authentication token: https://community.home-assistant.io/t/pi-hole-switch/22004/26

After upgrading pihole to v4.0.0, this doesn't work anymore. The sensor still works fine but this does not use (?) the same interface (I assume).

Expected behavior

Any way to get the API token or to gain access to PiHole's status and enabling/disabling it via curl or the like would do.

Actual behavior

When trying to get the token underMenu, Settings > API / Web interface > Show API token > Yes, show API token just displays "No password set". But no token.

Steps to reproduce

Install pihole and try to get the token, see above.

Home Assistant Community
Pi-Hole switch
yes it works: pihole_enable: curl -X GET 'http://LOCALIP:PORT/admin/api.php?enable&auth=AUTH' LOCALIP… Local Ip of your Hassio PORT: can be set within pi hole addon at --> “admin_port”: XXXX, AUTH: that was the “tricky” part. make a backup of your pihole addon (or complete Hassio Snapshot) Download this backup -> tar file open the file with 7zip (WINRAR doenst work for me) find the following file within “pihole”: setupVars.conf open it… here you will find the line WEBPASSWORD. This is you...
addons-assistant[bot] commented 5 years ago

:wave: Thanks for opening your first issue here! If you're reporting a :bug: bug, please make sure you include steps to reproduce it. Also, logs, error messages and information about your hardware might be usefull.

sinclairpaul commented 5 years ago

You shouldn't need the token anymore try using localhost:4865 as the server/port. If it fails still it may need a new release.

Edit - curl -X GET 'http://localhost:4865/admin/api.php?enable

CodeFinder2 commented 5 years ago

Thanks for your quick reply! Unfortunately, this still doesn't work. I simply removed the "&auth=MY_OLD_TOKEN" part in my curl commands but they do not have any effect.

More ideas? What do you mean with 'it may need a new release', what precisely needs a new release? This addon? 🙈

Thanks again! :-)

Edit: regarding your edit, yes this is exactly the command I have used. :(

sinclairpaul commented 5 years ago

90 Should fix it, just need to wait a bit for it 😄

From when I tested I believe curl -X GET 'http://localhost:4865/admin/api.php' would work and get the status, but the enable/disable would fail.

CodeFinder2 commented 5 years ago

Exactly, status works but enable/disable does not. 🙈

nickdos commented 4 years ago

I'm also trying to get this to work. FYI here's the use-case: https://www.reddit.com/r/pihole/comments/bvq5aq/pihole_quick_enabledisable_toggle_for_apples_ios/

reddit
Pi-hole Quick Enable/Disable Toggle for Apple's iOS Shortcuts App
I wanted a quick and easy way to toggle my Pi-hole on/off from my phone when needed, so I made a simple iOS Shortcut to take advantage of the API....
sinclairpaul commented 4 years ago

Please wait for the next release in which the issue should be resolved.

desiredbean commented 4 years ago

For my use that works for status but not turning on and off, to turn off I use curl -X GET 'http://localhost:4865/admin/api.php?disable=3600&auth=' I just removed the API token and it worked for me.

CodeFinder2 commented 4 years ago

Please wait for the next release in which the issue should be resolved.

Any plans for a new release yet?

wyx087 commented 4 years ago

Inspired by the curl URL, I've found you can use the following configuration for HA:

pi_hole:
  host: localhost:4865
  api_key: ""

I've successfully ran pi_hole.disable and .enable from HA to control the pi-hole HassIO addon.

So perhaps a minor documentation change is all that's needed. Add the api_key: "" line in this section.

CodeFinder2 commented 4 years ago

Thanks @wyx087, that's working for me as well (see also here)!

Nonetheless and IMHO, this is considered a bug so it should be fixed as stated by sinclairpaul.

alderete commented 4 years ago

While I am also able to disable the Pi-Hole addon by using the auth='' (empty token) trick, I can do that from any machine on my network. That seems like a security issue.

Any movement on making it possible to set a password for the Pi-Hole addon, so that there's a real API token?

sinclairpaul commented 4 years ago

The challenge is around allowing ingress access, and meeting the app security.

https://github.com/hassio-addons/addon-pi-hole/pull/114

This PR would enforce API access from HA/localhost only.

alderete commented 4 years ago

I get that it's a tricky technical challenge. :-)

But, I don't think the right solution is to restrict API access to Home Assistant-only. That would mean that I can only use Home Assistant to enable/disable, which is quite limiting.

For example, I have an iOS app called PHRemote that gives a nice, simple interface for disabling for various lengths of time. And there's a project on GitHub for a similar app, that I've thought about hacking on for my own enjoyment, to have absolute control over the UX.

I get that I can customize my Home Assistant user interface to give me a similarly simple UX. But I'm not the only user on my network, and getting the other residents of the house to use the Home Assistant app, or connect to the web interface, is not a simple undertaking. And blocking them from their Internet memes and other stuff is not going to go over well. I gotta have something simple to offer them.

sinclairpaul commented 4 years ago

From the PR May be worth considering making this configurable in the use case of controlling Pi-Hole external to HA?

Please consider that we get numerous requests from different users, in this case, we could enable API token usage again, but you will then also be prompted to login to the application, which then means moving the authentication to ingress becomes invalid.

Unfortunately it really isn't possible to please 100% of the people 100% of the time 😉

PS - I don't believe that Ad guard home has these issues.....

sinclairpaul commented 4 years ago

New release is out, please respond if the issue still exists.

CodeFinder2 commented 4 years ago

Thanks! As already stated above, it was and is still working fine.

However, IMHO the api_key option is obsolete now and should be removed, don't you think (from the docs as well as from the component config entry in confirmation.yaml)? 🙈

frenck commented 4 years ago

@CodeFinder2 The configuration option still applies to standalone installations of Pi-hole, so that is not correct.

CodeFinder2 commented 4 years ago

Ahh, thanks! Sorry, that makes sense! 🙏

addons-assistant[bot] commented 4 years ago

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.