mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
make PiHole module compatible with both versions 4 and 5 of PiHole.
This commit is contained in:
parent
e36d6ba78c
commit
988a9deee5
@ -23,9 +23,9 @@ type Status struct {
|
|||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
GravityLastUpdated struct {
|
GravityLastUpdated struct {
|
||||||
Relative struct {
|
Relative struct {
|
||||||
Days string `json:"days"`
|
Days FlexInt `json:"days"`
|
||||||
Hours string `json:"hours"`
|
Hours FlexInt `json:"hours"`
|
||||||
Minutes string `json:"minutes"`
|
Minutes FlexInt `json:"minutes"`
|
||||||
}
|
}
|
||||||
} `json:"gravity_last_updated"`
|
} `json:"gravity_last_updated"`
|
||||||
}
|
}
|
||||||
@ -76,13 +76,36 @@ func getStatus(c http.Client, apiURL string) (status Status, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err = json.Unmarshal(rBody, &status); err != nil {
|
if err = json.Unmarshal(rBody, &status); err != nil {
|
||||||
return status, fmt.Errorf(" failed to retrieve top items: check provided api URL and token\n %s",
|
return status, fmt.Errorf(" failed to retrieve status: check provided api URL and token\n %s",
|
||||||
parseError(err))
|
parseError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
return status, err
|
return status, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FlexInt int
|
||||||
|
|
||||||
|
func (fi *FlexInt) UnmarshalJSON(b []byte) error {
|
||||||
|
if b[0] != '"' {
|
||||||
|
return json.Unmarshal(b, (*int)(fi))
|
||||||
|
}
|
||||||
|
|
||||||
|
var s string
|
||||||
|
|
||||||
|
if err := json.Unmarshal(b, &s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
i, err := strconv.Atoi(s)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*fi = FlexInt(i)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type TopItems struct {
|
type TopItems struct {
|
||||||
TopQueries map[string]int `json:"top_queries"`
|
TopQueries map[string]int `json:"top_queries"`
|
||||||
TopAds map[string]int `json:"top_ads"`
|
TopAds map[string]int `json:"top_ads"`
|
||||||
|
@ -38,7 +38,7 @@ func getSummaryView(c http.Client, settings *Settings) string {
|
|||||||
summaryTable := createTable([]string{}, buf)
|
summaryTable := createTable([]string{}, buf)
|
||||||
summaryTable.Append([]string{"Domain blocklist", s.DomainsBeingBlocked, "Queries today", s.DNSQueriesToday})
|
summaryTable.Append([]string{"Domain blocklist", s.DomainsBeingBlocked, "Queries today", s.DNSQueriesToday})
|
||||||
summaryTable.Append([]string{"Ads blocked today", fmt.Sprintf("%s (%s%%)", s.AdsBlockedToday, s.AdsPercentageToday), "Cached queries", s.QueriesCached})
|
summaryTable.Append([]string{"Ads blocked today", fmt.Sprintf("%s (%s%%)", s.AdsBlockedToday, s.AdsPercentageToday), "Cached queries", s.QueriesCached})
|
||||||
summaryTable.Append([]string{"Blocklist Age", fmt.Sprintf("%sd %sh %sm", s.GravityLastUpdated.Relative.Days,
|
summaryTable.Append([]string{"Blocklist Age", fmt.Sprintf("%dd %dh %dm", s.GravityLastUpdated.Relative.Days,
|
||||||
s.GravityLastUpdated.Relative.Hours, s.GravityLastUpdated.Relative.Minutes), "Forwarded queries", s.QueriesForwarded})
|
s.GravityLastUpdated.Relative.Hours, s.GravityLastUpdated.Relative.Minutes), "Forwarded queries", s.QueriesForwarded})
|
||||||
summaryTable.Render()
|
summaryTable.Render()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user