avoid panic from environment; ref pterodactyl/panel#2307

This commit is contained in:
Dane Everitt 2020-09-07 15:37:35 -07:00
parent 5bead443ad
commit 001bbfad1b
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 10 additions and 9 deletions

View File

@ -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,

View File

@ -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),
}