diff --git a/handler/routes.go b/handler/routes.go index 4ed65a6..f204c9b 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -709,6 +709,19 @@ func CreateServer(db store.IStore) echo.HandlerFunc { } } +// RemoveServer handler deletes a server, refusing if any client still +// references it (see store.DeleteServer). Admin-only. +func RemoveServer(db store.IStore) echo.HandlerFunc { + return func(c echo.Context) error { + serverID := c.Param("id") + if err := db.DeleteServer(serverID); err != nil { + return c.JSON(http.StatusBadRequest, jsonHTTPResponse{false, err.Error()}) + } + log.Infof("Removed server %s", serverID) + return c.JSON(http.StatusOK, jsonHTTPResponse{true, "Server removed successfully"}) + } +} + // NewClient handler func NewClient(db store.IStore) echo.HandlerFunc { return func(c echo.Context) error { diff --git a/main.go b/main.go index e5596c6..2cbc8ec 100644 --- a/main.go +++ b/main.go @@ -264,6 +264,7 @@ func main() { app.POST(util.BasePath+"/servers/:id/settings", handler.SaveServerSettingsHandler(db), handler.ValidSession, handler.ContentTypeJson, handler.NeedsAdmin) app.POST(util.BasePath+"/servers/:id/interface", handler.UpdateServerInterfaceHandler(db), handler.ValidSession, handler.ContentTypeJson, handler.NeedsAdmin) app.POST(util.BasePath+"/servers/:id/keypair", handler.UpdateServerKeyPairHandler(db), handler.ValidSession, handler.ContentTypeJson, handler.NeedsAdmin) + app.POST(util.BasePath+"/servers/:id/delete", handler.RemoveServer(db), handler.ValidSession, handler.ContentTypeJson, handler.NeedsAdmin) app.POST(util.BasePath+"/backup/download", handler.DownloadBackup(db), handler.ValidSession, handler.ContentTypeJson, handler.NeedsAdmin) app.GET(util.BasePath+"/api/clients", handler.GetClients(db), handler.ValidSession) app.GET(util.BasePath+"/api/client/:id", handler.GetClient(db), handler.ValidSession) diff --git a/templates/servers.html b/templates/servers.html index c504c8a..f40c164 100644 --- a/templates/servers.html +++ b/templates/servers.html @@ -203,6 +203,9 @@ All Servers +