diff --git a/ntpdb/server.go b/ntpdb/server.go new file mode 100644 index 0000000..115a0b3 --- /dev/null +++ b/ntpdb/server.go @@ -0,0 +1,16 @@ +package ntpdb + +import "time" + +func (s *Server) DeletionAge(dur time.Duration) bool { + if !s.DeletionOn.Valid { + return false + } + if dur > 0 { + dur = dur * -1 + } + if s.DeletionOn.Time.Before(time.Now().Add(dur)) { + return true + } + return false +} diff --git a/server/graph_image.go b/server/graph_image.go index b0aaca7..d8022dc 100644 --- a/server/graph_image.go +++ b/server/graph_image.go @@ -8,6 +8,7 @@ import ( "net/http/httptrace" "net/url" "os" + "time" "github.com/hashicorp/go-retryablehttp" "github.com/labstack/echo/v4" @@ -49,6 +50,9 @@ func (srv *Server) graphImage(c echo.Context) error { if serverData.ID == 0 { return c.String(http.StatusNotFound, "not found") } + if serverData.DeletionAge(7 * 24 * time.Hour) { + return c.String(http.StatusNotFound, "not found") + } if serverData.Ip != serverID { return c.Redirect(308, fmt.Sprintf("/graph/%s/offset.png", serverData.Ip)) diff --git a/server/history.go b/server/history.go index ec8f6c7..86627e4 100644 --- a/server/history.go +++ b/server/history.go @@ -115,6 +115,10 @@ func (srv *Server) history(c echo.Context) error { span.RecordError(err) return c.String(http.StatusInternalServerError, "internal error") } + if server.DeletionAge(30 * 24 * time.Hour) { + span.AddEvent("server deleted") + return c.String(http.StatusNotFound, "server not found") + } if server.ID == 0 { span.AddEvent("server not found") return c.String(http.StatusNotFound, "server not found")