This commit is contained in:
unknown
2026-02-04 20:27:13 +08:00
commit 3b042d1dad
9410 changed files with 1488147 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package clusters
import (
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"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/ns/nsutils"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/types"
)
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()
// 线路限额
maxCustomRoutes, canCreate, err := nsutils.CheckRoutesQuota(this.UserContext(), 1)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["quotaMaxCustomRoutes"] = maxCustomRoutes
this.Data["quotaCanCreate"] = canCreate
this.Show()
}
func (this *CreatePopupAction) RunPost(params struct {
ClusterId int64
DomainId int64
UserId int64
Name string
RangesJSON []byte
Must *actions.Must
CSRF *actionutils.CSRF
}) {
var routeId = int64(0)
defer func() {
this.CreateLogInfo(codes.NSRoute_LogCreateNSRoute, routeId)
}()
// 线路限额
maxCustomRoutes, canCreate, err := nsutils.CheckRoutesQuota(this.UserContext(), 1)
if err != nil {
this.ErrorPage(err)
return
}
if !canCreate {
this.Fail("超出线路最大限额(" + types.String(maxCustomRoutes) + "个),请升级套餐后再试")
return
}
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.UserContext(), &pb.CreateNSRouteRequest{
NsClusterId: params.ClusterId,
NsDomainId: params.DomainId,
UserId: params.UserId,
Name: params.Name,
RangesJSON: params.RangesJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
routeId = createResp.NsRouteId
this.Success()
}

View File

@@ -0,0 +1,27 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package clusters
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 {
RouteId int64
}) {
defer this.CreateLogInfo(codes.NSRoute_LogDeleteNSRoute, params.RouteId)
_, err := this.RPC().NSRouteRPC().DeleteNSRoute(this.UserContext(), &pb.DeleteNSRouteRequest{NsRouteId: params.RouteId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,41 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package clusters
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("", "", "index")
}
func (this *IndexAction) RunGet(params struct{}) {
routesResp, err := this.RPC().NSRouteRPC().FindAllNSRoutes(this.UserContext(), &pb.FindAllNSRoutesRequest{
NsClusterId: 0,
NsDomainId: 0,
UserId: 0,
})
if err != nil {
this.ErrorPage(err)
return
}
var routeMaps = []maps.Map{}
for _, route := range routesResp.NsRoutes {
routeMaps = append(routeMaps, maps.Map{
"id": route.Id,
"name": route.Name,
"isOn": route.IsOn,
})
}
this.Data["routes"] = routeMaps
this.Show()
}

View File

@@ -0,0 +1,25 @@
package clusters
import (
"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", "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)).
EndAll()
})
}

View File

@@ -0,0 +1,89 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package clusters
import (
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/lists"
"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().NSRouteRPC().FindAllAgentNSRoutes(this.UserContext(), &pb.FindAllAgentNSRoutesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var agentRouteMaps = []maps.Map{}
for _, route := range agentsResp.NsRoutes {
agentRouteMaps = append(agentRouteMaps, maps.Map{
"name": route.Name,
"code": route.Code,
})
}
this.Data["agentRoutes"] = agentRouteMaps
// 系统内置公用线路
publicRoutesResp, err := this.RPC().NSRouteRPC().FindAllPublicNSRoutes(this.UserContext(), &pb.FindAllPublicRoutesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var publicCategoryMaps = []maps.Map{}
var publicCategoryIds = []int64{}
var publicRouteMaps = []maps.Map{}
for _, route := range publicRoutesResp.NsRoutes {
var categoryId int64 = 0
if route.NsRouteCategory != nil {
categoryId = route.NsRouteCategory.Id
}
publicRouteMaps = append(publicRouteMaps, maps.Map{
"id": route.Id,
"name": route.Name,
"code": route.Code,
"categoryId": categoryId,
})
// 未分类
if route.NsRouteCategory == nil {
if !lists.ContainsInt64(publicCategoryIds, 0) {
publicCategoryIds = append(publicCategoryIds, 0)
publicCategoryMaps = append(publicCategoryMaps, maps.Map{
"id": 0,
"name": "官方线路",
})
}
continue
}
// 有分类
if !lists.ContainsInt64(publicCategoryIds, route.NsRouteCategory.Id) {
publicCategoryIds = append(publicCategoryIds, route.NsRouteCategory.Id)
publicCategoryMaps = append(publicCategoryMaps, maps.Map{
"id": route.NsRouteCategory.Id,
"name": route.NsRouteCategory.Name,
})
}
}
this.Data["publicCategories"] = publicCategoryMaps
this.Data["publicRoutes"] = publicRouteMaps
this.Show()
}

View File

@@ -0,0 +1,203 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package clusters
import (
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/ns/nsutils"
"github.com/iwind/TeaGo/lists"
"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{}
planConfig, err := nsutils.FindUserPlanConfig(this.UserContext())
if err != nil {
this.ErrorPage(err)
return
}
// 默认线路
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.UserContext(), &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)
}
if !route.IsOn {
continue
}
routeMaps = append(routeMaps, maps.Map{
"name": route.Name,
"code": route.Code,
"type": "user",
})
}
// 运营商
this.Data["supportISPRoutes"] = false
if planConfig == nil || planConfig.SupportISPRoutes {
this.Data["supportISPRoutes"] = true
for _, route := range dnsconfigs.AllDefaultISPRoutes {
routeMaps = append(routeMaps, maps.Map{
"name": route.Name,
"code": route.Code,
"type": "isp",
})
}
}
// 中国省份
this.Data["supportChinaProvinceRoutes"] = false
if planConfig == nil || planConfig.SupportChinaProvinceRoutes {
this.Data["supportChinaProvinceRoutes"] = true
for _, route := range dnsconfigs.AllDefaultChinaProvinceRoutes {
routeMaps = append(routeMaps, maps.Map{
"name": route.Name,
"code": route.Code,
"type": "china",
})
}
}
// 全球
this.Data["supportWorldRegionRoutes"] = false
if planConfig == nil || planConfig.SupportCountryRoutes {
this.Data["supportWorldRegionRoutes"] = 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.UserContext(), &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
// 搜索引擎
this.Data["supportAgentRoutes"] = false
if planConfig == nil || planConfig.SupportAgentRoutes {
this.Data["supportAgentRoutes"] = true
agentsResp, err := this.RPC().NSRouteRPC().FindAllAgentNSRoutes(this.UserContext(), &pb.FindAllAgentNSRoutesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
for _, route := range agentsResp.NsRoutes {
routeMaps = append(routeMaps, maps.Map{
"name": route.Name,
"code": route.Code,
"type": "agent",
})
}
}
// 公共线路
this.Data["publicCategories"] = []maps.Map{}
this.Data["supportPublicRoutes"] = false
publicRoutesResp, err := this.RPC().NSRouteRPC().FindAllPublicNSRoutes(this.UserContext(), &pb.FindAllPublicRoutesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
if len(publicRoutesResp.NsRoutes) == 0 {
this.Data["supportPublicRoutes"] = true
} else if planConfig == nil || planConfig.SupportPublicRoutes {
this.Data["supportPublicRoutes"] = true
var publicCategoryMaps = []maps.Map{}
var publicCategoryIds = []int64{}
for _, route := range publicRoutesResp.NsRoutes {
var categoryId int64 = 0
if route.NsRouteCategory != nil {
categoryId = route.NsRouteCategory.Id
}
routeMaps = append(routeMaps, maps.Map{
"name": route.Name,
"code": route.Code,
"type": "public:category:" + types.String(categoryId),
})
// 未分类
if route.NsRouteCategory == nil {
if !lists.ContainsInt64(publicCategoryIds, 0) {
publicCategoryIds = append(publicCategoryIds, 0)
publicCategoryMaps = append(publicCategoryMaps, maps.Map{
"id": 0,
"name": "官方线路",
"type": "public:category:" + types.String(0),
})
}
continue
}
// 有分类
if !lists.ContainsInt64(publicCategoryIds, categoryId) {
publicCategoryIds = append(publicCategoryIds, route.NsRouteCategory.Id)
publicCategoryMaps = append(publicCategoryMaps, maps.Map{
"id": route.NsRouteCategory.Id,
"name": route.NsRouteCategory.Name,
"type": "public:category:" + types.String(categoryId),
})
}
}
this.Data["publicCategories"] = publicCategoryMaps
}
this.Data["routes"] = routeMaps
this.Success()
}

View File

@@ -0,0 +1,17 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package clusters
import "github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
type RouteAction struct {
actionutils.ParentAction
}
func (this *RouteAction) Init() {
this.Nav("", "", "")
}
func (this *RouteAction) RunGet(params struct{}) {
this.Show()
}

View File

@@ -0,0 +1,27 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package clusters
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 {
RouteIds []int64
}) {
defer this.CreateLogInfo(codes.NSRoute_LogSortNSRoutes)
_, err := this.RPC().NSRouteRPC().UpdateNSRouteOrders(this.UserContext(), &pb.UpdateNSRouteOrdersRequest{NsRouteIds: params.RouteIds})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,95 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package clusters
import (
"encoding/json"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"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 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.UserContext(), &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
}
}
this.Data["route"] = maps.Map{
"id": route.Id,
"name": route.Name,
"isOn": route.IsOn,
"ranges": rangeMaps,
}
// 范围类型
this.Data["rangeTypes"] = dnsconfigs.AllNSRouteRangeTypes()
this.Show()
}
func (this *UpdatePopupAction) RunPost(params struct {
RouteId int64
Name string
RangesJSON []byte
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.UserContext(), &pb.UpdateNSRouteRequest{
NsRouteId: params.RouteId,
Name: params.Name,
RangesJSON: params.RangesJSON,
IsOn: params.IsOn,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}