Skip to content

Commit 4d1d16b

Browse files
committed
Codespace
1 parent 1972bb3 commit 4d1d16b

File tree

120 files changed

+19359
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+19359
-0
lines changed

Makefile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
GIT_HEAD = $(shell git rev-parse HEAD | head -c8)
2+
3+
build:
4+
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -gcflags "all=-trimpath=$(pwd)" -o build/wings_linux_amd64 -v wings.go
5+
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -gcflags "all=-trimpath=$(pwd)" -o build/wings_linux_arm64 -v wings.go
6+
7+
debug:
8+
go build -ldflags="-X github.com/pterodactyl/wings/system.Version=$(GIT_HEAD)"
9+
sudo ./wings --debug --ignore-certificate-errors --config config.yml --pprof --pprof-block-rate 1
10+
11+
# Runs a remotly debuggable session for Wings allowing an IDE to connect and target
12+
# different breakpoints.
13+
rmdebug:
14+
go build -gcflags "all=-N -l" -ldflags="-X github.com/pterodactyl/wings/system.Version=$(GIT_HEAD)" -race
15+
sudo dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./wings -- --debug --ignore-certificate-errors --config config.yml
16+
17+
cross-build: clean build compress
18+
19+
clean:
20+
rm -rf build/wings_*
21+
22+
.PHONY: all build compress clean

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Please note that this is pre-release software; it may contain bugs or corrupt data – it should not be used on a production site.
2+
> Please be sure to back up all files and database content prior to using this pre-release software. <b>Use at your own risk!</b>
3+
4+
## Known issues
5+
- We cannot easily show disk usage of a persistent volume
6+
- Kubernetes metrics server does not have an implemented method to view network usage
7+
- Pterodactyl panel nodes and allocations systems must be modified to be compatible with Kubernetes
8+
9+
## Goals of the project
10+
- Self-healing servers.
11+
- Kubernetes multi-cluster environments that gives you: users and/or projects isolation by cluster, transfer servers to another cluster, simplified management, failover and much more ...
12+
13+
## How can I help the project?
14+
Report problems you faced. Merge requests are also welcome :)
15+
16+
## License
17+
Code released under the [MIT License](https://github.com/kubectyl/kuber/blob/develop/LICENSE).

build/wings_linux_amd64

47.5 MB
Binary file not shown.

build/wings_linux_arm64

45.9 MB
Binary file not shown.

cmd/configure.go

+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
package cmd
2+
3+
import (
4+
"crypto/tls"
5+
"fmt"
6+
"io"
7+
"net/http"
8+
"net/url"
9+
"os"
10+
"path"
11+
"regexp"
12+
"time"
13+
14+
"github.com/AlecAivazis/survey/v2"
15+
"github.com/AlecAivazis/survey/v2/terminal"
16+
"github.com/goccy/go-json"
17+
"github.com/spf13/cobra"
18+
19+
"github.com/pterodactyl/wings/config"
20+
)
21+
22+
var configureArgs struct {
23+
PanelURL string
24+
Token string
25+
ConfigPath string
26+
Node string
27+
Override bool
28+
AllowInsecure bool
29+
}
30+
31+
var nodeIdRegex = regexp.MustCompile(`^(\d+)$`)
32+
33+
var configureCmd = &cobra.Command{
34+
Use: "configure",
35+
Short: "Use a token to configure wings automatically",
36+
Run: configureCmdRun,
37+
}
38+
39+
func init() {
40+
configureCmd.PersistentFlags().StringVarP(&configureArgs.PanelURL, "panel-url", "p", "", "The base URL for this daemon's panel")
41+
configureCmd.PersistentFlags().StringVarP(&configureArgs.Token, "token", "t", "", "The API key to use for fetching node information")
42+
configureCmd.PersistentFlags().StringVarP(&configureArgs.Node, "node", "n", "", "The ID of the node which will be connected to this daemon")
43+
configureCmd.PersistentFlags().StringVarP(&configureArgs.ConfigPath, "config-path", "c", config.DefaultLocation, "The path where the configuration file should be made")
44+
configureCmd.PersistentFlags().BoolVar(&configureArgs.Override, "override", false, "Set to true to override an existing configuration for this node")
45+
configureCmd.PersistentFlags().BoolVar(&configureArgs.AllowInsecure, "allow-insecure", false, "Set to true to disable certificate checking")
46+
}
47+
48+
func configureCmdRun(cmd *cobra.Command, args []string) {
49+
if configureArgs.AllowInsecure {
50+
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{
51+
InsecureSkipVerify: true,
52+
}
53+
}
54+
55+
if _, err := os.Stat(configureArgs.ConfigPath); err == nil && !configureArgs.Override {
56+
survey.AskOne(&survey.Confirm{Message: "Override existing configuration file"}, &configureArgs.Override)
57+
if !configureArgs.Override {
58+
fmt.Println("Aborting process; a configuration file already exists for this node.")
59+
os.Exit(1)
60+
}
61+
} else if err != nil && !os.IsNotExist(err) {
62+
panic(err)
63+
}
64+
65+
var questions []*survey.Question
66+
if configureArgs.PanelURL == "" {
67+
questions = append(questions, &survey.Question{
68+
Name: "PanelURL",
69+
Prompt: &survey.Input{Message: "Panel URL: "},
70+
Validate: func(ans interface{}) error {
71+
if str, ok := ans.(string); ok {
72+
_, err := url.ParseRequestURI(str)
73+
return err
74+
}
75+
return nil
76+
},
77+
})
78+
}
79+
80+
if configureArgs.Token == "" {
81+
questions = append(questions, &survey.Question{
82+
Name: "Token",
83+
Prompt: &survey.Input{Message: "API Token: "},
84+
Validate: func(ans interface{}) error {
85+
if str, ok := ans.(string); ok {
86+
if len(str) == 0 {
87+
return fmt.Errorf("please provide a valid authentication token")
88+
}
89+
}
90+
return nil
91+
},
92+
})
93+
}
94+
95+
if configureArgs.Node == "" {
96+
questions = append(questions, &survey.Question{
97+
Name: "Node",
98+
Prompt: &survey.Input{Message: "Node ID: "},
99+
Validate: func(ans interface{}) error {
100+
if str, ok := ans.(string); ok {
101+
if !nodeIdRegex.Match([]byte(str)) {
102+
return fmt.Errorf("please provide a valid authentication token")
103+
}
104+
}
105+
return nil
106+
},
107+
})
108+
}
109+
110+
if err := survey.Ask(questions, &configureArgs); err != nil {
111+
if err == terminal.InterruptErr {
112+
return
113+
}
114+
115+
panic(err)
116+
}
117+
118+
c := &http.Client{
119+
Timeout: time.Second * 30,
120+
}
121+
122+
req, err := getRequest()
123+
if err != nil {
124+
panic(err)
125+
}
126+
127+
fmt.Printf("%+v", req.Header)
128+
fmt.Printf(req.URL.String())
129+
130+
res, err := c.Do(req)
131+
if err != nil {
132+
fmt.Println("Failed to fetch configuration from the panel.\n", err.Error())
133+
os.Exit(1)
134+
}
135+
defer res.Body.Close()
136+
137+
if res.StatusCode == http.StatusForbidden || res.StatusCode == http.StatusUnauthorized {
138+
fmt.Println("The authentication credentials provided were not valid.")
139+
os.Exit(1)
140+
} else if res.StatusCode != http.StatusOK {
141+
b, _ := io.ReadAll(res.Body)
142+
143+
fmt.Println("An error occurred while processing this request.\n", string(b))
144+
os.Exit(1)
145+
}
146+
147+
b, err := io.ReadAll(res.Body)
148+
149+
cfg, err := config.NewAtPath(configPath)
150+
if err != nil {
151+
panic(err)
152+
}
153+
154+
if err := json.Unmarshal(b, cfg); err != nil {
155+
panic(err)
156+
}
157+
158+
if err = config.WriteToDisk(cfg); err != nil {
159+
panic(err)
160+
}
161+
162+
fmt.Println("Successfully configured wings.")
163+
}
164+
165+
func getRequest() (*http.Request, error) {
166+
u, err := url.Parse(configureArgs.PanelURL)
167+
if err != nil {
168+
panic(err)
169+
}
170+
171+
u.Path = path.Join(u.Path, fmt.Sprintf("api/application/nodes/%s/configuration", configureArgs.Node))
172+
173+
r, err := http.NewRequest(http.MethodGet, u.String(), nil)
174+
if err != nil {
175+
return nil, err
176+
}
177+
178+
r.Header.Set("Accept", "application/vnd.pterodactyl.v1+json")
179+
r.Header.Set("Content-Type", "application/json")
180+
r.Header.Set("Authorization", fmt.Sprintf("Bearer %s", configureArgs.Token))
181+
182+
return r, nil
183+
}

0 commit comments

Comments
 (0)