blob: 9887015e033a724eee58948a4a353e5c2964747c [file] [log] [blame]
// 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 (
func (hub *Hub) initHTTP(addr string) {
http.HandleFunc("/", hub.httpSummary)
ln, err := net.Listen("tcp4", addr)
if err != nil {
log.Fatalf("failed to listen on %v: %v", addr, err)
log.Logf(0, "serving http on http://%v", ln.Addr())
go func() {
err := http.Serve(ln, nil)
log.Fatalf("failed to serve http: %v", err)
func (hub *Hub) httpSummary(w http.ResponseWriter, r *http.Request) {
data := &UISummaryData{
Log: log.CachedLogOutput(),
total := UIManager{
Name: "total",
Corpus: len(,
Repros: len(,
for name, mgr := range {
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,
Corpus: len(mgr.Corpus.Records),
Added: mgr.Added,
Deleted: mgr.Deleted,
New: mgr.New,
SentRepros: mgr.SentRepros,
RecvRepros: mgr.RecvRepros,
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)
func compileTemplate(html string) *template.Template {
return template.Must(template.New("").Parse(strings.Replace(html, "{{STYLE}}", htmlStyle, -1)))
type UISummaryData struct {
Managers []UIManager
Log string
type UIManager struct {
Name string
Corpus int
Added int
Deleted int
New int
Repros int
SentRepros int
RecvRepros int
type UIManagerArray []UIManager
func (a UIManagerArray) Len() int { return len(a) }
func (a UIManagerArray) Less(i, j int) bool { return a[i].Name < a[j].Name }
func (a UIManagerArray) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
var summaryTemplate = compileTemplate(`
<!doctype html>
{{range $m := $.Managers}}
<textarea id="log_textarea" readonly rows="50">
var textarea = document.getElementById("log_textarea");
textarea.scrollTop = textarea.scrollHeight;
const htmlStyle = `
<style type="text/css" media="screen">
table {
border:1px solid;
table caption {
font-weight: bold;
table td {
border:1px solid;
padding: 3px;
table th {
border:1px solid;
padding: 3px;
textarea {