Butcher the app in an attempt to make it boot past step 1

This commit is contained in:
Dane Everitt
2018-02-20 14:00:09 -06:00
parent bacdfae768
commit 4359d152b7
6 changed files with 99 additions and 197 deletions

View File

@@ -21,15 +21,12 @@ func NewAPI() InternalAPI {
// Configure the API and begin listening on the configured IP and Port.
func (api *InternalAPI) Listen() {
listener := fmt.Sprintf("%s:%d", viper.GetString(config.APIHost), viper.GetInt(config.APIPort))
if !viper.GetBool(config.Debug) {
gin.SetMode(gin.ReleaseMode)
}
api.router = gin.Default()
api.router.RedirectTrailingSlash = false
api.RegisterRoutes()
api.router.Use(func(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", "*")
@@ -40,7 +37,7 @@ func (api *InternalAPI) Listen() {
c.Header("Access-Control-Allow-Headers", "X-Access-Token")
})
api.registerRoutes()
api.RegisterRoutes()
listenString := fmt.Sprintf("%s:%d", viper.GetString(config.APIHost), viper.GetInt(config.APIPort))

View File

@@ -2,58 +2,59 @@ package api
import (
"net/http"
"runtime"
//"runtime"
"github.com/gin-gonic/gin"
"github.com/pterodactyl/wings/constants"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/mem"
//"github.com/shirou/gopsutil/cpu"
//"github.com/shirou/gopsutil/host"
//"github.com/shirou/gopsutil/mem"
log "github.com/sirupsen/logrus"
)
func GetIndex(c *gin.Context) {
auth := GetContextAuthManager(c)
//auth := GetContextAuthManager(c)
if auth != nil && auth.HasPermission("c:info") {
hostInfo, err := host.Info()
if err != nil {
log.WithError(err).Error("Failed to retrieve host information.")
}
cpuInfo, err := cpu.Info()
if err != nil {
log.WithError(err).Error("Failed to retrieve CPU information.")
}
memInfo, err := mem.VirtualMemory()
if err != nil {
log.WithError(err).Error("Failed to retrieve memory information.")
}
info := struct {
Name string `json:"name"`
Version string `json:"version"`
System struct {
SystemType string `json:"type"`
Platform string `json:"platform"`
Arch string `json:"arch"`
Release string `json:"release"`
Cpus int32 `json:"cpus"`
Freemem uint64 `json:"freemem"`
} `json:"system"`
}{
Name: "Pterodactyl wings",
Version: constants.Version,
}
info.System.SystemType = hostInfo.OS
info.System.Platform = hostInfo.Platform
info.System.Arch = runtime.GOARCH
info.System.Release = hostInfo.KernelVersion
info.System.Cpus = cpuInfo[0].Cores
info.System.Freemem = memInfo.Free
c.JSON(http.StatusOK, info)
return
}
//if auth != nil && auth.HasPermission("c:info") {
// hostInfo, err := host.Info()
// if err != nil {
// log.WithError(err).Error("Failed to retrieve host information.")
// }
// cpuInfo, err := cpu.Info()
// if err != nil {
// log.WithError(err).Error("Failed to retrieve CPU information.")
// }
// memInfo, err := mem.VirtualMemory()
// if err != nil {
// log.WithError(err).Error("Failed to retrieve memory information.")
// }
//
// info := struct {
// Name string `json:"name"`
// Version string `json:"version"`
// System struct {
// SystemType string `json:"type"`
// Platform string `json:"platform"`
// Arch string `json:"arch"`
// Release string `json:"release"`
// Cpus int32 `json:"cpus"`
// Freemem uint64 `json:"freemem"`
// } `json:"system"`
// }{
// Name: "Pterodactyl wings",
// Version: constants.Version,
// }
// info.System.SystemType = hostInfo.OS
// info.System.Platform = hostInfo.Platform
// info.System.Arch = runtime.GOARCH
// info.System.Release = hostInfo.KernelVersion
// info.System.Cpus = cpuInfo[0].Cores
// info.System.Freemem = memInfo.Free
//
// c.JSON(http.StatusOK, info)
// return
//}
c.Header("Content-Type", "text/html")
c.String(http.StatusOK, constants.IndexPage)

View File

@@ -6,7 +6,7 @@ func (api *InternalAPI) RegisterRoutes() {
v1 := api.router.Group("/v1")
{
v1.GET("/", AuthHandler(""), GetIndex)
v1.PATCH("/config", AuthHandler("c:config"), PatchConfiguration)
//v1.PATCH("/config", AuthHandler("c:config"), PatchConfiguration)
v1.GET("/servers", AuthHandler("c:list"), handleGetServers)
v1.POST("/servers", AuthHandler("c:create"), handlePostServers)
@@ -26,24 +26,24 @@ func (api *InternalAPI) RegisterRoutes() {
v1ServerRoutes.POST("/unsuspend", AuthHandler(""), handlePostServerUnsuspend)
}
v1ServerFileRoutes := v1.Group("/servers/:server/files")
{
v1ServerFileRoutes.GET("/file/:file", AuthHandler("s:files:read"), handleGetFile)
v1ServerFileRoutes.GET("/stat/:file", AuthHandler("s:files:"), handleGetFileStat)
v1ServerFileRoutes.GET("/dir/:directory", AuthHandler("s:files:get"), handleGetDirectory)
v1ServerFileRoutes.POST("/dir/:directory", AuthHandler("s:files:create"), handlePostFilesFolder)
v1ServerFileRoutes.POST("/file/:file", AuthHandler("s:files:post"), handlePostFile)
v1ServerFileRoutes.POST("/copy/:file", AuthHandler("s:files:copy"), handlePostFileCopy)
v1ServerFileRoutes.POST("/move/:file", AuthHandler("s:files:move"), handlePostFileMove)
v1ServerFileRoutes.POST("/rename/:file", AuthHandler("s:files:move"), handlePostFileMove)
v1ServerFileRoutes.POST("/compress/:file", AuthHandler("s:files:compress"), handlePostFileCompress)
v1ServerFileRoutes.POST("/decompress/:file", AuthHandler("s:files:decompress"), handlePostFileDecompress)
v1ServerFileRoutes.DELETE("/file/:file", AuthHandler("s:files:delete"), handleDeleteFile)
v1ServerFileRoutes.GET("/download/:token", handleGetDownloadFile)
}
//v1ServerFileRoutes := v1.Group("/servers/:server/files")
//{
// v1ServerFileRoutes.GET("/file/:file", AuthHandler("s:files:read"), handleGetFile)
// v1ServerFileRoutes.GET("/stat/:file", AuthHandler("s:files:"), handleGetFileStat)
// v1ServerFileRoutes.GET("/dir/:directory", AuthHandler("s:files:get"), handleGetDirectory)
//
// v1ServerFileRoutes.POST("/dir/:directory", AuthHandler("s:files:create"), handlePostFilesFolder)
// v1ServerFileRoutes.POST("/file/:file", AuthHandler("s:files:post"), handlePostFile)
//
// v1ServerFileRoutes.POST("/copy/:file", AuthHandler("s:files:copy"), handlePostFileCopy)
// v1ServerFileRoutes.POST("/move/:file", AuthHandler("s:files:move"), handlePostFileMove)
// v1ServerFileRoutes.POST("/rename/:file", AuthHandler("s:files:move"), handlePostFileMove)
// v1ServerFileRoutes.POST("/compress/:file", AuthHandler("s:files:compress"), handlePostFileCompress)
// v1ServerFileRoutes.POST("/decompress/:file", AuthHandler("s:files:decompress"), handlePostFileDecompress)
//
// v1ServerFileRoutes.DELETE("/file/:file", AuthHandler("s:files:delete"), handleDeleteFile)
//
// v1ServerFileRoutes.GET("/download/:token", handleGetDownloadFile)
//}
}
}