-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
100 lines (82 loc) · 2.75 KB
/
ui.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
)
type Config struct {
CpanelAPIKey string `json:"cpanelAPIKey"`
CpanelHost string `json:"cpanelHost"`
DefaultForwardersDomain string `json:"defaultForwardersDomain"`
YourRealEmail string `json:yourRealEmail`
Domains []string `json:"domains"`
}
func loadConfig() (Config, error) {
config := Config{}
if config.CpanelAPIKey == "" || config.CpanelHost == "" || config.DefaultForwardersDomain == "" || len(config.Domains) == 0 || config.YourRealEmail == "" {
file, err := ioutil.ReadFile("config/config.json")
if err != nil {
return config, err
}
err = json.Unmarshal(file, &config)
if err != nil {
return config, err
}
}
return config, nil
}
func createUI(myWindow fyne.Window) *fyne.Container {
config, err := loadConfig()
if err != nil {
log.Fatalf("Error loading configuration: %v", err)
}
cpanelAPIKey := config.CpanelAPIKey
cpanelHost := config.CpanelHost
defaultForwardersDomain := config.DefaultForwardersDomain
yourRealEmail := config.YourRealEmail
domains := config.Domains
alias := ""
label1 := widget.NewLabel("alias:")
input := widget.NewEntry()
grid := container.New(layout.NewFormLayout(), label1, input)
defaultForwardersDomain = domains[0]
defaultEmail := yourRealEmail
domainSelect := widget.NewSelect(domains, func(selectedDomain string) {
defaultForwardersDomain = selectedDomain
})
domainSelect.SetSelected(defaultForwardersDomain)
content := container.NewVBox(
grid,
container.NewHBox(widget.NewLabel("Select Domain:"), domainSelect),
widget.NewButton("Create!", func() {
returnvalue := AddAlias(strings.ToLower(input.Text), cpanelHost, defaultForwardersDomain, cpanelAPIKey, defaultEmail)
alias = returnvalue
runPopUp(myWindow, fmt.Sprintf("%v", returnvalue), "Copy and Close", func() {
clipboard := myWindow.Clipboard()
clipboard.SetContent(alias)
})
log.Println("Content was:", input.Text)
}),
widget.NewButton("Search!", func() {
returnvalue := FindAlias(strings.ToLower(input.Text), cpanelHost, cpanelAPIKey, domains[domainSelect.SelectedIndex()])
runPopUp(myWindow, fmt.Sprintf("%v", returnvalue), "Close", func() {})
log.Println("Content was:", input.Text)
}),
widget.NewButton("Delete!", func() {
returnvalue := TrashAlias(strings.ToLower(input.Text), cpanelHost, defaultForwardersDomain, cpanelAPIKey, yourRealEmail)
if returnvalue == 200 {
runPopUp(myWindow, "Success!", "Close", func() {})
} else {
runPopUp(myWindow, "Fail!", "Close", func() {})
}
log.Println("Content was:", input.Text)
}),
)
return content
}