Compare commits
1 Commits
v1.0.0-bet
...
v1.0.0-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f6cd384d5 |
32
Makefile
32
Makefile
@@ -1,10 +1,28 @@
|
||||
build:
|
||||
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -gcflags "all=-trimpath=/Users/dane/Sites/development/code" -o build/wings_linux_amd64 -v wings.go
|
||||
BINARY = "build/wings"
|
||||
OSARCHLIST = "darwin/386 darwin/amd64 linux/386 linux/amd64 linux/arm linux/arm64 windows/386 windows/amd64"
|
||||
|
||||
compress:
|
||||
upx --brute build/wings_*
|
||||
all: $(BINARY)
|
||||
|
||||
cross-build: clean build compress
|
||||
$(BINARY):
|
||||
go build -o $(BINARY)
|
||||
|
||||
clean:
|
||||
rm -rf build/wings_*
|
||||
cross-build:
|
||||
gox -osarch $(OSARCHLIST) -output "build/{{.Dir}}_{{.OS}}_{{.Arch}}"
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
go install
|
||||
|
||||
test:
|
||||
go test `go list ./... | grep -v "/vendor/"`
|
||||
|
||||
coverage:
|
||||
goverage -coverprofile=coverage.out ./...
|
||||
go tool cover -html=coverage.out
|
||||
|
||||
dependencies:
|
||||
glide install
|
||||
|
||||
install-tools:
|
||||
go get -u github.com/mitchellh/gox
|
||||
go get -u github.com/haya14busa/goverage
|
||||
|
||||
26
api/api.go
26
api/api.go
@@ -45,28 +45,6 @@ func (r *PanelRequest) GetEndpoint(endpoint string) string {
|
||||
)
|
||||
}
|
||||
|
||||
// Logs the request into the debug log with all of the important request bits.
|
||||
// The authorization key will be cleaned up before being output.
|
||||
func (r *PanelRequest) logDebug(req *http.Request) {
|
||||
headers := make(map[string][]string)
|
||||
for k, v := range req.Header {
|
||||
if k != "Authorization" || len(v) == 0 {
|
||||
headers[k] = v
|
||||
continue
|
||||
}
|
||||
|
||||
headers[k] = []string{v[0][0:15] + "(redacted)"}
|
||||
}
|
||||
|
||||
|
||||
zap.S().Debugw(
|
||||
"making request to external HTTP endpoint",
|
||||
zap.String("method", req.Method),
|
||||
zap.String("endpoint", req.URL.String()),
|
||||
zap.Any("headers", headers),
|
||||
)
|
||||
}
|
||||
|
||||
func (r *PanelRequest) Get(url string) (*http.Response, error) {
|
||||
c := r.GetClient()
|
||||
|
||||
@@ -77,7 +55,7 @@ func (r *PanelRequest) Get(url string) (*http.Response, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r.logDebug(req)
|
||||
zap.S().Debugw("GET request to endpoint", zap.String("endpoint", r.GetEndpoint(url)), zap.Any("headers", req.Header))
|
||||
|
||||
return c.Do(req)
|
||||
}
|
||||
@@ -92,7 +70,7 @@ func (r *PanelRequest) Post(url string, data []byte) (*http.Response, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r.logDebug(req)
|
||||
zap.S().Debugw("POST request to endpoint", zap.String("endpoint", r.GetEndpoint(url)), zap.Any("headers", req.Header))
|
||||
|
||||
return c.Do(req)
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// We've gone through a couple of iterations of where the configuration is stored. This
|
||||
// helpful little function will look through the three areas it might have ended up, and
|
||||
// return it.
|
||||
//
|
||||
// We only run this if the configuration flag for the instance is not actually passed in
|
||||
// via the command line. Once found, the configuration is moved into the expected default
|
||||
// location. Only errors are returned from this function, you can safely assume that after
|
||||
// running this the configuration can be found in the correct default location.
|
||||
func RelocateConfiguration() error {
|
||||
var match string
|
||||
check := []string{
|
||||
config.DefaultLocation,
|
||||
"/var/lib/pterodactyl/config.yml",
|
||||
"/etc/wings/config.yml",
|
||||
}
|
||||
|
||||
// Loop over all of the configuration paths, and return which one we found, if
|
||||
// any.
|
||||
for _, p := range check {
|
||||
if s, err := os.Stat(p); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
} else if !s.IsDir() {
|
||||
match = p
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Just return a generic not exist error at this point if we didn't have a match, this
|
||||
// will allow the caller to handle displaying a more friendly error to the user. If we
|
||||
// did match in the default location, go ahead and return successfully.
|
||||
if match == "" {
|
||||
return os.ErrNotExist
|
||||
} else if match == config.DefaultLocation {
|
||||
return nil
|
||||
}
|
||||
|
||||
// The rest of this function simply creates the new default location and moves the
|
||||
// old configuration file over to the new location, then sets the permissions on the
|
||||
// file correctly so that only the user running this process can read it.
|
||||
p, _ := filepath.Split(config.DefaultLocation)
|
||||
if err := os.MkdirAll(p, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.Rename(match, config.DefaultLocation); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return os.Chmod(config.DefaultLocation, 0600)
|
||||
}
|
||||
34
cmd/root.go
34
cmd/root.go
@@ -3,7 +3,6 @@ package cmd
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"github.com/mitchellh/colorstring"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
@@ -63,22 +62,11 @@ func readConfiguration() (*config.Configuration, error) {
|
||||
}
|
||||
|
||||
func rootCmdRun(*cobra.Command, []string) {
|
||||
// Profile wings in production!!!!
|
||||
if shouldRunProfiler {
|
||||
defer profile.Start().Stop()
|
||||
}
|
||||
|
||||
// Only attempt configuration file relocation if a custom location has not
|
||||
// been specified in the command startup.
|
||||
if configPath == config.DefaultLocation {
|
||||
if err := RelocateConfiguration(); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
exitWithConfigurationNotice()
|
||||
}
|
||||
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
c, err := readConfiguration()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -271,23 +259,3 @@ func printLogo() {
|
||||
fmt.Println(`Copyright © 2018 - 2020 Dane Everitt & Contributors`)
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
func exitWithConfigurationNotice() {
|
||||
fmt.Print(colorstring.Color(`
|
||||
[_red_][white][bold]Error: Configuration File Not Found[reset]
|
||||
|
||||
Wings was not able to locate your configuration file, and therefore is not
|
||||
able to complete its boot process.
|
||||
|
||||
Please ensure you have copied your instance configuration file into
|
||||
the default location, or have provided the --config flag to use a
|
||||
custom location.
|
||||
|
||||
Default Location: /etc/pterodactyl/config.yml
|
||||
|
||||
[yellow]This is not a bug with this software. Please do not make a bug report
|
||||
for this issue, it will be closed.[reset]
|
||||
|
||||
`))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
const DefaultLocation = "/etc/pterodactyl/config.yml"
|
||||
const DefaultLocation = "/var/lib/pterodactyl/config.yml"
|
||||
|
||||
type Configuration struct {
|
||||
sync.RWMutex `json:"-" yaml:"-"`
|
||||
@@ -46,9 +46,9 @@ type Configuration struct {
|
||||
// validate against it.
|
||||
AuthenticationToken string `json:"token" yaml:"token"`
|
||||
|
||||
Api ApiConfiguration `json:"api" yaml:"api"`
|
||||
System SystemConfiguration `json:"system" yaml:"system"`
|
||||
Docker DockerConfiguration `json:"docker" yaml:"docker"`
|
||||
Api ApiConfiguration
|
||||
System SystemConfiguration
|
||||
Docker DockerConfiguration
|
||||
|
||||
// The amount of time in seconds that should elapse between disk usage checks
|
||||
// run by the daemon. Setting a higher number can result in better IO performance
|
||||
|
||||
@@ -15,7 +15,7 @@ type dockerNetworkInterfaces struct {
|
||||
type DockerNetworkConfiguration struct {
|
||||
// The interface that should be used to create the network. Must not conflict
|
||||
// with any other interfaces in use by Docker or on the system.
|
||||
Interface string `default:"172.18.0.1" json:"interface" yaml:"interface"`
|
||||
Interface string `default:"172.18.0.1"`
|
||||
|
||||
// The DNS settings for containers.
|
||||
Dns []string `default:"[\"1.1.1.1\", \"1.0.0.1\"]"`
|
||||
@@ -26,7 +26,6 @@ type DockerNetworkConfiguration struct {
|
||||
Name string `default:"pterodactyl_nw"`
|
||||
ISPN bool `default:"false" yaml:"ispn"`
|
||||
Driver string `default:"bridge"`
|
||||
Mode string `default:"pterodactyl_nw" yaml:"network_mode"`
|
||||
IsInternal bool `default:"false" yaml:"is_internal"`
|
||||
EnableICC bool `default:"true" yaml:"enable_icc"`
|
||||
Interfaces dockerNetworkInterfaces `yaml:"interfaces"`
|
||||
@@ -45,7 +44,7 @@ type DockerConfiguration struct {
|
||||
UpdateImages bool `default:"true" json:"update_images" yaml:"update_images"`
|
||||
|
||||
// The location of the Docker socket.
|
||||
Socket string `default:"/var/run/docker.sock" json:"socket" yaml:"socket"`
|
||||
Socket string `default:"/var/run/docker.sock"`
|
||||
|
||||
// Defines the location of the timezone file on the host system that should
|
||||
// be mounted into the created containers so that they all use the same time.
|
||||
|
||||
18
go.mod
18
go.mod
@@ -36,7 +36,6 @@ require (
|
||||
github.com/gorilla/websocket v1.4.0
|
||||
github.com/gotestyourself/gotestyourself v2.2.0+incompatible // indirect
|
||||
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334
|
||||
github.com/icza/dyno v0.0.0-20200205103839-49cb13720835
|
||||
github.com/imdario/mergo v0.3.8
|
||||
github.com/klauspost/pgzip v1.2.3
|
||||
github.com/magiconair/properties v1.8.1
|
||||
@@ -51,24 +50,25 @@ require (
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/pkg/profile v1.4.0
|
||||
github.com/pkg/sftp v1.11.0 // indirect
|
||||
github.com/pterodactyl/sftp-server v1.1.2
|
||||
github.com/pkg/sftp v1.10.1 // indirect
|
||||
github.com/pterodactyl/sftp-server v1.1.1
|
||||
github.com/remeh/sizedwaitgroup v0.0.0-20180822144253-5e7302b12cce
|
||||
github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94
|
||||
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||
github.com/spf13/cobra v0.0.7
|
||||
github.com/stretchr/objx v0.2.0 // indirect
|
||||
github.com/yuin/goldmark v1.1.30 // indirect
|
||||
go.uber.org/zap v1.15.0
|
||||
golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79 // indirect
|
||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
|
||||
go.uber.org/atomic v1.5.1 // indirect
|
||||
go.uber.org/multierr v1.4.0 // indirect
|
||||
go.uber.org/zap v1.13.0
|
||||
golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 // indirect
|
||||
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect
|
||||
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 // indirect
|
||||
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a
|
||||
golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f // indirect
|
||||
golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5 // indirect
|
||||
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f // indirect
|
||||
golang.org/x/tools v0.0.0-20200426102838-f3a5411a4c3b // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||
gopkg.in/ini.v1 v1.51.0
|
||||
gopkg.in/yaml.v2 v2.2.8
|
||||
gotest.tools v2.2.0+incompatible // indirect
|
||||
honnef.co/go/tools v0.0.1-2020.1.3 // indirect
|
||||
)
|
||||
|
||||
22
go.sum
22
go.sum
@@ -123,8 +123,6 @@ github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDG
|
||||
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
|
||||
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 h1:VHgatEHNcBFEB7inlalqfNqw65aNkM1lGX2yt3NmbS8=
|
||||
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
|
||||
github.com/icza/dyno v0.0.0-20200205103839-49cb13720835 h1:f1irK5f03uGGj+FjgQfZ5VhdKNVQVJ4skHsedzVohQ4=
|
||||
github.com/icza/dyno v0.0.0-20200205103839-49cb13720835/go.mod h1:c1tRKs5Tx7E2+uHGSyyncziFjvGpgv4H2HrqXeUQ/Uk=
|
||||
github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ=
|
||||
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
@@ -218,8 +216,6 @@ github.com/pkg/sftp v1.8.3 h1:9jSe2SxTM8/3bXZjtqnkgTBW+lA8db0knZJyns7gpBA=
|
||||
github.com/pkg/sftp v1.8.3/go.mod h1:NxmoDg/QLVWluQDUYG7XBZTLUpKeFa8e3aMf1BfjyHk=
|
||||
github.com/pkg/sftp v1.10.1 h1:VasscCm72135zRysgrJDKsntdmPN+OuU3+nnHYA9wyc=
|
||||
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
|
||||
github.com/pkg/sftp v1.11.0 h1:4Zv0OGbpkg4yNuUtH0s8rvoYxRCNyT29NVUo6pgPmxI=
|
||||
github.com/pkg/sftp v1.11.0/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
@@ -233,8 +229,6 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
|
||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||
github.com/pterodactyl/sftp-server v1.1.1 h1:IjuOy21BNZxfejKnXG1RgLxXAYylDqBVpbKZ6+fG5FQ=
|
||||
github.com/pterodactyl/sftp-server v1.1.1/go.mod h1:b1VVWYv0RF9rxSZQqaD/rYXriiRMNPsbV//CKMXR4ag=
|
||||
github.com/pterodactyl/sftp-server v1.1.2 h1:5bI9upe0kBRn9ALDabn9S2GVU5gkYvSErYgs32dAKjk=
|
||||
github.com/pterodactyl/sftp-server v1.1.2/go.mod h1:KjSONrenRr1oCh94QIVAU6yEzMe+Hd7r/JHrh5/oQHs=
|
||||
github.com/remeh/sizedwaitgroup v0.0.0-20180822144253-5e7302b12cce h1:aP+C+YbHZfOQlutA4p4soHi7rVUqHQdWEVMSkHfDTqY=
|
||||
github.com/remeh/sizedwaitgroup v0.0.0-20180822144253-5e7302b12cce/go.mod h1:3j2R4OIe/SeS6YDhICBy22RWjJC5eNCJ1V+9+NVNYlo=
|
||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||
@@ -291,15 +285,11 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
go.uber.org/atomic v1.5.1 h1:rsqfU5vBkVknbhUGbAUwQKR2H4ItV8tjJ+6kJX4cxHM=
|
||||
go.uber.org/atomic v1.5.1/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
|
||||
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
|
||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
|
||||
go.uber.org/multierr v1.4.0 h1:f3WCSC2KzAcBXGATIxAB1E2XuCpNU255wNKZ505qi3E=
|
||||
go.uber.org/multierr v1.4.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
|
||||
go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
|
||||
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
|
||||
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
|
||||
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
||||
go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o=
|
||||
@@ -307,8 +297,6 @@ go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||
go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU=
|
||||
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
|
||||
go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM=
|
||||
go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20181025213731-e84da0312774/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
@@ -321,8 +309,6 @@ golang.org/x/crypto v0.0.0-20200414173820-0848c9571904 h1:bXoxMPcSLOq08zI3/c5dEB
|
||||
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 h1:Q7tZBpemrlsc2I7IyODzhtallWRSm4Q0d09pL6XbQtU=
|
||||
golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79 h1:IaQbIIB2X/Mp/DKctl6ROxz1KyMlKp4uyvL6+kQ7C88=
|
||||
golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
@@ -330,9 +316,7 @@ golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE=
|
||||
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
|
||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
@@ -372,8 +356,6 @@ golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 h1:opSr2sbRXk5X5/givKrrKj9HX
|
||||
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f h1:gWF768j/LaZugp8dyS4UwsslYCYz9XgFxvlgsn0n9H8=
|
||||
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f h1:mOhmO9WsBaJCNmaZHPtHs9wOcdqdKCjF6OPJlmDM3KI=
|
||||
golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
@@ -392,13 +374,10 @@ golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64
|
||||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200417140056-c07e33ef3290 h1:NXNmtp0ToD36cui5IqWy95LC4Y6vT/4y3RnPxlQPinU=
|
||||
golang.org/x/tools v0.0.0-20200417140056-c07e33ef3290/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20200426102838-f3a5411a4c3b h1:zSzQJAznWxAh9fZxiPy2FZo+ZZEYoYFYYDYdOrU7AaM=
|
||||
golang.org/x/tools v0.0.0-20200426102838-f3a5411a4c3b/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools/gopls v0.1.3/go.mod h1:vrCQzOKxvuiZLjCKSmbbov04oeBQQOb4VQqwYK2PWIY=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@@ -430,4 +409,3 @@ gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"go.uber.org/zap"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -47,14 +48,13 @@ func readFileBytes(path string) ([]byte, error) {
|
||||
}
|
||||
|
||||
// Gets the value of a key based on the value type defined.
|
||||
func (cfr *ConfigurationFileReplacement) getKeyValue(value []byte) interface{} {
|
||||
if cfr.ReplaceWith.Type() == jsonparser.Boolean {
|
||||
func getKeyValue(value []byte) interface{} {
|
||||
if reflect.ValueOf(value).Kind() == reflect.Bool {
|
||||
v, _ := strconv.ParseBool(string(value))
|
||||
return v
|
||||
}
|
||||
|
||||
// Try to parse into an int, if this fails just ignore the error and continue
|
||||
// through, returning the string.
|
||||
// Try to parse into an int, if this fails just ignore the error and
|
||||
if v, err := strconv.Atoi(string(value)); err == nil {
|
||||
return v
|
||||
}
|
||||
@@ -70,9 +70,7 @@ func (cfr *ConfigurationFileReplacement) getKeyValue(value []byte) interface{} {
|
||||
// configurations per-world (such as Spigot and Bungeecord) where we'll need to make
|
||||
// adjustments to the bind address for the user.
|
||||
//
|
||||
// This does not currently support nested wildcard matches. For example, foo.*.bar
|
||||
// will work, however foo.*.bar.*.baz will not, since we'll only be splitting at the
|
||||
// first wildcard, and not subsequent ones.
|
||||
// This does not currently support nested matches. container.*.foo.*.bar will not work.
|
||||
func (f *ConfigurationFile) IterateOverJson(data []byte) (*gabs.Container, error) {
|
||||
parsed, err := gabs.ParseJSON(data)
|
||||
if err != nil {
|
||||
@@ -145,7 +143,7 @@ func (cfr *ConfigurationFileReplacement) SetAtPathway(c *gabs.Container, path st
|
||||
}
|
||||
}
|
||||
|
||||
_, err := c.SetP(cfr.getKeyValue(value), path)
|
||||
_, err := c.SetP(getKeyValue(value), path)
|
||||
|
||||
return err
|
||||
}
|
||||
@@ -167,8 +165,11 @@ func (f *ConfigurationFile) LookupConfigurationValue(cfr ConfigurationFileReplac
|
||||
)
|
||||
|
||||
var path []string
|
||||
// The camel casing is important here, the configuration for the Daemon does not use
|
||||
// JSON, and as such all of the keys will be generated in CamelCase format, rather than
|
||||
// the expected snake_case from the old Daemon.
|
||||
for _, value := range strings.Split(huntPath, ".") {
|
||||
path = append(path, strcase.ToSnake(value))
|
||||
path = append(path, strcase.ToCamel(value))
|
||||
}
|
||||
|
||||
// Look for the key in the configuration file, and if found return that value to the
|
||||
|
||||
@@ -5,16 +5,14 @@ import (
|
||||
"encoding/json"
|
||||
"github.com/beevik/etree"
|
||||
"github.com/buger/jsonparser"
|
||||
"github.com/icza/dyno"
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/magiconair/properties"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"go.uber.org/zap"
|
||||
"gopkg.in/ini.v1"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -42,44 +40,6 @@ type ConfigurationFile struct {
|
||||
configuration []byte
|
||||
}
|
||||
|
||||
// Custom unmarshaler for configuration files. If there is an error while parsing out the
|
||||
// replacements, don't fail the entire operation, just log a global warning so someone can
|
||||
// find the issue, and return an empty array of replacements.
|
||||
//
|
||||
// I imagine people will notice configuration replacement isn't working correctly and then
|
||||
// the logs should help better expose that issue.
|
||||
func (f *ConfigurationFile) UnmarshalJSON(data []byte) error {
|
||||
var m map[string]*json.RawMessage
|
||||
if err := json.Unmarshal(data, &m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(*m["file"], &f.FileName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(*m["parser"], &f.Parser); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(*m["replace"], &f.Replace); err != nil {
|
||||
zap.S().Warnw(
|
||||
"failed to unmarshal configuration file replacement",
|
||||
zap.String("file", f.FileName),
|
||||
zap.Error(err),
|
||||
)
|
||||
|
||||
f.Replace = []ConfigurationFileReplacement{}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Regex to match paths such as foo[1].bar[2] and convert them into a format that
|
||||
// gabs can work with, such as foo.1.bar.2 in this case. This is applied when creating
|
||||
// the struct for the configuration file replacements.
|
||||
var cfrMatchReplacement = regexp.MustCompile(`\[(\d+)]`)
|
||||
|
||||
// Defines a single find/replace instance for a given server configuration file.
|
||||
type ConfigurationFileReplacement struct {
|
||||
Match string `json:"match"`
|
||||
@@ -92,34 +52,22 @@ type ConfigurationFileReplacement struct {
|
||||
func (cfr *ConfigurationFileReplacement) UnmarshalJSON(data []byte) error {
|
||||
m, err := jsonparser.GetString(data, "match")
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
// See comment on the replacement regex to understand what exactly this is doing.
|
||||
cfr.Match = cfrMatchReplacement.ReplaceAllString(m, ".$1")
|
||||
cfr.Match = m
|
||||
|
||||
iv, err := jsonparser.GetString(data, "if_value")
|
||||
// We only check keypath here since match & replace_with should be present on all of
|
||||
// them, however if_value is optional.
|
||||
if err != nil && err != jsonparser.KeyPathNotFoundError {
|
||||
return err
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
cfr.IfValue = iv
|
||||
|
||||
rw, dt, _, err := jsonparser.Get(data, "replace_with")
|
||||
if err != nil {
|
||||
if err != jsonparser.KeyPathNotFoundError {
|
||||
return err
|
||||
}
|
||||
|
||||
// Okay, likely dealing with someone who forgot to upgrade their eggs, so in
|
||||
// that case, fallback to using the old key which was "value".
|
||||
rw, dt, _, err = jsonparser.Get(data, "value")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
cfr.ReplaceWith = ReplaceValue{
|
||||
value: rw,
|
||||
valueType: dt,
|
||||
@@ -133,11 +81,8 @@ func (cfr *ConfigurationFileReplacement) UnmarshalJSON(data []byte) error {
|
||||
func (f *ConfigurationFile) Parse(path string, internal bool) error {
|
||||
zap.S().Debugw("parsing configuration file", zap.String("path", path), zap.String("parser", string(f.Parser)))
|
||||
|
||||
if mb, err := json.Marshal(config.Get()); err != nil {
|
||||
return err
|
||||
} else {
|
||||
f.configuration = mb
|
||||
}
|
||||
mb, _ := json.Marshal(config.Get())
|
||||
f.configuration = mb
|
||||
|
||||
var err error
|
||||
|
||||
@@ -359,15 +304,10 @@ func (f *ConfigurationFile) parseYamlFile(path string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
i := make(map[string]interface{})
|
||||
if err := yaml.Unmarshal(b, &i); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Unmarshal the yaml data into a JSON interface such that we can work with
|
||||
// any arbitrary data structure. If we don't do this, I can't use gabs which
|
||||
// makes working with unknown JSON signficiantly easier.
|
||||
jsonBytes, err := json.Marshal(dyno.ConvertMapI2MapS(i))
|
||||
jsonBytes, err := yaml.YAMLToJSON(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -380,7 +320,7 @@ func (f *ConfigurationFile) parseYamlFile(path string) error {
|
||||
}
|
||||
|
||||
// Remarshal the JSON into YAML format before saving it back to the disk.
|
||||
marshaled, err := yaml.Marshal(data.Data())
|
||||
marshaled, err := yaml.JSONToYAML(data.Bytes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,24 +4,14 @@ import (
|
||||
"bufio"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Returns the contents of a file on the server.
|
||||
func getServerFileContents(c *gin.Context) {
|
||||
s := GetServer(c.Param("server"))
|
||||
|
||||
p, err := url.QueryUnescape(c.Query("file"))
|
||||
if err != nil {
|
||||
TrackedServerError(err, s).AbortWithServerError(c)
|
||||
return
|
||||
}
|
||||
p = "/" + strings.TrimLeft(p, "/")
|
||||
|
||||
cleaned, err := s.Filesystem.SafePath(p)
|
||||
cleaned, err := s.Filesystem.SafePath(c.Query("file"))
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{
|
||||
"error": "The file requested could not be found.",
|
||||
@@ -66,13 +56,7 @@ func getServerFileContents(c *gin.Context) {
|
||||
func getServerListDirectory(c *gin.Context) {
|
||||
s := GetServer(c.Param("server"))
|
||||
|
||||
d, err := url.QueryUnescape(c.Query("directory"))
|
||||
if err != nil {
|
||||
TrackedServerError(err, s).AbortWithServerError(c)
|
||||
return
|
||||
}
|
||||
|
||||
stats, err := s.Filesystem.ListDirectory(d)
|
||||
stats, err := s.Filesystem.ListDirectory(c.Query("directory"))
|
||||
if err != nil {
|
||||
TrackedServerError(err, s).AbortWithServerError(c)
|
||||
return
|
||||
@@ -85,9 +69,9 @@ func getServerListDirectory(c *gin.Context) {
|
||||
func putServerRenameFile(c *gin.Context) {
|
||||
s := GetServer(c.Param("server"))
|
||||
|
||||
var data struct {
|
||||
var data struct{
|
||||
RenameFrom string `json:"rename_from"`
|
||||
RenameTo string `json:"rename_to"`
|
||||
RenameTo string `json:"rename_to"`
|
||||
}
|
||||
c.BindJSON(&data)
|
||||
|
||||
@@ -144,14 +128,7 @@ func postServerDeleteFile(c *gin.Context) {
|
||||
func postServerWriteFile(c *gin.Context) {
|
||||
s := GetServer(c.Param("server"))
|
||||
|
||||
f, err := url.QueryUnescape(c.Query("file"))
|
||||
if err != nil {
|
||||
TrackedServerError(err, s).AbortWithServerError(c)
|
||||
return
|
||||
}
|
||||
f = "/" + strings.TrimLeft(f, "/")
|
||||
|
||||
if err := s.Filesystem.Writefile(f, c.Request.Body); err != nil {
|
||||
if err := s.Filesystem.Writefile(c.Query("file"), c.Request.Body); err != nil {
|
||||
TrackedServerError(err, s).AbortWithServerError(c)
|
||||
return
|
||||
}
|
||||
@@ -175,4 +152,4 @@ func postServerCreateDirectory(c *gin.Context) {
|
||||
}
|
||||
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
}
|
||||
@@ -86,8 +86,7 @@ func (s *Server) Backup(b backup.BackupInterface) error {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
ad, err := b.Generate(inc, s.Filesystem.Path())
|
||||
if err != nil {
|
||||
if err := b.Generate(inc, s.Filesystem.Path()); err != nil {
|
||||
if notifyError := s.notifyPanelOfBackup(b.Identifier(), &backup.ArchiveDetails{}, false); notifyError != nil {
|
||||
zap.S().Warnw("failed to notify panel of failed backup state", zap.String("backup", b.Identifier()), zap.Error(err))
|
||||
}
|
||||
@@ -97,6 +96,7 @@ func (s *Server) Backup(b backup.BackupInterface) error {
|
||||
|
||||
// Try to notify the panel about the status of this backup. If for some reason this request
|
||||
// fails, delete the archive from the daemon and return that error up the chain to the caller.
|
||||
ad := b.Details()
|
||||
if notifyError := s.notifyPanelOfBackup(b.Identifier(), ad, true); notifyError != nil {
|
||||
b.Remove()
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ type BackupInterface interface {
|
||||
|
||||
// Generates a backup in whatever the configured source for the specific
|
||||
// implementation is.
|
||||
Generate(*IncludedFiles, string) (*ArchiveDetails, error)
|
||||
Generate(*IncludedFiles, string) error
|
||||
|
||||
// Returns the ignored files for this backup instance.
|
||||
Ignored() []string
|
||||
|
||||
@@ -41,15 +41,13 @@ func (b *LocalBackup) Remove() error {
|
||||
|
||||
// Generates a backup of the selected files and pushes it to the defined location
|
||||
// for this instance.
|
||||
func (b *LocalBackup) Generate(included *IncludedFiles, prefix string) (*ArchiveDetails, error) {
|
||||
func (b *LocalBackup) Generate(included *IncludedFiles, prefix string) error {
|
||||
a := &Archive{
|
||||
TrimPrefix: prefix,
|
||||
Files: included,
|
||||
}
|
||||
|
||||
if err := a.Create(b.Path(), context.Background()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err := a.Create(b.Path(), context.Background())
|
||||
|
||||
return b.Details(), nil
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package backup
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go.uber.org/zap"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -22,9 +21,7 @@ type S3Backup struct {
|
||||
|
||||
var _ BackupInterface = (*S3Backup)(nil)
|
||||
|
||||
// Generates a new backup on the disk, moves it into the S3 bucket via the provided
|
||||
// presigned URL, and then deletes the backup from the disk.
|
||||
func (s *S3Backup) Generate(included *IncludedFiles, prefix string) (*ArchiveDetails, error) {
|
||||
func (s *S3Backup) Generate(included *IncludedFiles, prefix string) error {
|
||||
defer s.Remove()
|
||||
|
||||
a := &Archive{
|
||||
@@ -33,26 +30,45 @@ func (s *S3Backup) Generate(included *IncludedFiles, prefix string) (*ArchiveDet
|
||||
}
|
||||
|
||||
if err := a.Create(s.Path(), context.Background()); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
rc, err := os.Open(s.Path())
|
||||
fmt.Println(s.PresignedUrl)
|
||||
|
||||
r, err := http.NewRequest(http.MethodPut, s.PresignedUrl, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
if sz, err := s.Size(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
r.ContentLength = sz
|
||||
r.Header.Add("Content-Length", strconv.Itoa(int(sz)))
|
||||
r.Header.Add("Content-Type", "application/x-gzip")
|
||||
}
|
||||
|
||||
var rc io.ReadCloser
|
||||
if f, err := os.Open(s.Path()); err != nil {
|
||||
return err
|
||||
} else {
|
||||
rc = f
|
||||
}
|
||||
defer rc.Close()
|
||||
|
||||
if resp, err := s.generateRemoteRequest(rc); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
resp.Body.Close()
|
||||
r.Body = rc
|
||||
resp, err := http.DefaultClient.Do(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("failed to put S3 object, %d:%s", resp.StatusCode, resp.Status)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
io.Copy(os.Stdout, resp.Body)
|
||||
return fmt.Errorf("failed to put S3 object, %d:%s", resp.StatusCode, resp.Status)
|
||||
}
|
||||
|
||||
return s.Details(), err
|
||||
return nil
|
||||
}
|
||||
|
||||
// Removes a backup from the system.
|
||||
@@ -60,24 +76,9 @@ func (s *S3Backup) Remove() error {
|
||||
return os.Remove(s.Path())
|
||||
}
|
||||
|
||||
// Generates the remote S3 request and begins the upload.
|
||||
func (s *S3Backup) generateRemoteRequest(rc io.ReadCloser) (*http.Response, error) {
|
||||
r, err := http.NewRequest(http.MethodPut, s.PresignedUrl, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
func (s *S3Backup) Details() *ArchiveDetails {
|
||||
return &ArchiveDetails{
|
||||
Checksum: "checksum",
|
||||
Size: 1024,
|
||||
}
|
||||
|
||||
if sz, err := s.Size(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
r.ContentLength = sz
|
||||
r.Header.Add("Content-Length", strconv.Itoa(int(sz)))
|
||||
r.Header.Add("Content-Type", "application/x-gzip")
|
||||
}
|
||||
|
||||
r.Body = rc
|
||||
|
||||
zap.S().Debugw("uploading backup to remote S3 endpoint", zap.String("endpoint", s.PresignedUrl), zap.Any("headers", r.Header))
|
||||
|
||||
return http.DefaultClient.Do(r)
|
||||
}
|
||||
|
||||
@@ -343,21 +343,11 @@ func (d *DockerEnvironment) Destroy() error {
|
||||
// Avoid crash detection firing off.
|
||||
d.Server.SetState(ProcessStoppingState)
|
||||
|
||||
err := d.Client.ContainerRemove(ctx, d.Server.Uuid, types.ContainerRemoveOptions{
|
||||
return d.Client.ContainerRemove(ctx, d.Server.Uuid, types.ContainerRemoveOptions{
|
||||
RemoveVolumes: true,
|
||||
RemoveLinks: false,
|
||||
Force: true,
|
||||
})
|
||||
|
||||
// Don't trigger a destroy failure if we try to delete a container that does not
|
||||
// exist on the system. We're just a step ahead of ourselves in that case.
|
||||
//
|
||||
// @see https://github.com/pterodactyl/panel/issues/2001
|
||||
if err != nil && client.IsErrNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Determine the container exit state and return the exit code and wether or not
|
||||
@@ -665,7 +655,7 @@ func (d *DockerEnvironment) Create() error {
|
||||
"setpcap", "mknod", "audit_write", "net_raw", "dac_override",
|
||||
"fowner", "fsetid", "net_bind_service", "sys_chroot", "setfcap",
|
||||
},
|
||||
NetworkMode: container.NetworkMode(config.Get().Docker.Network.Mode),
|
||||
NetworkMode: "pterodactyl_nw",
|
||||
}
|
||||
|
||||
if _, err := cli.ContainerCreate(ctx, conf, hostConf, nil, d.Server.Uuid); err != nil {
|
||||
@@ -784,7 +774,7 @@ eloop:
|
||||
}
|
||||
}
|
||||
|
||||
out = append(out, fmt.Sprintf("%s=%s", strings.ToUpper(k), v))
|
||||
out = append(out, fmt.Sprintf("%s=\"%s\"", strings.ToUpper(k), v))
|
||||
}
|
||||
|
||||
return out
|
||||
|
||||
@@ -401,12 +401,13 @@ func (fs *Filesystem) Copy(p string) error {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if s, err := os.Stat(cleaned); err != nil {
|
||||
return err
|
||||
} else if s.IsDir() || !s.Mode().IsRegular() {
|
||||
// If this is a directory or not a regular file, just throw a not-exist error
|
||||
// since anything calling this function should understand what that means.
|
||||
return os.ErrNotExist
|
||||
if s, err := os.Stat(cleaned); (err != nil && os.IsNotExist(err)) || s.IsDir() || !s.Mode().IsRegular() {
|
||||
// For now I think I am okay just returning a nil response if the thing
|
||||
// we're trying to copy doesn't exist. Probably will want to come back and
|
||||
// re-evaluate if this is a smart decision (I'm guessing not).
|
||||
return nil
|
||||
} else if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
base := filepath.Base(cleaned)
|
||||
|
||||
@@ -104,18 +104,6 @@ func NewInstallationProcess(s *Server, script *api.InstallationScript) (*Install
|
||||
return proc, nil
|
||||
}
|
||||
|
||||
// Removes the installer container for the server.
|
||||
func (ip *InstallationProcess) RemoveContainer() {
|
||||
err := ip.client.ContainerRemove(context.Background(), ip.Server.Uuid + "_installer", types.ContainerRemoveOptions{
|
||||
RemoveVolumes: true,
|
||||
Force: true,
|
||||
})
|
||||
|
||||
if err != nil && !client.IsErrNotFound(err) {
|
||||
zap.S().Warnw("failed to delete server installer container", zap.String("server", ip.Server.Uuid), zap.Error(errors.WithStack(err)))
|
||||
}
|
||||
}
|
||||
|
||||
// Runs the installation process, this is done as a backgrounded thread. This will configure
|
||||
// the required environment, and then spin up the installation container.
|
||||
//
|
||||
@@ -129,8 +117,6 @@ func (ip *InstallationProcess) Run() error {
|
||||
|
||||
cid, err := ip.Execute(installPath)
|
||||
if err != nil {
|
||||
ip.RemoveContainer()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -263,7 +249,6 @@ func (ip *InstallationProcess) GetLogPath() string {
|
||||
// installation container.
|
||||
func (ip *InstallationProcess) AfterExecute(containerId string) error {
|
||||
ctx := context.Background()
|
||||
defer ip.RemoveContainer()
|
||||
|
||||
zap.S().Debugw("pulling installation logs for server", zap.String("server", ip.Server.Uuid), zap.String("container_id", containerId))
|
||||
reader, err := ip.client.ContainerLogs(ctx, containerId, types.ContainerLogsOptions{
|
||||
@@ -288,6 +273,17 @@ func (ip *InstallationProcess) AfterExecute(containerId string) error {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
zap.S().Debugw("removing server installation container", zap.String("server", ip.Server.Uuid), zap.String("container_id", containerId))
|
||||
rErr := ip.client.ContainerRemove(ctx, containerId, types.ContainerRemoveOptions{
|
||||
RemoveVolumes: true,
|
||||
RemoveLinks: false,
|
||||
Force: true,
|
||||
})
|
||||
|
||||
if rErr != nil && !client.IsErrNotFound(rErr) {
|
||||
return errors.WithStack(rErr)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -335,7 +331,7 @@ func (ip *InstallationProcess) Execute(installPath string) (string, error) {
|
||||
Tmpfs: map[string]string{
|
||||
"/tmp": "rw,exec,nosuid,size=50M",
|
||||
},
|
||||
DNS: config.Get().Docker.Network.Dns,
|
||||
DNS: []string{"1.1.1.1", "8.8.8.8"},
|
||||
LogConfig: container.LogConfig{
|
||||
Type: "local",
|
||||
Config: map[string]string{
|
||||
@@ -345,7 +341,7 @@ func (ip *InstallationProcess) Execute(installPath string) (string, error) {
|
||||
},
|
||||
},
|
||||
Privileged: true,
|
||||
NetworkMode: container.NetworkMode(config.Get().Docker.Network.Mode),
|
||||
NetworkMode: "pterodactyl_nw",
|
||||
}
|
||||
|
||||
zap.S().Infow("creating installer container for server process", zap.String("server", ip.Server.Uuid))
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/server"
|
||||
"go.uber.org/zap"
|
||||
"path"
|
||||
)
|
||||
|
||||
func Initialize(config *config.Configuration) error {
|
||||
@@ -20,6 +21,8 @@ func Initialize(config *config.Configuration) error {
|
||||
ReadOnly: config.System.Sftp.ReadOnly,
|
||||
BindAddress: config.System.Sftp.Address,
|
||||
BindPort: config.System.Sftp.Port,
|
||||
ServerDataFolder: path.Join(config.System.Data, "/servers"),
|
||||
DisableDiskCheck: config.System.Sftp.DisableDiskChecking,
|
||||
},
|
||||
CredentialValidator: validateCredentials,
|
||||
PathValidator: validatePath,
|
||||
@@ -73,7 +76,6 @@ func validateDiskSpace(fs sftp_server.FileSystem) bool {
|
||||
// the server's UUID if the credentials were valid.
|
||||
func validateCredentials(c sftp_server.AuthenticationRequest) (*sftp_server.AuthenticationResponse, error) {
|
||||
resp, err := api.NewRequester().ValidateSftpCredentials(c)
|
||||
zap.S().Named("sftp").Debugw("validating credentials for SFTP connection", zap.String("username", c.User))
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -83,9 +85,8 @@ func validateCredentials(c sftp_server.AuthenticationRequest) (*sftp_server.Auth
|
||||
})
|
||||
|
||||
if s == nil {
|
||||
return resp, errors.New("no matching server with UUID found")
|
||||
return resp, errors.New("no server found with that UUID")
|
||||
}
|
||||
|
||||
zap.S().Named("sftp").Debugw("matched user to server instance, credentials successfully validated", zap.String("username", c.User), zap.String("server", s.Uuid))
|
||||
return resp, err
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ package system
|
||||
|
||||
const (
|
||||
// The current version of this software.
|
||||
Version = "1.0.0-beta.5"
|
||||
Version = "1.0.0-beta.4"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user