Add is_tor plumbing from collector->aggregator->frontend/cli
This commit is contained in:
@@ -53,6 +53,7 @@ type filterState struct {
|
||||
Status string // expression: "200", "!=200", ">=400", etc.
|
||||
WebsiteRe string // RE2 regex against website
|
||||
URIRe string // RE2 regex against request URI
|
||||
IsTor string // "", "1" (TOR only), "0" (non-TOR only)
|
||||
}
|
||||
|
||||
// QueryParams holds all parsed URL parameters for one page request.
|
||||
@@ -77,6 +78,7 @@ type PageData struct {
|
||||
Windows []Tab
|
||||
GroupBys []Tab
|
||||
Targets []Tab // source/target picker; empty when only one target available
|
||||
TorTabs []Tab // all / tor / no-tor toggle
|
||||
RefreshSecs int
|
||||
Error string
|
||||
FilterExpr string // current filter serialised to mini-language for the input box
|
||||
@@ -156,12 +158,13 @@ func (h *Handler) parseParams(r *http.Request) QueryParams {
|
||||
Status: q.Get("f_status"),
|
||||
WebsiteRe: q.Get("f_website_re"),
|
||||
URIRe: q.Get("f_uri_re"),
|
||||
IsTor: q.Get("f_is_tor"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func buildFilter(f filterState) *pb.Filter {
|
||||
if f.Website == "" && f.Prefix == "" && f.URI == "" && f.Status == "" && f.WebsiteRe == "" && f.URIRe == "" {
|
||||
if f.Website == "" && f.Prefix == "" && f.URI == "" && f.Status == "" && f.WebsiteRe == "" && f.URIRe == "" && f.IsTor == "" {
|
||||
return nil
|
||||
}
|
||||
out := &pb.Filter{}
|
||||
@@ -186,6 +189,12 @@ func buildFilter(f filterState) *pb.Filter {
|
||||
if f.URIRe != "" {
|
||||
out.UriRegex = &f.URIRe
|
||||
}
|
||||
switch f.IsTor {
|
||||
case "1":
|
||||
out.Tor = pb.TorFilter_TOR_YES
|
||||
case "0":
|
||||
out.Tor = pb.TorFilter_TOR_NO
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -214,6 +223,9 @@ func (p QueryParams) toValues() url.Values {
|
||||
if p.Filter.URIRe != "" {
|
||||
v.Set("f_uri_re", p.Filter.URIRe)
|
||||
}
|
||||
if p.Filter.IsTor != "" {
|
||||
v.Set("f_is_tor", p.Filter.IsTor)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
@@ -314,6 +326,18 @@ func buildCrumbs(p QueryParams) []Crumb {
|
||||
RemoveURL: p.buildURL(map[string]string{"f_uri_re": ""}),
|
||||
})
|
||||
}
|
||||
switch p.Filter.IsTor {
|
||||
case "1":
|
||||
crumbs = append(crumbs, Crumb{
|
||||
Text: "is_tor=1 (TOR only)",
|
||||
RemoveURL: p.buildURL(map[string]string{"f_is_tor": ""}),
|
||||
})
|
||||
case "0":
|
||||
crumbs = append(crumbs, Crumb{
|
||||
Text: "is_tor=0 (no TOR)",
|
||||
RemoveURL: p.buildURL(map[string]string{"f_is_tor": ""}),
|
||||
})
|
||||
}
|
||||
return crumbs
|
||||
}
|
||||
|
||||
@@ -341,6 +365,23 @@ func buildGroupByTabs(p QueryParams) []Tab {
|
||||
return tabs
|
||||
}
|
||||
|
||||
func buildTorTabs(p QueryParams) []Tab {
|
||||
specs := []struct{ val, label string }{
|
||||
{"", "all"},
|
||||
{"1", "tor"},
|
||||
{"0", "no tor"},
|
||||
}
|
||||
tabs := make([]Tab, len(specs))
|
||||
for i, s := range specs {
|
||||
tabs[i] = Tab{
|
||||
Label: s.label,
|
||||
URL: p.buildURL(map[string]string{"f_is_tor": s.val}),
|
||||
Active: p.Filter.IsTor == s.val,
|
||||
}
|
||||
}
|
||||
return tabs
|
||||
}
|
||||
|
||||
// buildTargetTabs builds the source/target picker tabs from a ListTargets response.
|
||||
// Returns nil (hide picker) when only one endpoint is reachable.
|
||||
func (h *Handler) buildTargetTabs(p QueryParams, lt *pb.ListTargetsResponse) []Tab {
|
||||
@@ -502,6 +543,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
Breadcrumbs: buildCrumbs(params),
|
||||
Windows: buildWindowTabs(params),
|
||||
GroupBys: buildGroupByTabs(params),
|
||||
TorTabs: buildTorTabs(params),
|
||||
Targets: h.buildTargetTabs(params, lt),
|
||||
RefreshSecs: h.refreshSecs,
|
||||
FilterExpr: filterExprInput,
|
||||
@@ -524,6 +566,7 @@ func (h *Handler) errorPage(params QueryParams, msg string) PageData {
|
||||
Params: params,
|
||||
Windows: buildWindowTabs(params),
|
||||
GroupBys: buildGroupByTabs(params),
|
||||
TorTabs: buildTorTabs(params),
|
||||
Breadcrumbs: buildCrumbs(params),
|
||||
RefreshSecs: h.refreshSecs,
|
||||
Error: msg,
|
||||
|
||||
Reference in New Issue
Block a user