-
Notifications
You must be signed in to change notification settings - Fork 2
/
honeygain.go
111 lines (103 loc) · 2.72 KB
/
honeygain.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
package main
import (
"errors"
"github.com/docker/docker/api/types/container"
"github.com/rivo/tview"
"github.com/toqueteos/webbrowser"
)
const (
HONEYGAIN_IMAGE_NAME = "honeygain/honeygain:latest"
HONEYGAIN_REFERRAL_LINK = "https://r.honeygain.me/SAMUEC73"
)
type HoneygainConfig struct {
DeviceName string
Email string
Password string
Configured bool
}
func (i *HoneygainConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, app *tview.Application) {
email := ""
password := ""
deviceName := ""
isError := false
showingError := false
form.AddInputField("Device Name", i.DeviceName, 15, nil, func(text string) {
deviceName = text
})
form.AddInputField("Email", i.Email, 50, nil, func(text string) {
email = text
})
form.AddPasswordField("Password", i.Password, 20, '*', func(text string) {
password = text
})
form.AddButton("Save", func() {
isError = stringIsEmpty(email) || stringIsEmpty(password) || stringIsEmpty(deviceName)
if isError {
if !showingError {
form.AddTextView("Error", "All fields are required", 0, 1, true, true)
showingError = true
}
return
}
i.Email = email
i.Password = password
i.DeviceName = deviceName
i.Configured = true
returnToMenu(frame, app)
})
form.AddButton("Cancel", func() {
returnToMenu(frame, app)
})
form.AddButton("Register", func() {
modal := tview.NewModal().
SetText("Register on Honeygain\n" + HONEYGAIN_REFERRAL_LINK).
AddButtons([]string{"Open", "Cancel"}).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
if buttonLabel == "Open" {
webbrowser.Open(HONEYGAIN_REFERRAL_LINK)
}
app.SetRoot(form, true)
})
app.SetRoot(modal, true)
})
}
func (i *HoneygainConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (string, error) {
switch kind {
case KIND_DOCKER_COMPOSE:
return `honeygain:
image: ` + HONEYGAIN_IMAGE_NAME + `
restart: unless-stopped
environment:
- HONEYGAIN_DUMMY=''
command: -tou-accept -email ` + i.Email + ` -pass ` + i.Password + ` -device ` + i.DeviceName + "\n", nil
case KIND_DIRECTLY_CONFIGURE_DOCKER:
hostConfig := &container.HostConfig{
RestartPolicy: container.RestartPolicy{
Name: "unless-stopped",
},
}
containerConfig := &container.Config{
Image: HONEYGAIN_IMAGE_NAME,
Env: []string{
"HONEYGAIN_DUMMY=",
},
Cmd: []string{
"-tou-accept",
"-email",
i.Email,
"-pass",
i.Password,
"-device",
i.DeviceName,
},
}
return "", createContainer("honeygain", containerConfig, hostConfig, form)
default:
return "", errors.New("unknown kind")
}
}
func (i *HoneygainConfig) IsConfigured() bool {
return i.Configured
}
func (i *HoneygainConfig) PostConfigure(form *tview.Form, app *tview.Application) {
}