From ea7cdbe0443c9d0530b4d3af778fce7b11f79606 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 20 Feb 2018 13:01:46 -0600 Subject: [PATCH 1/5] Switch to dep from glide. I maybe know what I'm doing, but probably not. --- Gopkg.lock | 377 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Gopkg.toml | 66 ++++++++++ glide.lock | 169 ------------------------ glide.yaml | 29 ----- wings.go | 2 +- 5 files changed, 444 insertions(+), 199 deletions(-) create mode 100644 Gopkg.lock create mode 100644 Gopkg.toml delete mode 100644 glide.lock delete mode 100644 glide.yaml diff --git a/Gopkg.lock b/Gopkg.lock new file mode 100644 index 0000000..137f0f3 --- /dev/null +++ b/Gopkg.lock @@ -0,0 +1,377 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + branch = "master" + name = "github.com/Azure/go-ansiterm" + packages = [ + ".", + "winterm" + ] + revision = "d6e3b3328b783f23731bc4d058875b0371ff8109" + +[[projects]] + name = "github.com/Microsoft/go-winio" + packages = ["."] + revision = "7da180ee92d8bd8bb8c37fc560e673e6557c392f" + version = "v0.4.7" + +[[projects]] + branch = "master" + name = "github.com/Nvveen/Gotty" + packages = ["."] + revision = "cd527374f1e5bff4938207604a14f2e38a9cf512" + +[[projects]] + branch = "develop" + name = "github.com/Pterodactyl/wings" + packages = [ + "api", + "config", + "constants", + "control", + "utils" + ] + revision = "44f42eec8cca473338f7930a625c26f54e77444f" + +[[projects]] + branch = "master" + name = "github.com/StackExchange/wmi" + packages = ["."] + revision = "5d049714c4a64225c3c79a7cf7d02f7fb5b96338" + +[[projects]] + branch = "master" + name = "github.com/containerd/continuity" + packages = ["pathdriver"] + revision = "d8fb8589b0e8e85b8c8bbaa8840226d0dfeb7371" + +[[projects]] + name = "github.com/davecgh/go-spew" + packages = ["spew"] + revision = "346938d642f2ec3594ed81d874461961cd0faa76" + version = "v1.1.0" + +[[projects]] + name = "github.com/docker/docker" + packages = [ + "api/types", + "api/types/blkiodev", + "api/types/container", + "api/types/filters", + "api/types/mount", + "api/types/network", + "api/types/registry", + "api/types/strslice", + "api/types/swarm", + "api/types/swarm/runtime", + "api/types/versions", + "opts", + "pkg/archive", + "pkg/fileutils", + "pkg/homedir", + "pkg/idtools", + "pkg/ioutils", + "pkg/jsonmessage", + "pkg/longpath", + "pkg/mount", + "pkg/pools", + "pkg/stdcopy", + "pkg/system", + "pkg/term", + "pkg/term/windows" + ] + revision = "fe8aac6f5ae413a967adb0adad0b54abdfb825c4" + +[[projects]] + name = "github.com/docker/go-connections" + packages = ["nat"] + revision = "3ede32e2033de7505e6500d6c868c2b9ed9f169d" + version = "v0.3.0" + +[[projects]] + name = "github.com/docker/go-units" + packages = ["."] + revision = "0dadbb0345b35ec7ef35e228dabb8de89a65bf52" + version = "v0.3.2" + +[[projects]] + name = "github.com/fsnotify/fsnotify" + packages = ["."] + revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9" + version = "v1.4.7" + +[[projects]] + name = "github.com/fsouza/go-dockerclient" + packages = ["."] + revision = "2ff310040c161b75fa19fb9b287a90a6e03c0012" + version = "1.1" + +[[projects]] + branch = "master" + name = "github.com/gin-contrib/sse" + packages = ["."] + revision = "22d885f9ecc78bf4ee5d72b937e4bbcdc58e8cae" + +[[projects]] + name = "github.com/gin-gonic/gin" + packages = [ + ".", + "binding", + "render" + ] + revision = "d459835d2b077e44f7c9b453505ee29881d5d12d" + version = "v1.2" + +[[projects]] + name = "github.com/go-ole/go-ole" + packages = [ + ".", + "oleutil" + ] + revision = "a41e3c4b706f6ae8dfbff342b06e40fa4d2d0506" + version = "v1.2.1" + +[[projects]] + name = "github.com/gogo/protobuf" + packages = ["proto"] + revision = "1adfc126b41513cc696b209667c8656ea7aac67c" + version = "v1.0.0" + +[[projects]] + name = "github.com/golang/protobuf" + packages = ["proto"] + revision = "925541529c1fa6821df4e44ce2723319eb2be768" + version = "v1.0.0" + +[[projects]] + branch = "master" + name = "github.com/hashicorp/hcl" + packages = [ + ".", + "hcl/ast", + "hcl/parser", + "hcl/scanner", + "hcl/strconv", + "hcl/token", + "json/parser", + "json/scanner", + "json/token" + ] + revision = "23c074d0eceb2b8a5bfdbb271ab780cde70f05a8" + +[[projects]] + name = "github.com/inconshreveable/mousetrap" + packages = ["."] + revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" + version = "v1.0" + +[[projects]] + name = "github.com/lestrrat/go-file-rotatelogs" + packages = ["."] + revision = "9df8b44f21785240553882138c5df2e9cc1db910" + version = "v2.1.0" + +[[projects]] + branch = "master" + name = "github.com/lestrrat/go-strftime" + packages = ["."] + revision = "ba3bf9c1d0421aa146564a632931730344f1f9f1" + +[[projects]] + name = "github.com/magiconair/properties" + packages = ["."] + revision = "c3beff4c2358b44d0493c7dda585e7db7ff28ae6" + version = "v1.7.6" + +[[projects]] + name = "github.com/mattn/go-isatty" + packages = ["."] + revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39" + version = "v0.0.3" + +[[projects]] + branch = "master" + name = "github.com/mitchellh/mapstructure" + packages = ["."] + revision = "a4e142e9c047c904fa2f1e144d9a84e6133024bc" + +[[projects]] + name = "github.com/opencontainers/go-digest" + packages = ["."] + revision = "279bed98673dd5bef374d3b6e4b09e2af76183bf" + version = "v1.0.0-rc1" + +[[projects]] + name = "github.com/opencontainers/image-spec" + packages = [ + "specs-go", + "specs-go/v1" + ] + revision = "d60099175f88c47cd379c4738d158884749ed235" + version = "v1.0.1" + +[[projects]] + name = "github.com/opencontainers/runc" + packages = [ + "libcontainer/system", + "libcontainer/user" + ] + revision = "baf6536d6259209c3edfa2b22237af82942d3dfa" + version = "v0.1.1" + +[[projects]] + name = "github.com/pelletier/go-toml" + packages = ["."] + revision = "acdc4509485b587f5e675510c4f2c63e90ff68a8" + version = "v1.1.0" + +[[projects]] + name = "github.com/pkg/errors" + packages = ["."] + revision = "645ef00459ed84a119197bfb8d8205042c6df63d" + version = "v0.8.0" + +[[projects]] + name = "github.com/pmezard/go-difflib" + packages = ["difflib"] + revision = "792786c7400a136282c1664665ae0a8db921c6c2" + version = "v1.0.0" + +[[projects]] + name = "github.com/rifflock/lfshook" + packages = ["."] + revision = "1fdc019a35147ddbb3d25aedf713ad6d1430c144" + version = "v2.2" + +[[projects]] + name = "github.com/shirou/gopsutil" + packages = [ + "cpu", + "host", + "internal/common", + "mem", + "net", + "process" + ] + revision = "c432be29ccce470088d07eea25b3ea7e68a8afbb" + version = "v2.18.01" + +[[projects]] + branch = "master" + name = "github.com/shirou/w32" + packages = ["."] + revision = "bb4de0191aa41b5507caa14b0650cdbddcd9280b" + +[[projects]] + name = "github.com/sirupsen/logrus" + packages = ["."] + revision = "d682213848ed68c0a260ca37d6dd5ace8423f5ba" + version = "v1.0.4" + +[[projects]] + name = "github.com/spf13/afero" + packages = [ + ".", + "mem" + ] + revision = "bb8f1927f2a9d3ab41c9340aa034f6b803f4359c" + version = "v1.0.2" + +[[projects]] + name = "github.com/spf13/cast" + packages = ["."] + revision = "8965335b8c7107321228e3e3702cab9832751bac" + version = "v1.2.0" + +[[projects]] + name = "github.com/spf13/cobra" + packages = ["."] + revision = "7b2c5ac9fc04fc5efafb60700713d4fa609b777b" + version = "v0.0.1" + +[[projects]] + branch = "master" + name = "github.com/spf13/jwalterweatherman" + packages = ["."] + revision = "7c0cea34c8ece3fbeb2b27ab9b59511d360fb394" + +[[projects]] + name = "github.com/spf13/pflag" + packages = ["."] + revision = "e57e3eeb33f795204c1ca35f56c44f83227c6e66" + version = "v1.0.0" + +[[projects]] + name = "github.com/spf13/viper" + packages = ["."] + revision = "25b30aa063fc18e48662b86996252eabdcf2f0c7" + version = "v1.0.0" + +[[projects]] + name = "github.com/stretchr/testify" + packages = ["assert"] + revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" + version = "v1.2.1" + +[[projects]] + name = "github.com/ugorji/go" + packages = ["codec"] + revision = "9831f2c3ac1068a78f50999a30db84270f647af6" + version = "v1.1" + +[[projects]] + branch = "master" + name = "golang.org/x/crypto" + packages = ["ssh/terminal"] + revision = "432090b8f568c018896cd8a0fb0345872bbac6ce" + +[[projects]] + branch = "master" + name = "golang.org/x/net" + packages = [ + "context", + "context/ctxhttp" + ] + revision = "cbe0f9307d0156177f9dd5dc85da1a31abc5f2fb" + +[[projects]] + branch = "master" + name = "golang.org/x/sys" + packages = [ + "unix", + "windows" + ] + revision = "37707fdb30a5b38865cfb95e5aab41707daec7fd" + +[[projects]] + branch = "master" + name = "golang.org/x/text" + packages = [ + "internal/gen", + "internal/triegen", + "internal/ucd", + "transform", + "unicode/cldr", + "unicode/norm" + ] + revision = "4e4a3210bb54bb31f6ab2cdca2edcc0b50c420c1" + +[[projects]] + name = "gopkg.in/go-playground/validator.v8" + packages = ["."] + revision = "5f1438d3fca68893a817e4a66806cea46a9e4ebf" + version = "v8.18.2" + +[[projects]] + branch = "v2" + name = "gopkg.in/yaml.v2" + packages = ["."] + revision = "d670f9405373e636a5a2765eea47fac0c9bc91a4" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "7f394f53c7f2fc5250192ef95a878bfa397ab1d68cb69d7ab470adb4ea216294" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 0000000..43fb43f --- /dev/null +++ b/Gopkg.toml @@ -0,0 +1,66 @@ +# Gopkg.toml example +# +# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" +# +# [prune] +# non-go = false +# go-tests = true +# unused-packages = true + + +[[constraint]] + branch = "develop" + name = "github.com/Pterodactyl/wings" + +[[constraint]] + name = "github.com/gin-gonic/gin" + version = "1.2.0" + +[[constraint]] + name = "github.com/lestrrat/go-file-rotatelogs" + version = "2.1.0" + +[[constraint]] + name = "github.com/rifflock/lfshook" + version = "2.2.0" + +[[constraint]] + name = "github.com/shirou/gopsutil" + version = "2.18.1" + +[[constraint]] + name = "github.com/sirupsen/logrus" + version = "1.0.4" + +[[constraint]] + name = "github.com/spf13/cobra" + version = "0.0.1" + +[[constraint]] + name = "github.com/spf13/viper" + version = "1.0.0" + +[[constraint]] + name = "github.com/stretchr/testify" + version = "1.2.1" + +[prune] + go-tests = true + unused-packages = true diff --git a/glide.lock b/glide.lock deleted file mode 100644 index 58f8bba..0000000 --- a/glide.lock +++ /dev/null @@ -1,169 +0,0 @@ -hash: e20502ccc280db349be5bb38269606eb6b84533b70ff81d7735ecc0e03256ead -updated: 2017-07-24T20:38:57.261980868+02:00 -imports: -- name: bitbucket.org/tebeka/strftime - version: 2194253a23c090a4d5953b152a3c63fb5da4f5a4 -- name: github.com/Azure/go-ansiterm - version: 19f72df4d05d31cbe1c56bfc8045c96babff6c7e - subpackages: - - winterm -- name: github.com/docker/docker - version: 90d35abf7b3535c1c319c872900fbd76374e521c - subpackages: - - api/types - - api/types/blkiodev - - api/types/container - - api/types/filters - - api/types/mount - - api/types/network - - api/types/registry - - api/types/strslice - - api/types/swarm - - api/types/versions - - opts - - pkg/archive - - pkg/fileutils - - pkg/homedir - - pkg/idtools - - pkg/ioutils - - pkg/jsonlog - - pkg/jsonmessage - - pkg/longpath - - pkg/pools - - pkg/promise - - pkg/stdcopy - - pkg/system - - pkg/term - - pkg/term/windows -- name: github.com/docker/go-connections - version: 3ede32e2033de7505e6500d6c868c2b9ed9f169d - subpackages: - - nat -- name: github.com/docker/go-units - version: 0dadbb0345b35ec7ef35e228dabb8de89a65bf52 -- name: github.com/fsnotify/fsnotify - version: 4da3e2cfbabc9f751898f250b49f2439785783a1 -- name: github.com/fsouza/go-dockerclient - version: 4df4873b288c855e4186534280c3a3a1af403e67 -- name: github.com/gin-gonic/gin - version: e2212d40c62a98b388a5eb48ecbdcf88534688ba - subpackages: - - binding - - render -- name: github.com/go-ole/go-ole - version: 085abb85892dc1949567b726dff00fa226c60c45 - subpackages: - - oleutil -- name: github.com/golang/protobuf - version: 2402d76f3d41f928c7902a765dfc872356dd3aad - subpackages: - - proto -- name: github.com/hashicorp/go-cleanhttp - version: 3573b8b52aa7b37b9358d966a898feb387f62437 -- name: github.com/hashicorp/hcl - version: 392dba7d905ed5d04a5794ba89f558b27e2ba1ca - subpackages: - - hcl/ast - - hcl/parser - - hcl/scanner - - hcl/strconv - - hcl/token - - json/parser - - json/scanner - - json/token -- name: github.com/inconshreveable/mousetrap - version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 -- name: github.com/lestrrat/go-file-rotatelogs - version: ab335c655133cea61d8164853c1ed0e97d6c77cb -- name: github.com/magiconair/properties - version: 51463bfca2576e06c62a8504b5c0f06d61312647 -- name: github.com/manucorporat/sse - version: ee05b128a739a0fb76c7ebd3ae4810c1de808d6d -- name: github.com/mattn/go-isatty - version: fc9e8d8ef48496124e79ae0df75490096eccf6fe -- name: github.com/Microsoft/go-winio - version: c4dc1301f1dc0307acd38e611aa375a64dfe0642 -- name: github.com/mitchellh/mapstructure - version: d0303fe809921458f417bcf828397a65db30a7e4 -- name: github.com/moby/moby - version: 90d35abf7b3535c1c319c872900fbd76374e521c - subpackages: - - client -- name: github.com/Nvveen/Gotty - version: cd527374f1e5bff4938207604a14f2e38a9cf512 -- name: github.com/opencontainers/runc - version: 6ca8b741bb67839b7170d96257dde5c246f8b784 - subpackages: - - libcontainer/system - - libcontainer/user -- name: github.com/pelletier/go-buffruneio - version: c37440a7cf42ac63b919c752ca73a85067e05992 -- name: github.com/pelletier/go-toml - version: 4a000a21a414d139727f616a8bb97f847b1b310b -- name: github.com/rifflock/lfshook - version: 6844c808343cb8fa357d7f141b1b990e05d24e41 -- name: github.com/shirou/gopsutil - version: aa0a3bce9d1f4efc710ed812f19f77851da2eedd - subpackages: - - cpu - - host - - internal/common - - mem - - net - - process -- name: github.com/shirou/w32 - version: bb4de0191aa41b5507caa14b0650cdbddcd9280b -- name: github.com/sirupsen/logrus - version: a3f95b5c423586578a4e099b11a46c2479628cac -- name: github.com/Sirupsen/logrus - version: a3f95b5c423586578a4e099b11a46c2479628cac - repo: https://github.com/sirupsen/logrus.git - vcs: git -- name: github.com/spf13/afero - version: 9be650865eab0c12963d8753212f4f9c66cdcf12 - subpackages: - - mem -- name: github.com/spf13/cast - version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4 -- name: github.com/spf13/cobra - version: 90fc11bbc0a789c29272c21b5ff9e93db183f8dc -- name: github.com/spf13/jwalterweatherman - version: 0efa5202c04663c757d84f90f5219c1250baf94f -- name: github.com/spf13/pflag - version: e57e3eeb33f795204c1ca35f56c44f83227c6e66 -- name: github.com/spf13/viper - version: c1de95864d73a5465492829d7cb2dd422b19ac96 -- name: github.com/StackExchange/wmi - version: ea383cf3ba6ec950874b8486cd72356d007c768f -- name: golang.org/x/net - version: f315505cf3349909cdf013ea56690da34e96a451 - subpackages: - - context - - context/ctxhttp -- name: golang.org/x/sys - version: f7928cfef4d09d1b080aa2b6fd3ca9ba1567c733 - subpackages: - - unix - - windows -- name: golang.org/x/text - version: 5a2c30c33799f1e813f7f3259000d594a5ed493a - subpackages: - - transform - - unicode/norm -- name: gopkg.in/go-playground/validator.v8 - version: c193cecd124b5cc722d7ee5538e945bdb3348435 -- name: gopkg.in/yaml.v2 - version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b -testImports: -- name: github.com/davecgh/go-spew - version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d - subpackages: - - spew -- name: github.com/pmezard/go-difflib - version: 792786c7400a136282c1664665ae0a8db921c6c2 - subpackages: - - difflib -- name: github.com/stretchr/testify - version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 - subpackages: - - assert diff --git a/glide.yaml b/glide.yaml deleted file mode 100644 index 2d49599..0000000 --- a/glide.yaml +++ /dev/null @@ -1,29 +0,0 @@ -package: github.com/Pterodactyl/wings -import: -- package: github.com/gin-gonic/gin - version: ~1.1.4 -- package: github.com/lestrrat/go-file-rotatelogs - version: ~2.0.0 -- package: github.com/rifflock/lfshook - version: ~1.7.0 -- package: github.com/sirupsen/logrus - version: ~1.0.0 -- package: github.com/Sirupsen/logrus - version: ~1.0.0 - repo: https://github.com/sirupsen/logrus.git - vcs: git -- package: github.com/spf13/viper -- package: github.com/spf13/cobra -- package: github.com/shirou/gopsutil - version: ^2.17.6 -- package: github.com/moby/moby - version: ~17.5.0-ce-rc3 - subpackages: - - client -- package: github.com/fsouza/go-dockerclient -- package: github.com/hashicorp/go-cleanhttp -testImport: -- package: github.com/stretchr/testify - version: ~1.1.4 - subpackages: - - assert diff --git a/wings.go b/wings.go index 68f8c0e..99a4704 100644 --- a/wings.go +++ b/wings.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/Pterodactyl/wings/command" + "github.com/pterodactyl/wings/command" ) func main() { From 3f07cdb4c058f41736f292d5bee093797ded3cb9 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 20 Feb 2018 13:11:34 -0600 Subject: [PATCH 2/5] Change example config to better match existing configurations and settings --- config.example.yml | 41 +++++++++++++++++++++++++++++++++++++++++ config.yml.example | 28 ---------------------------- 2 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 config.example.yml delete mode 100644 config.yml.example diff --git a/config.example.yml b/config.example.yml new file mode 100644 index 0000000..4eb8787 --- /dev/null +++ b/config.example.yml @@ -0,0 +1,41 @@ +debug: false +data: '/srv/daemon-data' +api: + host: '0.0.0.0' + port: 8080 + ssl: + enabled: false + cert: '' + key: '' + uploads: + size_limit: 150000000 +docker: + container: + user: '' + network: + interface: '172.18.0.1' + name: 'pterodactyl_nw' + update_images: true + socket: '/var/run/docker.sock' + timezone_path: '/etc/timezone' +sftp: + host: '0.0.0.0' + port: 2022 + keypair: + bits: 2048 + e: 65537 +log: + path: './logs/' + level: 'info' + prune_days: 10 +internal: + temp_logs: '/tmp/pterodactyl' + disk_check_seconds: 30 + set_permissions_on_boot: true + throttle: + kill_at_count: 5 + decay: 10 + bytes: 4096 + check_interval_ms: 100 +remote: 'http://example.com' +token: 'test123' diff --git a/config.yml.example b/config.yml.example deleted file mode 100644 index a170504..0000000 --- a/config.yml.example +++ /dev/null @@ -1,28 +0,0 @@ -debug: false -data: '/srv/daemon-data' -api: - host: '0.0.0.0' - port: 8080 - ssl: - enabled: false - cert: '' - key: '' - uploads: - maximumSize: 150000000 -docker: - socket: '/var/run/docker.sock' - autoupdateImages: true - networkInterface: '172.18.0.1' - timezonePath: '/etc/timezone' -sftp: - host: '0.0.0.0' - port: 2022 -query: - killOnFail: true - failLimit: 5 -remote: 'http://example.com' -log: - path: './logs/' - level: 'info' - deleteAfterDays: 10 -authKey: 'test123' From bacdfae76815a9fd2aa4d3820a1285398a654e13 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 20 Feb 2018 13:33:32 -0600 Subject: [PATCH 3/5] Probably breaks everything, lowercase pterodactyl --- .dev/vagrant/motd.txt | 2 +- .dev/vagrant/provision.sh | 4 +- Gopkg.lock | 11 +---- Gopkg.toml | 6 +-- README.md | 2 +- Vagrantfile | 2 +- api/api.go | 2 +- api/auth.go | 4 +- api/auth_test.go | 4 +- api/handlers.go | 2 +- api/handlers_server.go | 2 +- api/handlers_server_test.go | 2 +- api/utils.go | 2 +- command/root.go | 10 ++--- control/docker_environment.go | 2 +- control/server.go | 4 +- main.go | 77 +++++++++++++++++++++++++++++++++ utils/{logging.go => logger.go} | 40 ++++++++--------- wings.go | 15 ------- 19 files changed, 124 insertions(+), 69 deletions(-) create mode 100644 main.go rename utils/{logging.go => logger.go} (61%) delete mode 100644 wings.go diff --git a/.dev/vagrant/motd.txt b/.dev/vagrant/motd.txt index 39c0731..bb533fc 100644 --- a/.dev/vagrant/motd.txt +++ b/.dev/vagrant/motd.txt @@ -2,7 +2,7 @@ Pterodactyl go Daemon Vagrant VM Gopath: /home/ubuntu/go -Daemon: /home/ubuntu/go/src/github.com/Pterodactyl/wings.go +Daemon: /home/ubuntu/go/src/github.com/pterodactyl/wings.go Data: /srv/daemon-data ##################################################### diff --git a/.dev/vagrant/provision.sh b/.dev/vagrant/provision.sh index c92e9be..f473fac 100644 --- a/.dev/vagrant/provision.sh +++ b/.dev/vagrant/provision.sh @@ -1,7 +1,7 @@ #!/bin/bash echo "Provisioning development environment for Pterodactyl go daemon." -cp /home/ubuntu/go/github.com/Pterodactyl/wings.go/.dev/vagrant/motd.txt /etc/motd +cp /home/ubuntu/go/github.com/pterodactyl/wings.go/.dev/vagrant/motd.txt /etc/motd chown -R ubuntu:ubuntu /home/ubuntu/go chown -R ubuntu:ubuntu /srv @@ -32,5 +32,5 @@ apt-get -y install mercurial #tar unzip make gcc g++ python > /dev/null echo " ------------" echo "Gopath is /home/ubuntu/go" -echo "The project is mounted to /home/ubuntu/go/src/github.com/Pterodactyl/wings.go" +echo "The project is mounted to /home/ubuntu/go/src/github.com/pterodactyl/wings.go" echo "Provisioning is completed." diff --git a/Gopkg.lock b/Gopkg.lock index 137f0f3..5a85eef 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -24,7 +24,7 @@ [[projects]] branch = "develop" - name = "github.com/Pterodactyl/wings" + name = "github.com/pterodactyl/wings" packages = [ "api", "config", @@ -251,18 +251,11 @@ "host", "internal/common", "mem", - "net", "process" ] revision = "c432be29ccce470088d07eea25b3ea7e68a8afbb" version = "v2.18.01" -[[projects]] - branch = "master" - name = "github.com/shirou/w32" - packages = ["."] - revision = "bb4de0191aa41b5507caa14b0650cdbddcd9280b" - [[projects]] name = "github.com/sirupsen/logrus" packages = ["."] @@ -372,6 +365,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "7f394f53c7f2fc5250192ef95a878bfa397ab1d68cb69d7ab470adb4ea216294" + inputs-digest = "3f6a265d298db6e8379b05d796fcdff3d78a0216b6aaaccd4501440cbcfc0792" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 43fb43f..3725ff4 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -25,9 +25,9 @@ # unused-packages = true -[[constraint]] - branch = "develop" - name = "github.com/Pterodactyl/wings" +#[[constraint]] +# branch = "develop" +# name = "github.com/pterodactyl/wings" [[constraint]] name = "github.com/gin-gonic/gin" diff --git a/README.md b/README.md index e4685f8..431db1c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Pterodactyl wings [![travis](https://img.shields.io/travis/Pterodactyl/wings.svg?style=flat-square)](https://travis-ci.org/Pterodactyl/wings) [![codacy quality](https://img.shields.io/codacy/grade/27a1576bda86450f853b1052b12fa570.svg?style=flat-square)](https://www.codacy.com/app/schrej/wings/dashboard) [![codacy coverage](https://img.shields.io/codacy/coverage/27a1576bda86450f853b1052b12fa570.svg?style=flat-square)](https://www.codacy.com/app/schrej/wings/files) +# Pterodactyl wings [![travis](https://img.shields.io/travis/pterodactyl/wings.svg?style=flat-square)](https://travis-ci.org/pterodactyl/wings) [![codacy quality](https://img.shields.io/codacy/grade/27a1576bda86450f853b1052b12fa570.svg?style=flat-square)](https://www.codacy.com/app/schrej/wings/dashboard) [![codacy coverage](https://img.shields.io/codacy/coverage/27a1576bda86450f853b1052b12fa570.svg?style=flat-square)](https://www.codacy.com/app/schrej/wings/files) ``` ____ diff --git a/Vagrantfile b/Vagrantfile index 8656ee4..d98475d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,7 +1,7 @@ Vagrant.configure("2") do |cfg| cfg.vm.box = "ubuntu/xenial64" - cfg.vm.synced_folder "./", "/home/ubuntu/go/src/github.com/Pterodactyl/wings" + cfg.vm.synced_folder "./", "/home/ubuntu/go/src/github.com/pterodactyl/wings" cfg.vm.provision :shell, path: ".dev/vagrant/provision.sh" diff --git a/api/api.go b/api/api.go index ce06713..fe11273 100644 --- a/api/api.go +++ b/api/api.go @@ -8,7 +8,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/viper" - "github.com/Pterodactyl/wings/config" + "github.com/pterodactyl/wings/config" ) type InternalAPI struct { diff --git a/api/auth.go b/api/auth.go index 00cde92..ef67b66 100644 --- a/api/auth.go +++ b/api/auth.go @@ -3,9 +3,9 @@ package api import ( "net/http" - "github.com/Pterodactyl/wings/config" - "github.com/Pterodactyl/wings/control" "github.com/gin-gonic/gin" + "github.com/pterodactyl/wings/config" + "github.com/pterodactyl/wings/control" log "github.com/sirupsen/logrus" ) diff --git a/api/auth_test.go b/api/auth_test.go index c66e868..692e64a 100644 --- a/api/auth_test.go +++ b/api/auth_test.go @@ -8,8 +8,8 @@ import ( "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" - "github.com/Pterodactyl/wings/config" - "github.com/Pterodactyl/wings/control" + "github.com/pterodactyl/wings/config" + "github.com/pterodactyl/wings/control" ) const configFile = "_testdata/config.yml" diff --git a/api/handlers.go b/api/handlers.go index 77a43eb..f0bfc3f 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -4,8 +4,8 @@ import ( "net/http" "runtime" - "github.com/Pterodactyl/wings/constants" "github.com/gin-gonic/gin" + "github.com/pterodactyl/wings/constants" "github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/host" "github.com/shirou/gopsutil/mem" diff --git a/api/handlers_server.go b/api/handlers_server.go index 608cb54..09b10c3 100644 --- a/api/handlers_server.go +++ b/api/handlers_server.go @@ -3,8 +3,8 @@ package api import ( "net/http" - "github.com/Pterodactyl/wings/control" "github.com/gin-gonic/gin" + "github.com/pterodactyl/wings/control" log "github.com/sirupsen/logrus" ) diff --git a/api/handlers_server_test.go b/api/handlers_server_test.go index 25d15d9..34d3911 100644 --- a/api/handlers_server_test.go +++ b/api/handlers_server_test.go @@ -8,8 +8,8 @@ import ( "net/http/httptest" "testing" - "github.com/Pterodactyl/wings/control" "github.com/gin-gonic/gin" + "github.com/pterodactyl/wings/control" "github.com/stretchr/testify/assert" ) diff --git a/api/utils.go b/api/utils.go index d9a972e..c748c3a 100644 --- a/api/utils.go +++ b/api/utils.go @@ -1,8 +1,8 @@ package api import ( - "github.com/Pterodactyl/wings/control" "github.com/gin-gonic/gin" + "github.com/pterodactyl/wings/control" ) func getServerFromContext(context *gin.Context) control.Server { diff --git a/command/root.go b/command/root.go index 195b86c..f7aee50 100644 --- a/command/root.go +++ b/command/root.go @@ -6,11 +6,11 @@ import ( "github.com/spf13/viper" - "github.com/Pterodactyl/wings/api" - "github.com/Pterodactyl/wings/config" - "github.com/Pterodactyl/wings/constants" - "github.com/Pterodactyl/wings/control" - "github.com/Pterodactyl/wings/utils" + "github.com/pterodactyl/wings/api" + "github.com/pterodactyl/wings/config" + "github.com/pterodactyl/wings/constants" + "github.com/pterodactyl/wings/control" + "github.com/pterodactyl/wings/utils" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/control/docker_environment.go b/control/docker_environment.go index f9dd19f..03482bd 100644 --- a/control/docker_environment.go +++ b/control/docker_environment.go @@ -6,7 +6,7 @@ import ( "os" "strings" - "github.com/Pterodactyl/wings/constants" + "github.com/pterodactyl/wings/constants" "github.com/fsouza/go-dockerclient" log "github.com/sirupsen/logrus" diff --git a/control/server.go b/control/server.go index 26fadbd..289fa04 100644 --- a/control/server.go +++ b/control/server.go @@ -8,8 +8,8 @@ import ( "path/filepath" "strings" - "github.com/Pterodactyl/wings/config" - "github.com/Pterodactyl/wings/constants" + "github.com/pterodactyl/wings/config" + "github.com/pterodactyl/wings/constants" log "github.com/sirupsen/logrus" "github.com/spf13/viper" ) diff --git a/main.go b/main.go new file mode 100644 index 0000000..2bdfe2f --- /dev/null +++ b/main.go @@ -0,0 +1,77 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + "strconv" + + "github.com/pterodactyl/wings/api" + "github.com/pterodactyl/wings/command" + "github.com/pterodactyl/wings/config" + "github.com/pterodactyl/wings/constants" + "github.com/pterodactyl/wings/control" + "github.com/pterodactyl/wings/utils" + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +func main() { + if err := command.RootCommand.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} + +// RootCommand is the root command of wings +var RootCommand = &cobra.Command{ + Use: "wings", + Short: "", + Long: "", + Run: run, +} + +var configPath string + +func init() { + RootCommand.Flags().StringVarP(&configPath, "config", "c", "./config.yml", "Allows to set the path of the configuration file.") +} + +// Execute registers the RootCommand +func Execute() { + RootCommand.Execute() +} + +func run(cmd *cobra.Command, args []string) { + utils.InitLogging() + logrus.Info("Loading configuration...") + if err := config.LoadConfiguration(configPath); err != nil { + logrus.WithError(err).Fatal("Failed to find configuration file") + } + utils.ConfigureLogging() + + logrus.Info(` ____`) + logrus.Info(`__ Pterodactyl _____/___/_______ _______ ______`) + logrus.Info(`\_____\ \/\/ / / / __ / ___/`) + logrus.Info(` \___\ / / / / /_/ /___ /`) + logrus.Info(` \___/\___/___/___/___/___ /______/`) + logrus.Info(` /_______/ v` + constants.Version) + logrus.Info() + + logrus.Info("Configuration loaded successfully.") + + logrus.Info("Loading configured servers...") + if err := control.LoadServerConfigurations(filepath.Join(viper.GetString(config.DataPath), constants.ServersPath)); err != nil { + logrus.WithError(err).Error("Failed to load configured servers.") + } + if amount := len(control.GetServers()); amount == 1 { + logrus.Info("Loaded 1 server.") + } else { + logrus.Info("Loaded " + strconv.Itoa(amount) + " servers.") + } + + logrus.Info("Starting API Server...") + a := api.NewAPI() + a.Listen() +} diff --git a/utils/logging.go b/utils/logger.go similarity index 61% rename from utils/logging.go rename to utils/logger.go index ff05ebd..e988a62 100644 --- a/utils/logging.go +++ b/utils/logger.go @@ -1,18 +1,18 @@ -package tools +package utils import ( "os" "path/filepath" - "time" + //"time" - "github.com/Pterodactyl/wings/constants" + "github.com/pterodactyl/wings/constants" - rotatelogs "github.com/lestrrat/go-file-rotatelogs" - "github.com/rifflock/lfshook" + //"github.com/lestrrat/go-file-rotatelogs" + //"github.com/rifflock/lfshook" log "github.com/sirupsen/logrus" "github.com/spf13/viper" - "github.com/Pterodactyl/wings/config" + "github.com/pterodactyl/wings/config" ) // InitLogging initalizes the logging library for first use. @@ -30,20 +30,20 @@ func ConfigureLogging() error { if err := os.MkdirAll(path, constants.DefaultFolderPerms); err != nil { return err } - writer := rotatelogs.New( - path+"/wings.%Y%m%d-%H%M.log", - rotatelogs.WithLinkName(path), - rotatelogs.WithMaxAge(time.Duration(viper.GetInt(config.LogDeleteAfterDays))*time.Hour*24), - rotatelogs.WithRotationTime(time.Duration(604800)*time.Second), - ) - - log.AddHook(lfshook.NewHook(lfshook.WriterMap{ - log.DebugLevel: writer, - log.InfoLevel: writer, - log.WarnLevel: writer, - log.ErrorLevel: writer, - log.FatalLevel: writer, - })) + //writer := rotatelogs.New( + // path+"/wings.%Y%m%d-%H%M.log", + // rotatelogs.WithLinkName(path), + // rotatelogs.WithMaxAge(time.Duration(viper.GetInt(config.LogDeleteAfterDays))*time.Hour*24), + // rotatelogs.WithRotationTime(time.Duration(604800)*time.Second), + //) + // + //log.AddHook(lfshook.NewHook(lfshook.WriterMap{ + // log.DebugLevel: writer, + // log.InfoLevel: writer, + // log.WarnLevel: writer, + // log.ErrorLevel: writer, + // log.FatalLevel: writer, + //})) level := viper.GetString(config.LogLevel) diff --git a/wings.go b/wings.go deleted file mode 100644 index 99a4704..0000000 --- a/wings.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -import ( - "fmt" - "os" - - "github.com/pterodactyl/wings/command" -) - -func main() { - if err := command.RootCommand.Execute(); err != nil { - fmt.Println(err) - os.Exit(1) - } -} From 4359d152b70078b3851560b9f2c275b4bfe12c5f Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 20 Feb 2018 14:00:09 -0600 Subject: [PATCH 4/5] Butcher the app in an attempt to make it boot past step 1 --- Gopkg.lock | 40 +++++----------------- api/api.go | 5 +-- api/handlers.go | 89 +++++++++++++++++++++++++------------------------ api/routes.go | 40 +++++++++++----------- command/root.go | 68 ------------------------------------- main.go | 54 +++++++++++++----------------- 6 files changed, 99 insertions(+), 197 deletions(-) delete mode 100644 command/root.go diff --git a/Gopkg.lock b/Gopkg.lock index 5a85eef..7d671b8 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -22,18 +22,6 @@ packages = ["."] revision = "cd527374f1e5bff4938207604a14f2e38a9cf512" -[[projects]] - branch = "develop" - name = "github.com/pterodactyl/wings" - packages = [ - "api", - "config", - "constants", - "control", - "utils" - ] - revision = "44f42eec8cca473338f7930a625c26f54e77444f" - [[projects]] branch = "master" name = "github.com/StackExchange/wmi" @@ -166,18 +154,6 @@ revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" version = "v1.0" -[[projects]] - name = "github.com/lestrrat/go-file-rotatelogs" - packages = ["."] - revision = "9df8b44f21785240553882138c5df2e9cc1db910" - version = "v2.1.0" - -[[projects]] - branch = "master" - name = "github.com/lestrrat/go-strftime" - packages = ["."] - revision = "ba3bf9c1d0421aa146564a632931730344f1f9f1" - [[projects]] name = "github.com/magiconair/properties" packages = ["."] @@ -238,24 +214,26 @@ revision = "792786c7400a136282c1664665ae0a8db921c6c2" version = "v1.0.0" -[[projects]] - name = "github.com/rifflock/lfshook" - packages = ["."] - revision = "1fdc019a35147ddbb3d25aedf713ad6d1430c144" - version = "v2.2" - [[projects]] name = "github.com/shirou/gopsutil" packages = [ + ".", "cpu", "host", "internal/common", "mem", + "net", "process" ] revision = "c432be29ccce470088d07eea25b3ea7e68a8afbb" version = "v2.18.01" +[[projects]] + branch = "master" + name = "github.com/shirou/w32" + packages = ["."] + revision = "bb4de0191aa41b5507caa14b0650cdbddcd9280b" + [[projects]] name = "github.com/sirupsen/logrus" packages = ["."] @@ -365,6 +343,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "3f6a265d298db6e8379b05d796fcdff3d78a0216b6aaaccd4501440cbcfc0792" + inputs-digest = "8a295fa1730b9ed537e5fceeeee2a87c233eee4dea1bf0697d9f94b0c0d23e7d" solver-name = "gps-cdcl" solver-version = 1 diff --git a/api/api.go b/api/api.go index fe11273..ee0751c 100644 --- a/api/api.go +++ b/api/api.go @@ -21,15 +21,12 @@ func NewAPI() InternalAPI { // Configure the API and begin listening on the configured IP and Port. func (api *InternalAPI) Listen() { - listener := fmt.Sprintf("%s:%d", viper.GetString(config.APIHost), viper.GetInt(config.APIPort)) - if !viper.GetBool(config.Debug) { gin.SetMode(gin.ReleaseMode) } api.router = gin.Default() api.router.RedirectTrailingSlash = false - api.RegisterRoutes() api.router.Use(func(c *gin.Context) { c.Header("Access-Control-Allow-Origin", "*") @@ -40,7 +37,7 @@ func (api *InternalAPI) Listen() { c.Header("Access-Control-Allow-Headers", "X-Access-Token") }) - api.registerRoutes() + api.RegisterRoutes() listenString := fmt.Sprintf("%s:%d", viper.GetString(config.APIHost), viper.GetInt(config.APIPort)) diff --git a/api/handlers.go b/api/handlers.go index f0bfc3f..813bd51 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -2,58 +2,59 @@ package api import ( "net/http" - "runtime" + //"runtime" "github.com/gin-gonic/gin" "github.com/pterodactyl/wings/constants" - "github.com/shirou/gopsutil/cpu" - "github.com/shirou/gopsutil/host" - "github.com/shirou/gopsutil/mem" + + //"github.com/shirou/gopsutil/cpu" + //"github.com/shirou/gopsutil/host" + //"github.com/shirou/gopsutil/mem" log "github.com/sirupsen/logrus" ) func GetIndex(c *gin.Context) { - auth := GetContextAuthManager(c) + //auth := GetContextAuthManager(c) - if auth != nil && auth.HasPermission("c:info") { - hostInfo, err := host.Info() - if err != nil { - log.WithError(err).Error("Failed to retrieve host information.") - } - cpuInfo, err := cpu.Info() - if err != nil { - log.WithError(err).Error("Failed to retrieve CPU information.") - } - memInfo, err := mem.VirtualMemory() - if err != nil { - log.WithError(err).Error("Failed to retrieve memory information.") - } - - info := struct { - Name string `json:"name"` - Version string `json:"version"` - System struct { - SystemType string `json:"type"` - Platform string `json:"platform"` - Arch string `json:"arch"` - Release string `json:"release"` - Cpus int32 `json:"cpus"` - Freemem uint64 `json:"freemem"` - } `json:"system"` - }{ - Name: "Pterodactyl wings", - Version: constants.Version, - } - info.System.SystemType = hostInfo.OS - info.System.Platform = hostInfo.Platform - info.System.Arch = runtime.GOARCH - info.System.Release = hostInfo.KernelVersion - info.System.Cpus = cpuInfo[0].Cores - info.System.Freemem = memInfo.Free - - c.JSON(http.StatusOK, info) - return - } + //if auth != nil && auth.HasPermission("c:info") { + // hostInfo, err := host.Info() + // if err != nil { + // log.WithError(err).Error("Failed to retrieve host information.") + // } + // cpuInfo, err := cpu.Info() + // if err != nil { + // log.WithError(err).Error("Failed to retrieve CPU information.") + // } + // memInfo, err := mem.VirtualMemory() + // if err != nil { + // log.WithError(err).Error("Failed to retrieve memory information.") + // } + // + // info := struct { + // Name string `json:"name"` + // Version string `json:"version"` + // System struct { + // SystemType string `json:"type"` + // Platform string `json:"platform"` + // Arch string `json:"arch"` + // Release string `json:"release"` + // Cpus int32 `json:"cpus"` + // Freemem uint64 `json:"freemem"` + // } `json:"system"` + // }{ + // Name: "Pterodactyl wings", + // Version: constants.Version, + // } + // info.System.SystemType = hostInfo.OS + // info.System.Platform = hostInfo.Platform + // info.System.Arch = runtime.GOARCH + // info.System.Release = hostInfo.KernelVersion + // info.System.Cpus = cpuInfo[0].Cores + // info.System.Freemem = memInfo.Free + // + // c.JSON(http.StatusOK, info) + // return + //} c.Header("Content-Type", "text/html") c.String(http.StatusOK, constants.IndexPage) diff --git a/api/routes.go b/api/routes.go index 7804e19..c80bcd6 100644 --- a/api/routes.go +++ b/api/routes.go @@ -6,7 +6,7 @@ func (api *InternalAPI) RegisterRoutes() { v1 := api.router.Group("/v1") { v1.GET("/", AuthHandler(""), GetIndex) - v1.PATCH("/config", AuthHandler("c:config"), PatchConfiguration) + //v1.PATCH("/config", AuthHandler("c:config"), PatchConfiguration) v1.GET("/servers", AuthHandler("c:list"), handleGetServers) v1.POST("/servers", AuthHandler("c:create"), handlePostServers) @@ -26,24 +26,24 @@ func (api *InternalAPI) RegisterRoutes() { v1ServerRoutes.POST("/unsuspend", AuthHandler(""), handlePostServerUnsuspend) } - v1ServerFileRoutes := v1.Group("/servers/:server/files") - { - v1ServerFileRoutes.GET("/file/:file", AuthHandler("s:files:read"), handleGetFile) - v1ServerFileRoutes.GET("/stat/:file", AuthHandler("s:files:"), handleGetFileStat) - v1ServerFileRoutes.GET("/dir/:directory", AuthHandler("s:files:get"), handleGetDirectory) - - v1ServerFileRoutes.POST("/dir/:directory", AuthHandler("s:files:create"), handlePostFilesFolder) - v1ServerFileRoutes.POST("/file/:file", AuthHandler("s:files:post"), handlePostFile) - - v1ServerFileRoutes.POST("/copy/:file", AuthHandler("s:files:copy"), handlePostFileCopy) - v1ServerFileRoutes.POST("/move/:file", AuthHandler("s:files:move"), handlePostFileMove) - v1ServerFileRoutes.POST("/rename/:file", AuthHandler("s:files:move"), handlePostFileMove) - v1ServerFileRoutes.POST("/compress/:file", AuthHandler("s:files:compress"), handlePostFileCompress) - v1ServerFileRoutes.POST("/decompress/:file", AuthHandler("s:files:decompress"), handlePostFileDecompress) - - v1ServerFileRoutes.DELETE("/file/:file", AuthHandler("s:files:delete"), handleDeleteFile) - - v1ServerFileRoutes.GET("/download/:token", handleGetDownloadFile) - } + //v1ServerFileRoutes := v1.Group("/servers/:server/files") + //{ + // v1ServerFileRoutes.GET("/file/:file", AuthHandler("s:files:read"), handleGetFile) + // v1ServerFileRoutes.GET("/stat/:file", AuthHandler("s:files:"), handleGetFileStat) + // v1ServerFileRoutes.GET("/dir/:directory", AuthHandler("s:files:get"), handleGetDirectory) + // + // v1ServerFileRoutes.POST("/dir/:directory", AuthHandler("s:files:create"), handlePostFilesFolder) + // v1ServerFileRoutes.POST("/file/:file", AuthHandler("s:files:post"), handlePostFile) + // + // v1ServerFileRoutes.POST("/copy/:file", AuthHandler("s:files:copy"), handlePostFileCopy) + // v1ServerFileRoutes.POST("/move/:file", AuthHandler("s:files:move"), handlePostFileMove) + // v1ServerFileRoutes.POST("/rename/:file", AuthHandler("s:files:move"), handlePostFileMove) + // v1ServerFileRoutes.POST("/compress/:file", AuthHandler("s:files:compress"), handlePostFileCompress) + // v1ServerFileRoutes.POST("/decompress/:file", AuthHandler("s:files:decompress"), handlePostFileDecompress) + // + // v1ServerFileRoutes.DELETE("/file/:file", AuthHandler("s:files:delete"), handleDeleteFile) + // + // v1ServerFileRoutes.GET("/download/:token", handleGetDownloadFile) + //} } } diff --git a/command/root.go b/command/root.go deleted file mode 100644 index f7aee50..0000000 --- a/command/root.go +++ /dev/null @@ -1,68 +0,0 @@ -package command - -import ( - "path/filepath" - "strconv" - - "github.com/spf13/viper" - - "github.com/pterodactyl/wings/api" - "github.com/pterodactyl/wings/config" - "github.com/pterodactyl/wings/constants" - "github.com/pterodactyl/wings/control" - "github.com/pterodactyl/wings/utils" - log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" -) - -// RootCommand is the root command of wings -var RootCommand = &cobra.Command{ - Use: "wings", - Short: "", - Long: "", - Run: run, -} - -var configPath string - -func init() { - RootCommand.Flags().StringVarP(&configPath, "config", "c", "./config.yml", "Allows to set the path of the configuration file.") -} - -// Execute registers the RootCommand -func Execute() { - RootCommand.Execute() -} - -func run(cmd *cobra.Command, args []string) { - tools.InitLogging() - log.Info("Loading configuration...") - if err := config.LoadConfiguration(configPath); err != nil { - log.WithError(err).Fatal("Failed to find configuration file") - } - tools.ConfigureLogging() - - log.Info(` ____`) - log.Info(`__ Pterodactyl _____/___/_______ _______ ______`) - log.Info(`\_____\ \/\/ / / / __ / ___/`) - log.Info(` \___\ / / / / /_/ /___ /`) - log.Info(` \___/\___/___/___/___/___ /______/`) - log.Info(` /_______/ v` + constants.Version) - log.Info() - - log.Info("Configuration loaded successfully.") - - log.Info("Loading configured servers...") - if err := control.LoadServerConfigurations(filepath.Join(viper.GetString(config.DataPath), constants.ServersPath)); err != nil { - log.WithError(err).Error("Failed to load configured servers.") - } - if amount := len(control.GetServers()); amount == 1 { - log.Info("Loaded 1 server.") - } else { - log.Info("Loaded " + strconv.Itoa(amount) + " servers.") - } - - log.Info("Starting api webserver...") - api := api.NewAPI() - api.Listen() -} diff --git a/main.go b/main.go index 2bdfe2f..6aefe36 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,6 @@ import ( "strconv" "github.com/pterodactyl/wings/api" - "github.com/pterodactyl/wings/command" "github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/constants" "github.com/pterodactyl/wings/control" @@ -17,38 +16,36 @@ import ( "github.com/spf13/viper" ) +var configPath string +var RootCommand = &cobra.Command{ + Use: "wings", + Short: "Wings is the next generation server control daemon for Pterodactyl", + Long: "Wings is the next generation server control daemon for Pterodactyl", + Run: run, +} + +// Entrypoint of the application. Currently just boots up the cobra command +// and lets that handle everything else. func main() { - if err := command.RootCommand.Execute(); err != nil { + RootCommand.Flags().StringVarP(&configPath, "config", "c", "./config.yml", "Allows to set the path of the configuration file.") + + if err := RootCommand.Execute(); err != nil { fmt.Println(err) os.Exit(1) } } -// RootCommand is the root command of wings -var RootCommand = &cobra.Command{ - Use: "wings", - Short: "", - Long: "", - Run: run, -} - -var configPath string - -func init() { - RootCommand.Flags().StringVarP(&configPath, "config", "c", "./config.yml", "Allows to set the path of the configuration file.") -} - -// Execute registers the RootCommand -func Execute() { - RootCommand.Execute() -} - +// Bootstraps the application and beging the process of running the API and +// server instances. func run(cmd *cobra.Command, args []string) { utils.InitLogging() - logrus.Info("Loading configuration...") + + logrus.Info("Booting configuration file...") if err := config.LoadConfiguration(configPath); err != nil { - logrus.WithError(err).Fatal("Failed to find configuration file") + logrus.WithError(err).Fatal("Could not locate a suitable config.yml file for this Daemon.") } + + logrus.Info("Configuration successfully loaded, booting application.") utils.ConfigureLogging() logrus.Info(` ____`) @@ -59,19 +56,16 @@ func run(cmd *cobra.Command, args []string) { logrus.Info(` /_______/ v` + constants.Version) logrus.Info() - logrus.Info("Configuration loaded successfully.") - - logrus.Info("Loading configured servers...") + logrus.Info("Loading configured servers.") if err := control.LoadServerConfigurations(filepath.Join(viper.GetString(config.DataPath), constants.ServersPath)); err != nil { logrus.WithError(err).Error("Failed to load configured servers.") } + if amount := len(control.GetServers()); amount == 1 { - logrus.Info("Loaded 1 server.") - } else { - logrus.Info("Loaded " + strconv.Itoa(amount) + " servers.") + logrus.Info("Found and loaded " + strconv.Itoa(amount) + " server(s).") } - logrus.Info("Starting API Server...") + logrus.Info("Registering API server and booting.") a := api.NewAPI() a.Listen() } From bbc6d26b352d555b498a6195077f55bf285110fe Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 20 Feb 2018 15:20:57 -0600 Subject: [PATCH 5/5] Break more of everything --- Gopkg.lock | 6 ++-- Gopkg.toml | 2 +- api/api.go | 77 ++++++++++++++++++++++++++++++++++++++++--------- api/auth.go | 2 +- api/handlers.go | 33 +++++++++++++++++---- api/routes.go | 49 ------------------------------- main.go | 2 +- 7 files changed, 96 insertions(+), 75 deletions(-) delete mode 100644 api/routes.go diff --git a/Gopkg.lock b/Gopkg.lock index 7d671b8..f35a959 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -217,7 +217,6 @@ [[projects]] name = "github.com/shirou/gopsutil" packages = [ - ".", "cpu", "host", "internal/common", @@ -225,8 +224,7 @@ "net", "process" ] - revision = "c432be29ccce470088d07eea25b3ea7e68a8afbb" - version = "v2.18.01" + revision = "543a05cce094293c7747322720256bee15d88a12" [[projects]] branch = "master" @@ -343,6 +341,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "8a295fa1730b9ed537e5fceeeee2a87c233eee4dea1bf0697d9f94b0c0d23e7d" + inputs-digest = "3f1bdf5882e27f292b13d4b95c9f51eb1a7609af61ccda0fae50a806b0a2ba4f" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 3725ff4..b165b96 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -43,7 +43,7 @@ [[constraint]] name = "github.com/shirou/gopsutil" - version = "2.18.1" + revision = "543a05cce094293c7747322720256bee15d88a12" [[constraint]] name = "github.com/sirupsen/logrus" diff --git a/api/api.go b/api/api.go index ee0751c..f54d7f6 100644 --- a/api/api.go +++ b/api/api.go @@ -5,20 +5,15 @@ import ( "net/http" "github.com/gin-gonic/gin" - log "github.com/sirupsen/logrus" - "github.com/spf13/viper" - "github.com/pterodactyl/wings/config" + "github.com/sirupsen/logrus" + "github.com/spf13/viper" ) type InternalAPI struct { router *gin.Engine } -func NewAPI() InternalAPI { - return InternalAPI{} -} - // Configure the API and begin listening on the configured IP and Port. func (api *InternalAPI) Listen() { if !viper.GetBool(config.Debug) { @@ -28,21 +23,75 @@ func (api *InternalAPI) Listen() { api.router = gin.Default() api.router.RedirectTrailingSlash = false + // Setup Access-Control origin headers. Down the road once this is closer to + // release we should setup this header properly and lock it down to the domain + // used to run the Panel. api.router.Use(func(c *gin.Context) { c.Header("Access-Control-Allow-Origin", "*") }) api.router.OPTIONS("/", func(c *gin.Context) { c.Header("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS") - c.Header("Access-Control-Allow-Headers", "X-Access-Token") + c.Header("Access-Control-Allow-Headers", "Authorization") }) - api.RegisterRoutes() + // Register all of the API route bindings. + api.register() - listenString := fmt.Sprintf("%s:%d", viper.GetString(config.APIHost), viper.GetInt(config.APIPort)) + l := fmt.Sprintf("%s:%d", viper.GetString(config.APIHost), viper.GetInt(config.APIPort)) + api.router.Run(l) - api.router.Run(listenString) - - log.Info("Now listening on %s", listenString) - log.Fatal(http.ListenAndServe(listenString, nil)) + logrus.Info("Now listening on %s", l) + logrus.Fatal(http.ListenAndServe(l, nil)) +} + +// Register routes for v1 of the API. This API should be fully backwards compatable with +// the existing Nodejs Daemon API. +// +// Routes that are not yet completed are commented out. Routes are grouped where possible +// to keep this function organized. +func (api *InternalAPI) register() { + v1 := api.router.Group("/api/v1") + { + v1.GET("/", AuthHandler(""), GetIndex) + //v1.PATCH("/config", AuthHandler("c:config"), PatchConfiguration) + + v1.GET("/servers", AuthHandler("c:list"), handleGetServers) + v1.POST("/servers", AuthHandler("c:create"), handlePostServers) + + v1ServerRoutes := v1.Group("/servers/:server") + { + v1ServerRoutes.GET("/", AuthHandler("s:get"), handleGetServer) + v1ServerRoutes.PATCH("/", AuthHandler("s:config"), handlePatchServer) + v1ServerRoutes.DELETE("/", AuthHandler("g:server:delete"), handleDeleteServer) + v1ServerRoutes.POST("/reinstall", AuthHandler("s:install-server"), handlePostServerReinstall) + v1ServerRoutes.POST("/rebuild", AuthHandler("g:server:rebuild"), handlePostServerRebuild) + v1ServerRoutes.POST("/password", AuthHandler(""), handlePostServerPassword) + v1ServerRoutes.POST("/power", AuthHandler("s:power"), handlePostServerPower) + v1ServerRoutes.POST("/command", AuthHandler("s:command"), handlePostServerCommand) + v1ServerRoutes.GET("/log", AuthHandler("s:console"), handleGetServerLog) + v1ServerRoutes.POST("/suspend", AuthHandler(""), handlePostServerSuspend) + v1ServerRoutes.POST("/unsuspend", AuthHandler(""), handlePostServerUnsuspend) + } + + //v1ServerFileRoutes := v1.Group("/servers/:server/files") + //{ + // v1ServerFileRoutes.GET("/file/:file", AuthHandler("s:files:read"), handleGetFile) + // v1ServerFileRoutes.GET("/stat/:file", AuthHandler("s:files:"), handleGetFileStat) + // v1ServerFileRoutes.GET("/dir/:directory", AuthHandler("s:files:get"), handleGetDirectory) + // + // v1ServerFileRoutes.POST("/dir/:directory", AuthHandler("s:files:create"), handlePostFilesFolder) + // v1ServerFileRoutes.POST("/file/:file", AuthHandler("s:files:post"), handlePostFile) + // + // v1ServerFileRoutes.POST("/copy/:file", AuthHandler("s:files:copy"), handlePostFileCopy) + // v1ServerFileRoutes.POST("/move/:file", AuthHandler("s:files:move"), handlePostFileMove) + // v1ServerFileRoutes.POST("/rename/:file", AuthHandler("s:files:move"), handlePostFileMove) + // v1ServerFileRoutes.POST("/compress/:file", AuthHandler("s:files:compress"), handlePostFileCompress) + // v1ServerFileRoutes.POST("/decompress/:file", AuthHandler("s:files:decompress"), handlePostFileDecompress) + // + // v1ServerFileRoutes.DELETE("/file/:file", AuthHandler("s:files:delete"), handleDeleteFile) + // + // v1ServerFileRoutes.GET("/download/:token", handleGetDownloadFile) + //} + } } diff --git a/api/auth.go b/api/auth.go index ef67b66..d958b1f 100644 --- a/api/auth.go +++ b/api/auth.go @@ -10,7 +10,7 @@ import ( ) const ( - accessTokenHeader = "X-Access-Token" + accessTokenHeader = "Authorization" contextVarServer = "server" contextVarAuth = "auth" diff --git a/api/handlers.go b/api/handlers.go index 813bd51..469f271 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -1,13 +1,15 @@ package api import ( + "fmt" "net/http" //"runtime" "github.com/gin-gonic/gin" - "github.com/pterodactyl/wings/constants" + //"github.com/pterodactyl/wings/constants" + //"github.com/shirou/gopsutil/host" - //"github.com/shirou/gopsutil/cpu" + "github.com/shirou/gopsutil/cpu" //"github.com/shirou/gopsutil/host" //"github.com/shirou/gopsutil/mem" log "github.com/sirupsen/logrus" @@ -15,6 +17,30 @@ import ( func GetIndex(c *gin.Context) { //auth := GetContextAuthManager(c) + //if auth == nil { + // c.Header("Content-Type", "text/html") + // c.String(http.StatusOK, constants.IndexPage) + //} + + s, err := cpu.Counts(true) + if err != nil { + log.WithError(err).Error("Failed to retrieve host information.") + } + + fmt.Println(s) + i := struct { + Name string + Cpu struct { + Cores int + } + }{ + Name: "Wings", + } + + i.Cpu.Cores = s + + c.JSON(http.StatusOK, i) + return //if auth != nil && auth.HasPermission("c:info") { // hostInfo, err := host.Info() @@ -55,9 +81,6 @@ func GetIndex(c *gin.Context) { // c.JSON(http.StatusOK, info) // return //} - - c.Header("Content-Type", "text/html") - c.String(http.StatusOK, constants.IndexPage) } type incomingConfiguration struct { diff --git a/api/routes.go b/api/routes.go deleted file mode 100644 index c80bcd6..0000000 --- a/api/routes.go +++ /dev/null @@ -1,49 +0,0 @@ -package api - -func (api *InternalAPI) RegisterRoutes() { - // Register routes for v1 of the API. This API should be fully backwards compatable with - // the existing Nodejs Daemon API. - v1 := api.router.Group("/v1") - { - v1.GET("/", AuthHandler(""), GetIndex) - //v1.PATCH("/config", AuthHandler("c:config"), PatchConfiguration) - - v1.GET("/servers", AuthHandler("c:list"), handleGetServers) - v1.POST("/servers", AuthHandler("c:create"), handlePostServers) - - v1ServerRoutes := v1.Group("/servers/:server") - { - v1ServerRoutes.GET("/", AuthHandler("s:get"), handleGetServer) - v1ServerRoutes.PATCH("/", AuthHandler("s:config"), handlePatchServer) - v1ServerRoutes.DELETE("/", AuthHandler("g:server:delete"), handleDeleteServer) - v1ServerRoutes.POST("/reinstall", AuthHandler("s:install-server"), handlePostServerReinstall) - v1ServerRoutes.POST("/rebuild", AuthHandler("g:server:rebuild"), handlePostServerRebuild) - v1ServerRoutes.POST("/password", AuthHandler(""), handlePostServerPassword) - v1ServerRoutes.POST("/power", AuthHandler("s:power"), handlePostServerPower) - v1ServerRoutes.POST("/command", AuthHandler("s:command"), handlePostServerCommand) - v1ServerRoutes.GET("/log", AuthHandler("s:console"), handleGetServerLog) - v1ServerRoutes.POST("/suspend", AuthHandler(""), handlePostServerSuspend) - v1ServerRoutes.POST("/unsuspend", AuthHandler(""), handlePostServerUnsuspend) - } - - //v1ServerFileRoutes := v1.Group("/servers/:server/files") - //{ - // v1ServerFileRoutes.GET("/file/:file", AuthHandler("s:files:read"), handleGetFile) - // v1ServerFileRoutes.GET("/stat/:file", AuthHandler("s:files:"), handleGetFileStat) - // v1ServerFileRoutes.GET("/dir/:directory", AuthHandler("s:files:get"), handleGetDirectory) - // - // v1ServerFileRoutes.POST("/dir/:directory", AuthHandler("s:files:create"), handlePostFilesFolder) - // v1ServerFileRoutes.POST("/file/:file", AuthHandler("s:files:post"), handlePostFile) - // - // v1ServerFileRoutes.POST("/copy/:file", AuthHandler("s:files:copy"), handlePostFileCopy) - // v1ServerFileRoutes.POST("/move/:file", AuthHandler("s:files:move"), handlePostFileMove) - // v1ServerFileRoutes.POST("/rename/:file", AuthHandler("s:files:move"), handlePostFileMove) - // v1ServerFileRoutes.POST("/compress/:file", AuthHandler("s:files:compress"), handlePostFileCompress) - // v1ServerFileRoutes.POST("/decompress/:file", AuthHandler("s:files:decompress"), handlePostFileDecompress) - // - // v1ServerFileRoutes.DELETE("/file/:file", AuthHandler("s:files:delete"), handleDeleteFile) - // - // v1ServerFileRoutes.GET("/download/:token", handleGetDownloadFile) - //} - } -} diff --git a/main.go b/main.go index 6aefe36..4e1e7e8 100644 --- a/main.go +++ b/main.go @@ -66,6 +66,6 @@ func run(cmd *cobra.Command, args []string) { } logrus.Info("Registering API server and booting.") - a := api.NewAPI() + a := api.InternalAPI{} a.Listen() }