1.4.5.2
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
GroupId int64
|
||||
}) {
|
||||
// 创建日志
|
||||
defer this.CreateLogInfo(codes.ServerGroup_LogDeleteServerGroup, params.GroupId)
|
||||
|
||||
// 检查是否正在使用
|
||||
countResp, err := this.RPC().ServerRPC().CountAllEnabledServersWithServerGroupId(this.UserContext(), &pb.CountAllEnabledServersWithServerGroupIdRequest{ServerGroupId: params.GroupId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
if countResp.Count > 0 {
|
||||
this.Fail("此分组正在被使用不能删除,请修改相关服务后再删除")
|
||||
}
|
||||
|
||||
_, err = this.RPC().ServerGroupRPC().DeleteServerGroup(this.UserContext(), &pb.DeleteServerGroupRequest{ServerGroupId: params.GroupId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package group
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
"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
|
||||
}) {
|
||||
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.Show()
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package servergrouputils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"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.UserContext(), &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.UserContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ServerGroupId: groupId})
|
||||
if err != nil {
|
||||
return group, err
|
||||
}
|
||||
|
||||
var urlPrefix = "/servers/groups/group/settings"
|
||||
var leftMenuItems = []maps.Map{
|
||||
{
|
||||
"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,
|
||||
},
|
||||
}
|
||||
|
||||
leftMenuItems = append([]maps.Map{
|
||||
{
|
||||
"name": "Web设置",
|
||||
"url": urlPrefix + "/web?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "web",
|
||||
"isOn": configInfoResp.HasRootConfig,
|
||||
},
|
||||
}, leftMenuItems...)
|
||||
leftMenuItems = append(leftMenuItems, []maps.Map{
|
||||
{
|
||||
"name": "-",
|
||||
"url": "",
|
||||
},
|
||||
{
|
||||
"name": "WAF",
|
||||
"url": urlPrefix + "/waf?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "waf",
|
||||
"isOn": configInfoResp.HasWAFConfig,
|
||||
},
|
||||
{
|
||||
"name": "缓存",
|
||||
"url": urlPrefix + "//cache?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "cache",
|
||||
"isOn": configInfoResp.HasCacheConfig,
|
||||
},
|
||||
{
|
||||
"name": "字符编码",
|
||||
"url": urlPrefix + "/charset?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "charset",
|
||||
"isOn": configInfoResp.HasCharsetConfig,
|
||||
},
|
||||
{
|
||||
"name": "访问日志",
|
||||
"url": urlPrefix + "/accessLog?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "accessLog",
|
||||
"isOn": configInfoResp.HasAccessLogConfig,
|
||||
},
|
||||
{
|
||||
"name": "统计",
|
||||
"url": urlPrefix + "/stat?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "stat",
|
||||
"isOn": configInfoResp.HasStatConfig,
|
||||
},
|
||||
{
|
||||
"name": "内容压缩",
|
||||
"url": urlPrefix + "/compression?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "compression",
|
||||
"isOn": configInfoResp.HasCompressionConfig,
|
||||
},
|
||||
{
|
||||
"name": "自定义页面",
|
||||
"url": urlPrefix + "/pages?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "pages",
|
||||
"isOn": configInfoResp.HasPagesConfig,
|
||||
},
|
||||
{
|
||||
"name": "HTTP报头",
|
||||
"url": urlPrefix + "/headers?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "headers",
|
||||
"isOn": configInfoResp.HasRequestHeadersConfig || configInfoResp.HasResponseHeadersConfig,
|
||||
},
|
||||
{
|
||||
"name": "Websocket",
|
||||
"url": urlPrefix + "/websocket?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "websocket",
|
||||
"isOn": configInfoResp.HasWebsocketConfig,
|
||||
},
|
||||
{
|
||||
"name": "WebP",
|
||||
"url": urlPrefix + "/webp?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "webp",
|
||||
"isOn": configInfoResp.HasWebPConfig,
|
||||
},
|
||||
}...)
|
||||
|
||||
leftMenuItems = append(leftMenuItems, maps.Map{
|
||||
"name": "-",
|
||||
"url": "",
|
||||
})
|
||||
leftMenuItems = append(leftMenuItems, maps.Map{
|
||||
"name": "访客IP地址",
|
||||
"url": urlPrefix + "/remoteAddr?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "remoteAddr",
|
||||
"isOn": configInfoResp.HasRemoteAddrConfig,
|
||||
})
|
||||
|
||||
leftMenuItems = append(leftMenuItems, maps.Map{
|
||||
"name": "请求限制",
|
||||
"url": urlPrefix + "/requestLimit?groupId=" + types.String(groupId),
|
||||
"isActive": menuItem == "requestLimit",
|
||||
"isOn": configInfoResp.HasRequestLimitConfig,
|
||||
})
|
||||
parent.Data["leftMenuItems"] = leftMenuItems
|
||||
}
|
||||
|
||||
return group, nil
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpdateAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateAction) Init() {
|
||||
this.Nav("", "", "group.update")
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunGet(params struct {
|
||||
GroupId int64
|
||||
}) {
|
||||
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.Show()
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunPost(params struct {
|
||||
GroupId int64
|
||||
Name string
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
// 创建日志
|
||||
defer this.CreateLogInfo(codes.ServerGroup_LogUpdateServerGroup, params.GroupId)
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入分组名称")
|
||||
_, err := this.RPC().ServerGroupRPC().UpdateServerGroup(this.UserContext(), &pb.UpdateServerGroupRequest{
|
||||
ServerGroupId: params.GroupId,
|
||||
Name: params.Name,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user