-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpeer2profit.go
119 lines (110 loc) · 2.87 KB
/
peer2profit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"errors"
"runtime"
"github.com/docker/docker/api/types/container"
"github.com/rivo/tview"
"github.com/toqueteos/webbrowser"
)
const (
PEER2PROFIT_IMAGE_NAME = "enwaiax/peer2profit:latest"
PEER2PROFIT_REFERRAL_LINK = "https://t.me/peer2profit_app_bot?start=1671204644639c8f24d663c"
)
type Peer2ProfitConfig struct {
Email string
Configured bool
}
func (i *Peer2ProfitConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, app *tview.Application) {
email := ""
isError := false
showingError := false
form.AddInputField("Email", i.Email, 50, nil, func(text string) {
email = text
})
form.AddButton("Save", func() {
isError = stringIsEmpty(email)
if isError {
if !showingError {
form.AddTextView("Error", "All fields are required", 0, 1, true, true)
showingError = true
}
return
}
i.Email = email
i.Configured = true
returnToMenu(frame, app)
})
form.AddButton("Cancel", func() {
returnToMenu(frame, app)
})
form.AddButton("Register", func() {
modal := tview.NewModal().
SetText("Register on Peer2Profit\n" + PEER2PROFIT_REFERRAL_LINK).
AddButtons([]string{"Open", "Cancel"}).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
if buttonLabel == "Open" {
webbrowser.Open(PEER2PROFIT_REFERRAL_LINK)
}
app.SetRoot(form, true)
})
app.SetRoot(modal, true)
})
}
func (i *Peer2ProfitConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (string, error) {
switch kind {
case KIND_DOCKER_COMPOSE:
compose := `peer2profit:
image: ` + PEER2PROFIT_IMAGE_NAME + `
environment:
- email=` + i.Email + `
- use_proxy=false
restart: unless-stopped
platform: linux/amd64
`
if runtime.GOARCH == "arm64" {
return compose + `binfmt:
image: tonistiigi/binfmt:latest
privileged: true
command: --install all
restart: unless-stopped
`, nil
}
return compose, nil
case KIND_DIRECTLY_CONFIGURE_DOCKER:
if runtime.GOARCH == "arm64" {
containerConfig := &container.Config{
Image: "tonistiigi/binfmt:latest",
Env: []string{},
Cmd: []string{"--install", "all"},
}
hostConfig := &container.HostConfig{
Privileged: true,
RestartPolicy: container.RestartPolicy{
Name: "unless-stopped",
},
}
if err := createContainer("binfmt", containerConfig, hostConfig, form); err != nil {
return "", err
}
}
containerConfig := &container.Config{
Image: PEER2PROFIT_IMAGE_NAME,
Env: []string{
"email=" + i.Email,
"use_proxy=false",
},
}
hostConfig := &container.HostConfig{
RestartPolicy: container.RestartPolicy{
Name: "unless-stopped",
},
}
return "", createContainer("peer2profit", containerConfig, hostConfig, form)
}
return "", errors.New("unknown kind")
}
func (i *Peer2ProfitConfig) IsConfigured() bool {
return i.Configured
}
func (i *Peer2ProfitConfig) PostConfigure(form *tview.Form, app *tview.Application) {
}