Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package groups
|
||||
|
||||
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/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
Name string
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入分组名称")
|
||||
createResp, err := this.RPC().ServerGroupRPC().CreateServerGroup(this.UserContext(), &pb.CreateServerGroupRequest{
|
||||
Name: params.Name,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["group"] = maps.Map{
|
||||
"id": createResp.ServerGroupId,
|
||||
"name": params.Name,
|
||||
}
|
||||
|
||||
// 创建日志
|
||||
defer this.CreateLogInfo(codes.ServerGroup_LogCreateServerGroup, createResp.ServerGroupId)
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package groups
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "group")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
groupsResp, err := this.RPC().ServerGroupRPC().FindAllEnabledServerGroups(this.UserContext(), &pb.FindAllEnabledServerGroupsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var groupMaps = []maps.Map{}
|
||||
for _, group := range groupsResp.ServerGroups {
|
||||
countResp, err := this.RPC().ServerRPC().CountAllEnabledServersWithServerGroupId(this.UserContext(), &pb.CountAllEnabledServersWithServerGroupIdRequest{ServerGroupId: group.Id})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
countServers := countResp.Count
|
||||
|
||||
groupMaps = append(groupMaps, maps.Map{
|
||||
"id": group.Id,
|
||||
"name": group.Name,
|
||||
"countServers": countServers,
|
||||
})
|
||||
}
|
||||
this.Data["groups"] = groupMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
27
EdgeUser/internal/web/actions/default/servers/groups/init.go
Normal file
27
EdgeUser/internal/web/actions/default/servers/groups/init.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package groups
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/servers/groups/group"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth("")).
|
||||
Data("teaMenu", "servers").
|
||||
Prefix("/servers/groups").
|
||||
GetPost("", new(IndexAction)).
|
||||
GetPost("/createPopup", new(CreatePopupAction)).
|
||||
Post("/sort", new(SortAction)).
|
||||
GetPost("/selectPopup", new(SelectPopupAction)).
|
||||
|
||||
// 详情
|
||||
Prefix("/servers/groups/group").
|
||||
Get("", new(group.IndexAction)).
|
||||
Post("/delete", new(group.DeleteAction)).
|
||||
GetPost("/update", new(group.UpdateAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package groups
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SelectPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SelectPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *SelectPopupAction) RunGet(params struct {
|
||||
SelectedGroupIds string
|
||||
}) {
|
||||
groupsResp, err := this.RPC().ServerGroupRPC().FindAllEnabledServerGroups(this.UserContext(), &pb.FindAllEnabledServerGroupsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
}
|
||||
|
||||
selectedGroupIds := []int64{}
|
||||
if len(params.SelectedGroupIds) > 0 {
|
||||
for _, v := range strings.Split(params.SelectedGroupIds, ",") {
|
||||
selectedGroupIds = append(selectedGroupIds, types.Int64(v))
|
||||
}
|
||||
}
|
||||
|
||||
groupMaps := []maps.Map{}
|
||||
for _, group := range groupsResp.ServerGroups {
|
||||
// 已经选过的就跳过
|
||||
if lists.ContainsInt64(selectedGroupIds, group.Id) {
|
||||
continue
|
||||
}
|
||||
groupMaps = append(groupMaps, maps.Map{
|
||||
"id": group.Id,
|
||||
"name": group.Name,
|
||||
})
|
||||
}
|
||||
this.Data["groups"] = groupMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *SelectPopupAction) RunPost(params struct {
|
||||
GroupId int64
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
if params.GroupId <= 0 {
|
||||
this.Fail("请选择要使用的分组")
|
||||
}
|
||||
|
||||
groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroup(this.UserContext(), &pb.FindEnabledServerGroupRequest{ServerGroupId: 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,
|
||||
"name": group.Name,
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
26
EdgeUser/internal/web/actions/default/servers/groups/sort.go
Normal file
26
EdgeUser/internal/web/actions/default/servers/groups/sort.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package groups
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
)
|
||||
|
||||
type SortAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SortAction) RunPost(params struct {
|
||||
GroupIds []int64
|
||||
}) {
|
||||
// 创建日志
|
||||
defer this.CreateLogInfo(codes.ServerGroup_LogSortServerGroups)
|
||||
|
||||
_, err := this.RPC().ServerGroupRPC().UpdateServerGroupOrders(this.UserContext(), &pb.UpdateServerGroupOrdersRequest{ServerGroupIds: params.GroupIds})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user