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
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
6 changed files with 99 additions and 197 deletions

40
Gopkg.lock generated
View File

@ -22,18 +22,6 @@
packages = ["."] packages = ["."]
revision = "cd527374f1e5bff4938207604a14f2e38a9cf512" revision = "cd527374f1e5bff4938207604a14f2e38a9cf512"
[[projects]]
branch = "develop"
name = "github.com/pterodactyl/wings"
packages = [
"api",
"config",
"constants",
"control",
"utils"
]
revision = "44f42eec8cca473338f7930a625c26f54e77444f"
[[projects]] [[projects]]
branch = "master" branch = "master"
name = "github.com/StackExchange/wmi" name = "github.com/StackExchange/wmi"
@ -166,18 +154,6 @@
revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75"
version = "v1.0" version = "v1.0"
[[projects]]
name = "github.com/lestrrat/go-file-rotatelogs"
packages = ["."]
revision = "9df8b44f21785240553882138c5df2e9cc1db910"
version = "v2.1.0"
[[projects]]
branch = "master"
name = "github.com/lestrrat/go-strftime"
packages = ["."]
revision = "ba3bf9c1d0421aa146564a632931730344f1f9f1"
[[projects]] [[projects]]
name = "github.com/magiconair/properties" name = "github.com/magiconair/properties"
packages = ["."] packages = ["."]
@ -238,24 +214,26 @@
revision = "792786c7400a136282c1664665ae0a8db921c6c2" revision = "792786c7400a136282c1664665ae0a8db921c6c2"
version = "v1.0.0" version = "v1.0.0"
[[projects]]
name = "github.com/rifflock/lfshook"
packages = ["."]
revision = "1fdc019a35147ddbb3d25aedf713ad6d1430c144"
version = "v2.2"
[[projects]] [[projects]]
name = "github.com/shirou/gopsutil" name = "github.com/shirou/gopsutil"
packages = [ packages = [
".",
"cpu", "cpu",
"host", "host",
"internal/common", "internal/common",
"mem", "mem",
"net",
"process" "process"
] ]
revision = "c432be29ccce470088d07eea25b3ea7e68a8afbb" revision = "c432be29ccce470088d07eea25b3ea7e68a8afbb"
version = "v2.18.01" version = "v2.18.01"
[[projects]]
branch = "master"
name = "github.com/shirou/w32"
packages = ["."]
revision = "bb4de0191aa41b5507caa14b0650cdbddcd9280b"
[[projects]] [[projects]]
name = "github.com/sirupsen/logrus" name = "github.com/sirupsen/logrus"
packages = ["."] packages = ["."]
@ -365,6 +343,6 @@
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "3f6a265d298db6e8379b05d796fcdff3d78a0216b6aaaccd4501440cbcfc0792" inputs-digest = "8a295fa1730b9ed537e5fceeeee2a87c233eee4dea1bf0697d9f94b0c0d23e7d"
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View File

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

View File

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

View File

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

View File

@ -1,68 +0,0 @@
package command
import (
"path/filepath"
"strconv"
"github.com/spf13/viper"
"github.com/pterodactyl/wings/api"
"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/constants"
"github.com/pterodactyl/wings/control"
"github.com/pterodactyl/wings/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
// RootCommand is the root command of wings
var RootCommand = &cobra.Command{
Use: "wings",
Short: "",
Long: "",
Run: run,
}
var configPath string
func init() {
RootCommand.Flags().StringVarP(&configPath, "config", "c", "./config.yml", "Allows to set the path of the configuration file.")
}
// Execute registers the RootCommand
func Execute() {
RootCommand.Execute()
}
func run(cmd *cobra.Command, args []string) {
tools.InitLogging()
log.Info("Loading configuration...")
if err := config.LoadConfiguration(configPath); err != nil {
log.WithError(err).Fatal("Failed to find configuration file")
}
tools.ConfigureLogging()
log.Info(` ____`)
log.Info(`__ Pterodactyl _____/___/_______ _______ ______`)
log.Info(`\_____\ \/\/ / / / __ / ___/`)
log.Info(` \___\ / / / / /_/ /___ /`)
log.Info(` \___/\___/___/___/___/___ /______/`)
log.Info(` /_______/ v` + constants.Version)
log.Info()
log.Info("Configuration loaded successfully.")
log.Info("Loading configured servers...")
if err := control.LoadServerConfigurations(filepath.Join(viper.GetString(config.DataPath), constants.ServersPath)); err != nil {
log.WithError(err).Error("Failed to load configured servers.")
}
if amount := len(control.GetServers()); amount == 1 {
log.Info("Loaded 1 server.")
} else {
log.Info("Loaded " + strconv.Itoa(amount) + " servers.")
}
log.Info("Starting api webserver...")
api := api.NewAPI()
api.Listen()
}

54
main.go
View File

@ -7,7 +7,6 @@ import (
"strconv" "strconv"
"github.com/pterodactyl/wings/api" "github.com/pterodactyl/wings/api"
"github.com/pterodactyl/wings/command"
"github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/constants" "github.com/pterodactyl/wings/constants"
"github.com/pterodactyl/wings/control" "github.com/pterodactyl/wings/control"
@ -17,38 +16,36 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
var configPath string
var RootCommand = &cobra.Command{
Use: "wings",
Short: "Wings is the next generation server control daemon for Pterodactyl",
Long: "Wings is the next generation server control daemon for Pterodactyl",
Run: run,
}
// Entrypoint of the application. Currently just boots up the cobra command
// and lets that handle everything else.
func main() { func main() {
if err := command.RootCommand.Execute(); err != nil { RootCommand.Flags().StringVarP(&configPath, "config", "c", "./config.yml", "Allows to set the path of the configuration file.")
if err := RootCommand.Execute(); err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
} }
// RootCommand is the root command of wings // Bootstraps the application and beging the process of running the API and
var RootCommand = &cobra.Command{ // server instances.
Use: "wings",
Short: "",
Long: "",
Run: run,
}
var configPath string
func init() {
RootCommand.Flags().StringVarP(&configPath, "config", "c", "./config.yml", "Allows to set the path of the configuration file.")
}
// Execute registers the RootCommand
func Execute() {
RootCommand.Execute()
}
func run(cmd *cobra.Command, args []string) { func run(cmd *cobra.Command, args []string) {
utils.InitLogging() utils.InitLogging()
logrus.Info("Loading configuration...")
logrus.Info("Booting configuration file...")
if err := config.LoadConfiguration(configPath); err != nil { if err := config.LoadConfiguration(configPath); err != nil {
logrus.WithError(err).Fatal("Failed to find configuration file") logrus.WithError(err).Fatal("Could not locate a suitable config.yml file for this Daemon.")
} }
logrus.Info("Configuration successfully loaded, booting application.")
utils.ConfigureLogging() utils.ConfigureLogging()
logrus.Info(` ____`) logrus.Info(` ____`)
@ -59,19 +56,16 @@ func run(cmd *cobra.Command, args []string) {
logrus.Info(` /_______/ v` + constants.Version) logrus.Info(` /_______/ v` + constants.Version)
logrus.Info() logrus.Info()
logrus.Info("Configuration loaded successfully.") logrus.Info("Loading configured servers.")
logrus.Info("Loading configured servers...")
if err := control.LoadServerConfigurations(filepath.Join(viper.GetString(config.DataPath), constants.ServersPath)); err != nil { if err := control.LoadServerConfigurations(filepath.Join(viper.GetString(config.DataPath), constants.ServersPath)); err != nil {
logrus.WithError(err).Error("Failed to load configured servers.") logrus.WithError(err).Error("Failed to load configured servers.")
} }
if amount := len(control.GetServers()); amount == 1 { if amount := len(control.GetServers()); amount == 1 {
logrus.Info("Loaded 1 server.") logrus.Info("Found and loaded " + strconv.Itoa(amount) + " server(s).")
} else {
logrus.Info("Loaded " + strconv.Itoa(amount) + " servers.")
} }
logrus.Info("Starting API Server...") logrus.Info("Registering API server and booting.")
a := api.NewAPI() a := api.NewAPI()
a.Listen() a.Listen()
} }