From 0c17e240f400b59bda424c653a082850d79dad8a Mon Sep 17 00:00:00 2001 From: antony1060 Date: Wed, 24 Mar 2021 10:26:03 +0100 Subject: [PATCH 1/5] Added app name --- config/config.go | 2 ++ server/console.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 7f28d8f..137b921 100644 --- a/config/config.go +++ b/config/config.go @@ -247,6 +247,8 @@ type Configuration struct { // if the debug flag is passed through the command line arguments. Debug bool + AppName string `json:"app_name" yaml:"app_name"` + // A unique identifier for this node in the Panel. Uuid string diff --git a/server/console.go b/server/console.go index 1a41f2b..23043a4 100644 --- a/server/console.go +++ b/server/console.go @@ -127,6 +127,6 @@ func (s *Server) Throttler() *ConsoleThrottler { func (s *Server) PublishConsoleOutputFromDaemon(data string) { s.Events().Publish( ConsoleOutputEvent, - colorstring.Color(fmt.Sprintf("[yellow][bold][Pterodactyl Daemon]:[default] %s", data)), + colorstring.Color(fmt.Sprintf("[yellow][bold][%s Daemon]:[default] %s", config.Get().AppName, data)), ) } From 52fcf1e37f38dd37a564f92da623d256a696f850 Mon Sep 17 00:00:00 2001 From: Antony Date: Wed, 24 Mar 2021 11:24:54 +0100 Subject: [PATCH 2/5] Added defaults Co-authored-by: Jakob --- config/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 137b921..eb1e2c0 100644 --- a/config/config.go +++ b/config/config.go @@ -247,7 +247,7 @@ type Configuration struct { // if the debug flag is passed through the command line arguments. Debug bool - AppName string `json:"app_name" yaml:"app_name"` + AppName string `default:"Pterodactyl" json:"app_name" yaml:"app_name"` // A unique identifier for this node in the Panel. Uuid string @@ -619,4 +619,4 @@ func getSystemName() (string, error) { return "", err } return release["ID"], nil -} \ No newline at end of file +} From b691b8f06febdbfd9b317df1da4de9c930e8a44d Mon Sep 17 00:00:00 2001 From: antony1060 Date: Fri, 2 Apr 2021 21:32:30 +0200 Subject: [PATCH 3/5] Fixed /api/servers --- router/router_system.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/router/router_system.go b/router/router_system.go index b3eb1ce..f85dc38 100644 --- a/router/router_system.go +++ b/router/router_system.go @@ -28,7 +28,15 @@ func getSystemInformation(c *gin.Context) { // Returns all of the servers that are registered and configured correctly on // this wings instance. func getAllServers(c *gin.Context) { - c.JSON(http.StatusOK, middleware.ExtractManager(c).All()) + servers := middleware.ExtractManager(c).All() + var procData []serverProcData + for _, v := range servers { + procData = append(procData, serverProcData{ + ResourceUsage: v.Proc(), + Suspended: v.IsSuspended(), + }) + } + c.JSON(http.StatusOK, procData) } // Creates a new server on the wings daemon and begins the installation process From b448310a33094bf1ef6598306e99105b6d8f0ecc Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 3 Apr 2021 11:08:26 -0700 Subject: [PATCH 4/5] Correctly return servers installed on wings and their resource usage --- router/router_system.go | 22 ++++++++++++++-------- server/configuration.go | 3 +-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/router/router_system.go b/router/router_system.go index f85dc38..58ff70c 100644 --- a/router/router_system.go +++ b/router/router_system.go @@ -10,6 +10,7 @@ import ( "github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/installer" "github.com/pterodactyl/wings/router/middleware" + "github.com/pterodactyl/wings/server" "github.com/pterodactyl/wings/system" ) @@ -28,15 +29,20 @@ func getSystemInformation(c *gin.Context) { // Returns all of the servers that are registered and configured correctly on // this wings instance. func getAllServers(c *gin.Context) { - servers := middleware.ExtractManager(c).All() - var procData []serverProcData - for _, v := range servers { - procData = append(procData, serverProcData{ - ResourceUsage: v.Proc(), - Suspended: v.IsSuspended(), - }) + type serverItem struct { + *server.Configuration + Resources server.ResourceUsage `json:"resources"` } - c.JSON(http.StatusOK, procData) + + servers := middleware.ExtractManager(c).All() + out := make([]serverItem, len(servers), len(servers)) + for i, v := range servers { + out[i] = serverItem{ + Configuration: v.Config(), + Resources: v.Proc(), + } + } + c.JSON(http.StatusOK, out) } // Creates a new server on the wings daemon and begins the installation process diff --git a/server/configuration.go b/server/configuration.go index b7f16b7..100b4ab 100644 --- a/server/configuration.go +++ b/server/configuration.go @@ -8,7 +8,7 @@ import ( type EggConfiguration struct { // The internal UUID of the Egg on the Panel. - ID string + ID string `json:"id"` // Maintains a list of files that are blacklisted for opening/editing/downloading // or basically any type of access on the server by any user. This is NOT the same @@ -43,7 +43,6 @@ type Configuration struct { Build environment.Limits `json:"build"` CrashDetectionEnabled bool `default:"true" json:"enabled" yaml:"enabled"` Mounts []Mount `json:"mounts"` - Resources ResourceUsage `json:"resources"` Egg EggConfiguration `json:"egg,omitempty"` Container struct { From 1b1eaa3171801ff733ce3230c0a7391d9df17193 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 3 Apr 2021 11:11:36 -0700 Subject: [PATCH 5/5] Avoid expensive copies of the config for every line output --- server/console.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/console.go b/server/console.go index 23043a4..5689191 100644 --- a/server/console.go +++ b/server/console.go @@ -13,6 +13,11 @@ import ( "github.com/pterodactyl/wings/system" ) +// appName is a local cache variable to avoid having to make expensive copies of +// the configuration every time we need to send output along to the websocket for +// a server. +var appName string + var ErrTooMuchConsoleData = errors.New("console is outputting too much data") type ConsoleThrottler struct { @@ -122,11 +127,14 @@ func (s *Server) Throttler() *ConsoleThrottler { return s.throttler } -// Sends output to the server console formatted to appear correctly as being sent -// from Wings. +// PublishConsoleOutputFromDaemon sends output to the server console formatted +// to appear correctly as being sent from Wings. func (s *Server) PublishConsoleOutputFromDaemon(data string) { + if appName == "" { + appName = config.Get().AppName + } s.Events().Publish( ConsoleOutputEvent, - colorstring.Color(fmt.Sprintf("[yellow][bold][%s Daemon]:[default] %s", config.Get().AppName, data)), + colorstring.Color(fmt.Sprintf("[yellow][bold][%s Daemon]:[default] %s", appName, data)), ) }