// Copyright 2016 syzkaller project authors. All rights reserved. // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. package main import ( "fmt" "html/template" "net/http" "sort" "strings" "github.com/google/syzkaller/pkg/log" ) func (hub *Hub) httpSummary(w http.ResponseWriter, r *http.Request) { hub.mu.Lock() defer hub.mu.Unlock() data := &UISummaryData{ Log: log.CachedLogOutput(), } total := UIManager{ Name: "total", Corpus: len(hub.st.Corpus.Records), Repros: len(hub.st.Repros.Records), } for name, mgr := range hub.st.Managers { total.Added += mgr.Added total.Deleted += mgr.Deleted total.New += mgr.New total.SentRepros += mgr.SentRepros total.RecvRepros += mgr.RecvRepros data.Managers = append(data.Managers, UIManager{ Name: name, HTTP: mgr.HTTP, Domain: mgr.Domain, Corpus: len(mgr.Corpus.Records), Added: mgr.Added, Deleted: mgr.Deleted, New: mgr.New, SentRepros: mgr.SentRepros, RecvRepros: mgr.RecvRepros, }) } sort.Slice(data.Managers, func(i, j int) bool { return data.Managers[i].Name < data.Managers[j].Name }) data.Managers = append([]UIManager{total}, data.Managers...) if err := summaryTemplate.Execute(w, data); err != nil { log.Logf(0, "failed to execute template: %v", err) http.Error(w, fmt.Sprintf("failed to execute template: %v", err), http.StatusInternalServerError) return } } func compileTemplate(html string) *template.Template { return template.Must(template.New("").Parse(strings.ReplaceAll(html, "{{STYLE}}", htmlStyle))) } type UISummaryData struct { Managers []UIManager Log string } type UIManager struct { Name string HTTP string Domain string Corpus int Added int Deleted int New int Repros int SentRepros int RecvRepros int } var summaryTemplate = compileTemplate(`
| Name | URL | Domain | Corpus | Added | Deleted | New | Repros | Sent | Recv |
|---|---|---|---|---|---|---|---|---|---|
| {{$m.Name}} | {{$m.HTTP}} | {{$m.Domain}} | {{$m.Corpus}} | {{$m.Added}} | {{$m.Deleted}} | {{$m.New}} | {{$m.Repros}} | {{$m.SentRepros}} | {{$m.RecvRepros}} |