Private
Public Access
1
0

Return not found for more recently deleted servers, too

This commit is contained in:
2023-12-14 23:14:37 -08:00
parent 2cd4d8a35a
commit 404c64b910
3 changed files with 24 additions and 0 deletions

16
ntpdb/server.go Normal file
View File

@@ -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
}

View File

@@ -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))

View File

@@ -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")