diff --git a/core/webserver/handlers.go b/core/webserver/handlers.go index e46e46b4..0db2ff4c 100644 --- a/core/webserver/handlers.go +++ b/core/webserver/handlers.go @@ -13,8 +13,7 @@ import ( // Returns the main index file. // If index.html becomes a template, this is where it can be compiled. func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) { - index := filepath.Join(s.HTMLPath, "index.html") - http.ServeFile(w, r, index) + http.ServeFile(w, r, filepath.Join(s.HTMLPath, "index.html")) } // Arbitrary /health handler. diff --git a/core/webserver/plugins_types.go b/core/webserver/plugins_types.go index a3f055c9..5a6b4072 100644 --- a/core/webserver/plugins_types.go +++ b/core/webserver/plugins_types.go @@ -49,7 +49,7 @@ type Site struct { Controller string `json:"controller"` } -// Events is all the events a plugin has. string = Controller.UUID + text. +// Events is all the events a plugin has. string = SiteID + text, or plugin name, or "whatever". type Events map[string]*EventGroup // EventGroup allows each plugin to have a map of events. ie. one map per controller. @@ -60,14 +60,14 @@ type EventGroup struct { // Event is like a log message. type Event struct { - Ts time.Time `json:"ts"` + Ts time.Time `json:"ts"` // nolint: stylecheck Msg string `json:"msg"` Tags map[string]string `json:"tags,omitempty"` } -func (e Events) Groups(filter string) (groups []string) { +func (e Events) Groups(prefix string) (groups []string) { for n := range e { - if filter == "" || strings.HasPrefix(n, filter) { + if prefix == "" || strings.HasPrefix(n, prefix) { groups = append(groups, n) } } diff --git a/core/webserver/server.go b/core/webserver/server.go index 892d57b2..87f22a48 100644 --- a/core/webserver/server.go +++ b/core/webserver/server.go @@ -66,7 +66,7 @@ func init() { // nolint: gochecknoinits // Run starts the server and gets things going. func (s *Server) Run(c poller.Collect) error { if s.Collect = c; s.Config == nil || s.Port == 0 || s.HTMLPath == "" || !s.Enable { - s.Logf("Web server disabled!") + s.Logf("Internal web server disabled!") return nil } @@ -97,11 +97,11 @@ func (s *Server) Start() (err error) { err = s.server.ListenAndServeTLS(s.SSLCrtPath, s.SSLKeyPath) } - if errors.Is(err, http.ErrServerClosed) { - return nil + if !errors.Is(err, http.ErrServerClosed) { + return err } - return err + return nil } func (s *Server) newRouter() *mux.Router { @@ -129,13 +129,14 @@ func (s *Server) newRouter() *mux.Router { // PasswordIsCorrect returns true if the provided password matches a user's account. func (a accounts) PasswordIsCorrect(user, pass string, ok bool) bool { - if len(a) == 0 { // If true then no accounts defined in config; allow anyone. - return true - } else if !ok { // If true then r.BasicAuth() failed, not a valid user. - return false + if len(a) == 0 { + return true // No accounts defined in config; allow anyone. + } else if !ok { + return false // r.BasicAuth() failed, not a valid user. } else if user, ok = a[user]; !ok { // The user var is now the password hash. - return false + return false // The username provided doesn't exist. } + // If this is returns nil, the provided password matches, so return true. return bcrypt.CompareHashAndPassword([]byte(user), []byte(pass)) == nil }