diff --git a/satellite/console/consoleweb/server.go b/satellite/console/consoleweb/server.go index b38ccf346..0da3032f5 100644 --- a/satellite/console/consoleweb/server.go +++ b/satellite/console/consoleweb/server.go @@ -263,7 +263,7 @@ func (s *Server) passwordRecoveryHandler(w http.ResponseWriter, req *http.Reques } switch req.Method { - case "POST": + case http.MethodPost: err := req.ParseForm() if err != nil { s.serveError(w, req) @@ -281,7 +281,7 @@ func (s *Server) passwordRecoveryHandler(w http.ResponseWriter, req *http.Reques s.serveError(w, req) } http.ServeFile(w, req, filepath.Join(s.config.StaticDir, "static", "resetPassword", "success.html")) - default: + case http.MethodGet: t, err := template.ParseFiles(filepath.Join(s.config.StaticDir, "static", "resetPassword", "resetPassword.html")) if err != nil { s.serveError(w, req) @@ -291,6 +291,9 @@ func (s *Server) passwordRecoveryHandler(w http.ResponseWriter, req *http.Reques if err != nil { s.serveError(w, req) } + default: + s.serveError(w, req) + return } } @@ -309,6 +312,7 @@ func (s *Server) cancelPasswordRecoveryHandler(w http.ResponseWriter, req *http. } func (s *Server) serveError(w http.ResponseWriter, req *http.Request) { + w.WriteHeader(http.StatusNotFound) http.ServeFile(w, req, filepath.Join(s.config.StaticDir, "static", "errors", "404.html")) } diff --git a/storagenode/console/consoleserver/server.go b/storagenode/console/consoleserver/server.go index 5fb300a36..d27bd4144 100644 --- a/storagenode/console/consoleserver/server.go +++ b/storagenode/console/consoleserver/server.go @@ -133,32 +133,34 @@ func (s *Server) dashboardHandler(w http.ResponseWriter, req *http.Request) { } }() - satelliteIDParam := req.URL.Query().Get("satelliteId") - s.log.Info("param: " + satelliteIDParam) - satelliteID, err := s.parseSatelliteIDParam(satelliteIDParam) - if satelliteID != nil { - s.log.Info("ID: " + satelliteID.String()) + if req.Method != http.MethodGet { + w.WriteHeader(http.StatusNotFound) + return } + + satelliteIDParam := req.URL.Query().Get("satelliteId") + satelliteID, err := s.parseSatelliteIDParam(satelliteIDParam) if err != nil { s.log.Error("satellite id is not valid", zap.Error(err)) response.Error = "satellite id is not valid" + w.WriteHeader(http.StatusBadRequest) return } satellites, err := s.service.GetSatellites(ctx) - if satellites == nil { - s.log.Info("SATELLITES ARE NIL") - } if err != nil { s.log.Error("can not get satellites list", zap.Error(err)) response.Error = "can not get satellites list" + w.WriteHeader(http.StatusInternalServerError) return } + // checks if current satellite id is related to current storage node if satelliteID != nil { if err = s.checkSatelliteID(satellites, *satelliteID); err != nil { s.log.Error(err.Error()) response.Error = err.Error() + w.WriteHeader(http.StatusBadRequest) return } } @@ -167,6 +169,7 @@ func (s *Server) dashboardHandler(w http.ResponseWriter, req *http.Request) { if err != nil { s.log.Error("can not get disk space usage", zap.Error(err)) response.Error = "can not get disk space usage" + w.WriteHeader(http.StatusInternalServerError) return } @@ -174,6 +177,7 @@ func (s *Server) dashboardHandler(w http.ResponseWriter, req *http.Request) { if err != nil { s.log.Error("can not get bandwidth usage", zap.Error(err)) response.Error = "can not get bandwidth usage" + w.WriteHeader(http.StatusInternalServerError) return } @@ -185,6 +189,7 @@ func (s *Server) dashboardHandler(w http.ResponseWriter, req *http.Request) { if err != nil { s.log.Error("can not check latest storage node version", zap.Error(err)) response.Error = "can not check latest storage node version" + w.WriteHeader(http.StatusInternalServerError) return } @@ -199,6 +204,8 @@ func (s *Server) dashboardHandler(w http.ResponseWriter, req *http.Request) { response.Data.Uptime = uptime response.Data.NodeID = nodeID.String() response.Data.Satellites = satellites + + w.WriteHeader(http.StatusOK) } func (s *Server) getBandwidth(ctx context.Context, satelliteID *storj.NodeID) (_ *console.BandwidthInfo, err error) {