api: add first status implementation on /

This commit is contained in:
Jakob Schrettenbrunner 2017-08-02 22:49:59 +02:00
parent 0a2eab96bb
commit 91ff924933

View File

@ -5,6 +5,10 @@ import (
"github.com/Pterodactyl/wings/constants" "github.com/Pterodactyl/wings/constants"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/mem"
log "github.com/sirupsen/logrus"
) )
// handleGetIndex handles GET / // handleGetIndex handles GET /
@ -12,18 +16,47 @@ func handleGetIndex(c *gin.Context) {
auth, _ := c.Get(ContextVarAuth) auth, _ := c.Get(ContextVarAuth)
if auth := auth.(AuthorizationManager); auth.hasPermission("c:info") { if auth := auth.(AuthorizationManager); 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"`
Release string `json:"release"`
Cpus int32 `json:"cpus"`
Freemem uint64 `json:"freemem"`
} `json:"os"`
}{
Name: "Pterodactyl wings",
Version: constants.Version,
}
info.System.SystemType = hostInfo.OS
info.System.Platform = hostInfo.Platform
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.Header("Content-Type", "text/html")
c.String(http.StatusOK, constants.IndexPage) c.String(http.StatusOK, constants.IndexPage)
} }
// handlePutConfig handles PUT /config
func handlePutConfig(c *gin.Context) {
}
// handlePatchConfig handles PATCH /config // handlePatchConfig handles PATCH /config
func handlePatchConfig(c *gin.Context) { func handlePatchConfig(c *gin.Context) {