replace deprecated ioutil function calls
This commit is contained in:
parent
be543ce3e0
commit
d8df353ce8
|
@ -4,7 +4,7 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -19,8 +19,7 @@ import (
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var configureArgs struct {
|
||||||
configureArgs struct {
|
|
||||||
PanelURL string
|
PanelURL string
|
||||||
Token string
|
Token string
|
||||||
ConfigPath string
|
ConfigPath string
|
||||||
|
@ -28,7 +27,6 @@ var (
|
||||||
Override bool
|
Override bool
|
||||||
AllowInsecure bool
|
AllowInsecure bool
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
var nodeIdRegex = regexp.MustCompile(`^(\d+)$`)
|
var nodeIdRegex = regexp.MustCompile(`^(\d+)$`)
|
||||||
|
|
||||||
|
@ -140,13 +138,13 @@ func configureCmdRun(cmd *cobra.Command, args []string) {
|
||||||
fmt.Println("The authentication credentials provided were not valid.")
|
fmt.Println("The authentication credentials provided were not valid.")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
} else if res.StatusCode != http.StatusOK {
|
} else if res.StatusCode != http.StatusOK {
|
||||||
b, _ := ioutil.ReadAll(res.Body)
|
b, _ := io.ReadAll(res.Body)
|
||||||
|
|
||||||
fmt.Println("An error occurred while processing this request.\n", string(b))
|
fmt.Println("An error occurred while processing this request.\n", string(b))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := ioutil.ReadAll(res.Body)
|
b, err := io.ReadAll(res.Body)
|
||||||
|
|
||||||
cfg, err := config.NewAtPath(configPath)
|
cfg, err := config.NewAtPath(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -29,18 +28,18 @@ import (
|
||||||
"github.com/pterodactyl/wings/system"
|
"github.com/pterodactyl/wings/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultHastebinUrl = "https://ptero.co"
|
const (
|
||||||
const DefaultLogLines = 200
|
DefaultHastebinUrl = "https://ptero.co"
|
||||||
|
DefaultLogLines = 200
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var diagnosticsArgs struct {
|
||||||
diagnosticsArgs struct {
|
|
||||||
IncludeEndpoints bool
|
IncludeEndpoints bool
|
||||||
IncludeLogs bool
|
IncludeLogs bool
|
||||||
ReviewBeforeUpload bool
|
ReviewBeforeUpload bool
|
||||||
HastebinURL string
|
HastebinURL string
|
||||||
LogLines int
|
LogLines int
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
func newDiagnosticsCommand() *cobra.Command {
|
func newDiagnosticsCommand() *cobra.Command {
|
||||||
command := &cobra.Command{
|
command := &cobra.Command{
|
||||||
|
@ -110,7 +109,6 @@ func diagnosticsCmdRun(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
printHeader(output, "Wings Configuration")
|
printHeader(output, "Wings Configuration")
|
||||||
if err := config.FromFile(config.DefaultLocation); err != nil {
|
if err := config.FromFile(config.DefaultLocation); err != nil {
|
||||||
|
|
||||||
}
|
}
|
||||||
cfg := config.Get()
|
cfg := config.Get()
|
||||||
fmt.Fprintln(output, " Panel Location:", redact(cfg.PanelLocation))
|
fmt.Fprintln(output, " Panel Location:", redact(cfg.PanelLocation))
|
||||||
|
@ -226,7 +224,7 @@ func uploadToHastebin(hbUrl, content string) (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
pres := make(map[string]interface{})
|
pres := make(map[string]interface{})
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
body, err := io.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failed to parse response.", err)
|
fmt.Println("Failed to parse response.", err)
|
||||||
return "", err
|
return "", err
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
@ -380,7 +379,7 @@ func WriteToDisk(c *Configuration) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(c.path, b, 0o600); err != nil {
|
if err := os.WriteFile(c.path, b, 0o600); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -448,7 +447,7 @@ func EnsurePterodactylUser() error {
|
||||||
// FromFile reads the configuration from the provided file and stores it in the
|
// FromFile reads the configuration from the provided file and stores it in the
|
||||||
// global singleton for this instance.
|
// global singleton for this instance.
|
||||||
func FromFile(path string) error {
|
func FromFile(path string) error {
|
||||||
b, err := ioutil.ReadFile(path)
|
b, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -592,7 +591,7 @@ func ConfigureTimezone() error {
|
||||||
_config.System.Timezone = tz
|
_config.System.Timezone = tz
|
||||||
}
|
}
|
||||||
if _config.System.Timezone == "" {
|
if _config.System.Timezone == "" {
|
||||||
b, err := ioutil.ReadFile("/etc/timezone")
|
b, err := os.ReadFile("/etc/timezone")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
return errors.WithMessage(err, "config: failed to open timezone file")
|
return errors.WithMessage(err, "config: failed to open timezone file")
|
||||||
|
|
97
go.mod
97
go.mod
|
@ -1,22 +1,18 @@
|
||||||
module github.com/pterodactyl/wings
|
module github.com/pterodactyl/wings
|
||||||
|
|
||||||
go 1.16
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
emperror.dev/errors v0.8.0
|
emperror.dev/errors v0.8.0
|
||||||
github.com/AlecAivazis/survey/v2 v2.2.15
|
github.com/AlecAivazis/survey/v2 v2.2.15
|
||||||
github.com/Jeffail/gabs/v2 v2.6.1
|
github.com/Jeffail/gabs/v2 v2.6.1
|
||||||
github.com/Microsoft/go-winio v0.5.0 // indirect
|
|
||||||
github.com/Microsoft/hcsshim v0.8.20 // indirect
|
|
||||||
github.com/NYTimes/logrotate v1.0.0
|
github.com/NYTimes/logrotate v1.0.0
|
||||||
github.com/andybalholm/brotli v1.0.3 // indirect
|
|
||||||
github.com/apex/log v1.9.0
|
github.com/apex/log v1.9.0
|
||||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
|
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
|
||||||
github.com/beevik/etree v1.1.0
|
github.com/beevik/etree v1.1.0
|
||||||
github.com/buger/jsonparser v1.1.1
|
github.com/buger/jsonparser v1.1.1
|
||||||
github.com/cenkalti/backoff/v4 v4.1.1
|
github.com/cenkalti/backoff/v4 v4.1.1
|
||||||
github.com/cobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249
|
github.com/cobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249
|
||||||
github.com/containerd/containerd v1.5.5 // indirect
|
|
||||||
github.com/creasty/defaults v1.5.1
|
github.com/creasty/defaults v1.5.1
|
||||||
github.com/docker/docker v20.10.7+incompatible
|
github.com/docker/docker v20.10.7+incompatible
|
||||||
github.com/docker/go-connections v0.4.0
|
github.com/docker/go-connections v0.4.0
|
||||||
|
@ -26,47 +22,94 @@ require (
|
||||||
github.com/gammazero/workerpool v1.1.2
|
github.com/gammazero/workerpool v1.1.2
|
||||||
github.com/gbrlsnchs/jwt/v3 v3.0.1
|
github.com/gbrlsnchs/jwt/v3 v3.0.1
|
||||||
github.com/gin-gonic/gin v1.7.2
|
github.com/gin-gonic/gin v1.7.2
|
||||||
github.com/go-playground/validator/v10 v10.8.0 // indirect
|
|
||||||
github.com/golang/snappy v0.0.4 // indirect
|
|
||||||
github.com/google/uuid v1.3.0
|
github.com/google/uuid v1.3.0
|
||||||
github.com/gorilla/mux v1.7.4 // indirect
|
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
github.com/iancoleman/strcase v0.2.0
|
github.com/iancoleman/strcase v0.2.0
|
||||||
github.com/icza/dyno v0.0.0-20210726202311-f1bafe5d9996
|
github.com/icza/dyno v0.0.0-20210726202311-f1bafe5d9996
|
||||||
github.com/juju/ratelimit v1.0.1
|
github.com/juju/ratelimit v1.0.1
|
||||||
github.com/karrick/godirwalk v1.16.1
|
github.com/karrick/godirwalk v1.16.1
|
||||||
github.com/klauspost/compress v1.13.2 // indirect
|
|
||||||
github.com/klauspost/pgzip v1.2.5
|
github.com/klauspost/pgzip v1.2.5
|
||||||
github.com/magefile/mage v1.11.0 // indirect
|
|
||||||
github.com/magiconair/properties v1.8.5
|
github.com/magiconair/properties v1.8.5
|
||||||
github.com/mattn/go-colorable v0.1.8
|
github.com/mattn/go-colorable v0.1.8
|
||||||
github.com/mattn/go-isatty v0.0.13 // indirect
|
|
||||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
|
||||||
github.com/mholt/archiver/v3 v3.5.0
|
github.com/mholt/archiver/v3 v3.5.0
|
||||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
|
||||||
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
|
|
||||||
github.com/morikuni/aec v1.0.0 // indirect
|
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
|
||||||
github.com/nwaples/rardecode v1.1.1 // indirect
|
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||||
github.com/pierrec/lz4/v4 v4.1.8 // indirect
|
|
||||||
github.com/pkg/profile v1.6.0
|
github.com/pkg/profile v1.6.0
|
||||||
github.com/pkg/sftp v1.13.2
|
github.com/pkg/sftp v1.13.2
|
||||||
github.com/prometheus/common v0.30.0 // indirect
|
|
||||||
github.com/prometheus/procfs v0.7.1 // indirect
|
|
||||||
github.com/sabhiram/go-gitignore v0.0.0-20201211210132-54b8a0bf510f
|
github.com/sabhiram/go-gitignore v0.0.0-20201211210132-54b8a0bf510f
|
||||||
github.com/spf13/cobra v1.2.1
|
github.com/spf13/cobra v1.2.1
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.7.0
|
||||||
github.com/ulikunitz/xz v0.5.10 // indirect
|
|
||||||
go.uber.org/atomic v1.9.0 // indirect
|
|
||||||
go.uber.org/multierr v1.7.0 // indirect
|
|
||||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
|
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
|
||||||
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985 // indirect
|
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
||||||
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
|
|
||||||
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
|
|
||||||
google.golang.org/genproto v0.0.0-20210729151513-df9385d47c1b // indirect
|
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
|
||||||
gopkg.in/ini.v1 v1.62.0
|
gopkg.in/ini.v1 v1.62.0
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
|
||||||
|
github.com/Microsoft/go-winio v0.5.0 // indirect
|
||||||
|
github.com/Microsoft/hcsshim v0.8.20 // indirect
|
||||||
|
github.com/andybalholm/brotli v1.0.3 // indirect
|
||||||
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.1.1 // indirect
|
||||||
|
github.com/containerd/containerd v1.5.5 // indirect
|
||||||
|
github.com/containerd/fifo v1.0.0 // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/docker/distribution v2.7.1+incompatible // indirect
|
||||||
|
github.com/docker/go-metrics v0.0.1 // indirect
|
||||||
|
github.com/docker/go-units v0.4.0 // indirect
|
||||||
|
github.com/dsnet/compress v0.0.1 // indirect
|
||||||
|
github.com/fsnotify/fsnotify v1.4.9 // indirect
|
||||||
|
github.com/gammazero/deque v0.1.0 // indirect
|
||||||
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
|
github.com/go-playground/locales v0.13.0 // indirect
|
||||||
|
github.com/go-playground/universal-translator v0.17.0 // indirect
|
||||||
|
github.com/go-playground/validator/v10 v10.8.0 // indirect
|
||||||
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
|
github.com/golang/protobuf v1.5.2 // indirect
|
||||||
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
|
github.com/gorilla/mux v1.7.4 // indirect
|
||||||
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.11 // indirect
|
||||||
|
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||||
|
github.com/klauspost/compress v1.13.2 // indirect
|
||||||
|
github.com/kr/fs v0.1.0 // indirect
|
||||||
|
github.com/leodido/go-urn v1.2.1 // indirect
|
||||||
|
github.com/magefile/mage v1.11.0 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.13 // indirect
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
|
||||||
|
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
||||||
|
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
github.com/modern-go/reflect2 v1.0.1 // indirect
|
||||||
|
github.com/morikuni/aec v1.0.0 // indirect
|
||||||
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||||
|
github.com/nwaples/rardecode v1.1.1 // indirect
|
||||||
|
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||||
|
github.com/opencontainers/image-spec v1.0.1 // indirect
|
||||||
|
github.com/pierrec/lz4/v4 v4.1.8 // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/prometheus/client_golang v1.11.0 // indirect
|
||||||
|
github.com/prometheus/client_model v0.2.0 // indirect
|
||||||
|
github.com/prometheus/common v0.30.0 // indirect
|
||||||
|
github.com/prometheus/procfs v0.7.1 // indirect
|
||||||
|
github.com/sirupsen/logrus v1.8.1 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
github.com/ugorji/go/codec v1.1.7 // indirect
|
||||||
|
github.com/ulikunitz/xz v0.5.10 // indirect
|
||||||
|
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
|
||||||
|
go.uber.org/atomic v1.9.0 // indirect
|
||||||
|
go.uber.org/multierr v1.7.0 // indirect
|
||||||
|
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985 // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
|
||||||
|
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
|
||||||
|
golang.org/x/text v0.3.6 // indirect
|
||||||
|
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||||
|
google.golang.org/genproto v0.0.0-20210729151513-df9385d47c1b // indirect
|
||||||
|
google.golang.org/grpc v1.39.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.27.1 // indirect
|
||||||
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||||
|
)
|
||||||
|
|
|
@ -2,7 +2,7 @@ package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -38,13 +38,13 @@ var xmlValueMatchRegex = regexp.MustCompile(`^\[([\w]+)='(.*)'\]$`)
|
||||||
// Gets the []byte representation of a configuration file to be passed through to other
|
// Gets the []byte representation of a configuration file to be passed through to other
|
||||||
// handler functions. If the file does not currently exist, it will be created.
|
// handler functions. If the file does not currently exist, it will be created.
|
||||||
func readFileBytes(path string) ([]byte, error) {
|
func readFileBytes(path string) ([]byte, error) {
|
||||||
file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0644)
|
file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
return ioutil.ReadAll(file)
|
return io.ReadAll(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the value of a key based on the value type defined.
|
// Gets the value of a key based on the value type defined.
|
||||||
|
|
|
@ -3,7 +3,6 @@ package parser
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -357,7 +356,6 @@ func (f *ConfigurationFile) parseIniFile(path string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
path = append(path, string(v))
|
path = append(path, string(v))
|
||||||
// path := strings.SplitN(replacement.Match, ".", 2)
|
|
||||||
|
|
||||||
value, err := f.LookupConfigurationValue(replacement)
|
value, err := f.LookupConfigurationValue(replacement)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -410,7 +408,7 @@ func (f *ConfigurationFile) parseJsonFile(path string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
output := []byte(data.StringIndent("", " "))
|
output := []byte(data.StringIndent("", " "))
|
||||||
return ioutil.WriteFile(path, output, 0o644)
|
return os.WriteFile(path, output, 0o644)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses a yaml file and updates any matching key/value pairs before persisting
|
// Parses a yaml file and updates any matching key/value pairs before persisting
|
||||||
|
@ -447,14 +445,14 @@ func (f *ConfigurationFile) parseYamlFile(path string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ioutil.WriteFile(path, marshaled, 0o644)
|
return os.WriteFile(path, marshaled, 0o644)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses a text file using basic find and replace. This is a highly inefficient method of
|
// Parses a text file using basic find and replace. This is a highly inefficient method of
|
||||||
// scanning a file and performing a replacement. You should attempt to use anything other
|
// scanning a file and performing a replacement. You should attempt to use anything other
|
||||||
// than this function where possible.
|
// than this function where possible.
|
||||||
func (f *ConfigurationFile) parseTextFile(path string) error {
|
func (f *ConfigurationFile) parseTextFile(path string) error {
|
||||||
input, err := ioutil.ReadFile(path)
|
input, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -472,7 +470,7 @@ func (f *ConfigurationFile) parseTextFile(path string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(path, []byte(strings.Join(lines, "\n")), 0o644); err != nil {
|
if err := os.WriteFile(path, []byte(strings.Join(lines, "\n")), 0o644); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -224,9 +223,9 @@ func (r *Response) Read() ([]byte, error) {
|
||||||
return nil, errors.New("remote: attempting to read missing response")
|
return nil, errors.New("remote: attempting to read missing response")
|
||||||
}
|
}
|
||||||
if r.Response.Body != nil {
|
if r.Response.Body != nil {
|
||||||
b, _ = ioutil.ReadAll(r.Response.Body)
|
b, _ = io.ReadAll(r.Response.Body)
|
||||||
}
|
}
|
||||||
r.Response.Body = ioutil.NopCloser(bytes.NewBuffer(b))
|
r.Response.Body = io.NopCloser(bytes.NewBuffer(b))
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package server
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -49,7 +48,7 @@ func (s *Server) getServerwideIgnoredFiles() (string, error) {
|
||||||
// Don't read a symlinked ignore file, or a file larger than 32KiB in size.
|
// Don't read a symlinked ignore file, or a file larger than 32KiB in size.
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
b, err := ioutil.ReadAll(f)
|
b, err := io.ReadAll(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package filesystem
|
package filesystem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"os"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -19,11 +19,10 @@ func TestFilesystem_DecompressFile(t *testing.T) {
|
||||||
fs, rfs := NewFs()
|
fs, rfs := NewFs()
|
||||||
|
|
||||||
g.Describe("Decompress", func() {
|
g.Describe("Decompress", func() {
|
||||||
|
|
||||||
for _, ext := range []string{"zip", "rar", "tar", "tar.gz"} {
|
for _, ext := range []string{"zip", "rar", "tar", "tar.gz"} {
|
||||||
g.It("can decompress a "+ext, func() {
|
g.It("can decompress a "+ext, func() {
|
||||||
// copy the file to the new FS
|
// copy the file to the new FS
|
||||||
c, err := ioutil.ReadFile("./testdata/test." + ext)
|
c, err := os.ReadFile("./testdata/test." + ext)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
err = rfs.CreateServerFile("./test."+ext, c)
|
err = rfs.CreateServerFile("./test."+ext, c)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
|
|
|
@ -3,7 +3,6 @@ package filesystem
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -25,7 +24,7 @@ func NewFs() (*Filesystem, *rootFs) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "pterodactyl")
|
tmpDir, err := os.MkdirTemp(os.TempDir(), "pterodactyl")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -71,7 +70,7 @@ func (rfs *rootFs) reset() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.Mkdir(filepath.Join(rfs.root, "/server"), 0755); err != nil {
|
if err := os.Mkdir(filepath.Join(rfs.root, "/server"), 0o755); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +98,7 @@ func TestFilesystem_Readfile(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("returns an error if the \"file\" is a directory", func() {
|
g.It("returns an error if the \"file\" is a directory", func() {
|
||||||
err := os.Mkdir(filepath.Join(rfs.root, "/server/test.txt"), 0755)
|
err := os.Mkdir(filepath.Join(rfs.root, "/server/test.txt"), 0o755)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
|
|
||||||
err = fs.Readfile("test.txt", buf)
|
err = fs.Readfile("test.txt", buf)
|
||||||
|
@ -341,7 +340,7 @@ func TestFilesystem_Rename(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("allows a folder to be renamed", func() {
|
g.It("allows a folder to be renamed", func() {
|
||||||
err := os.Mkdir(filepath.Join(rfs.root, "/server/source_dir"), 0755)
|
err := os.Mkdir(filepath.Join(rfs.root, "/server/source_dir"), 0o755)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
|
|
||||||
err = fs.Rename("source_dir", "target_dir")
|
err = fs.Rename("source_dir", "target_dir")
|
||||||
|
@ -405,7 +404,7 @@ func TestFilesystem_Copy(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("should return an error if the source directory is outside the root", func() {
|
g.It("should return an error if the source directory is outside the root", func() {
|
||||||
err := os.MkdirAll(filepath.Join(rfs.root, "/nested/in/dir"), 0755)
|
err := os.MkdirAll(filepath.Join(rfs.root, "/nested/in/dir"), 0o755)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
|
|
||||||
err = rfs.CreateServerFileFromString("/../nested/in/dir/ext-source.txt", "external content")
|
err = rfs.CreateServerFileFromString("/../nested/in/dir/ext-source.txt", "external content")
|
||||||
|
@ -421,7 +420,7 @@ func TestFilesystem_Copy(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("should return an error if the source is a directory", func() {
|
g.It("should return an error if the source is a directory", func() {
|
||||||
err := os.Mkdir(filepath.Join(rfs.root, "/server/dir"), 0755)
|
err := os.Mkdir(filepath.Join(rfs.root, "/server/dir"), 0o755)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
|
|
||||||
err = fs.Copy("dir")
|
err = fs.Copy("dir")
|
||||||
|
@ -466,7 +465,7 @@ func TestFilesystem_Copy(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("should create a copy inside of a directory", func() {
|
g.It("should create a copy inside of a directory", func() {
|
||||||
err := os.MkdirAll(filepath.Join(rfs.root, "/server/nested/in/dir"), 0755)
|
err := os.MkdirAll(filepath.Join(rfs.root, "/server/nested/in/dir"), 0o755)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
|
|
||||||
err = rfs.CreateServerFileFromString("nested/in/dir/source.txt", "test content")
|
err = rfs.CreateServerFileFromString("nested/in/dir/source.txt", "test content")
|
||||||
|
@ -545,7 +544,7 @@ func TestFilesystem_Delete(t *testing.T) {
|
||||||
"foo/bar/baz/source.txt",
|
"foo/bar/baz/source.txt",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := os.MkdirAll(filepath.Join(rfs.root, "/server/foo/bar/baz"), 0755)
|
err := os.MkdirAll(filepath.Join(rfs.root, "/server/foo/bar/baz"), 0o755)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
|
|
||||||
for _, s := range sources {
|
for _, s := range sources {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -137,7 +136,7 @@ func (m *Manager) PersistStates() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(config.Get().System.GetStatesPath(), data, 0644); err != nil {
|
if err := os.WriteFile(config.Get().System.GetStatesPath(), data, 0o644); err != nil {
|
||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -145,7 +144,7 @@ func (m *Manager) PersistStates() error {
|
||||||
|
|
||||||
// ReadStates returns the state of the servers.
|
// ReadStates returns the state of the servers.
|
||||||
func (m *Manager) ReadStates() (map[string]string, error) {
|
func (m *Manager) ReadStates() (map[string]string, error) {
|
||||||
f, err := os.OpenFile(config.Get().System.GetStatesPath(), os.O_RDONLY|os.O_CREATE, 0644)
|
f, err := os.OpenFile(config.Get().System.GetStatesPath(), os.O_RDONLY|os.O_CREATE, 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,12 +142,12 @@ func (h *Handler) Filecmd(request *sftp.Request) error {
|
||||||
}
|
}
|
||||||
mode := request.Attributes().FileMode().Perm()
|
mode := request.Attributes().FileMode().Perm()
|
||||||
// If the client passes an invalid FileMode just use the default 0644.
|
// If the client passes an invalid FileMode just use the default 0644.
|
||||||
if mode == 0000 {
|
if mode == 0o000 {
|
||||||
mode = os.FileMode(0644)
|
mode = os.FileMode(0o644)
|
||||||
}
|
}
|
||||||
// Force directories to be 0755.
|
// Force directories to be 0755.
|
||||||
if request.Attributes().FileMode().IsDir() {
|
if request.Attributes().FileMode().IsDir() {
|
||||||
mode = 0755
|
mode = 0o755
|
||||||
}
|
}
|
||||||
if err := h.fs.Chmod(request.Filepath, mode); err != nil {
|
if err := h.fs.Chmod(request.Filepath, mode); err != nil {
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
|
@ -260,7 +260,6 @@ func (h *Handler) Filelist(request *sftp.Request) (sftp.ListerAt, error) {
|
||||||
files, err := ioutil.ReadDir(p)
|
files, err := ioutil.ReadDir(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.logger.WithField("source", request.Filepath).WithField("error", err).Error("error while listing directory")
|
h.logger.WithField("source", request.Filepath).WithField("error", err).Error("error while listing directory")
|
||||||
|
|
||||||
return nil, sftp.ErrSSHFxFailure
|
return nil, sftp.ErrSSHFxFailure
|
||||||
}
|
}
|
||||||
return ListerAt(files), nil
|
return ListerAt(files), nil
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
@ -59,7 +58,7 @@ func (c *SFTPServer) Run() error {
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return errors.Wrap(err, "sftp: could not stat private key file")
|
return errors.Wrap(err, "sftp: could not stat private key file")
|
||||||
}
|
}
|
||||||
pb, err := ioutil.ReadFile(c.PrivateKeyPath())
|
pb, err := os.ReadFile(c.PrivateKeyPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "sftp: could not read private key file")
|
return errors.Wrap(err, "sftp: could not read private key file")
|
||||||
}
|
}
|
||||||
|
@ -159,10 +158,10 @@ func (c *SFTPServer) generateED25519PrivateKey() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "sftp: failed to generate ED25519 private key")
|
return errors.Wrap(err, "sftp: failed to generate ED25519 private key")
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(path.Dir(c.PrivateKeyPath()), 0755); err != nil {
|
if err := os.MkdirAll(path.Dir(c.PrivateKeyPath()), 0o755); err != nil {
|
||||||
return errors.Wrap(err, "sftp: could not create internal sftp data directory")
|
return errors.Wrap(err, "sftp: could not create internal sftp data directory")
|
||||||
}
|
}
|
||||||
o, err := os.OpenFile(c.PrivateKeyPath(), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
|
o, err := os.OpenFile(c.PrivateKeyPath(), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,15 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Extends the default SFTP server to return a quota exceeded error to the client.
|
// ErrSSHQuotaExceeded extends the default SFTP server to return a quota exceeded error to the client.
|
||||||
//
|
//
|
||||||
// @see https://tools.ietf.org/id/draft-ietf-secsh-filexfer-13.txt
|
// @see https://tools.ietf.org/id/draft-ietf-secsh-filexfer-13.txt
|
||||||
ErrSSHQuotaExceeded = fxerr(15)
|
ErrSSHQuotaExceeded = fxErr(15)
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListerAt []os.FileInfo
|
type ListerAt []os.FileInfo
|
||||||
|
|
||||||
// Returns the number of entries copied and an io.EOF error if we made it to the end of the file list.
|
// ListAt returns the number of entries copied and an io.EOF error if we made it to the end of the file list.
|
||||||
// Take a look at the pkg/sftp godoc for more information about how this function should work.
|
// Take a look at the pkg/sftp godoc for more information about how this function should work.
|
||||||
func (l ListerAt) ListAt(f []os.FileInfo, offset int64) (int, error) {
|
func (l ListerAt) ListAt(f []os.FileInfo, offset int64) (int, error) {
|
||||||
if offset >= int64(len(l)) {
|
if offset >= int64(len(l)) {
|
||||||
|
@ -28,9 +28,9 @@ func (l ListerAt) ListAt(f []os.FileInfo, offset int64) (int, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type fxerr uint32
|
type fxErr uint32
|
||||||
|
|
||||||
func (e fxerr) Error() string {
|
func (e fxErr) Error() string {
|
||||||
switch e {
|
switch e {
|
||||||
case ErrSSHQuotaExceeded:
|
case ErrSSHQuotaExceeded:
|
||||||
return "Quota Exceeded"
|
return "Quota Exceeded"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user