bpennypacker / phad

Pi-Hole Alternate Display
GNU General Public License v3.0
75 stars 8 forks source link

Remove OpenDNS for external IP fetch #24

Closed PureFallen closed 3 years ago

PureFallen commented 3 years ago

Recently OpenDNS removed the possibility to fetch someone's own raw public IP address using https://diagnostic.opendns.com/myip, while diagnostic.opendns.com asks for a login.

Instead of trying a new address, PHAD fetches the html-code of the "fake 404"-page and inserts it as public IP into phad.dat:

[...]

public_ip=<html>
 <head>
  <title>404 Not Found</title>
 </head>
 <body>
  <h1>404 Not Found</h1>
  The resource could not be found.<br /><br />

 </body>
</html>

As result of that, PHAD fails to get the value afterwards, throwing an ValueError and causing PHAD to close. Depending how PHAD has been added to ./bashrc, that might causes PHAD to loop, keep crashing python and starting from a new.

  File "./phad", line 1128, in <module>
    data = fetch_data(config)
  File "./phad", line 783, in fetch_data
    get_timed_data(config, data)
  File "./phad", line 336, in get_timed_data
    (key, val) = chomp(line).split("=")
ValueError: not enough values to unpack (expected 2, got 1)
Exception ignored in: <function InputDevice.__del__ at 0x75cb1a08>
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/evdev/device.py", line 159, in __del__
  File "/home/pi/.local/lib/python3.7/site-packages/evdev/device.py", line 304, in close
  File "/home/pi/.local/lib/python3.7/site-packages/evdev/eventio_async.py", line 54, in close
  File "/usr/lib/python3.7/asyncio/events.py", line 726, in get_event_loop_policy
  File "/usr/lib/python3.7/asyncio/events.py", line 719, in _init_event_loop_policy
ImportError: sys.meta_path is None, Python is likely shutting down

Obvious Fix for now is to remove the no longer functioning OpenDNS URL from phad.conf, yet we probably will have to look into ErrorHandling for anything other then "unavailable". In order to get PHAD back working, user also have to delete phad.dat manually after removing the URL as the error inside the dat-file still exists.

macilath commented 3 years ago

@PureFallen We just came across this issue internally in something completely unrelated; but it looks like OpenDNS now has a different endpoint for checking your IP address: https://myip.dnsomatic.com | See OpenDNS Troubleshooting KB Hope that's helpful.

PureFallen commented 3 years ago

DNS-o-matic is indeed owned by OpenDNS. Weird change with a lot of breakage. We could eventually add this domain as a new alternative in the phad.conf, through if (and at which priority in the list) is probably something for @bpennypacker to decide.

PureFallen commented 3 years ago

https://diagnostic.opendns.com/myip is now back operating. The question is for how long that will be the case and if people with a corrupt phad.dat are able to retrieve the external IP again. Removing the Hostname from the config seems no longer required but i still smell the opportunity that this accident should be used to work on error handling for the case that something like this happens again.

bpennypacker commented 3 years ago

Thanks for digging into this & providing a patch to remove it. I'll definitely look into adding some error handling etc. around the logic to get the external IP when I get a chance.