glance icon indicating copy to clipboard operation
glance copied to clipboard

Enhancement/add support pihole v6

Open KallanX opened this issue 9 months ago • 8 comments

Adding support for the newly released Pi-hole major version 6. This update changed how you interact with the API.

KallanX avatar Feb 20 '25 04:02 KallanX

@ralphocdol I've been able to fix a good portion of your comments. The only thing left is for me to understand these two values:

QueriesSeries piholeQueriesSeries `json:"domains_over_time"`
BlockedSeries map[int64]int       `json:"ads_over_time"`

Are these in the original /api/stats/summary response or are they separate? I was able to grab the top blocked domains by hitting the separate /api/stats/top_domains?blocked=true.

KallanX avatar Feb 20 '25 19:02 KallanX

@KallanX I think this has something to do with the widget's bar graph based on the comment on this code

// Pihole _should_ return data for the last 24 hours in a 10 minute interval, 6*24 = 144
if len(r.QueriesSeries) != 144 || len(r.BlockedSeries) != 144 {
	return stats
}

So the API /api/stats/database/summary?from=1740020400&until=1740021160 was incorrect.

Looking at the screenshot from the DNS Stats docs

The reddish one is most likely the BlockedSeries while the gray one is the QueriesSeries

ralphocdol avatar Feb 21 '25 01:02 ralphocdol

/api/history looks closer

{
  "history": [
    {
      "timestamp": 1511819900.539157,
      "total": 2134,
      "cached": 525,
      "blocked": 413,
      "forwarded": 1196
    },
    {
      "timestamp": 1511820500.583821,
      "total": 2014,
      "cached": 52,
      "blocked": 43,
      "forwarded": 1910
    }
  ],
  "took": 0.003
}

BlockedSeries = blocked QueriesSeries = total

ralphocdol avatar Feb 21 '25 01:02 ralphocdol

@ralphocdol

This kind of got away from me. Took some time away to think about it all. I really don't understand why the Pi-hole developers had to change so much of their API. If it was for security reasons, I would argue they make it an opt-in feature, rather then a permanent feature. As I would assume most users of Pi-hole host their instances within their own home networks with no outside access (as I do) which would make the security argument a rather mute point.

I ran into an issue where SIDs were refused access after a period of time and hitting any endpoint would not revive them. So I had to include a check function along side a fetch function for the SIDs.

Anyways, check the latest. Let me know.

KallanX avatar Feb 26 '25 21:02 KallanX

Made a pull request on your fork https://github.com/KallanX/glance/pull/1

ralphocdol avatar Feb 27 '25 15:02 ralphocdol

Any chance we can get some push on this one? I'd love to see it implemented soon if possible.

@svilenmarkov

N0Klu3 avatar Mar 12 '25 23:03 N0Klu3

Thanks for looking into this and sorting it out guys.

I'll be honest, I haven't taken care of it yet because I'm genuinely frustrated by this change as it makes no sense to me. The reason behind it was:

The concept of gaining access to all resources by using a static token is too insecure going forward.

(from https://discourse.pi-hole.net/t/authenticating-to-v6-api/66010/6)

Except... you now STILL use a static thing (a password) to generate a dynamic temporary thing that you then use to authenticate. And then that dynamic "temporary" thing has its lifetime extended every time you use it, allowing you to reuse it for long periods of time. How's that any different than just adding an extra step? I've gone over the docs multiple times and still feel like there's gotta be something I'm missing.

</rant>

I'll get it fixed and and release a new version by the end of the week. Sorry for the wait.

svilenmarkov avatar Mar 13 '25 20:03 svilenmarkov

@svilenmarkov 100% agree with you. While I was coding out the changes needed to accommodate the new API, I grew increasingly frustrated at the reasoning to all this. It just makes little sense to me. Again, the security point is a mute point. As the new method is the same but with extra steps and I would also assume most users setup Pihole behind their home/office networks. So why all the fuss with new security methods?

Oh well...

The code I wrote for it is also rough. I debated about deleting most of it and only supporting the new method going forward. Having legacy functions and maintaining both gets messy. Also, you could rightly assume user's will all upgrade to the newer versions eventually so the legacy is more a placeholder then anything else.

Anyways, thanks for looking into this and getting a fix out.

KallanX avatar Mar 14 '25 01:03 KallanX