-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
331 lines (296 loc) · 9.23 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
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
package main
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"image/color"
"proxy-node2more/config"
"proxy-node2more/utils"
"regexp"
"strconv"
"strings"
)
func main() {
app := app.New()
//theme := &ChineseWordTheme{}
//theme.SetFonts("./assets/font/msyh.ttf", "")
app.Settings().SetTheme(&CustomTheme{})
window := app.NewWindow("CDN节点快速提取替换工具")
window.Resize(fyne.NewSize(875, 590))
//全局配置
var globalConfig = config.AllConfig{
InputNodeStr: nil,
CDNName: 0,
CustomCDNIp: nil,
GetMethodName: 0,
WantedNodeNum: 100,
OutPutNodeList: nil,
}
//输入节点
nodeinput := widget.NewMultiLineEntry()
nodeinput.SetPlaceHolder("请输入Vmess/Trojan/Vless节点分享链接...\n请确保输入的节点已经套用了CDN,并且能正常使用.")
nodeinput.SetMinRowsVisible(8)
inputNodeLabel := widget.NewLabel("原始节点: ")
inputNodeLabel.Resize(fyne.NewSize(400, 400))
inputContainer := container.New(layout.NewFormLayout(), inputNodeLabel, nodeinput)
//自定义CDN ip列表输入框
customCdnIpLabel := widget.NewLabel("CDN IP列表: ")
customCdnIpInput := widget.NewMultiLineEntry()
customCdnIpInput.SetPlaceHolder("192.168.1.1\n172.3.5.2")
customCdnIpInput.SetMinRowsVisible(8)
customIpContainer := container.New(layout.NewFormLayout(), customCdnIpLabel, customCdnIpInput)
//默认设置为不可输入
customCdnIpInput.Disable()
//选择栏
cdnProviderLabel := widget.NewLabel("CDN提供商: ")
var cdnProvider = []string{"Cloudflare", "CloudFront", "Gcore", "自定义"}
cdnSelectList := widget.NewSelect(cdnProvider, func(value string) {
fmt.Println("CDN Provider你选择了: ", value)
var tempValue config.CdnProvider = 0
if value == "Cloudflare" {
tempValue = config.CDNCloudflare
if !customCdnIpInput.Disabled() {
customCdnIpInput.Disable()
customIpContainer.Refresh()
}
}
if value == "CloudFront" {
tempValue = config.CDNCloudFront
if !customCdnIpInput.Disabled() {
customCdnIpInput.Disable()
customIpContainer.Refresh()
}
}
if value == "Gcore" {
tempValue = config.CDNGcore
if !customCdnIpInput.Disabled() {
customCdnIpInput.Disable()
customIpContainer.Refresh()
}
}
if value == "自定义" {
tempValue = config.CDNOther
if customCdnIpInput.Disabled() {
customCdnIpInput.Enable()
customIpContainer.Refresh()
}
}
globalConfig.CDNName = tempValue
})
cdnSelectList.Selected = "Cloudflare"
cdnSelectList.Alignment = fyne.TextAlignCenter
//获取方式
getMethodLabel := widget.NewLabel("获取方式: ")
var getMethodProvider = []string{"顺序", "随机"}
getMethodList := widget.NewSelect(getMethodProvider, func(value string) {
fmt.Println("你选择了: ", value)
var tempValue config.GetMethod = 0
if value == "顺序" {
tempValue = config.GetMethodSequance
}
if value == "随机" {
tempValue = config.GetMethodRandom
}
globalConfig.GetMethodName = tempValue
})
getMethodList.Selected = "顺序"
getMethodList.Alignment = fyne.TextAlignCenter
//获取节点数
getNodeNumLabel := widget.NewLabel("获取节点数(一个原始节点): ")
inputNodeNum := widget.NewEntry()
inputNodeNum.SetText("100")
inputNodeNum.SetMinRowsVisible(10)
inputNodeNum.OnChanged = func(value string) {
fmt.Println("GetNodeNum 你输入了: ", value)
number, err := strconv.Atoi(value)
if err != nil {
fmt.Println("格式输入错误: ", err.Error())
return
}
globalConfig.WantedNodeNum = number
}
//提交按钮
subButton := widget.NewButton("↓点击提取节点↓", func() {
})
selectContainer := container.New(layout.NewHBoxLayout(),
cdnProviderLabel, cdnSelectList,
getMethodLabel, getMethodList,
getNodeNumLabel, inputNodeNum, subButton)
//输出
textarea := widget.NewMultiLineEntry()
textarea.SetMinRowsVisible(8)
outPutNodes := widget.NewLabel("节点列表: ")
outPutContainer := container.New(layout.NewFormLayout(), outPutNodes, textarea)
window.SetContent(container.New(layout.NewVBoxLayout(),
inputContainer,
customIpContainer,
selectContainer,
outPutContainer,
))
subButton.OnTapped = func() {
text := textarea.Text
//清空
if text != "" {
textarea.SetText("")
}
fmt.Println("提交按钮已点击")
//获取输入框内容
var nodeInpputStr = nodeinput.Text
//nodeInpputStr = strings.ReplaceAll(nodeInpputStr, " ", "")
//nodeInpputStr = strings.ReplaceAll(nodeInpputStr, "\t", "")
//nodeInpputStr = strings.ReplaceAll(nodeInpputStr, "\n", "")
//process nodeinputStr
var nodes []string
if strings.Contains(nodeInpputStr, "vmess://") {
pattern := "vmess://[\\w\\d\\+\\/=]+"
// Compile the regular expression pattern
regex := regexp.MustCompile(pattern)
// Find all the matches in the input string
matches := regex.FindAllString(nodeInpputStr, -1)
// Print the matches
for _, match := range matches {
//fmt.Printf("Match %d: %s\n", i+1, match)
nodes = append(nodes, match)
//移除
nodeInpputStr = strings.ReplaceAll(nodeInpputStr, match, "")
}
}
if strings.Contains(nodeInpputStr, "vless://") {
re := regexp.MustCompile(`vless://[^\s]+`)
matches := re.FindAllString(nodeInpputStr, -1)
// Print the matches
for _, match := range matches {
//fmt.Printf("Match %d: %s\n", i+1, match)
nodes = append(nodes, match)
//移除
nodeInpputStr = strings.ReplaceAll(nodeInpputStr, match, "")
}
}
if strings.Contains(nodeInpputStr, "trojan") {
//extract trojan nodes
re := regexp.MustCompile(`trojan://[^\s]+`)
matches := re.FindAllString(nodeInpputStr, -1)
for _, match := range matches {
//fmt.Printf("Match %d: %s\n", i+1, match)
nodes = append(nodes, match)
//移除
nodeInpputStr = strings.ReplaceAll(nodeInpputStr, match, "")
}
}
if nodes == nil {
textarea.SetText("请输入合法的节点分享链接!")
return
}
globalConfig.InputNodeStr = nodes
fmt.Println(nodeInpputStr)
//获取cdn类型
//自定义cdn
if globalConfig.CDNName == 3 {
customCdns := customCdnIpInput.Text
split := strings.Split(customCdns, "\n")
var resultCdnIps []string
for _, line := range split {
ip := strings.TrimSpace(line)
resultCdnIps = append(resultCdnIps, ip)
}
fmt.Println(customCdns)
globalConfig.CustomCDNIp = resultCdnIps
}
nodesResult, err := utils.CaculateNodesResult(&globalConfig)
if err != nil {
fmt.Println("程序运行出错: ", err.Error())
textarea.SetText(err.Error())
} else {
nodeList := nodesResult.OutPutNodeList
resultStr := strings.Join(nodeList, "\n")
//更新界面
textarea.SetText(resultStr)
}
}
window.ShowAndRun()
}
// CustomTheme 参考自: https://github.com/lusingander/fyne-font-example
type CustomTheme struct{}
func (t *CustomTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color {
return theme.DefaultTheme().Color(name, variant)
}
func (t *CustomTheme) Icon(name fyne.ThemeIconName) fyne.Resource {
return theme.DefaultTheme().Icon(name)
}
func (t *CustomTheme) Size(name fyne.ThemeSizeName) float32 {
return theme.DefaultTheme().Size(name)
}
func (*CustomTheme) Font(s fyne.TextStyle) fyne.Resource {
if s.Monospace {
return theme.DefaultTheme().Font(s)
}
if s.Bold {
if s.Italic {
return theme.DefaultTheme().Font(s)
}
return ResourceMsyhTtf
}
if s.Italic {
return theme.DefaultTheme().Font(s)
}
return ResourceMsyhTtf
}
// ChineseWordTheme 自定义主题支持中文显示 deprecated
type ChineseWordTheme struct {
regular, bold, italic, boldItalic, monospace fyne.Resource
}
func (cwt *ChineseWordTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color {
return theme.DefaultTheme().Color(name, variant)
}
func (cwt *ChineseWordTheme) Icon(name fyne.ThemeIconName) fyne.Resource {
return theme.DefaultTheme().Icon(name)
}
func (cwt *ChineseWordTheme) Font(style fyne.TextStyle) fyne.Resource {
if style.Monospace {
return cwt.monospace
}
if style.Bold {
if style.Italic {
return cwt.boldItalic
}
return cwt.bold
}
if style.Italic {
return cwt.italic
}
return cwt.regular
}
func (cwt *ChineseWordTheme) Size(name fyne.ThemeSizeName) float32 {
return theme.DefaultTheme().Size(name)
}
func (cwt *ChineseWordTheme) SetFonts(regularFontPath string, monoFontPath string) {
cwt.regular = theme.TextFont()
cwt.bold = theme.TextBoldFont()
cwt.italic = theme.TextItalicFont()
cwt.boldItalic = theme.TextBoldItalicFont()
cwt.monospace = theme.TextMonospaceFont()
if regularFontPath != "" {
cwt.regular = loadCustomFont(regularFontPath, "Regular", cwt.regular)
cwt.bold = loadCustomFont(regularFontPath, "Bold", cwt.bold)
cwt.italic = loadCustomFont(regularFontPath, "Italic", cwt.italic)
cwt.boldItalic = loadCustomFont(regularFontPath, "BoldItalic", cwt.boldItalic)
}
if monoFontPath != "" {
cwt.monospace = loadCustomFont(monoFontPath, "Regular", cwt.monospace)
} else {
cwt.monospace = cwt.regular
}
}
func loadCustomFont(env, variant string, fallback fyne.Resource) fyne.Resource {
variantPath := strings.Replace(env, "Regular", variant, -1)
res, err := fyne.LoadResourceFromPath(variantPath)
if err != nil {
fyne.LogError("Error loading specified font", err)
return fallback
}
return res
}