From 001bbfad1b22b3c04f550a551de8508758b347aa Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Mon, 7 Sep 2020 15:37:35 -0700 Subject: [PATCH] avoid panic from environment; ref pterodactyl/panel#2307 --- environment/docker/container.go | 9 +++++++++ server/server.go | 10 +--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/environment/docker/container.go b/environment/docker/container.go index 9d2ffd9..e468e89 100644 --- a/environment/docker/container.go +++ b/environment/docker/container.go @@ -143,6 +143,15 @@ func (e *Environment) Create() error { a := e.Configuration.Allocations() + evs := e.Configuration.EnvironmentVariables() + for i, v := range evs { + // Convert 127.0.0.1 to the pterodactyl0 network interface if the environment is Docker + // so that the server operates as expected. + if v == "SERVER_IP=127.0.0.1" { + evs[i] = "SERVER_IP="+config.Get().Docker.Network.Interface + } + } + conf := &container.Config{ Hostname: e.Id, Domainname: config.Get().Docker.Domainname, diff --git a/server/server.go b/server/server.go index 1fd64b2..2f6996d 100644 --- a/server/server.go +++ b/server/server.go @@ -6,7 +6,6 @@ import ( "github.com/apex/log" "github.com/pkg/errors" "github.com/pterodactyl/wings/api" - "github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/environment" "github.com/pterodactyl/wings/environment/docker" "github.com/pterodactyl/wings/events" @@ -75,18 +74,11 @@ func (s *Server) Id() string { func (s *Server) GetEnvironmentVariables() []string { zone, _ := time.Now().In(time.Local).Zone() - var ip = s.Config().Allocations.DefaultMapping.Ip - // Convert 127.0.0.1 to the pterodactyl0 network interface if the environment is Docker - // so that the server operates as expected. - if s.Environment.Type() == "docker" && ip == "127.0.0.1" { - ip = config.Get().Docker.Network.Interface - } - var out = []string{ fmt.Sprintf("TZ=%s", zone), fmt.Sprintf("STARTUP=%s", s.Config().Invocation), fmt.Sprintf("SERVER_MEMORY=%d", s.MemoryLimit()), - fmt.Sprintf("SERVER_IP=%s", ip), + fmt.Sprintf("SERVER_IP=%s", s.Config().Allocations.DefaultMapping.Ip), fmt.Sprintf("SERVER_PORT=%d", s.Config().Allocations.DefaultMapping.Port), }