mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
可以在分组中设置一些全局配置选项
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package groups
|
||||
package group
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||
193
internal/web/actions/default/servers/groups/group/index.go
Normal file
193
internal/web/actions/default/servers/groups/group/index.go
Normal file
@@ -0,0 +1,193 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package group
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "group.index")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
GroupId int64
|
||||
Keyword string
|
||||
}) {
|
||||
this.Data["keyword"] = params.Keyword
|
||||
|
||||
group, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["group"] = maps.Map{
|
||||
"id": group.Id,
|
||||
"name": group.Name,
|
||||
}
|
||||
|
||||
// 是否有用户管理权限
|
||||
this.Data["canVisitUser"] = configloaders.AllowModule(this.AdminId(), configloaders.AdminModuleCodeUser)
|
||||
|
||||
// 服务列表
|
||||
countResp, err := this.RPC().ServerRPC().CountAllEnabledServersMatch(this.AdminContext(), &pb.CountAllEnabledServersMatchRequest{
|
||||
ServerGroupId: params.GroupId,
|
||||
Keyword: params.Keyword,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
count := countResp.Count
|
||||
page := this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
// 服务列表
|
||||
serversResp, err := this.RPC().ServerRPC().ListEnabledServersMatch(this.AdminContext(), &pb.ListEnabledServersMatchRequest{
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
ServerGroupId: params.GroupId,
|
||||
Keyword: params.Keyword,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
serverMaps := []maps.Map{}
|
||||
for _, server := range serversResp.Servers {
|
||||
config := &serverconfigs.ServerConfig{}
|
||||
err = json.Unmarshal(server.Config, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 端口列表
|
||||
portMaps := []maps.Map{}
|
||||
if len(server.HttpJSON) > 0 && config.HTTP.IsOn {
|
||||
for _, listen := range config.HTTP.Listen {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"protocol": listen.Protocol,
|
||||
"portRange": listen.PortRange,
|
||||
})
|
||||
}
|
||||
}
|
||||
if config.HTTPS != nil && config.HTTPS.IsOn {
|
||||
for _, listen := range config.HTTPS.Listen {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"protocol": listen.Protocol,
|
||||
"portRange": listen.PortRange,
|
||||
})
|
||||
}
|
||||
}
|
||||
if config.TCP != nil && config.TCP.IsOn {
|
||||
for _, listen := range config.TCP.Listen {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"protocol": listen.Protocol,
|
||||
"portRange": listen.PortRange,
|
||||
})
|
||||
}
|
||||
}
|
||||
if config.TLS != nil && config.TLS.IsOn {
|
||||
for _, listen := range config.TLS.Listen {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"protocol": listen.Protocol,
|
||||
"portRange": listen.PortRange,
|
||||
})
|
||||
}
|
||||
}
|
||||
if config.Unix != nil && config.Unix.IsOn {
|
||||
for _, listen := range config.Unix.Listen {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"protocol": listen.Protocol,
|
||||
"portRange": listen.Host,
|
||||
})
|
||||
}
|
||||
}
|
||||
if config.UDP != nil && config.UDP.IsOn {
|
||||
for _, listen := range config.UDP.Listen {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"protocol": listen.Protocol,
|
||||
"portRange": listen.PortRange,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 分组
|
||||
groupMaps := []maps.Map{}
|
||||
if len(server.ServerGroups) > 0 {
|
||||
for _, group := range server.ServerGroups {
|
||||
groupMaps = append(groupMaps, maps.Map{
|
||||
"id": group.Id,
|
||||
"name": group.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 域名列表
|
||||
serverNames := []*serverconfigs.ServerNameConfig{}
|
||||
if server.IsAuditing || (server.AuditingResult != nil && !server.AuditingResult.IsOk) {
|
||||
server.ServerNamesJSON = server.AuditingServerNamesJSON
|
||||
}
|
||||
auditingIsOk := true
|
||||
if !server.IsAuditing && server.AuditingResult != nil && !server.AuditingResult.IsOk {
|
||||
auditingIsOk = false
|
||||
}
|
||||
if len(server.ServerNamesJSON) > 0 {
|
||||
err = json.Unmarshal(server.ServerNamesJSON, &serverNames)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
countServerNames := 0
|
||||
for _, serverName := range serverNames {
|
||||
if len(serverName.SubNames) == 0 {
|
||||
countServerNames++
|
||||
} else {
|
||||
countServerNames += len(serverName.SubNames)
|
||||
}
|
||||
}
|
||||
|
||||
// 用户
|
||||
var userMap maps.Map = nil
|
||||
if server.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": server.User.Id,
|
||||
"fullname": server.User.Fullname,
|
||||
}
|
||||
}
|
||||
|
||||
serverMaps = append(serverMaps, maps.Map{
|
||||
"id": server.Id,
|
||||
"isOn": server.IsOn,
|
||||
"name": server.Name,
|
||||
"cluster": maps.Map{
|
||||
"id": server.NodeCluster.Id,
|
||||
"name": server.NodeCluster.Name,
|
||||
},
|
||||
"ports": portMaps,
|
||||
"serverTypeName": serverconfigs.FindServerType(server.Type).GetString("name"),
|
||||
"groups": groupMaps,
|
||||
"serverNames": serverNames,
|
||||
"countServerNames": countServerNames,
|
||||
"isAuditing": server.IsAuditing,
|
||||
"auditingIsOk": auditingIsOk,
|
||||
"user": userMap,
|
||||
})
|
||||
}
|
||||
this.Data["servers"] = serverMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package servergrouputils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
// InitGroup 初始化分组信息
|
||||
func InitGroup(parent *actionutils.ParentAction, groupId int64, menuItem string) (*pb.ServerGroup, error) {
|
||||
groupResp, err := parent.RPC().ServerGroupRPC().FindEnabledServerGroup(parent.AdminContext(), &pb.FindEnabledServerGroupRequest{ServerGroupId: groupId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var group = groupResp.ServerGroup
|
||||
if group == nil {
|
||||
return nil, errors.New("group with id '" + types.String(groupId) + "' not found")
|
||||
}
|
||||
|
||||
parent.Data["group"] = maps.Map{
|
||||
"id": group.Id,
|
||||
"name": group.Name,
|
||||
}
|
||||
|
||||
// 初始化设置菜单
|
||||
if len(menuItem) > 0 {
|
||||
// 获取设置概要信息
|
||||
configInfoResp, err := parent.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(parent.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ServerGroupId: groupId})
|
||||
if err != nil {
|
||||
return group, err
|
||||
}
|
||||
|
||||
var urlPrefix = "/servers/groups/group/settings"
|
||||
parent.Data["leftMenuItems"] = []maps.Map{
|
||||
/**{
|
||||
"name": "Web设置",
|
||||
"url": urlPrefix + "/web?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "web",
|
||||
},**/
|
||||
{
|
||||
"name": "HTTP反向代理",
|
||||
"url": urlPrefix + "/httpReverseProxy?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "httpReverseProxy",
|
||||
"isOn": configInfoResp.HasHTTPReverseProxy,
|
||||
},
|
||||
{
|
||||
"name": "TCP反向代理",
|
||||
"url": urlPrefix + "/tcpReverseProxy?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "tcpReverseProxy",
|
||||
"isOn": configInfoResp.HasTCPReverseProxy,
|
||||
},
|
||||
{
|
||||
"name": "UDP反向代理",
|
||||
"url": urlPrefix + "/udpReverseProxy?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "udpReverseProxy",
|
||||
"isOn": configInfoResp.HasUDPReverseProxy,
|
||||
},
|
||||
/**{
|
||||
"name": "-",
|
||||
"url": "",
|
||||
},
|
||||
{
|
||||
"name": "WAF",
|
||||
"url": urlPrefix + "/waf?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "waf",
|
||||
},
|
||||
{
|
||||
"name": "缓存",
|
||||
"url": urlPrefix + "/cache?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "cache",
|
||||
},
|
||||
{
|
||||
"name": "访问日志",
|
||||
"url": urlPrefix + "/accessLog?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "accessLog",
|
||||
},
|
||||
{
|
||||
"name": "统计",
|
||||
"url": urlPrefix + "/stat?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "stat",
|
||||
},
|
||||
{
|
||||
"name": "Gzip压缩",
|
||||
"url": urlPrefix + "/gzip?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "gzip",
|
||||
},
|
||||
{
|
||||
"name": "特殊页面",
|
||||
"url": urlPrefix + "/pages?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "page",
|
||||
},
|
||||
{
|
||||
"name": "HTTP Header",
|
||||
"url": urlPrefix + "/headers?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "header",
|
||||
},
|
||||
{
|
||||
"name": "Websocket",
|
||||
"url": urlPrefix + "/websocket?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "websocket",
|
||||
},**/
|
||||
}
|
||||
}
|
||||
|
||||
return group, nil
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package httpReverseProxy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
// IndexAction 源站列表
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.FirstMenu("index")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
GroupId int64
|
||||
}) {
|
||||
_, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "httpReverseProxy")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["serverType"] = "httpProxy"
|
||||
|
||||
reverseProxyResp, err := this.RPC().ServerGroupRPC().FindAndInitServerGroupHTTPReverseProxyConfig(this.AdminContext(), &pb.FindAndInitServerGroupHTTPReverseProxyConfigRequest{ServerGroupId: params.GroupId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
reverseProxyRef := &serverconfigs.ReverseProxyRef{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyRefJSON, reverseProxyRef)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["reverseProxyRef"] = reverseProxyRef
|
||||
|
||||
reverseProxy := &serverconfigs.ReverseProxyConfig{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["reverseProxyConfig"] = reverseProxy
|
||||
|
||||
primaryOriginMaps := []maps.Map{}
|
||||
backupOriginMaps := []maps.Map{}
|
||||
for _, originConfig := range reverseProxy.PrimaryOrigins {
|
||||
if len(originConfig.Domains) == 0 {
|
||||
originConfig.Domains = []string{}
|
||||
}
|
||||
m := maps.Map{
|
||||
"id": originConfig.Id,
|
||||
"weight": originConfig.Weight,
|
||||
"addr": originConfig.Addr.Protocol.String() + "://" + originConfig.Addr.Host + ":" + originConfig.Addr.PortRange,
|
||||
"name": originConfig.Name,
|
||||
"isOn": originConfig.IsOn,
|
||||
"domains": originConfig.Domains,
|
||||
}
|
||||
primaryOriginMaps = append(primaryOriginMaps, m)
|
||||
}
|
||||
for _, originConfig := range reverseProxy.BackupOrigins {
|
||||
if len(originConfig.Domains) == 0 {
|
||||
originConfig.Domains = []string{}
|
||||
}
|
||||
m := maps.Map{
|
||||
"id": originConfig.Id,
|
||||
"weight": originConfig.Weight,
|
||||
"addr": originConfig.Addr.Protocol.String() + "://" + originConfig.Addr.Host + ":" + originConfig.Addr.PortRange,
|
||||
"name": originConfig.Name,
|
||||
"isOn": originConfig.IsOn,
|
||||
"domains": originConfig.Domains,
|
||||
}
|
||||
backupOriginMaps = append(backupOriginMaps, m)
|
||||
}
|
||||
this.Data["primaryOrigins"] = primaryOriginMaps
|
||||
this.Data["backupOrigins"] = backupOriginMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package httpReverseProxy
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
|
||||
Data("teaMenu", "servers").
|
||||
Data("teaSubMenu", "group").
|
||||
Prefix("/servers/groups/group/settings/httpReverseProxy").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/scheduling", new(SchedulingAction)).
|
||||
GetPost("/setting", new(SettingAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package httpReverseProxy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/schedulingconfigs"
|
||||
)
|
||||
|
||||
type SchedulingAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SchedulingAction) Init() {
|
||||
this.FirstMenu("scheduling")
|
||||
}
|
||||
|
||||
func (this *SchedulingAction) RunGet(params struct {
|
||||
GroupId int64
|
||||
}) {
|
||||
_, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "httpReverseProxy")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["family"] = "http"
|
||||
|
||||
reverseProxyResp, err := this.RPC().ServerGroupRPC().FindAndInitServerGroupHTTPReverseProxyConfig(this.AdminContext(), &pb.FindAndInitServerGroupHTTPReverseProxyConfigRequest{ServerGroupId: params.GroupId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
reverseProxy := &serverconfigs.ReverseProxyConfig{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["reverseProxyId"] = reverseProxy.Id
|
||||
|
||||
schedulingCode := reverseProxy.FindSchedulingConfig().Code
|
||||
schedulingMap := schedulingconfigs.FindSchedulingType(schedulingCode)
|
||||
if schedulingMap == nil {
|
||||
this.ErrorPage(errors.New("invalid scheduling code '" + schedulingCode + "'"))
|
||||
return
|
||||
}
|
||||
this.Data["scheduling"] = schedulingMap
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package httpReverseProxy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
type SettingAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SettingAction) Init() {
|
||||
this.FirstMenu("setting")
|
||||
}
|
||||
|
||||
func (this *SettingAction) RunGet(params struct {
|
||||
GroupId int64
|
||||
}) {
|
||||
_, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "httpReverseProxy")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["family"] = "http"
|
||||
|
||||
reverseProxyResp, err := this.RPC().ServerGroupRPC().FindAndInitServerGroupHTTPReverseProxyConfig(this.AdminContext(), &pb.FindAndInitServerGroupHTTPReverseProxyConfigRequest{ServerGroupId: params.GroupId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
reverseProxyRef := &serverconfigs.ReverseProxyRef{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyRefJSON, reverseProxyRef)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
reverseProxy := &serverconfigs.ReverseProxyConfig{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["reverseProxyRef"] = reverseProxyRef
|
||||
this.Data["reverseProxyConfig"] = reverseProxy
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *SettingAction) RunPost(params struct {
|
||||
GroupId int64
|
||||
ReverseProxyRefJSON []byte
|
||||
ReverseProxyJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
defer this.CreateLogInfo("修改分组 %d 的反向代理设置", params.GroupId)
|
||||
|
||||
// TODO 校验配置
|
||||
|
||||
reverseProxyConfig := &serverconfigs.ReverseProxyConfig{}
|
||||
err := json.Unmarshal(params.ReverseProxyJSON, reverseProxyConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
err = reverseProxyConfig.Init()
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
// 设置是否启用
|
||||
_, err = this.RPC().ServerGroupRPC().UpdateServerGroupHTTPReverseProxy(this.AdminContext(), &pb.UpdateServerGroupHTTPReverseProxyRequest{
|
||||
ServerGroupId: params.GroupId,
|
||||
ReverseProxyJSON: params.ReverseProxyRefJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 设置反向代理相关信息
|
||||
_, err = this.RPC().ReverseProxyRPC().UpdateReverseProxy(this.AdminContext(), &pb.UpdateReverseProxyRequest{
|
||||
ReverseProxyId: reverseProxyConfig.Id,
|
||||
RequestHostType: types.Int32(reverseProxyConfig.RequestHostType),
|
||||
RequestHost: reverseProxyConfig.RequestHost,
|
||||
RequestURI: reverseProxyConfig.RequestURI,
|
||||
StripPrefix: reverseProxyConfig.StripPrefix,
|
||||
AutoFlush: reverseProxyConfig.AutoFlush,
|
||||
AddHeaders: reverseProxyConfig.AddHeaders,
|
||||
})
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package reverseProxy
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
GroupId int64
|
||||
}) {
|
||||
this.RedirectURL("/servers/groups/group/settings/httpReverseProxy?groupId=" + types.String(params.GroupId))
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package reverseProxy
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/locationutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
|
||||
Helper(locationutils.NewLocationHelper()).
|
||||
Helper(serverutils.NewServerHelper()).
|
||||
Data("mainTab", "setting").
|
||||
Prefix("/servers/groups/group/settings").
|
||||
Get("", new(IndexAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package tcpReverseProxy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
// IndexAction 源站列表
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.FirstMenu("index")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
GroupId int64
|
||||
}) {
|
||||
_, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "tcpReverseProxy")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["serverType"] = "tcpProxy"
|
||||
|
||||
reverseProxyResp, err := this.RPC().ServerGroupRPC().FindAndInitServerGroupTCPReverseProxyConfig(this.AdminContext(), &pb.FindAndInitServerGroupTCPReverseProxyConfigRequest{ServerGroupId: params.GroupId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
reverseProxyRef := &serverconfigs.ReverseProxyRef{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyRefJSON, reverseProxyRef)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["reverseProxyRef"] = reverseProxyRef
|
||||
|
||||
reverseProxy := &serverconfigs.ReverseProxyConfig{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["reverseProxyConfig"] = reverseProxy
|
||||
|
||||
primaryOriginMaps := []maps.Map{}
|
||||
backupOriginMaps := []maps.Map{}
|
||||
for _, originConfig := range reverseProxy.PrimaryOrigins {
|
||||
if len(originConfig.Domains) == 0 {
|
||||
originConfig.Domains = []string{}
|
||||
}
|
||||
m := maps.Map{
|
||||
"id": originConfig.Id,
|
||||
"weight": originConfig.Weight,
|
||||
"addr": originConfig.Addr.Protocol.String() + "://" + originConfig.Addr.Host + ":" + originConfig.Addr.PortRange,
|
||||
"name": originConfig.Name,
|
||||
"isOn": originConfig.IsOn,
|
||||
"domains": originConfig.Domains,
|
||||
}
|
||||
primaryOriginMaps = append(primaryOriginMaps, m)
|
||||
}
|
||||
for _, originConfig := range reverseProxy.BackupOrigins {
|
||||
if len(originConfig.Domains) == 0 {
|
||||
originConfig.Domains = []string{}
|
||||
}
|
||||
m := maps.Map{
|
||||
"id": originConfig.Id,
|
||||
"weight": originConfig.Weight,
|
||||
"addr": originConfig.Addr.Protocol.String() + "://" + originConfig.Addr.Host + ":" + originConfig.Addr.PortRange,
|
||||
"name": originConfig.Name,
|
||||
"isOn": originConfig.IsOn,
|
||||
"domains": originConfig.Domains,
|
||||
}
|
||||
backupOriginMaps = append(backupOriginMaps, m)
|
||||
}
|
||||
this.Data["primaryOrigins"] = primaryOriginMaps
|
||||
this.Data["backupOrigins"] = backupOriginMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package tcpReverseProxy
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
|
||||
Data("teaMenu", "servers").
|
||||
Data("teaSubMenu", "group").
|
||||
Prefix("/servers/groups/group/settings/tcpReverseProxy").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/scheduling", new(SchedulingAction)).
|
||||
GetPost("/setting", new(SettingAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package tcpReverseProxy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/schedulingconfigs"
|
||||
)
|
||||
|
||||
type SchedulingAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SchedulingAction) Init() {
|
||||
this.FirstMenu("scheduling")
|
||||
}
|
||||
|
||||
func (this *SchedulingAction) RunGet(params struct {
|
||||
GroupId int64
|
||||
}) {
|
||||
_, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "tcpReverseProxy")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["family"] = "tcp"
|
||||
|
||||
reverseProxyResp, err := this.RPC().ServerGroupRPC().FindAndInitServerGroupTCPReverseProxyConfig(this.AdminContext(), &pb.FindAndInitServerGroupTCPReverseProxyConfigRequest{ServerGroupId: params.GroupId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
reverseProxy := &serverconfigs.ReverseProxyConfig{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["reverseProxyId"] = reverseProxy.Id
|
||||
|
||||
schedulingCode := reverseProxy.FindSchedulingConfig().Code
|
||||
schedulingMap := schedulingconfigs.FindSchedulingType(schedulingCode)
|
||||
if schedulingMap == nil {
|
||||
this.ErrorPage(errors.New("invalid scheduling code '" + schedulingCode + "'"))
|
||||
return
|
||||
}
|
||||
this.Data["scheduling"] = schedulingMap
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package tcpReverseProxy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
type SettingAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SettingAction) Init() {
|
||||
this.FirstMenu("setting")
|
||||
}
|
||||
|
||||
func (this *SettingAction) RunGet(params struct {
|
||||
GroupId int64
|
||||
}) {
|
||||
_, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "tcpReverseProxy")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["family"] = "tcp"
|
||||
|
||||
reverseProxyResp, err := this.RPC().ServerGroupRPC().FindAndInitServerGroupTCPReverseProxyConfig(this.AdminContext(), &pb.FindAndInitServerGroupTCPReverseProxyConfigRequest{ServerGroupId: params.GroupId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
reverseProxyRef := &serverconfigs.ReverseProxyRef{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyRefJSON, reverseProxyRef)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
reverseProxy := &serverconfigs.ReverseProxyConfig{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["reverseProxyRef"] = reverseProxyRef
|
||||
this.Data["reverseProxyConfig"] = reverseProxy
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *SettingAction) RunPost(params struct {
|
||||
GroupId int64
|
||||
ReverseProxyRefJSON []byte
|
||||
ReverseProxyJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
defer this.CreateLogInfo("修改分组 %d 的反向代理设置", params.GroupId)
|
||||
|
||||
// TODO 校验配置
|
||||
|
||||
reverseProxyConfig := &serverconfigs.ReverseProxyConfig{}
|
||||
err := json.Unmarshal(params.ReverseProxyJSON, reverseProxyConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
err = reverseProxyConfig.Init()
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
// 设置是否启用
|
||||
_, err = this.RPC().ServerGroupRPC().UpdateServerGroupTCPReverseProxy(this.AdminContext(), &pb.UpdateServerGroupTCPReverseProxyRequest{
|
||||
ServerGroupId: params.GroupId,
|
||||
ReverseProxyJSON: params.ReverseProxyRefJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 设置反向代理相关信息
|
||||
_, err = this.RPC().ReverseProxyRPC().UpdateReverseProxy(this.AdminContext(), &pb.UpdateReverseProxyRequest{
|
||||
ReverseProxyId: reverseProxyConfig.Id,
|
||||
RequestHostType: types.Int32(reverseProxyConfig.RequestHostType),
|
||||
RequestHost: reverseProxyConfig.RequestHost,
|
||||
RequestURI: reverseProxyConfig.RequestURI,
|
||||
StripPrefix: reverseProxyConfig.StripPrefix,
|
||||
AutoFlush: reverseProxyConfig.AutoFlush,
|
||||
AddHeaders: reverseProxyConfig.AddHeaders,
|
||||
})
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package udpReverseProxy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
// IndexAction 源站列表
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.FirstMenu("index")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
GroupId int64
|
||||
}) {
|
||||
_, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "udpReverseProxy")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["serverType"] = "udpProxy"
|
||||
|
||||
reverseProxyResp, err := this.RPC().ServerGroupRPC().FindAndInitServerGroupUDPReverseProxyConfig(this.AdminContext(), &pb.FindAndInitServerGroupUDPReverseProxyConfigRequest{ServerGroupId: params.GroupId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
reverseProxyRef := &serverconfigs.ReverseProxyRef{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyRefJSON, reverseProxyRef)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["reverseProxyRef"] = reverseProxyRef
|
||||
|
||||
reverseProxy := &serverconfigs.ReverseProxyConfig{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["reverseProxyConfig"] = reverseProxy
|
||||
|
||||
primaryOriginMaps := []maps.Map{}
|
||||
backupOriginMaps := []maps.Map{}
|
||||
for _, originConfig := range reverseProxy.PrimaryOrigins {
|
||||
if len(originConfig.Domains) == 0 {
|
||||
originConfig.Domains = []string{}
|
||||
}
|
||||
m := maps.Map{
|
||||
"id": originConfig.Id,
|
||||
"weight": originConfig.Weight,
|
||||
"addr": originConfig.Addr.Protocol.String() + "://" + originConfig.Addr.Host + ":" + originConfig.Addr.PortRange,
|
||||
"name": originConfig.Name,
|
||||
"isOn": originConfig.IsOn,
|
||||
"domains": originConfig.Domains,
|
||||
}
|
||||
primaryOriginMaps = append(primaryOriginMaps, m)
|
||||
}
|
||||
for _, originConfig := range reverseProxy.BackupOrigins {
|
||||
if len(originConfig.Domains) == 0 {
|
||||
originConfig.Domains = []string{}
|
||||
}
|
||||
m := maps.Map{
|
||||
"id": originConfig.Id,
|
||||
"weight": originConfig.Weight,
|
||||
"addr": originConfig.Addr.Protocol.String() + "://" + originConfig.Addr.Host + ":" + originConfig.Addr.PortRange,
|
||||
"name": originConfig.Name,
|
||||
"isOn": originConfig.IsOn,
|
||||
"domains": originConfig.Domains,
|
||||
}
|
||||
backupOriginMaps = append(backupOriginMaps, m)
|
||||
}
|
||||
this.Data["primaryOrigins"] = primaryOriginMaps
|
||||
this.Data["backupOrigins"] = backupOriginMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package udpReverseProxy
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
|
||||
Data("teaMenu", "servers").
|
||||
Data("teaSubMenu", "group").
|
||||
Prefix("/servers/groups/group/settings/udpReverseProxy").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/scheduling", new(SchedulingAction)).
|
||||
GetPost("/setting", new(SettingAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package udpReverseProxy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/schedulingconfigs"
|
||||
)
|
||||
|
||||
type SchedulingAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SchedulingAction) Init() {
|
||||
this.FirstMenu("scheduling")
|
||||
}
|
||||
|
||||
func (this *SchedulingAction) RunGet(params struct {
|
||||
GroupId int64
|
||||
}) {
|
||||
_, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "udpReverseProxy")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["family"] = "udp"
|
||||
|
||||
reverseProxyResp, err := this.RPC().ServerGroupRPC().FindAndInitServerGroupUDPReverseProxyConfig(this.AdminContext(), &pb.FindAndInitServerGroupUDPReverseProxyConfigRequest{ServerGroupId: params.GroupId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
reverseProxy := &serverconfigs.ReverseProxyConfig{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["reverseProxyId"] = reverseProxy.Id
|
||||
|
||||
schedulingCode := reverseProxy.FindSchedulingConfig().Code
|
||||
schedulingMap := schedulingconfigs.FindSchedulingType(schedulingCode)
|
||||
if schedulingMap == nil {
|
||||
this.ErrorPage(errors.New("invalid scheduling code '" + schedulingCode + "'"))
|
||||
return
|
||||
}
|
||||
this.Data["scheduling"] = schedulingMap
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package udpReverseProxy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
type SettingAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SettingAction) Init() {
|
||||
this.FirstMenu("setting")
|
||||
}
|
||||
|
||||
func (this *SettingAction) RunGet(params struct {
|
||||
GroupId int64
|
||||
}) {
|
||||
_, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "udpReverseProxy")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["family"] = "udp"
|
||||
|
||||
reverseProxyResp, err := this.RPC().ServerGroupRPC().FindAndInitServerGroupUDPReverseProxyConfig(this.AdminContext(), &pb.FindAndInitServerGroupUDPReverseProxyConfigRequest{ServerGroupId: params.GroupId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
reverseProxyRef := &serverconfigs.ReverseProxyRef{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyRefJSON, reverseProxyRef)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
reverseProxy := &serverconfigs.ReverseProxyConfig{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["reverseProxyRef"] = reverseProxyRef
|
||||
this.Data["reverseProxyConfig"] = reverseProxy
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *SettingAction) RunPost(params struct {
|
||||
GroupId int64
|
||||
ReverseProxyRefJSON []byte
|
||||
ReverseProxyJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
defer this.CreateLogInfo("修改分组 %d 的反向代理设置", params.GroupId)
|
||||
|
||||
// TODO 校验配置
|
||||
|
||||
reverseProxyConfig := &serverconfigs.ReverseProxyConfig{}
|
||||
err := json.Unmarshal(params.ReverseProxyJSON, reverseProxyConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
err = reverseProxyConfig.Init()
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
// 设置是否启用
|
||||
_, err = this.RPC().ServerGroupRPC().UpdateServerGroupUDPReverseProxy(this.AdminContext(), &pb.UpdateServerGroupUDPReverseProxyRequest{
|
||||
ServerGroupId: params.GroupId,
|
||||
ReverseProxyJSON: params.ReverseProxyRefJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 设置反向代理相关信息
|
||||
_, err = this.RPC().ReverseProxyRPC().UpdateReverseProxy(this.AdminContext(), &pb.UpdateReverseProxyRequest{
|
||||
ReverseProxyId: reverseProxyConfig.Id,
|
||||
RequestHostType: types.Int32(reverseProxyConfig.RequestHostType),
|
||||
RequestHost: reverseProxyConfig.RequestHost,
|
||||
RequestURI: reverseProxyConfig.RequestURI,
|
||||
StripPrefix: reverseProxyConfig.StripPrefix,
|
||||
AutoFlush: reverseProxyConfig.AutoFlush,
|
||||
AddHeaders: reverseProxyConfig.AddHeaders,
|
||||
})
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -1,34 +1,30 @@
|
||||
package groups
|
||||
package group
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpdatePopupAction struct {
|
||||
type UpdateAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
func (this *UpdateAction) Init() {
|
||||
this.Nav("", "", "group.update")
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
func (this *UpdateAction) RunGet(params struct {
|
||||
GroupId int64
|
||||
}) {
|
||||
groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroup(this.AdminContext(), &pb.FindEnabledServerGroupRequest{ServerGroupId: params.GroupId})
|
||||
group, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
group := groupResp.ServerGroup
|
||||
if group == nil {
|
||||
this.NotFound("serverGroup", params.GroupId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["group"] = maps.Map{
|
||||
"id": group.Id,
|
||||
@@ -38,7 +34,7 @@ func (this *UpdatePopupAction) RunGet(params struct {
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
func (this *UpdateAction) RunPost(params struct {
|
||||
GroupId int64
|
||||
Name string
|
||||
|
||||
@@ -2,6 +2,7 @@ package groups
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
@@ -12,13 +13,17 @@ func init() {
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
|
||||
Helper(NewHelper()).
|
||||
Data("teaSubMenu", "group").
|
||||
Prefix("/servers/components/groups").
|
||||
Prefix("/servers/groups").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/createPopup", new(CreatePopupAction)).
|
||||
GetPost("/updatePopup", new(UpdatePopupAction)).
|
||||
GetPost("/selectPopup", new(SelectPopupAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
Post("/sort", new(SortAction)).
|
||||
|
||||
// 详情
|
||||
Prefix("/servers/groups/group").
|
||||
Get("", new(group.IndexAction)).
|
||||
Post("/delete", new(group.DeleteAction)).
|
||||
GetPost("/update", new(group.UpdateAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -21,18 +21,24 @@ type AddPopupAction struct {
|
||||
|
||||
func (this *AddPopupAction) RunGet(params struct {
|
||||
ServerId int64
|
||||
ServerType string
|
||||
ReverseProxyId int64
|
||||
OriginType string
|
||||
}) {
|
||||
this.Data["reverseProxyId"] = params.ReverseProxyId
|
||||
this.Data["originType"] = params.OriginType
|
||||
|
||||
serverTypeResp, err := this.RPC().ServerRPC().FindEnabledServerType(this.AdminContext(), &pb.FindEnabledServerTypeRequest{ServerId: params.ServerId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
var serverType = ""
|
||||
if params.ServerId > 0 {
|
||||
serverTypeResp, err := this.RPC().ServerRPC().FindEnabledServerType(this.AdminContext(), &pb.FindEnabledServerTypeRequest{ServerId: params.ServerId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
serverType = serverTypeResp.Type
|
||||
} else {
|
||||
serverType = params.ServerType
|
||||
}
|
||||
serverType := serverTypeResp.Type
|
||||
this.Data["serverType"] = serverType
|
||||
|
||||
// 是否为HTTP
|
||||
|
||||
@@ -26,6 +26,7 @@ func (this *UpdatePopupAction) Init() {
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
ServerId int64
|
||||
ServerType string
|
||||
ReverseProxyId int64
|
||||
OriginType string
|
||||
OriginId int64
|
||||
@@ -34,15 +35,20 @@ func (this *UpdatePopupAction) RunGet(params struct {
|
||||
this.Data["reverseProxyId"] = params.ReverseProxyId
|
||||
this.Data["originId"] = params.OriginId
|
||||
|
||||
serverTypeResp, err := this.RPC().ServerRPC().FindEnabledServerType(this.AdminContext(), &pb.FindEnabledServerTypeRequest{
|
||||
ServerId: params.ServerId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
var serverType = ""
|
||||
if params.ServerId > 0 {
|
||||
serverTypeResp, err := this.RPC().ServerRPC().FindEnabledServerType(this.AdminContext(), &pb.FindEnabledServerTypeRequest{
|
||||
ServerId: params.ServerId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
serverType = serverTypeResp.Type
|
||||
} else {
|
||||
serverType = params.ServerType
|
||||
}
|
||||
this.Data["serverType"] = serverTypeResp.Type
|
||||
serverType := serverTypeResp.Type
|
||||
this.Data["serverType"] = serverType
|
||||
|
||||
// 是否为HTTP
|
||||
this.Data["isHTTP"] = serverType == "httpProxy" || serverType == "httpWeb"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
// 源站列表
|
||||
// IndexAction 源站列表
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
@@ -27,6 +27,23 @@ func (this *IndexAction) RunGet(params struct {
|
||||
}
|
||||
serverType := serverTypeResp.Type
|
||||
|
||||
// 当前是否有分组设置
|
||||
groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ServerId: params.ServerId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["hasGroupConfig"] = false
|
||||
switch serverType {
|
||||
case serverconfigs.ServerTypeHTTPWeb, serverconfigs.ServerTypeHTTPProxy:
|
||||
this.Data["hasGroupConfig"] = groupResp.HasHTTPReverseProxy
|
||||
case serverconfigs.ServerTypeTCPProxy:
|
||||
this.Data["hasGroupConfig"] = groupResp.HasTCPReverseProxy
|
||||
case serverconfigs.ServerTypeUDPProxy:
|
||||
this.Data["hasGroupConfig"] = groupResp.HasUDPReverseProxy
|
||||
}
|
||||
|
||||
// 当前服务的配置
|
||||
reverseProxyResp, err := this.RPC().ServerRPC().FindAndInitServerReverseProxyConfig(this.AdminContext(), &pb.FindAndInitServerReverseProxyConfigRequest{ServerId: params.ServerId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
// 修改调度算法
|
||||
// UpdateSchedulingPopupAction 修改调度算法
|
||||
type UpdateSchedulingPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
@@ -24,17 +24,15 @@ func (this *UpdateSchedulingPopupAction) Init() {
|
||||
func (this *UpdateSchedulingPopupAction) RunGet(params struct {
|
||||
Type string
|
||||
ServerId int64
|
||||
GroupId int64
|
||||
ReverseProxyId int64
|
||||
Family string
|
||||
}) {
|
||||
this.Data["dataType"] = params.Type
|
||||
this.Data["serverId"] = params.ServerId
|
||||
this.Data["groupId"] = params.GroupId
|
||||
this.Data["reverseProxyId"] = params.ReverseProxyId
|
||||
|
||||
_, serverConfig, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
|
||||
if !isOk {
|
||||
return
|
||||
}
|
||||
|
||||
reverseProxyResp, err := this.RPC().ReverseProxyRPC().FindEnabledReverseProxyConfig(this.AdminContext(), &pb.FindEnabledReverseProxyConfigRequest{
|
||||
ReverseProxyId: params.ReverseProxyId,
|
||||
})
|
||||
@@ -62,6 +60,33 @@ func (this *UpdateSchedulingPopupAction) RunGet(params struct {
|
||||
|
||||
// 调度类型
|
||||
schedulingTypes := []maps.Map{}
|
||||
|
||||
var isHTTPFamily = false
|
||||
var isTCPFamily = false
|
||||
var isUDPFamily = false
|
||||
var isUnixFamily = false
|
||||
if params.ServerId > 0 {
|
||||
_, serverConfig, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
|
||||
if !isOk {
|
||||
return
|
||||
}
|
||||
isHTTPFamily = serverConfig.IsHTTPFamily()
|
||||
isTCPFamily = serverConfig.IsTCPFamily()
|
||||
isUDPFamily = serverConfig.IsUDPFamily()
|
||||
isUnixFamily = serverConfig.IsUnixFamily()
|
||||
} else {
|
||||
switch params.Family {
|
||||
case "http":
|
||||
isHTTPFamily = true
|
||||
case "tcp":
|
||||
isTCPFamily = true
|
||||
case "udp":
|
||||
isUDPFamily = true
|
||||
case "unix":
|
||||
isUnixFamily = true
|
||||
}
|
||||
}
|
||||
|
||||
for _, m := range schedulingconfigs.AllSchedulingTypes() {
|
||||
networks, ok := m["networks"]
|
||||
if !ok {
|
||||
@@ -70,10 +95,10 @@ func (this *UpdateSchedulingPopupAction) RunGet(params struct {
|
||||
if !types.IsSlice(networks) {
|
||||
continue
|
||||
}
|
||||
if (serverConfig.IsHTTPFamily() && lists.Contains(networks, "http")) ||
|
||||
(serverConfig.IsTCPFamily() && lists.Contains(networks, "tcp")) ||
|
||||
(serverConfig.IsUDPFamily() && lists.Contains(networks, "udp")) ||
|
||||
(serverConfig.IsUnixFamily() && lists.Contains(networks, "unix")) {
|
||||
if (isHTTPFamily && lists.Contains(networks, "http")) ||
|
||||
(isTCPFamily && lists.Contains(networks, "tcp")) ||
|
||||
(isUDPFamily && lists.Contains(networks, "udp")) ||
|
||||
(isUnixFamily && lists.Contains(networks, "unix")) {
|
||||
schedulingTypes = append(schedulingTypes, m)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,6 +180,11 @@ func (this *userMustAuth) modules(adminId int64) []maps.Map {
|
||||
"subtitle": "服务列表",
|
||||
"icon": "clone outsize",
|
||||
"subItems": []maps.Map{
|
||||
{
|
||||
"name": "服务分组",
|
||||
"url": "/servers/groups",
|
||||
"code": "group",
|
||||
},
|
||||
{
|
||||
"name": "证书管理",
|
||||
"url": "/servers/certs",
|
||||
@@ -216,11 +221,6 @@ func (this *userMustAuth) modules(adminId int64) []maps.Map {
|
||||
"url": "/servers/metrics",
|
||||
"code": "metric",
|
||||
},
|
||||
{
|
||||
"name": "服务分组",
|
||||
"url": "/servers/components/groups",
|
||||
"code": "group",
|
||||
},
|
||||
{
|
||||
"name": "通用设置",
|
||||
"url": "/servers/components",
|
||||
|
||||
@@ -41,9 +41,13 @@ import (
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/certs"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/cache"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/groups"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/log"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/waf"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/settings/httpReverseProxy"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/settings/index"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/settings/tcpReverseProxy"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/settings/udpReverseProxy"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/logs"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/metrics"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/metrics/charts"
|
||||
|
||||
Reference in New Issue
Block a user