/
zca.go
132 lines (109 loc) · 3.38 KB
/
zca.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
package main
import (
"crypto"
"crypto/x509"
"os"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/widgets"
)
type issuer struct {
key crypto.Signer
cert *x509.Certificate
}
var GlobalForm = ""
var GlobalCert = ""
func main() {
//if first run create config file and directories
CkConfig()
app := widgets.NewQApplication(len(os.Args), os.Args)
window := mkWindow(app)
mkgui(app, window)
app.Exec()
}
func mkWindow(app *widgets.QApplication) *widgets.QMainWindow {
window := widgets.NewQMainWindow(nil, 0)
window.SetMinimumSize2(800, 600)
window.SetWindowTitle("ZCA")
return window
}
func mkgui(app *widgets.QApplication, window *widgets.QMainWindow) *widgets.QVBoxLayout {
centralWidget := widgets.NewQWidget(nil, 0)
window.SetCentralWidget(centralWidget)
verticalLayout := widgets.NewQVBoxLayout()
toolbar := toolbarInit(app, window, widgets.NewQToolBar2(nil), centralWidget)
verticalLayout.SetMenuBar(toolbar)
centralWidget.SetLayout(verticalLayout)
// make the window visible
window.Show()
return verticalLayout
}
func toolbarInit(app *widgets.QApplication, window *widgets.QMainWindow, toolbar *widgets.QToolBar, centralWidget *widgets.QWidget) *widgets.QToolBar {
toolbar.SetToolButtonStyle(core.Qt__ToolButtonTextOnly)
toolbar.SetMovable(true)
label := widgets.NewQLabel2("Select Action", nil, 0)
toolbar.AddWidget(label)
newSelector := widgets.NewQComboBox(nil)
items := []string{"Select Action", "Create User Certificate", "List CA Certificates", "List Certificates", "New Root", "New Intermediate", "New Server/Client"}
newSelector.AddItems(items)
newSelector.ConnectCurrentTextChanged(func(text string) {
if text == "Create User Certificate" {
centralWidget.DeleteLater()
vlayout2 := mkgui(app, window)
vlayout2.AddLayout(showUserForm(app, window), 0)
GlobalForm = text
}
if text == "List CA Certificates" {
centralWidget.DeleteLater()
vlayout2 := mkgui(app, window)
vlayout2.AddLayout(listCACerts(app, window), 0)
GlobalForm = text
}
if text == "List Certificates" {
centralWidget.DeleteLater()
vlayout2 := mkgui(app, window)
vlayout2.AddLayout(listCerts(app, window), 0)
GlobalForm = text
}
if text == "New Root" {
centralWidget.DeleteLater()
vlayout2 := mkgui(app, window)
vlayout2.AddLayout(showCAForm(app, window), 0)
GlobalForm = "New Root"
}
if text == "New Intermediate" {
centralWidget.DeleteLater()
vlayout2 := mkgui(app, window)
vlayout2.AddLayout(showCAIntForm(app, window), 0)
GlobalForm = text
}
if text == "New Server/Client" {
centralWidget.DeleteLater()
vlayout2 := mkgui(app, window)
vlayout2.AddLayout(showServerForm(app, window), 0)
GlobalForm = "New Server/Client"
}
window.Show()
})
toolbar.AddWidget(newSelector)
// showCerts := widgets.NewQPushButton2("List Certs", nil)
// toolbar.AddWidget(showCerts)
// showCerts.ConnectClicked(func(checked bool) {
// if GlobalForm != "LC" {
// centralWidget.DeleteLater()
// vlayout2 := mkgui(app, window)
// vlayout2.AddLayout(listCerts(app, window), 0)
// GlobalForm = "LC"
// }
// })
showConfig := widgets.NewQPushButton2("Config", nil)
toolbar.AddWidget(showConfig)
showConfig.ConnectClicked(func(checked bool) {
if GlobalForm != "C" {
centralWidget.DeleteLater()
vlayout2 := mkgui(app, window)
vlayout2.AddLayout(configEdit(app, window), 0)
GlobalForm = "C"
}
})
return toolbar
}