1.4.5.2
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package category
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
CategoryId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NSRouteCategory_LogDeleteNSRouteCategory, params.CategoryId)
|
||||
|
||||
_, err := this.RPC().NSRouteCategoryRPC().DeleteNSRouteCategory(this.AdminContext(), &pb.DeleteNSRouteCategoryRequest{NsRouteCategoryId: params.CategoryId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package category
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpdatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
CategoryId int64
|
||||
}) {
|
||||
categoryResp, err := this.RPC().NSRouteCategoryRPC().FindNSRouteCategory(this.AdminContext(), &pb.FindNSRouteCategoryRequest{NsRouteCategoryId: params.CategoryId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var category = categoryResp.NsRouteCategory
|
||||
if category == nil {
|
||||
this.NotFound("NSRouteCategory", params.CategoryId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["category"] = maps.Map{
|
||||
"id": category.Id,
|
||||
"name": category.Name,
|
||||
"isOn": category.IsOn,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
CategoryId int64
|
||||
Name string
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NSRouteCategory_LogUpdateNSRouteCategory, params.CategoryId)
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入分类名称")
|
||||
|
||||
_, err := this.RPC().NSRouteCategoryRPC().UpdateNSRouteCategory(this.AdminContext(), &pb.UpdateNSRouteCategoryRequest{
|
||||
NsRouteCategoryId: params.CategoryId,
|
||||
Name: params.Name,
|
||||
IsOn: params.IsOn,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package categories
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
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
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var categoryId int64
|
||||
defer func() {
|
||||
this.CreateLogInfo(codes.NSRouteCategory_LogCreateNSRouteCategory, categoryId)
|
||||
}()
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入分类名称")
|
||||
|
||||
createResp, err := this.RPC().NSRouteCategoryRPC().CreateNSRouteCategory(this.AdminContext(), &pb.CreateNSRouteCategoryRequest{Name: params.Name})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
categoryId = createResp.NsRouteCategoryId
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package categories
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "category")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
categoriesResp, err := this.RPC().NSRouteCategoryRPC().FindAllNSRouteCategories(this.AdminContext(), &pb.FindAllNSRouteCategoriesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var categoryMaps = []maps.Map{}
|
||||
for _, category := range categoriesResp.NsRouteCategories {
|
||||
categoryMaps = append(categoryMaps, maps.Map{
|
||||
"id": category.Id,
|
||||
"name": category.Name,
|
||||
"isOn": category.IsOn,
|
||||
})
|
||||
}
|
||||
this.Data["categories"] = categoryMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//go:build plus
|
||||
|
||||
package categories
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/routes/categories/category"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(plus.NewHelper(plus.ComponentCodeNS)).
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNS)).
|
||||
Data("teaMenu", "ns").
|
||||
Data("teaSubMenu", "route").
|
||||
Prefix("/ns/routes/categories").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/createPopup", new(CreatePopupAction)).
|
||||
Post("/sort", new(SortAction)).
|
||||
|
||||
//
|
||||
GetPost("/category/updatePopup", new(category.UpdatePopupAction)).
|
||||
Post("/category/delete", new(category.DeleteAction)).
|
||||
|
||||
//
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package categories
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type SortAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SortAction) RunPost(params struct {
|
||||
CategoryIds []int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NSRouteCategory_LogSortNSRouteCategories)
|
||||
|
||||
_, err := this.RPC().NSRouteCategoryRPC().UpdateNSRouteCategoryOrders(this.AdminContext(), &pb.UpdateNSRouteCategoryOrders{NsRouteCategoryIds: params.CategoryIds})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct {
|
||||
ClusterId int64
|
||||
DomainId int64
|
||||
UserId int64
|
||||
}) {
|
||||
this.Data["clusterId"] = params.ClusterId
|
||||
this.Data["domainId"] = params.DomainId
|
||||
this.Data["userId"] = params.UserId
|
||||
|
||||
this.Data["rangeTypes"] = dnsconfigs.AllNSRouteRangeTypes()
|
||||
|
||||
// 所有分类
|
||||
categoriesResp, err := this.RPC().NSRouteCategoryRPC().FindAllNSRouteCategories(this.AdminContext(), &pb.FindAllNSRouteCategoriesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var categoryMaps = []maps.Map{}
|
||||
for _, category := range categoriesResp.NsRouteCategories {
|
||||
categoryMaps = append(categoryMaps, maps.Map{
|
||||
"id": category.Id,
|
||||
"name": category.Name,
|
||||
})
|
||||
}
|
||||
this.Data["categories"] = categoryMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
DomainId int64
|
||||
UserId int64
|
||||
|
||||
Name string
|
||||
RangesJSON []byte
|
||||
IsPublic bool
|
||||
CategoryId int64
|
||||
Priority int32
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var routeId = int64(0)
|
||||
defer func() {
|
||||
this.CreateLogInfo(codes.NSRoute_LogCreateNSRoute, routeId)
|
||||
}()
|
||||
|
||||
params.Must.Field("name", params.Name).
|
||||
Require("请输入线路名称")
|
||||
|
||||
ranges, err := dnsconfigs.InitNSRangesFromJSON(params.RangesJSON)
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
if len(ranges) == 0 {
|
||||
this.Fail("请添加线路范围")
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().NSRouteRPC().CreateNSRoute(this.AdminContext(), &pb.CreateNSRouteRequest{
|
||||
NsClusterId: params.ClusterId,
|
||||
NsDomainId: params.DomainId,
|
||||
UserId: params.UserId,
|
||||
Name: params.Name,
|
||||
RangesJSON: params.RangesJSON,
|
||||
IsPublic: params.IsPublic,
|
||||
NsRouteCategoryId: params.CategoryId,
|
||||
Priority: params.Priority,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
routeId = createResp.NsRouteId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
28
EdgeAdmin/internal/web/actions/default/ns/routes/delete.go
Normal file
28
EdgeAdmin/internal/web/actions/default/ns/routes/delete.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
RouteId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NSRoute_LogDeleteNSRoute, params.RouteId)
|
||||
|
||||
_, err := this.RPC().NSRouteRPC().DeleteNSRoute(this.AdminContext(), &pb.DeleteNSRouteRequest{NsRouteId: params.RouteId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package routes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ExportAgentIPsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ExportAgentIPsAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *ExportAgentIPsAction) RunGet(params struct{}) {
|
||||
var lastId int64 = 0
|
||||
var agentIPMaps = []maps.Map{}
|
||||
for {
|
||||
resp, err := this.RPC().ClientAgentIPRPC().ListClientAgentIPsAfterId(this.AdminContext(), &pb.ListClientAgentIPsAfterIdRequest{
|
||||
Id: lastId,
|
||||
Size: 10000,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var agentIPs = resp.ClientAgentIPs
|
||||
if len(agentIPs) == 0 {
|
||||
break
|
||||
}
|
||||
for _, agentIP := range agentIPs {
|
||||
if lastId < agentIP.Id {
|
||||
lastId = agentIP.Id
|
||||
}
|
||||
if agentIP.ClientAgent == nil {
|
||||
continue
|
||||
}
|
||||
agentIPMaps = append(agentIPMaps, maps.Map{
|
||||
"ip": agentIP.Ip,
|
||||
"ptr": agentIP.Ptr,
|
||||
"agentCode": agentIP.ClientAgent.Code,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
agentIPsJSON, err := json.Marshal(agentIPMaps)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.AddHeader("Content-Disposition", "attachment; filename=\"AGENT-IP-LIST.json\";")
|
||||
this.AddHeader("Content-Length", strconv.Itoa(len(agentIPsJSON)))
|
||||
_, _ = this.Write(agentIPsJSON)
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package routes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net"
|
||||
)
|
||||
|
||||
type ImportAgentIPsPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ImportAgentIPsPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *ImportAgentIPsPopupAction) RunGet(params struct {
|
||||
}) {
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *ImportAgentIPsPopupAction) RunPost(params struct {
|
||||
File *actions.File
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
if params.File == nil {
|
||||
this.Fail("请选择要导入的文件")
|
||||
return
|
||||
}
|
||||
|
||||
data, err := params.File.Read()
|
||||
if err != nil {
|
||||
this.Fail("读文件失败:" + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var ipMaps = []maps.Map{}
|
||||
err = json.Unmarshal(data, &ipMaps)
|
||||
if err != nil {
|
||||
this.Fail("解析文件失败:" + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var pbIPs = []*pb.CreateClientAgentIPsRequest_AgentIPInfo{}
|
||||
for _, ipMap := range ipMaps {
|
||||
var ip = ipMap.GetString("ip")
|
||||
var ptr = ipMap.GetString("ptr")
|
||||
var agentCode = ipMap.GetString("agentCode")
|
||||
if len(ip) == 0 || len(agentCode) == 0 || net.ParseIP(ip) == nil {
|
||||
continue
|
||||
}
|
||||
pbIPs = append(pbIPs, &pb.CreateClientAgentIPsRequest_AgentIPInfo{
|
||||
AgentCode: agentCode,
|
||||
Ip: ip,
|
||||
Ptr: ptr,
|
||||
})
|
||||
}
|
||||
|
||||
if len(pbIPs) == 0 {
|
||||
this.Fail("文件中没有包含有效的数据")
|
||||
return
|
||||
}
|
||||
|
||||
var size = 10000
|
||||
for {
|
||||
var pbIPList []*pb.CreateClientAgentIPsRequest_AgentIPInfo
|
||||
var isEnd = false
|
||||
if len(pbIPs) > size {
|
||||
pbIPList = pbIPs[:size]
|
||||
pbIPs = pbIPs[size:]
|
||||
} else {
|
||||
pbIPList = pbIPs
|
||||
isEnd = true
|
||||
}
|
||||
|
||||
_, err = this.RPC().ClientAgentIPRPC().CreateClientAgentIPs(this.AdminContext(), &pb.CreateClientAgentIPsRequest{AgentIPs: pbIPList})
|
||||
if err != nil {
|
||||
this.Fail("导入失败:" + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if isEnd {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
76
EdgeAdmin/internal/web/actions/default/ns/routes/index.go
Normal file
76
EdgeAdmin/internal/web/actions/default/ns/routes/index.go
Normal file
@@ -0,0 +1,76 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "index")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
CategoryId int64
|
||||
}) {
|
||||
this.Data["categoryId"] = params.CategoryId
|
||||
|
||||
routesResp, err := this.RPC().NSRouteRPC().FindAllNSRoutes(this.AdminContext(), &pb.FindAllNSRoutesRequest{
|
||||
NsClusterId: 0,
|
||||
NsDomainId: 0,
|
||||
UserId: 0,
|
||||
NsRouteCategoryId: params.CategoryId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var routeMaps = []maps.Map{}
|
||||
for _, route := range routesResp.NsRoutes {
|
||||
// 分类
|
||||
var categoryMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if route.NsRouteCategory != nil {
|
||||
categoryMap = maps.Map{
|
||||
"id": route.NsRouteCategory.Id,
|
||||
"name": route.NsRouteCategory.Name,
|
||||
}
|
||||
}
|
||||
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"id": route.Id,
|
||||
"name": route.Name,
|
||||
"isOn": route.IsOn,
|
||||
"isPublic": route.IsPublic,
|
||||
"priority": route.Priority,
|
||||
"category": categoryMap,
|
||||
})
|
||||
}
|
||||
this.Data["routes"] = routeMaps
|
||||
|
||||
// 所有分类
|
||||
categoriesResp, err := this.RPC().NSRouteCategoryRPC().FindAllNSRouteCategories(this.AdminContext(), &pb.FindAllNSRouteCategoriesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var categoryMaps = []maps.Map{}
|
||||
for _, category := range categoriesResp.NsRouteCategories {
|
||||
categoryMaps = append(categoryMaps, maps.Map{
|
||||
"id": category.Id,
|
||||
"name": category.Name,
|
||||
})
|
||||
}
|
||||
this.Data["categories"] = categoryMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
32
EdgeAdmin/internal/web/actions/default/ns/routes/init.go
Normal file
32
EdgeAdmin/internal/web/actions/default/ns/routes/init.go
Normal file
@@ -0,0 +1,32 @@
|
||||
//go:build plus
|
||||
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(plus.NewHelper(plus.ComponentCodeNS)).
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNS)).
|
||||
Data("teaMenu", "ns").
|
||||
Data("teaSubMenu", "route").
|
||||
Prefix("/ns/routes").
|
||||
Get("", new(IndexAction)).
|
||||
Get("/route", new(RouteAction)).
|
||||
GetPost("/createPopup", new(CreatePopupAction)).
|
||||
GetPost("/updatePopup", new(UpdatePopupAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
Post("/sort", new(SortAction)).
|
||||
Post("/options", new(OptionsAction)).
|
||||
Get("/internal", new(InternalAction)).
|
||||
Get("/exportAgentIPs", new(ExportAgentIPsAction)).
|
||||
GetPost("/importAgentIPsPopup", new(ImportAgentIPsPopupAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
47
EdgeAdmin/internal/web/actions/default/ns/routes/internal.go
Normal file
47
EdgeAdmin/internal/web/actions/default/ns/routes/internal.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type InternalAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *InternalAction) Init() {
|
||||
this.Nav("", "", "internal")
|
||||
}
|
||||
|
||||
func (this *InternalAction) RunGet(params struct{}) {
|
||||
this.Data["ispRoutes"] = dnsconfigs.AllDefaultISPRoutes
|
||||
this.Data["chinaProvinceRoutes"] = dnsconfigs.AllDefaultChinaProvinceRoutes
|
||||
this.Data["worldRegionRoutes"] = dnsconfigs.AllDefaultWorldRegionRoutes
|
||||
|
||||
// Agent相关线路
|
||||
agentsResp, err := this.RPC().ClientAgentRPC().FindAllClientAgents(this.AdminContext(), &pb.FindAllClientAgentsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var agentRouteMaps = []maps.Map{}
|
||||
var hasEmptyAgents = false
|
||||
for _, agent := range agentsResp.ClientAgents {
|
||||
agentRouteMaps = append(agentRouteMaps, maps.Map{
|
||||
"name": agent.Name,
|
||||
"code": "agent:" + agent.Code,
|
||||
"countIPs": agent.CountIPs,
|
||||
})
|
||||
if agent.CountIPs == 0 {
|
||||
hasEmptyAgents = true
|
||||
}
|
||||
}
|
||||
this.Data["agentRoutes"] = agentRouteMaps
|
||||
this.Data["hasEmptyAgents"] = hasEmptyAgents
|
||||
|
||||
this.Show()
|
||||
}
|
||||
126
EdgeAdmin/internal/web/actions/default/ns/routes/options.go
Normal file
126
EdgeAdmin/internal/web/actions/default/ns/routes/options.go
Normal file
@@ -0,0 +1,126 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
type OptionsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *OptionsAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
DomainId int64
|
||||
UserId int64
|
||||
}) {
|
||||
var routeMaps = []maps.Map{}
|
||||
|
||||
// 默认线路
|
||||
for _, route := range dnsconfigs.AllDefaultRoutes {
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"name": route.Name,
|
||||
"code": route.Code,
|
||||
"type": "default",
|
||||
})
|
||||
}
|
||||
|
||||
// 自定义
|
||||
routesResp, err := this.RPC().NSRouteRPC().FindAllNSRoutes(this.AdminContext(), &pb.FindAllNSRoutesRequest{
|
||||
NsClusterId: params.ClusterId,
|
||||
NsDomainId: params.DomainId,
|
||||
UserId: params.UserId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, route := range routesResp.NsRoutes {
|
||||
if len(route.Code) == 0 {
|
||||
route.Code = "id:" + types.String(route.Id)
|
||||
}
|
||||
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"name": route.Name,
|
||||
"code": route.Code,
|
||||
"type": "user",
|
||||
})
|
||||
}
|
||||
|
||||
// 运营商
|
||||
this.Data["hasISPRoutes"] = true
|
||||
for _, route := range dnsconfigs.AllDefaultISPRoutes {
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"name": route.Name,
|
||||
"code": route.Code,
|
||||
"type": "isp",
|
||||
})
|
||||
}
|
||||
|
||||
// 中国
|
||||
this.Data["hasChinaProvinceRoutes"] = true
|
||||
for _, route := range dnsconfigs.AllDefaultChinaProvinceRoutes {
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"name": route.Name,
|
||||
"code": route.Code,
|
||||
"type": "china",
|
||||
})
|
||||
}
|
||||
|
||||
// 全球
|
||||
this.Data["hasWorldRegionRoutes"] = true
|
||||
for _, route := range dnsconfigs.AllDefaultWorldRegionRoutes {
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"name": route.Name,
|
||||
"code": route.Code,
|
||||
"type": "world",
|
||||
})
|
||||
}
|
||||
|
||||
// 省份
|
||||
provincesResp, err := this.RPC().RegionProvinceRPC().FindAllRegionProvinces(this.AdminContext(), &pb.FindAllRegionProvincesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var provinceMaps = []maps.Map{}
|
||||
for _, province := range provincesResp.RegionProvinces {
|
||||
if province.RegionCountry == nil || len(province.RegionCountry.RouteCode) == 0 {
|
||||
continue
|
||||
}
|
||||
provinceMaps = append(provinceMaps, maps.Map{
|
||||
"id": province.Id,
|
||||
"name": province.Name,
|
||||
"code": "region:province:" + types.String(province.Id),
|
||||
"type": "province",
|
||||
"countryCode": province.RegionCountry.RouteCode,
|
||||
})
|
||||
}
|
||||
this.Data["provinces"] = provinceMaps
|
||||
|
||||
// 搜索引擎
|
||||
agentsResp, err := this.RPC().NSRouteRPC().FindAllAgentNSRoutes(this.AdminContext(), &pb.FindAllAgentNSRoutesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["hasAgentRoutes"] = true
|
||||
for _, route := range agentsResp.NsRoutes {
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"name": route.Name,
|
||||
"code": route.Code,
|
||||
"type": "agent",
|
||||
})
|
||||
}
|
||||
|
||||
this.Data["routes"] = routeMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
17
EdgeAdmin/internal/web/actions/default/ns/routes/route.go
Normal file
17
EdgeAdmin/internal/web/actions/default/ns/routes/route.go
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package routes
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
|
||||
type RouteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *RouteAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *RouteAction) RunGet(params struct{}) {
|
||||
this.Show()
|
||||
}
|
||||
28
EdgeAdmin/internal/web/actions/default/ns/routes/sort.go
Normal file
28
EdgeAdmin/internal/web/actions/default/ns/routes/sort.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type SortAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SortAction) RunPost(params struct {
|
||||
RouteIds []int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NSRoute_LogSortNSRoutes)
|
||||
|
||||
_, err := this.RPC().NSRouteRPC().UpdateNSRouteOrders(this.AdminContext(), &pb.UpdateNSRouteOrdersRequest{NsRouteIds: params.RouteIds})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
125
EdgeAdmin/internal/web/actions/default/ns/routes/updatePopup.go
Normal file
125
EdgeAdmin/internal/web/actions/default/ns/routes/updatePopup.go
Normal file
@@ -0,0 +1,125 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package routes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpdatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
RouteId int64
|
||||
}) {
|
||||
routeResp, err := this.RPC().NSRouteRPC().FindNSRoute(this.AdminContext(), &pb.FindNSRouteRequest{NsRouteId: params.RouteId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var route = routeResp.NsRoute
|
||||
if route == nil {
|
||||
this.NotFound("nsRoute", params.RouteId)
|
||||
return
|
||||
}
|
||||
|
||||
var rangeMaps = []maps.Map{}
|
||||
if len(route.RangesJSON) > 0 {
|
||||
err = json.Unmarshal(route.RangesJSON, &rangeMaps)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 分类
|
||||
var categoryId int64 = 0
|
||||
if route.NsRouteCategory != nil {
|
||||
categoryId = route.NsRouteCategory.Id
|
||||
}
|
||||
|
||||
this.Data["route"] = maps.Map{
|
||||
"id": route.Id,
|
||||
"name": route.Name,
|
||||
"isOn": route.IsOn,
|
||||
"isPublic": route.IsPublic,
|
||||
"categoryId": categoryId,
|
||||
"priority": route.Priority,
|
||||
"ranges": rangeMaps,
|
||||
}
|
||||
|
||||
// 范围类型
|
||||
this.Data["rangeTypes"] = dnsconfigs.AllNSRouteRangeTypes()
|
||||
|
||||
// 所有分类
|
||||
categoriesResp, err := this.RPC().NSRouteCategoryRPC().FindAllNSRouteCategories(this.AdminContext(), &pb.FindAllNSRouteCategoriesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var categoryMaps = []maps.Map{}
|
||||
for _, category := range categoriesResp.NsRouteCategories {
|
||||
categoryMaps = append(categoryMaps, maps.Map{
|
||||
"id": category.Id,
|
||||
"name": category.Name,
|
||||
})
|
||||
}
|
||||
this.Data["categories"] = categoryMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
RouteId int64
|
||||
Name string
|
||||
RangesJSON []byte
|
||||
IsPublic bool
|
||||
CategoryId int64
|
||||
Priority int32
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NSRoute_LogUpdateNSRoute, params.RouteId)
|
||||
|
||||
params.Must.Field("name", params.Name).
|
||||
Require("请输入线路名称")
|
||||
|
||||
ranges, err := dnsconfigs.InitNSRangesFromJSON(params.RangesJSON)
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
if len(ranges) == 0 {
|
||||
this.Fail("请添加线路范围")
|
||||
}
|
||||
|
||||
_, err = this.RPC().NSRouteRPC().UpdateNSRoute(this.AdminContext(), &pb.UpdateNSRouteRequest{
|
||||
NsRouteId: params.RouteId,
|
||||
Name: params.Name,
|
||||
RangesJSON: params.RangesJSON,
|
||||
IsPublic: params.IsPublic,
|
||||
NsRouteCategoryId: params.CategoryId,
|
||||
Priority: params.Priority,
|
||||
IsOn: params.IsOn,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user