-
Notifications
You must be signed in to change notification settings - Fork 34
/
menu.go
181 lines (166 loc) · 4.85 KB
/
menu.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 proxyutils
import (
"github.com/TeaWeb/code/teaconfigs"
"github.com/TeaWeb/code/teaweb/utils"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
)
// 添加服务器菜单
func AddServerMenu(actionWrapper actions.ActionWrapper) {
action := actionWrapper.Object()
// 选中代理
action.Data["teaMenu"] = "proxy"
// 子菜单
menuGroup := utils.NewMenuGroup()
// 服务
var hasServer = false
var isTCP = false
isIndex := !action.HasPrefix("/proxy/add", "/cache", "/proxy/waf", "/proxy/log/policies", "/proxy/certs")
serverId := action.ParamString("serverId")
serverList, err := teaconfigs.SharedServerList()
if err != nil {
logs.Error(err)
}
if isIndex {
menu := menuGroup.FindMenu("", "")
for _, server := range serverList.FindAllServers() {
urlPrefix := "/proxy/board"
if server.IsTCP() { // TCP
urlPrefix = "/proxy/detail"
} else { // HTTP
if action.HasPrefix("/proxy/stat") {
urlPrefix = "/proxy/stat"
} else if action.HasPrefix("/proxy/log") {
urlPrefix = "/proxy/log"
} else if action.HasPrefix("/proxy") && !action.HasPrefix("/proxy/board", "/proxy/add") {
urlPrefix = "/proxy/detail"
}
}
item := menu.Add(server.Description, "", urlPrefix+"?serverId="+server.Id, serverId == server.Id)
item.IsSortable = true
if server.IsTCP() {
item.SupName = "tcp"
}
if server.Id == serverId {
isTCP = server.IsTCP()
}
hasServer = true
}
if hasServer {
if action.Request.URL.Path == "/proxy/board" {
menu.Name = "代理服务"
} else {
menu.Name = "代理服务"
}
}
}
// 其他
{
menu := menuGroup.FindMenu("operations", "[操作]")
menu.AlwaysActive = true
menuGroup.AlwaysMenu = menu
menu.Add("代理服务", "", "/proxy", isIndex)
menu.Add("+添加新代理", "", "/proxy/add", action.Spec.ClassName == "proxy.AddAction", )
menu.Add("缓存策略", "", "/cache", action.HasPrefix("/cache"))
menu.Add("WAF策略", "", "/proxy/waf", action.HasPrefix("/proxy/waf"))
menu.Add("日志策略", "", "/proxy/log/policies", action.HasPrefix("/proxy/log/policies"))
menu.Add("SSL证书管理", "", "/proxy/certs", action.HasPrefix("/proxy/certs"))
}
utils.SetSubMenu(action, menuGroup)
// Tabbar
if hasServer {
if action.Spec.HasClassPrefix(
"proxy",
"ssl",
"locations",
"access.",
"fastcgi",
"rewrite",
"headers",
"backend",
"board",
"websocket",
"groups",
"stat.",
"log.",
"servers.",
"tunnel.",
) && !action.Spec.HasClassPrefix("proxy.AddAction", "log.RuntimeAction") {
if isTCP { // TCP
tabbar := []maps.Map{
{
"name": "设置",
"subName": "",
"url": "/proxy/detail?serverId=" + serverId,
"icon": "setting",
"active": !action.HasPrefix("/proxy/delete"),
},
{
"name": "删除",
"subName": "",
"url": "/proxy/delete?serverId=" + serverId,
"icon": "trash",
"active": action.HasPrefix("/proxy/delete"),
},
}
action.Data["teaTabbar"] = tabbar
} else { // HTTP
tabbar := []maps.Map{
{
"name": "看板",
"subName": "",
"url": "/proxy/board?serverId=" + serverId,
"active": action.HasPrefix("/proxy/board") && action.ParamString("boardType") != "stat",
"icon": "dashboard",
},
{
"name": "日志",
"subName": "",
"url": "/proxy/log?serverId=" + serverId,
"active": action.HasPrefix("/proxy/log"),
"icon": "history",
},
{
"name": "统计",
"subName": "",
"url": "/proxy/stat?serverId=" + serverId,
"active": action.HasPrefix("/proxy/stat") || (action.HasPrefix("/proxy/board") && action.ParamString("boardType") == "stat"),
"icon": "chart area",
},
{
"name": "设置",
"subName": "",
"url": "/proxy/detail?serverId=" + serverId,
"icon": "setting",
"active": action.Spec.HasClassPrefix("proxy", "ssl", "locations", "fastcgi", "rewrite", "headers", "backend", "websocket", "access", "servers", "tunnel") && !action.HasPrefix("/proxy/delete"),
},
{
"name": "删除",
"subName": "",
"url": "/proxy/delete?serverId=" + serverId,
"icon": "trash",
"active": action.HasPrefix("/proxy/delete"),
},
}
action.Data["teaTabbar"] = tabbar
}
}
}
}
// 包装Server相关数据
func WrapServerData(server *teaconfigs.ServerConfig) maps.Map {
return maps.Map{
"id": server.Id,
"description": server.Description,
"backends": server.Backends,
"headers": server.Headers,
"cachePolicy": server.CachePolicy,
"cacheOn": server.CacheOn,
"ssl": server.SSL,
"locations": server.Locations,
"wafOn": server.WAFOn,
"wafId": server.WafId,
"tunnelOn": server.Tunnel != nil && server.Tunnel.On,
}
}