diff --git a/api/api.go b/api/api.go index 42f62c5..7fde00a 100644 --- a/api/api.go +++ b/api/api.go @@ -51,7 +51,7 @@ func (api *InternalAPI) Listen() { func (api *InternalAPI) register() { v1 := api.router.Group("/api/v1") { - v1.GET("/", AuthHandler(""), GetIndex) + v1.GET("", AuthHandler(""), GetIndex) //v1.PATCH("/config", AuthHandler("c:config"), PatchConfiguration) v1.GET("/servers", AuthHandler("c:list"), handleGetServers) @@ -59,15 +59,15 @@ func (api *InternalAPI) register() { v1ServerRoutes := v1.Group("/servers/:server") { - v1ServerRoutes.GET("/", AuthHandler("s:get"), handleGetServer) - v1ServerRoutes.PATCH("/", AuthHandler("s:config"), handlePatchServer) - v1ServerRoutes.DELETE("/", AuthHandler("g:server:delete"), handleDeleteServer) + v1ServerRoutes.GET("", AuthHandler("s:get"), handleGetServer) + v1ServerRoutes.PATCH("", AuthHandler("s:config"), handlePatchServer) + v1ServerRoutes.DELETE("", AuthHandler("g:server:delete"), handleDeleteServer) v1ServerRoutes.POST("/reinstall", AuthHandler("s:install-server"), handlePostServerReinstall) v1ServerRoutes.POST("/rebuild", AuthHandler("g:server:rebuild"), handlePostServerRebuild) v1ServerRoutes.POST("/password", AuthHandler(""), handlePostServerPassword) v1ServerRoutes.POST("/power", AuthHandler("s:power"), handlePostServerPower) v1ServerRoutes.POST("/command", AuthHandler("s:command"), handlePostServerCommand) - v1ServerRoutes.GET("/log", AuthHandler("s:console"), handleGetServerLog) + v1ServerRoutes.GET("/log", AuthHandler("s:console"), handleGetConsole) v1ServerRoutes.POST("/suspend", AuthHandler(""), handlePostServerSuspend) v1ServerRoutes.POST("/unsuspend", AuthHandler(""), handlePostServerUnsuspend) } diff --git a/api/auth.go b/api/auth.go index b9bb645..f19efee 100644 --- a/api/auth.go +++ b/api/auth.go @@ -2,8 +2,9 @@ package api import ( "net/http" + "strings" - "strconv" + "strconv" "github.com/gin-gonic/gin" "github.com/google/jsonapi" @@ -71,7 +72,9 @@ func (a *authorizationManager) HasPermission(permission string) bool { func AuthHandler(permission string) gin.HandlerFunc { return func(c *gin.Context) { requestToken := c.Request.Header.Get(accessTokenHeader) - if requestToken == "" { + if requestToken != "" && strings.HasPrefix(requestToken, "Baerer ") { + requestToken = requestToken[7:] + } else { requestToken = c.Query("token") } requestServer := c.Param("server") diff --git a/api/handlers_server.go b/api/handlers_server.go index a339b3c..3107f12 100644 --- a/api/handlers_server.go +++ b/api/handlers_server.go @@ -181,10 +181,6 @@ func handleGetConsole(c *gin.Context) { server.Websockets().Upgrade(c.Writer, c.Request) } -func handleGetServerLog(c *gin.Context) { - -} - func handlePostServerSuspend(c *gin.Context) { } diff --git a/config/config_test.go b/config/config_test.go index 1773208..7450c44 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" ) -const configFile = "../config.yml.example" +const configFile = "../config.example.yml" func TestLoadConfiguraiton(t *testing.T) { err := LoadConfiguration(configFile) diff --git a/wings-api.paw b/wings-api.paw index a13dc59..af01f9c 100644 Binary files a/wings-api.paw and b/wings-api.paw differ