2017-08-02 20:02:34 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2017-10-01 18:42:17 +00:00
|
|
|
"runtime"
|
2017-08-02 20:02:34 +00:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2018-02-20 20:25:31 +00:00
|
|
|
"github.com/pterodactyl/wings/constants"
|
2017-08-02 20:49:59 +00:00
|
|
|
"github.com/shirou/gopsutil/cpu"
|
|
|
|
"github.com/shirou/gopsutil/host"
|
|
|
|
"github.com/shirou/gopsutil/mem"
|
|
|
|
log "github.com/sirupsen/logrus"
|
2017-08-02 20:02:34 +00:00
|
|
|
)
|
|
|
|
|
2017-10-01 18:59:32 +00:00
|
|
|
func GetIndex(c *gin.Context) {
|
2017-08-02 21:47:09 +00:00
|
|
|
auth := GetContextAuthManager(c)
|
2017-08-02 20:02:34 +00:00
|
|
|
|
2017-08-02 21:47:09 +00:00
|
|
|
if auth != nil && auth.HasPermission("c:info") {
|
2017-08-02 20:49:59 +00:00
|
|
|
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"`
|
2017-10-01 18:42:17 +00:00
|
|
|
Arch string `json:"arch"`
|
2017-08-02 20:49:59 +00:00
|
|
|
Release string `json:"release"`
|
|
|
|
Cpus int32 `json:"cpus"`
|
|
|
|
Freemem uint64 `json:"freemem"`
|
2017-10-01 18:42:17 +00:00
|
|
|
} `json:"system"`
|
2017-08-02 20:49:59 +00:00
|
|
|
}{
|
|
|
|
Name: "Pterodactyl wings",
|
|
|
|
Version: constants.Version,
|
|
|
|
}
|
|
|
|
info.System.SystemType = hostInfo.OS
|
|
|
|
info.System.Platform = hostInfo.Platform
|
2017-10-01 18:42:17 +00:00
|
|
|
info.System.Arch = runtime.GOARCH
|
2017-08-02 20:49:59 +00:00
|
|
|
info.System.Release = hostInfo.KernelVersion
|
|
|
|
info.System.Cpus = cpuInfo[0].Cores
|
|
|
|
info.System.Freemem = memInfo.Free
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, info)
|
|
|
|
return
|
2017-08-02 20:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c.Header("Content-Type", "text/html")
|
|
|
|
c.String(http.StatusOK, constants.IndexPage)
|
|
|
|
}
|
|
|
|
|
2017-10-01 18:42:17 +00:00
|
|
|
type incomingConfiguration struct {
|
|
|
|
Debug bool `mapstructure:"debug"`
|
|
|
|
Web struct {
|
|
|
|
ListenHost string `mapstructure:"host"`
|
|
|
|
ListenPort int16 `mapstructure:"port"`
|
|
|
|
SSL struct {
|
|
|
|
Enabled bool `mapstructure:"enabled"`
|
|
|
|
Certificate string `mapstructure:"certificate"`
|
|
|
|
Key string `mapstructure:"key"`
|
|
|
|
} `mapstructure:"ssl"`
|
|
|
|
|
|
|
|
Uploads struct {
|
|
|
|
MaximumSize int64 `mapstructure:"maximumSize"`
|
|
|
|
} `mapstructure:"uploads"`
|
|
|
|
} `mapstructure:"web"`
|
|
|
|
|
|
|
|
Docker struct {
|
|
|
|
Socket string `mapstructure:"socket"`
|
|
|
|
AutoupdateImages bool `mapstructure:"autoupdateImages"`
|
|
|
|
NetworkInterface string `mapstructure:"networkInterface"`
|
|
|
|
TimezonePath string `mapstructure:"timezonePath"`
|
|
|
|
} `mapstructure:"docker"`
|
|
|
|
|
|
|
|
Sftp struct {
|
|
|
|
Path string `mapstructure:"path"`
|
|
|
|
Port int16 `mapstructure:"port"`
|
|
|
|
} `mapstructure:"sftp"`
|
|
|
|
|
|
|
|
Query struct {
|
|
|
|
KillOnFail bool `mapstructure:"killOnFail"`
|
|
|
|
FailLimit bool `mapstructure:"failLimit"`
|
|
|
|
} `mapstructure:"query"`
|
|
|
|
|
|
|
|
Remote string `mapstructure:"remote"`
|
|
|
|
|
|
|
|
Log struct {
|
|
|
|
Path string `mapstructure:"path"`
|
|
|
|
Level string `mapstructure:"level"`
|
|
|
|
DeleteAfterDays int `mapstructure:"deleteAfterDays"`
|
|
|
|
} `mapstructure:"log"`
|
|
|
|
|
|
|
|
AuthKeys []string `mapstructure:"authKeys"`
|
|
|
|
}
|
|
|
|
|
2017-08-02 20:02:34 +00:00
|
|
|
// handlePatchConfig handles PATCH /config
|
2017-10-09 19:01:24 +00:00
|
|
|
func PatchConfiguration(c *gin.Context) {
|
2017-10-01 18:42:17 +00:00
|
|
|
// reqBody, err := ioutil.ReadAll(c.Request.Body)
|
|
|
|
// if err != nil {
|
|
|
|
// log.WithError(err).Error("Failed to read input.")
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// reqJSON := new(incomingConfiguration)
|
|
|
|
// err = json.Unmarshal(reqBody, reqJSON)
|
|
|
|
// if err != nil {
|
|
|
|
// log.WithError(err).Error("Failed to decode JSON.")
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
var json incomingConfiguration
|
|
|
|
if err := c.BindJSON(&json); err != nil {
|
|
|
|
log.WithError(err).Error("Failed to bind Json.")
|
|
|
|
}
|
2017-08-02 20:02:34 +00:00
|
|
|
}
|