You've already forked caddy-opnsense-blocker
Add dashboard activity leaderboards
This commit is contained in:
@@ -91,8 +91,15 @@ func (s *Service) Run(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GetOverview(ctx context.Context, limit int) (model.Overview, error) {
|
||||
return s.store.GetOverview(ctx, limit)
|
||||
func (s *Service) GetOverview(ctx context.Context, since time.Time, limit int) (model.Overview, error) {
|
||||
overview, err := s.store.GetOverview(ctx, since, limit)
|
||||
if err != nil {
|
||||
return model.Overview{}, err
|
||||
}
|
||||
if err := s.decorateOverviewTopIPs(ctx, &overview); err != nil {
|
||||
return model.Overview{}, err
|
||||
}
|
||||
return overview, nil
|
||||
}
|
||||
|
||||
func (s *Service) ListEvents(ctx context.Context, limit int) ([]model.Event, error) {
|
||||
@@ -665,3 +672,37 @@ func recentRowIPs(items []model.RecentIPRow) []string {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (s *Service) decorateOverviewTopIPs(ctx context.Context, overview *model.Overview) error {
|
||||
if overview == nil {
|
||||
return nil
|
||||
}
|
||||
ips := append(topIPRowIPs(overview.TopIPsByEvents), topIPRowIPs(overview.TopIPsByTraffic)...)
|
||||
investigations, err := s.store.GetInvestigationsForIPs(ctx, ips)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for index := range overview.TopIPsByEvents {
|
||||
if investigation, ok := investigations[overview.TopIPsByEvents[index].IP]; ok {
|
||||
overview.TopIPsByEvents[index].Bot = investigation.Bot
|
||||
} else {
|
||||
s.enqueueInvestigation(overview.TopIPsByEvents[index].IP)
|
||||
}
|
||||
}
|
||||
for index := range overview.TopIPsByTraffic {
|
||||
if investigation, ok := investigations[overview.TopIPsByTraffic[index].IP]; ok {
|
||||
overview.TopIPsByTraffic[index].Bot = investigation.Bot
|
||||
} else {
|
||||
s.enqueueInvestigation(overview.TopIPsByTraffic[index].IP)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func topIPRowIPs(items []model.TopIPRow) []string {
|
||||
result := make([]string, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, item.IP)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user