forked from TurboHsu/Vocab-Master
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
150 lines (123 loc) · 3.13 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
package main
import (
"flag"
"fmt"
"log"
"os"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"github.com/TurboHsu/Vocab-Master/aid"
"github.com/TurboHsu/Vocab-Master/automatic"
"github.com/TurboHsu/Vocab-Master/grab"
"github.com/lqqyt2423/go-mitmproxy/proxy"
)
const version = "1.2.0"
// Declare some global variable
var dataset grab.VocabDataset
var window fyne.Window
var toggle *widget.Check
var auto *widget.Button
var openBtn *widget.Button
var jsHijackCheck *widget.Check
// Declare some flags
var shouldOperateProxy bool = true
var jsHijack bool = false
// Initiate the flag parser
func init() {
flag.BoolVar(&shouldOperateProxy, "proxy", true, "Operates the system proxy when start and stop.")
}
func main() {
flag.Parse()
//DEBUG
//shouldOperateProxy = false
platform, err := GetPlatform()
if err != nil {
//Platform specific failed, use default
platform = GetDefaultPlatform()
}
//Init font
os.Setenv("FYNE_FONT", platform.Font)
var originStatus []ProxyState
if shouldOperateProxy {
log.Println("Processing proxy settings...")
//Get proxy
var err error
originStatus, err = ReadSystemStatus()
if err != nil {
panic(err)
}
//Set proxy
err = SetSystemProxy("localhost:38848")
if err != nil {
panic(err)
}
}
opts := &proxy.Options{
Addr: "0.0.0.0:38848",
StreamLargeBodies: 1024 * 1024 * 5,
CaRootPath: platform.CertDir,
}
p, err := proxy.NewProxy(opts)
if err != nil {
log.Fatal(err)
}
p.AddAddon(&VocabMasterHandler{})
a := app.New()
window = a.NewWindow("Vocab Master! " + version)
label := widget.NewLabel(
"Hey! Here is Vocab Master.\n" +
"Install this cert as trusted root: " + opts.CaRootPath + "\n" +
"Then start a class task, program will run itself ;)\n\n" +
"Project addr: github.com/TurboHsu/VocabMaster\n" +
"Font in use: " + platform.Font)
toggle = widget.NewCheck("Enable processor", func(b bool) {
IsEnabled = b
fmt.Println("Processor enabler is set to ", IsEnabled)
})
toggle.Checked = true
grabConsole := widget.NewButton("Database Console", func() {
grabWindow := grab.GenerateNewWindow(&a)
grabWindow.Show()
})
auto = widget.NewButton("Automation", func() {
autoWindow := automatic.GenerateNewWindow(&a)
autoWindow.Show()
})
jsHijackCheck = widget.NewCheck("Enable JS hijack", func(b bool) {
jsHijack = b
jsHijackCheck.Text = "Waiting for JS Hijacking..."
})
openBtn = widget.NewButton("Open certificates directory", func() {
platform.OpenCertDir()
})
aidConsoleBtn := widget.NewButton("Aid Console", func() {
aidWindow := aid.GenerateNewWindow(&a)
aidWindow.Show()
})
window.SetContent(
container.NewVBox(label,
container.NewHBox(toggle, jsHijackCheck),
container.NewHBox(openBtn, auto, grabConsole, aidConsoleBtn),
),
)
go p.Start()
window.ShowAndRun()
//Unset font
os.Unsetenv("FYNE_FONT")
if shouldOperateProxy {
//Unset proxy
err = ApplyProxyStatus(originStatus)
if err != nil {
panic(err)
}
}
}
func GetDefaultPlatform() Platform {
return Platform{
DataDir: ".",
CertDir: "./cert",
Font: "./font/red_bean.ttf",
}
}