-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
311 lines (276 loc) · 8.4 KB
/
main.go
File metadata and controls
311 lines (276 loc) · 8.4 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
package main
import (
"bufio"
"encoding/csv"
"fmt"
"image/color"
"os"
"reflect"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
"fish666/api"
// "fish666/theme"
"fish666/tool"
"fish666/views"
)
var proxyList api.ProxyList
var myapp fyne.App
var mywindow fyne.Window
func init() {
proxyList = api.ProxyList{
NoProxy: "",
Local: fmt.Sprintf("%s:%s", tool.ReadIni("local_proxy", "host"), tool.ReadIni("local_proxy", "port")),
Alpha: fmt.Sprintf("%s:%s", tool.ReadIni("alpha_proxy", "host"), tool.ReadIni("alpha_proxy", "port")),
Beta: fmt.Sprintf("%s:%s", tool.ReadIni("beta_proxy", "host"), tool.ReadIni("beta_proxy", "port")),
Gamma: fmt.Sprintf("%s:%s", tool.ReadIni("gamma_proxy", "host"), tool.ReadIni("gamma_proxy", "port")),
}
fmt.Println(proxyList)
}
func main() {
os.Setenv("FYNE_FONT", "./fonts/"+tool.ReadIni("ui", "font"))
myapp = app.New()
// myapp.Settings().SetTheme(&theme.MyTheme{})
mywindow = myapp.NewWindow("GUI Program")
mywindow.SetContent(UI(mywindow))
mywindow.Resize(fyne.NewSize(1280, 600))
mywindow.ShowAndRun()
}
func Alert(str string) {
dialog.ShowInformation("Alert", str, mywindow)
}
func GetCsvSlices(old [][7]string) [][]string {
ret := make([][]string, len(old))
for i := range old {
ret[i] = make([]string, len(old[i]))
for j := range old[i] {
if old[i][j] == "" {
ret[i][j] = "0"
} else {
ret[i][j] = old[i][j]
}
}
}
return ret
}
func UI(window fyne.Window) *fyne.Container {
table := api.TableData{
TopTableItems: [][7]string{{"website", "all", "hour", "day", "week", "month", "year"}},
TableItems: [][7]string{},
}
searchTypeArr := []string{"any", "url"}
searchTimeArr := []string{"all", "hour", "day", "week", "month", "year"}
wordEntry := widget.NewEntry()
wordEntry.SetPlaceHolder("Plase entry keywords")
wordEntry.SetText(tool.ReadIni("ui", "default_word"))
websiteEntry := widget.NewEntry()
websiteEntry.SetPlaceHolder("Plase entry the website address")
websiteEntry.SetText(tool.ReadIni("ui", "default_web"))
searchTypeSelect := widget.NewSelect(searchTypeArr, nil)
searchTypeSelect.SetSelectedIndex(tool.GetKeyIndex(searchTypeArr, tool.ReadIni("ui", "default_type")))
searchTimeSelect := widget.NewSelect(searchTimeArr, nil)
searchTimeSelect.SetSelectedIndex(tool.GetKeyIndex(searchTimeArr, tool.ReadIni("ui", "default_time")))
proxyArray := make([]string, 0)
t := reflect.TypeOf(proxyList)
if t.Kind() == reflect.Struct {
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
proxyArray = append(proxyArray, field.Name)
}
}
proxySelect := widget.NewSelect(proxyArray, nil)
proxySelect.SetSelectedIndex(tool.GetKeyIndex(proxyArray, tool.ReadIni("ui", "default_proxy")))
test := canvas.NewText("aa", color.White)
test.TextSize = 2
dosort := true
var tableBody *widget.Table
tableTop := widget.NewTable(
func() (int, int) { return len(table.TopTableItems), len(table.TopTableItems[0]) },
func() fyne.CanvasObject {
button := widget.NewButton("TestTestTestTestTest", nil)
return button
},
func(tci widget.TableCellID, co fyne.CanvasObject) {
button := co.(*widget.Button)
button.SetText(table.TopTableItems[0][tci.Col])
button.OnTapped = func() {
if tci.Row == 0 && tci.Col > 0 {
// 开始排序
fmt.Printf("开始排序:%d", tci.Col)
dosort = !dosort
if dosort {
table.Ascend(tci.Col)
} else {
table.Descend(tci.Col)
}
tableBody.Refresh()
}
}
},
)
fmt.Printf("minisize: %.2f, %.2f\n", tableTop.MinSize().Width, tableTop.MinSize().Height)
// tableTop.SetRowHeight(0, 35)
tableTop.SetColumnWidth(0, 200)
tableBody = widget.NewTable(
func() (int, int) { return len(table.TableItems), len(table.TableItems[0]) },
func() fyne.CanvasObject {
return widget.NewLabel("TestTestTestTestTestTest")
},
func(tci widget.TableCellID, co fyne.CanvasObject) {
var itemData string
if itemData = table.TableItems[tci.Row][tci.Col]; itemData == "" {
itemData = "0"
}
co.(*widget.Label).SetText(itemData)
},
)
tableBody.SetColumnWidth(0, 200)
tableBody.SetColumnWidth(1, tableTop.MinSize().Width)
tableBody.SetColumnWidth(2, tableTop.MinSize().Width)
tableBody.SetColumnWidth(3, tableTop.MinSize().Width)
tableBody.SetColumnWidth(4, tableTop.MinSize().Width)
tableBody.SetColumnWidth(5, tableTop.MinSize().Width)
tableBody.SetColumnWidth(6, tableTop.MinSize().Width)
// tableBox := container.NewVBox(tableTop, tableBody)
tableBox := container.NewVScroll(tableBody)
tableBox.SetMinSize(fyne.NewSize(800, 300))
ml := views.NewMyLogs()
openFileButton := dialog.NewFileOpen(func(uc fyne.URIReadCloser, err error) {
if err != nil || uc == nil {
fmt.Println("Read file failed.")
return
}
filePath := uc.URI().Path()
fmt.Printf("Path: %s", filePath)
if filePath[len(filePath)-4:] != ".txt" {
fmt.Println("no txt")
return
}
fmt.Println("selected: " + filePath)
file, err := os.Open(filePath)
if err != nil {
fmt.Println("Open file failed.")
return
}
defer file.Close()
// 清空列表
table.Clean()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if line == "" {
continue
}
table.TableItems = append(table.TableItems, [7]string{line})
}
tableBody.Refresh()
if scanner.Err() != nil {
fmt.Println("Read line filed.")
}
websiteEntry.SetText("")
}, window)
form := &widget.Form{
Items: []*widget.FormItem{
{Text: "Word", Widget: wordEntry},
{Text: "Time", Widget: searchTimeSelect},
{Text: "Web", Widget: websiteEntry},
{Text: "", Widget: widget.NewButton("Import", func() {
openFileButton.Show()
})},
{Text: "Type", Widget: searchTypeSelect},
{Text: "Proxy", Widget: proxySelect},
{Text: "", Widget: tableTop},
{Text: "", Widget: tableBox},
// {Text: "", Widget: tableBody},
{Text: "", Widget: widget.NewButton("Export", func() {
file, err := os.Create("output.csv")
if err != nil {
fmt.Println("output.csv create failed.")
return
}
defer file.Close()
writer := csv.NewWriter(file)
err = writer.WriteAll(GetCsvSlices(table.TableItems))
if err != nil {
Alert("output.csv writeall failed.")
return
}
writer.Flush()
if err := writer.Error(); err != nil {
Alert("output.csv flush failed.")
return
}
ml.Info("Export out.csv success.")
Alert("Export out.csv success.")
})},
{Text: "Logs", Widget: ml.GetView()},
},
OnSubmit: func() {
// 反射获取代理映射值
ml.Info("Start Search")
proxyText := reflect.ValueOf(proxyList).FieldByName(proxySelect.Selected).Interface().(string)
if websiteEntry.Text != "" && strings.Contains(websiteEntry.Text, ".") {
table.Clean()
table.TableItems = append(table.TableItems, [7]string{websiteEntry.Text})
tableBody.Refresh()
}
go func() {
for index := 0; index < len(table.TableItems); index++ {
curweb := table.TableItems[index][0]
ml.Info(fmt.Sprintf("[+] index: [%d];web: [%s]", index, curweb))
para := api.UIParameter{
Word: wordEntry.Text,
Time: searchTimeSelect.Selected,
Web: curweb,
Type: searchTypeSelect.Selected,
Proxy: proxyText,
}
api.GetSearchRet(para, func(s string, err error) {
if err != nil || s == "" {
ml.Info(fmt.Sprintf("[!] index: [%d];web: [%s]; search failed.", index, curweb))
ml.Info(fmt.Sprintf("[!] error: %s", err.Error()))
return
}
s = strings.ReplaceAll(s, ",", "")
fmt.Printf("i: %d\n", index)
switch para.Time {
case "all":
table.TableItems[index][1] = s
case "hour":
table.TableItems[index][2] = s
case "day":
table.TableItems[index][3] = s
case "week":
table.TableItems[index][4] = s
case "month":
table.TableItems[index][5] = s
case "year":
table.TableItems[index][6] = s
}
tableBody.Refresh()
fmt.Println("[*] 搜索完成.")
ml.Info(fmt.Sprintf("[+] index: [%d];web: [%s]; search success.", index, curweb))
})
}
Alert("Searched.")
}()
},
OnCancel: func() {
wordEntry.SetText("")
websiteEntry.SetText("")
ml.Cancel()
// table.Clean()
// table.TableItems = append(table.TableItems, [7]string{})
// tableBody.Refresh()
ml.Info("Cancel all")
// 清除表格
},
}
return container.NewVBox(
form,
)
}