From ef21eaed33804078a8d46567faebb970affd4191 Mon Sep 17 00:00:00 2001 From: Lyndsay Roger Date: Tue, 8 Sep 2015 14:00:07 +1200 Subject: [PATCH] Improve the web page layout --- http.go | 23 ++++++++++++++++------- main.go | 12 +++--------- seeder.go | 10 ++++++++++ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/http.go b/http.go index 7e89ac9..59ab7b8 100644 --- a/http.go +++ b/http.go @@ -440,8 +440,10 @@ func summaryHandler(w http.ResponseWriter, r *http.Request) { } writeHeader(w, r) - // loop through each of the seeders - for _, s := range config.seeders { + // loop through each of the seeder name from a slice so they are always returned in + // the same order then get a pointer to the seeder struct + for _, n := range config.order { + s := config.seeders[n] hc.Name = s.name // fill the structs so they can be displayed via the template @@ -505,16 +507,23 @@ func summaryHandler(w http.ResponseWriter, r *http.Request) { // writeHeader will output the standard header func writeHeader(w http.ResponseWriter, r *http.Request) { // we are using basic and simple html here. No fancy graphics or css - h := ` + h1 := ` dnsseeder
Summary -
-
-
` - fmt.Fprintf(w, h) + fmt.Fprintf(w, h1) + + // read the seeder name + n := r.FormValue("s") + if n != "" { + s := getSeederByName(n) + if s != nil { + fmt.Fprintf(w, "
Seeder: %s", html.EscapeString(s.name)) + } + } + fmt.Fprintf(w, "

") } // writeFooter will output the standard footer diff --git a/main.go b/main.go index 689c68e..47b696d 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,7 @@ type configData struct { stats bool // stats cmdline option seeders map[string]*dnsseeder // holds a pointer to all the current seeders smtx sync.RWMutex // protect the seeders map + order []string // the order of loading the netfiles so we can display in this order dns map[string][]dns.RR // holds details of all the currently served dns records dnsmtx sync.RWMutex // protect the dns map dnsUnknown uint64 // the number of dns requests for we are not configured to handle @@ -77,6 +78,7 @@ func main() { config.seeders = make(map[string]*dnsseeder) config.dns = make(map[string][]dns.RR) + config.order = []string{} for _, nwFile := range netwFiles { nnw, err := loadNetwork(nwFile) @@ -87,6 +89,7 @@ func main() { if nnw != nil { // FIXME - lock this config.seeders[nnw.name] = nnw + config.order = append(config.order, nnw.name) } } @@ -214,15 +217,6 @@ func updateDNSCounts(name, qtype string) { } } -func getSeederByName(name string) *dnsseeder { - for _, s := range config.seeders { - if s.name == name { - return s - } - } - return nil -} - /* */ diff --git a/seeder.go b/seeder.go index a54075f..3ae3dfe 100644 --- a/seeder.go +++ b/seeder.go @@ -390,6 +390,16 @@ func (s *dnsseeder) isFull() bool { return false } +// getSeederByName returns a pointer to the seeder based on its name or nil if not found +func getSeederByName(name string) *dnsseeder { + for _, s := range config.seeders { + if s.name == name { + return s + } + } + return nil +} + /* */