Files
EdgeAdmin/internal/web/actions/default/servers/server/settings/reverseProxy/index.go

126 lines
4.1 KiB
Go
Raw Normal View History

2020-08-21 21:09:42 +08:00
package reverseProxy
import (
2020-09-15 14:44:52 +08:00
"encoding/json"
2020-08-21 21:09:42 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2020-09-15 14:44:52 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
2020-08-21 21:09:42 +08:00
)
// IndexAction 源站列表
2020-08-21 21:09:42 +08:00
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
2020-09-15 14:44:52 +08:00
this.FirstMenu("index")
2020-08-21 21:09:42 +08:00
}
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
2020-09-21 11:37:24 +08:00
serverTypeResp, err := this.RPC().ServerRPC().FindEnabledServerType(this.AdminContext(), &pb.FindEnabledServerTypeRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
2020-09-15 14:44:52 +08:00
return
}
2022-06-29 21:56:44 +08:00
var serverType = serverTypeResp.Type
2020-09-15 14:44:52 +08:00
// 当前是否有分组设置
groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["hasGroupConfig"] = false
this.Data["groupSettingURL"] = ""
switch serverType {
case serverconfigs.ServerTypeHTTPWeb, serverconfigs.ServerTypeHTTPProxy:
this.Data["hasGroupConfig"] = groupResp.HasHTTPReverseProxy
if groupResp.ServerGroupId > 0 {
this.Data["groupSettingURL"] = "/servers/groups/group/settings/httpReverseProxy?groupId=" + types.String(groupResp.ServerGroupId)
}
case serverconfigs.ServerTypeTCPProxy:
this.Data["hasGroupConfig"] = groupResp.HasTCPReverseProxy
if groupResp.ServerGroupId > 0 {
this.Data["groupSettingURL"] = "/servers/groups/group/settings/tcpReverseProxy?groupId=" + types.String(groupResp.ServerGroupId)
}
case serverconfigs.ServerTypeUDPProxy:
this.Data["hasGroupConfig"] = groupResp.HasUDPReverseProxy
if groupResp.ServerGroupId > 0 {
this.Data["groupSettingURL"] = "/servers/groups/group/settings/udpReverseProxy?groupId=" + types.String(groupResp.ServerGroupId)
}
}
// 当前服务的配置
2020-09-21 11:37:24 +08:00
reverseProxyResp, err := this.RPC().ServerRPC().FindAndInitServerReverseProxyConfig(this.AdminContext(), &pb.FindAndInitServerReverseProxyConfigRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
2022-06-29 21:56:44 +08:00
var reverseProxyRef = &serverconfigs.ReverseProxyRef{}
2020-09-21 19:51:50 +08:00
err = json.Unmarshal(reverseProxyResp.ReverseProxyRefJSON, reverseProxyRef)
2020-09-21 11:37:24 +08:00
if err != nil {
this.ErrorPage(err)
return
}
this.Data["reverseProxyRef"] = reverseProxyRef
2020-09-15 14:44:52 +08:00
var reverseProxy = serverconfigs.NewReverseProxyConfig()
2020-09-21 19:51:50 +08:00
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
2020-09-21 11:37:24 +08:00
if err != nil {
this.ErrorPage(err)
return
}
this.Data["reverseProxyConfig"] = reverseProxy
2020-09-16 09:09:10 +08:00
2020-09-21 11:37:24 +08:00
this.Data["serverType"] = serverType
2022-06-29 21:56:44 +08:00
var primaryOriginMaps = []maps.Map{}
var backupOriginMaps = []maps.Map{}
2020-09-21 11:37:24 +08:00
for _, originConfig := range reverseProxy.PrimaryOrigins {
if len(originConfig.Domains) == 0 {
originConfig.Domains = []string{}
}
2022-06-29 21:56:44 +08:00
var m = maps.Map{
2023-06-23 11:43:36 +08:00
"id": originConfig.Id,
"weight": originConfig.Weight,
"addr": originConfig.AddrSummary(),
"isOSS": originConfig.IsOSS(),
"name": originConfig.Name,
"isOn": originConfig.IsOn,
"domains": originConfig.Domains,
"hasCert": originConfig.Cert != nil,
"host": originConfig.RequestHost,
"followPort": originConfig.FollowPort,
"http2Enabled": originConfig.HTTP2Enabled,
2020-09-16 09:09:10 +08:00
}
2020-09-21 11:37:24 +08:00
primaryOriginMaps = append(primaryOriginMaps, m)
}
for _, originConfig := range reverseProxy.BackupOrigins {
if len(originConfig.Domains) == 0 {
originConfig.Domains = []string{}
}
2022-06-29 21:56:44 +08:00
var m = maps.Map{
2023-06-23 11:43:36 +08:00
"id": originConfig.Id,
"weight": originConfig.Weight,
"addr": originConfig.AddrSummary(),
"isOSS": originConfig.IsOSS(),
"name": originConfig.Name,
"isOn": originConfig.IsOn,
"domains": originConfig.Domains,
"hasCert": originConfig.Cert != nil,
"host": originConfig.RequestHost,
"followPort": originConfig.FollowPort,
"http2Enabled": originConfig.HTTP2Enabled,
2020-09-15 14:44:52 +08:00
}
2020-09-21 11:37:24 +08:00
backupOriginMaps = append(backupOriginMaps, m)
2020-09-15 14:44:52 +08:00
}
2020-09-21 11:37:24 +08:00
this.Data["primaryOrigins"] = primaryOriginMaps
this.Data["backupOrigins"] = backupOriginMaps
2020-08-21 21:09:42 +08:00
this.Show()
}