-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
181 lines (153 loc) · 4.22 KB
/
main.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package main
import (
"fmt"
"log"
"os"
"os/user"
"github.com/getlantern/systray"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
var Urgency string
var Problem string
type SupportTicket struct {
Name string
Email string
Problem string
Urgency string
Complete chan struct{}
}
var supportChannel = make(chan *SupportTicket)
var supportWindowOpen bool = false
func main() {
systray.Run(onReady, onExit)
}
func onReady() {
log.Println("onReady executed")
systray.SetIcon(iconData)
systray.SetTitle("Support Tray")
systray.SetTooltip("Tactical RMM Support")
menuSupport := systray.AddMenuItem("Support", "Request support")
menuSupport.SetTooltip("Support Ticket")
go func() {
for {
select {
case <-menuSupport.ClickedCh:
log.Println("Support clicked")
OpenSupport()
}
}
}()
}
func onExit() {
}
func OpenSupport() {
if supportWindowOpen {
log.Println("Support window already open.")
return
}
supportWindowOpen = true
var mw *walk.MainWindow
var submitButton *walk.PushButton
icon, err := walk.NewIconFromResource("MYICON")
if err != nil {
log.Println("Error creating icon from resource:", err)
return
}
var nameLineEdit, emailLineEdit, problemTextEdit *walk.TextEdit
var urgencyComboBox *walk.ComboBox
validateFields := func(name, email, problem, urgency string) bool {
return name != "" && email != "" && problem != "" && urgency != ""
}
if err := (MainWindow{
AssignTo: &mw,
Title: "Support Ticket",
Icon: icon,
Size: Size{400, 300},
MinSize: Size{400, 300},
MaxSize: Size{400, 300},
Layout: VBox{},
Background: SolidColorBrush{Color: walk.RGB(255, 255, 255)},
Children: []Widget{
Label{
Text: "Tactical RMM Support",
Font: Font{
Bold: true,
Family: "Segoe UI",
PointSize: 10,
},
TextAlignment: AlignCenter,
MaxSize: Size{0, 20},
},
Label{Text: "Name:"},
TextEdit{AssignTo: &nameLineEdit},
Label{Text: "Email:"},
TextEdit{AssignTo: &emailLineEdit},
Label{Text: "Problem Description:"},
TextEdit{AssignTo: &problemTextEdit, MinSize: Size{100, 50}},
Label{Text: "Urgency:"},
ComboBox{
AssignTo: &urgencyComboBox,
Model: []string{"Low", "Medium", "High"},
},
PushButton{
AssignTo: &submitButton,
Text: "Submit",
OnClicked: func() {
name := nameLineEdit.Text()
email := emailLineEdit.Text()
problem := problemTextEdit.Text()
urgency := urgencyComboBox.Text()
Urgency = urgency
Problem = problem
if !validateFields(name, email, problem, urgency) {
walk.MsgBox(mw, "Support Ticket", "Please fill out all fields!", walk.MsgBoxIconError)
return
}
submitButton.SetEnabled(false)
nameLineEdit.SetReadOnly(true)
emailLineEdit.SetReadOnly(true)
problemTextEdit.SetReadOnly(true)
urgencyComboBox.SetEnabled(false)
hostname, err := os.Hostname()
if err != nil {
log.Println("Unable to retrieve hostname:", err)
hostname = "UnknownDevice"
}
SendAlert()
makeToast()
currentUser, err := user.Current()
loggedInUser := "UnknownUser"
if err == nil {
loggedInUser = currentUser.Username
}
ticket := fmt.Sprintf("Received ticket from %s (%s): %s - Urgency: %s", name, email, problem, urgency)
log.Println(ticket)
subject := hostname + " has requested assistance"
content := fmt.Sprintf("<b>Name:</b> %s<br><b>Email:</b> %s<br><b>Problem:</b> %s<br><b>Urgency:</b> %s<br><b>Logged in user:</b> %s<br><b>Device:</b> %s", name, email, problem, urgency, loggedInUser, hostname)
TriggerEmail(subject, content)
mw.Close()
},
},
Composite{
Layout: HBox{},
Children: []Widget{
HSpacer{},
PushButton{
Text: "Close",
OnClicked: func() {
mw.Close()
},
},
},
},
},
}).Create(); err != nil {
log.Println("Error creating main window:", err)
return
}
mw.Closing().Attach(func(canceled *bool, reason walk.CloseReason) {
supportWindowOpen = false
})
mw.Run()
}