Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package antiddos
|
||||
|
||||
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/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"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{}) {
|
||||
// 线路选项
|
||||
networkResp, err := this.RPC().ADNetworkRPC().FindAllADNetworks(this.AdminContext(), &pb.FindAllADNetworkRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var networkMaps = []maps.Map{}
|
||||
for _, network := range networkResp.AdNetworks {
|
||||
networkMaps = append(networkMaps, maps.Map{
|
||||
"id": network.Id,
|
||||
"name": network.Name,
|
||||
"isOn": network.IsOn,
|
||||
})
|
||||
}
|
||||
this.Data["networks"] = networkMaps
|
||||
|
||||
// 带宽单位
|
||||
this.Data["protectionUnitOptions"] = []maps.Map{
|
||||
{
|
||||
"code": userconfigs.ADPackageSizeUnitGb,
|
||||
"name": "Gbps",
|
||||
},
|
||||
{
|
||||
"code": userconfigs.ADPackageSizeUnitTb,
|
||||
"name": "Tbps",
|
||||
},
|
||||
}
|
||||
this.Data["serverUnitOptions"] = []maps.Map{
|
||||
{
|
||||
"code": userconfigs.ADPackageSizeUnitMb,
|
||||
"name": "Mbps",
|
||||
},
|
||||
{
|
||||
"code": userconfigs.ADPackageSizeUnitGb,
|
||||
"name": "Gbps",
|
||||
},
|
||||
{
|
||||
"code": userconfigs.ADPackageSizeUnitTb,
|
||||
"name": "Tbps",
|
||||
},
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
NetworkId int64
|
||||
ProtectionBandwidthSize int32
|
||||
ProtectionBandwidthUnit string
|
||||
ServerBandwidthSize int32
|
||||
ServerBandwidthUnit string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var packageId int64
|
||||
defer func() {
|
||||
this.CreateLogInfo(codes.ADPackage_LogCreateADPackage, packageId)
|
||||
}()
|
||||
|
||||
if params.NetworkId <= 0 {
|
||||
this.Fail("请选择所属线路")
|
||||
return
|
||||
}
|
||||
if params.ProtectionBandwidthSize <= 0 || len(params.ProtectionBandwidthUnit) == 0 {
|
||||
this.FailField("protectionBandwidthSize", "请输入防护带宽")
|
||||
return
|
||||
}
|
||||
if params.ServerBandwidthSize <= 0 || len(params.ServerBandwidthUnit) == 0 {
|
||||
this.FailField("serverBandwidthSize", "请输入业务带宽")
|
||||
return
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().ADPackageRPC().CreateADPackage(this.AdminContext(), &pb.CreateADPackageRequest{
|
||||
AdNetworkId: params.NetworkId,
|
||||
ProtectionBandwidthSize: params.ProtectionBandwidthSize,
|
||||
ProtectionBandwidthUnit: params.ProtectionBandwidthUnit,
|
||||
ServerBandwidthSize: params.ServerBandwidthSize,
|
||||
ServerBandwidthUnit: params.ServerBandwidthUnit,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
packageId = createResp.AdPackageId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package antiddos
|
||||
|
||||
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 {
|
||||
PackageId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.ADPackage_LogDeleteADPackage, params.PackageId)
|
||||
|
||||
_, err := this.RPC().ADPackageRPC().DeleteADPackage(this.AdminContext(), &pb.DeleteADPackageRequest{AdPackageId: params.PackageId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package antiddos
|
||||
|
||||
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 {
|
||||
NetworkId int64
|
||||
}) {
|
||||
this.Data["networkId"] = params.NetworkId
|
||||
|
||||
countResp, err := this.RPC().ADPackageRPC().CountADPackages(this.AdminContext(), &pb.CountADPackagesRequest{
|
||||
AdNetworkId: params.NetworkId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
packagesResp, err := this.RPC().ADPackageRPC().ListADPackages(this.AdminContext(), &pb.ListADPackagesRequest{
|
||||
AdNetworkId: params.NetworkId,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var packageMaps = []maps.Map{}
|
||||
for _, p := range packagesResp.AdPackages {
|
||||
// 线路
|
||||
var networkMap = maps.Map{
|
||||
"id": 0,
|
||||
"name": "",
|
||||
"isOn": false,
|
||||
}
|
||||
if p.AdNetwork != nil {
|
||||
networkMap = maps.Map{
|
||||
"id": p.AdNetwork.Id,
|
||||
"name": p.AdNetwork.Name,
|
||||
"isOn": p.AdNetwork.IsOn,
|
||||
}
|
||||
}
|
||||
|
||||
// 价格项数量
|
||||
countPricesResp, err := this.RPC().ADPackagePriceRPC().CountADPackagePrices(this.AdminContext(), &pb.CountADPackagePricesRequest{AdPackageId: p.Id})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var countPrices = countPricesResp.Count
|
||||
|
||||
// 实例数量
|
||||
countInstancesResp, err := this.RPC().ADPackageInstanceRPC().CountADPackageInstances(this.AdminContext(), &pb.CountADPackageInstancesRequest{AdPackageId: p.Id})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var countInstances = countInstancesResp.Count
|
||||
|
||||
packageMaps = append(packageMaps, maps.Map{
|
||||
"id": p.Id,
|
||||
"isOn": p.IsOn,
|
||||
"protectionBandwidthSize": p.ProtectionBandwidthSize,
|
||||
"protectionBandwidthUnit": p.ProtectionBandwidthUnit,
|
||||
"serverBandwidthSize": p.ServerBandwidthSize,
|
||||
"serverBandwidthUnit": p.ServerBandwidthUnit,
|
||||
"network": networkMap,
|
||||
"countPrices": countPrices,
|
||||
"countInstances": countInstances,
|
||||
})
|
||||
}
|
||||
this.Data["packages"] = packageMaps
|
||||
|
||||
// 所有线路
|
||||
networkResp, err := this.RPC().ADNetworkRPC().FindAllADNetworks(this.AdminContext(), &pb.FindAllADNetworkRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var networkMaps = []maps.Map{}
|
||||
for _, network := range networkResp.AdNetworks {
|
||||
networkMaps = append(networkMaps, maps.Map{
|
||||
"id": network.Id,
|
||||
"name": network.Name,
|
||||
"isOn": network.IsOn,
|
||||
})
|
||||
}
|
||||
this.Data["networks"] = networkMaps
|
||||
|
||||
// 价格项总数量
|
||||
periodsResp, err := this.RPC().ADPackagePeriodRPC().FindAllAvailableADPackagePeriods(this.AdminContext(), &pb.FindAllAvailableADPackagePeriodsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["totalPriceItems"] = len(periodsResp.AdPackagePeriods)
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
//go:build plus
|
||||
|
||||
package antiddos
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/anti-ddos/instances"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/anti-ddos/instances/instance"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/anti-ddos/networks"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/anti-ddos/networks/network"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/anti-ddos/periods"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/anti-ddos/periods/period"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/anti-ddos/user-instances"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(plus.NewHelper(plus.ComponentCodeAntiDDoS)).
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNode)).
|
||||
Data("teaMenu", "clusters").
|
||||
Data("teaSubMenu", "antiDDoS").
|
||||
|
||||
// 高防产品
|
||||
Prefix("/clusters/anti-ddos").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/createPopup", new(CreatePopupAction)).
|
||||
GetPost("/updatePopup", new(UpdatePopupAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
GetPost("/updatePricesPopup", new(UpdatePricesPopupAction)).
|
||||
Post("/updatePrice", new(UpdatePriceAction)).
|
||||
|
||||
// 实例
|
||||
Prefix("/clusters/anti-ddos/instances").
|
||||
Get("", new(instances.IndexAction)).
|
||||
GetPost("/createPopup", new(instances.CreatePopupAction)).
|
||||
GetPost("/instance/updatePopup", new(instance.UpdatePopupAction)).
|
||||
Post("/instance/delete", new(instance.DeleteAction)).
|
||||
|
||||
// 高防线路
|
||||
Prefix("/clusters/anti-ddos/networks").
|
||||
Get("", new(networks.IndexAction)).
|
||||
GetPost("/createPopup", new(networks.CreatePopupAction)).
|
||||
GetPost("/network/updatePopup", new(network.UpdatePopupAction)).
|
||||
Post("/network/delete", new(network.DeleteAction)).
|
||||
|
||||
// 高防实例有效期
|
||||
Prefix("/clusters/anti-ddos/periods").
|
||||
Get("", new(periods.IndexAction)).
|
||||
GetPost("/createPopup", new(periods.CreatePopupAction)).
|
||||
|
||||
// 高防实例有效期详情
|
||||
Prefix("/clusters/anti-ddos/periods/period").
|
||||
GetPost("/updatePopup", new(period.UpdatePopupAction)).
|
||||
Post("/delete", new(period.DeleteAction)).
|
||||
|
||||
// 用户高防实例
|
||||
Prefix("/clusters/anti-ddos/user-instances").
|
||||
Get("", new(userinstances.IndexAction)).
|
||||
GetPost("/createPopup", new(userinstances.CreatePopupAction)).
|
||||
Post("/price", new(userinstances.PriceAction)).
|
||||
Post("/delete", new(userinstances.DeleteAction)).
|
||||
GetPost("/renewPopup", new(userinstances.RenewPopupAction)).
|
||||
GetPost("/updateObjectsPopup", new(userinstances.UpdateObjectsPopupAction)).
|
||||
Post("/userServers", new(userinstances.UserServersAction)).
|
||||
|
||||
//
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package instances
|
||||
|
||||
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 CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct {
|
||||
NetworkId int64
|
||||
PackageId int64
|
||||
}) {
|
||||
// 两个参数只能二选一
|
||||
if params.PackageId > 0 {
|
||||
params.NetworkId = 0
|
||||
}
|
||||
|
||||
// 产品
|
||||
this.Data["packageId"] = params.PackageId
|
||||
this.Data["packageSummary"] = ""
|
||||
if params.PackageId > 0 {
|
||||
packageResp, err := this.RPC().ADPackageRPC().FindADPackage(this.AdminContext(), &pb.FindADPackageRequest{AdPackageId: params.PackageId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if packageResp.AdPackage == nil {
|
||||
this.NotFound("adPackage", params.PackageId)
|
||||
return
|
||||
}
|
||||
this.Data["packageSummary"] = packageResp.AdPackage.Summary
|
||||
}
|
||||
|
||||
// 线路
|
||||
this.Data["networkId"] = params.NetworkId
|
||||
networksResp, err := this.RPC().ADNetworkRPC().FindAllAvailableADNetworks(this.AdminContext(), &pb.FindAllAvailableADNetworksRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var networkMaps = []maps.Map{}
|
||||
for _, network := range networksResp.AdNetworks {
|
||||
networkMaps = append(networkMaps, maps.Map{
|
||||
"id": network.Id,
|
||||
"name": network.Name,
|
||||
})
|
||||
}
|
||||
this.Data["networks"] = networkMaps
|
||||
|
||||
// 所有产品
|
||||
this.Data["packages"] = []maps.Map{}
|
||||
var packageMaps = []maps.Map{}
|
||||
var offset int64 = 0
|
||||
var size int64 = 20
|
||||
for {
|
||||
// 这里查询所有线路
|
||||
packageResp, err := this.RPC().ADPackageRPC().ListADPackages(this.AdminContext(), &pb.ListADPackagesRequest{
|
||||
Offset: offset,
|
||||
Size: size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if len(packageResp.AdPackages) == 0 {
|
||||
break
|
||||
}
|
||||
for _, p := range packageResp.AdPackages {
|
||||
packageMaps = append(packageMaps, maps.Map{
|
||||
"id": p.Id,
|
||||
"networkId": p.AdNetworkId,
|
||||
"summary": p.Summary,
|
||||
})
|
||||
}
|
||||
offset += size
|
||||
}
|
||||
this.Data["packages"] = packageMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
PackageId int64
|
||||
ClusterId int64
|
||||
NodeIds []int64
|
||||
IpAddresses []string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var createdInstanceId int64
|
||||
defer func() {
|
||||
this.CreateLogInfo(codes.ADPackageInstance_LogCreateADPackageInstance, createdInstanceId)
|
||||
}()
|
||||
|
||||
if params.PackageId <= 0 {
|
||||
this.Fail("请选择所属高防产品")
|
||||
return
|
||||
}
|
||||
|
||||
if params.ClusterId <= 0 {
|
||||
this.Fail("请选择要部署的集群")
|
||||
return
|
||||
}
|
||||
|
||||
if len(params.IpAddresses) == 0 {
|
||||
this.Fail("请输入高防IP地址")
|
||||
return
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().ADPackageInstanceRPC().CreateADPackageInstance(this.AdminContext(), &pb.CreateADPackageInstanceRequest{
|
||||
AdPackageId: params.PackageId,
|
||||
NodeClusterId: params.ClusterId,
|
||||
NodeIds: params.NodeIds,
|
||||
IpAddresses: params.IpAddresses,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
createdInstanceId = createResp.AdPackageInstanceId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package instances
|
||||
|
||||
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("", "", "instance")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
NetworkId int64
|
||||
PackageId int64
|
||||
UserId int64
|
||||
Ip string
|
||||
|
||||
SelectedPackageId int64
|
||||
}) {
|
||||
this.Data["networkId"] = params.NetworkId
|
||||
this.Data["packageId"] = params.PackageId
|
||||
this.Data["ip"] = params.Ip
|
||||
|
||||
this.Data["selectedPackageId"] = params.SelectedPackageId
|
||||
|
||||
var networkId = params.NetworkId
|
||||
var packageId = params.PackageId
|
||||
|
||||
var selectedPackageMap = maps.Map{
|
||||
"id": 0,
|
||||
"summary": "",
|
||||
}
|
||||
if params.SelectedPackageId > 0 {
|
||||
packageId = params.SelectedPackageId
|
||||
packageResp, err := this.RPC().ADPackageRPC().FindADPackage(this.AdminContext(), &pb.FindADPackageRequest{
|
||||
AdPackageId: params.SelectedPackageId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var adPackage = packageResp.AdPackage
|
||||
if adPackage == nil {
|
||||
this.NotFound("adPackage", params.SelectedPackageId)
|
||||
return
|
||||
}
|
||||
|
||||
selectedPackageMap = maps.Map{
|
||||
"id": adPackage.Id,
|
||||
"summary": adPackage.Summary,
|
||||
}
|
||||
}
|
||||
this.Data["selectedPackage"] = selectedPackageMap
|
||||
|
||||
countResp, err := this.RPC().ADPackageInstanceRPC().CountADPackageInstances(this.AdminContext(), &pb.CountADPackageInstancesRequest{
|
||||
AdNetworkId: networkId,
|
||||
AdPackageId: packageId,
|
||||
UserId: params.UserId,
|
||||
Ip: params.Ip,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var page = this.NewPage(countResp.Count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
listResp, err := this.RPC().ADPackageInstanceRPC().ListADPackageInstances(this.AdminContext(), &pb.ListADPackageInstancesRequest{
|
||||
AdNetworkId: networkId,
|
||||
AdPackageId: packageId,
|
||||
UserId: params.UserId,
|
||||
Ip: params.Ip,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var instanceMaps = []maps.Map{}
|
||||
for _, instance := range listResp.AdPackageInstances {
|
||||
// network
|
||||
var networkMap = maps.Map{
|
||||
"id": 0,
|
||||
"name": "",
|
||||
}
|
||||
|
||||
// package
|
||||
var packageMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
|
||||
if instance.AdPackage != nil {
|
||||
packageMap = maps.Map{
|
||||
"id": instance.AdPackage.Id,
|
||||
"protectionBandwidthSize": instance.AdPackage.ProtectionBandwidthSize,
|
||||
"protectionBandwidthUnit": instance.AdPackage.ProtectionBandwidthUnit,
|
||||
"serverBandwidthSize": instance.AdPackage.ServerBandwidthSize,
|
||||
"serverBandwidthUnit": instance.AdPackage.ServerBandwidthUnit,
|
||||
}
|
||||
|
||||
if instance.AdPackage.AdNetwork != nil {
|
||||
networkMap = maps.Map{
|
||||
"id": instance.AdPackage.AdNetwork.Id,
|
||||
"name": instance.AdPackage.AdNetwork.Name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 集群
|
||||
var clusterMap = maps.Map{
|
||||
"id": 0,
|
||||
"name": "",
|
||||
}
|
||||
if instance.NodeCluster != nil {
|
||||
clusterMap = maps.Map{
|
||||
"id": instance.NodeCluster.Id,
|
||||
"name": instance.NodeCluster.Name,
|
||||
}
|
||||
}
|
||||
|
||||
// IP地址
|
||||
if instance.IpAddresses == nil {
|
||||
instance.IpAddresses = []string{}
|
||||
}
|
||||
|
||||
// user
|
||||
var userMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if instance.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": instance.User.Id,
|
||||
"fullname": instance.User.Fullname,
|
||||
"username": instance.User.Username,
|
||||
}
|
||||
}
|
||||
|
||||
var userDayTo = instance.UserDayTo
|
||||
if len(userDayTo) == 8 {
|
||||
userDayTo = userDayTo[:4] + "-" + userDayTo[4:6] + "-" + userDayTo[6:]
|
||||
}
|
||||
|
||||
instanceMaps = append(instanceMaps, maps.Map{
|
||||
"id": instance.Id,
|
||||
"isOn": instance.IsOn,
|
||||
"network": networkMap,
|
||||
"package": packageMap,
|
||||
"cluster": clusterMap,
|
||||
"ipAddresses": instance.IpAddresses,
|
||||
"userDayTo": userDayTo,
|
||||
"user": userMap,
|
||||
})
|
||||
}
|
||||
this.Data["instances"] = instanceMaps
|
||||
|
||||
// 所有线路
|
||||
var networkMaps = []maps.Map{}
|
||||
networksResp, err := this.RPC().ADNetworkRPC().FindAllAvailableADNetworks(this.AdminContext(), &pb.FindAllAvailableADNetworksRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for _, network := range networksResp.AdNetworks {
|
||||
networkMaps = append(networkMaps, maps.Map{
|
||||
"id": network.Id,
|
||||
"name": network.Name,
|
||||
})
|
||||
}
|
||||
this.Data["networks"] = networkMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package instance
|
||||
|
||||
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 {
|
||||
InstanceId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.ADPackageInstance_LogDeleteADPackageInstance, params.InstanceId)
|
||||
|
||||
_, err := this.RPC().ADPackageInstanceRPC().DeleteADPackageInstance(this.AdminContext(), &pb.DeleteADPackageInstanceRequest{AdPackageInstanceId: params.InstanceId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package instance
|
||||
|
||||
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 {
|
||||
InstanceId int64
|
||||
}) {
|
||||
this.Data["instanceId"] = params.InstanceId
|
||||
|
||||
instanceResp, err := this.RPC().ADPackageInstanceRPC().FindADPackageInstance(this.AdminContext(), &pb.FindADPackageInstanceRequest{AdPackageInstanceId: params.InstanceId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var instance = instanceResp.AdPackageInstance
|
||||
if instance == nil {
|
||||
this.NotFound("adPackageInstance", params.InstanceId)
|
||||
return
|
||||
}
|
||||
|
||||
var ipAddresses = instance.IpAddresses
|
||||
if ipAddresses == nil {
|
||||
ipAddresses = []string{}
|
||||
}
|
||||
|
||||
// network
|
||||
var networkMap = maps.Map{
|
||||
"id": 0,
|
||||
"name": "",
|
||||
}
|
||||
|
||||
// package
|
||||
var packageMap = maps.Map{
|
||||
"id": 0,
|
||||
"summary": "",
|
||||
}
|
||||
|
||||
if instance.AdPackage != nil {
|
||||
packageMap = maps.Map{
|
||||
"id": instance.AdPackage.Id,
|
||||
"protectionBandwidthSize": instance.AdPackage.ProtectionBandwidthSize,
|
||||
"protectionBandwidthUnit": instance.AdPackage.ProtectionBandwidthUnit,
|
||||
"serverBandwidthSize": instance.AdPackage.ServerBandwidthSize,
|
||||
"serverBandwidthUnit": instance.AdPackage.ServerBandwidthUnit,
|
||||
"summary": instance.AdPackage.Summary,
|
||||
}
|
||||
|
||||
if instance.AdPackage.AdNetwork != nil {
|
||||
networkMap = maps.Map{
|
||||
"id": instance.AdPackage.AdNetwork.Id,
|
||||
"name": instance.AdPackage.AdNetwork.Name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["instance"] = maps.Map{
|
||||
"id": instance.Id,
|
||||
"clusterId": instance.NodeClusterId,
|
||||
"ipAddresses": ipAddresses,
|
||||
"isOn": instance.IsOn,
|
||||
"network": networkMap,
|
||||
"package": packageMap,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
InstanceId int64
|
||||
ClusterId int64
|
||||
NodeIds []int64
|
||||
IpAddresses []string
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.ADPackageInstance_LogUpdateADPackageInstance, params.InstanceId)
|
||||
|
||||
if params.ClusterId <= 0 {
|
||||
this.Fail("请选择要部署的集群")
|
||||
return
|
||||
}
|
||||
|
||||
if len(params.IpAddresses) == 0 {
|
||||
this.Fail("请输入高防IP地址")
|
||||
return
|
||||
}
|
||||
|
||||
_, err := this.RPC().ADPackageInstanceRPC().UpdateADPackageInstance(this.AdminContext(), &pb.UpdateADPackageInstanceRequest{
|
||||
AdPackageInstanceId: params.InstanceId,
|
||||
NodeClusterId: params.ClusterId,
|
||||
NodeIds: params.NodeIds,
|
||||
IpAddresses: params.IpAddresses,
|
||||
IsOn: params.IsOn,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package networks
|
||||
|
||||
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
|
||||
Description string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var networkId int64
|
||||
defer func() {
|
||||
this.CreateLogInfo(codes.ADNetwork_LogCreateADNetwork, networkId)
|
||||
}()
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入线路名称")
|
||||
|
||||
createResp, err := this.RPC().ADNetworkRPC().CreateADNetwork(this.AdminContext(), &pb.CreateADNetworkRequest{
|
||||
Name: params.Name,
|
||||
Description: params.Description,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
networkId = createResp.AdNetworkId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package networks
|
||||
|
||||
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("", "", "network")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
networksResp, err := this.RPC().ADNetworkRPC().FindAllADNetworks(this.AdminContext(), &pb.FindAllADNetworkRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var networkMaps = []maps.Map{}
|
||||
for _, network := range networksResp.AdNetworks {
|
||||
networkMaps = append(networkMaps, maps.Map{
|
||||
"id": network.Id,
|
||||
"name": network.Name,
|
||||
"description": network.Description,
|
||||
"isOn": network.IsOn,
|
||||
})
|
||||
}
|
||||
this.Data["networks"] = networkMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package network
|
||||
|
||||
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 {
|
||||
NetworkId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.ADNetwork_LogDeleteADNetwork)
|
||||
|
||||
_, err := this.RPC().ADNetworkRPC().DeleteADNetwork(this.AdminContext(), &pb.DeleteADNetworkRequest{AdNetworkId: params.NetworkId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package network
|
||||
|
||||
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 {
|
||||
NetworkId int64
|
||||
}) {
|
||||
networkResp, err := this.RPC().ADNetworkRPC().FindADNetwork(this.AdminContext(), &pb.FindADNetworkRequest{AdNetworkId: params.NetworkId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var network = networkResp.AdNetwork
|
||||
if network == nil {
|
||||
this.NotFound("adNetwork", params.NetworkId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["network"] = maps.Map{
|
||||
"id": network.Id,
|
||||
"name": network.Name,
|
||||
"description": network.Description,
|
||||
"isOn": network.IsOn,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
NetworkId int64
|
||||
Name string
|
||||
Description string
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.ADNetwork_LogUpdateADNetwork, params.NetworkId)
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入线路名称")
|
||||
|
||||
_, err := this.RPC().ADNetworkRPC().UpdateADNetwork(this.AdminContext(), &pb.UpdateADNetworkRequest{
|
||||
AdNetworkId: params.NetworkId,
|
||||
IsOn: params.IsOn,
|
||||
Name: params.Name,
|
||||
Description: params.Description,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package periods
|
||||
|
||||
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 {
|
||||
Count int32
|
||||
Unit string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var periodId int64
|
||||
|
||||
defer func() {
|
||||
this.CreateLogInfo(codes.ADPackagePeriod_LogCreateADPackagePeriod, periodId)
|
||||
}()
|
||||
|
||||
if params.Count <= 0 {
|
||||
this.FailField("count", "请输入有效期数量")
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().ADPackagePeriodRPC().CreateADPackagePeriod(this.AdminContext(), &pb.CreateADPackagePeriodRequest{
|
||||
Count: params.Count,
|
||||
Unit: params.Unit,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
periodId = createResp.AdPackagePeriodId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package periods
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "period")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
// 所有有效期
|
||||
periodsResp, err := this.RPC().ADPackagePeriodRPC().FindAllADPackagePeriods(this.AdminContext(), &pb.FindAllADPackagePeriodsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var periodMaps = []maps.Map{}
|
||||
for _, period := range periodsResp.AdPackagePeriods {
|
||||
periodMaps = append(periodMaps, maps.Map{
|
||||
"id": period.Id,
|
||||
"count": period.Count,
|
||||
"unit": period.Unit,
|
||||
"unitName": userconfigs.ADPackagePeriodUnitName(period.Unit),
|
||||
"isOn": period.IsOn,
|
||||
})
|
||||
}
|
||||
this.Data["periods"] = periodMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package period
|
||||
|
||||
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 {
|
||||
PeriodId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.ADPackagePeriod_LogDeleteADPackagePeriod, params.PeriodId)
|
||||
|
||||
_, err := this.RPC().ADPackagePeriodRPC().DeleteADPackagePeriod(this.AdminContext(), &pb.DeleteADPackagePeriodRequest{AdPackagePeriodId: params.PeriodId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package period
|
||||
|
||||
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/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"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 {
|
||||
PeriodId int64
|
||||
}) {
|
||||
periodResp, err := this.RPC().ADPackagePeriodRPC().FindADPackagePeriod(this.AdminContext(), &pb.FindADPackagePeriodRequest{AdPackagePeriodId: params.PeriodId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var period = periodResp.AdPackagePeriod
|
||||
if period == nil {
|
||||
this.NotFound("adPackagePeriod", params.PeriodId)
|
||||
return
|
||||
}
|
||||
this.Data["period"] = maps.Map{
|
||||
"id": period.Id,
|
||||
"count": period.Count,
|
||||
"unitName": userconfigs.PricePeriodName(period.Unit),
|
||||
"isOn": period.IsOn,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
PeriodId int64
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.ADPackagePeriod_LogUpdateADPackagePeriod, params.PeriodId)
|
||||
|
||||
_, err := this.RPC().ADPackagePeriodRPC().UpdateADPackagePeriod(this.AdminContext(), &pb.UpdateADPackagePeriodRequest{
|
||||
AdPackagePeriodId: params.PeriodId,
|
||||
IsOn: params.IsOn,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package antiddos
|
||||
|
||||
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/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"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 {
|
||||
PackageId int64
|
||||
}) {
|
||||
packageResp, err := this.RPC().ADPackageRPC().FindADPackage(this.AdminContext(), &pb.FindADPackageRequest{AdPackageId: params.PackageId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var adPackage = packageResp.AdPackage
|
||||
if adPackage == nil {
|
||||
this.NotFound("adPackage", params.PackageId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["package"] = maps.Map{
|
||||
"id": adPackage.Id,
|
||||
"isOn": adPackage.IsOn,
|
||||
"protectionBandwidthSize": adPackage.ProtectionBandwidthSize,
|
||||
"protectionBandwidthUnit": adPackage.ProtectionBandwidthUnit,
|
||||
"serverBandwidthSize": adPackage.ServerBandwidthSize,
|
||||
"serverBandwidthUnit": adPackage.ServerBandwidthUnit,
|
||||
"networkId": adPackage.AdNetworkId,
|
||||
}
|
||||
|
||||
// 线路选项
|
||||
networkResp, err := this.RPC().ADNetworkRPC().FindAllADNetworks(this.AdminContext(), &pb.FindAllADNetworkRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var networkMaps = []maps.Map{}
|
||||
for _, network := range networkResp.AdNetworks {
|
||||
networkMaps = append(networkMaps, maps.Map{
|
||||
"id": network.Id,
|
||||
"name": network.Name,
|
||||
"isOn": network.IsOn,
|
||||
})
|
||||
}
|
||||
this.Data["networks"] = networkMaps
|
||||
|
||||
// 带宽单位
|
||||
this.Data["protectionUnitOptions"] = []maps.Map{
|
||||
{
|
||||
"code": userconfigs.ADPackageSizeUnitGb,
|
||||
"name": "Gbps",
|
||||
},
|
||||
{
|
||||
"code": userconfigs.ADPackageSizeUnitTb,
|
||||
"name": "Tbps",
|
||||
},
|
||||
}
|
||||
this.Data["serverUnitOptions"] = []maps.Map{
|
||||
{
|
||||
"code": userconfigs.ADPackageSizeUnitMb,
|
||||
"name": "Mbps",
|
||||
},
|
||||
{
|
||||
"code": userconfigs.ADPackageSizeUnitGb,
|
||||
"name": "Gbps",
|
||||
},
|
||||
{
|
||||
"code": userconfigs.ADPackageSizeUnitTb,
|
||||
"name": "Tbps",
|
||||
},
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
PackageId int64
|
||||
NetworkId int64
|
||||
ProtectionBandwidthSize int32
|
||||
ProtectionBandwidthUnit string
|
||||
ServerBandwidthSize int32
|
||||
ServerBandwidthUnit string
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.ADPackage_LogUpdateADPackage, params.PackageId)
|
||||
|
||||
if params.PackageId <= 0 {
|
||||
this.Fail("请选择要修改的高防产品")
|
||||
return
|
||||
}
|
||||
if params.NetworkId <= 0 {
|
||||
this.Fail("请选择所属线路")
|
||||
return
|
||||
}
|
||||
if params.ProtectionBandwidthSize <= 0 || len(params.ProtectionBandwidthUnit) == 0 {
|
||||
this.Fail("请输入防护带宽")
|
||||
return
|
||||
}
|
||||
if params.ServerBandwidthSize <= 0 || len(params.ServerBandwidthUnit) == 0 {
|
||||
this.Fail("请输入业务带宽")
|
||||
return
|
||||
}
|
||||
|
||||
_, err := this.RPC().ADPackageRPC().UpdateADPackage(this.AdminContext(), &pb.UpdateADPackageRequest{
|
||||
AdPackageId: params.PackageId,
|
||||
AdNetworkId: params.NetworkId,
|
||||
ProtectionBandwidthSize: params.ProtectionBandwidthSize,
|
||||
ProtectionBandwidthUnit: params.ProtectionBandwidthUnit,
|
||||
ServerBandwidthSize: params.ServerBandwidthSize,
|
||||
ServerBandwidthUnit: params.ServerBandwidthUnit,
|
||||
IsOn: params.IsOn,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package antiddos
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type UpdatePriceAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePriceAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePriceAction) RunPost(params struct {
|
||||
PackageId int64
|
||||
PeriodId int64
|
||||
Price float64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.ADPackagePrice_LogUpdateADPackagePrice, params.PackageId, params.PeriodId)
|
||||
|
||||
_, err := this.RPC().ADPackagePriceRPC().UpdateADPackagePrice(this.AdminContext(), &pb.UpdateADPackagePriceRequest{
|
||||
AdPackageId: params.PackageId,
|
||||
AdPackagePeriodId: params.PeriodId,
|
||||
Price: params.Price,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package antiddos
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
type UpdatePricesPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePricesPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePricesPopupAction) RunGet(params struct {
|
||||
PackageId int64
|
||||
}) {
|
||||
// 高防产品信息
|
||||
packageResp, err := this.RPC().ADPackageRPC().FindADPackage(this.AdminContext(), &pb.FindADPackageRequest{AdPackageId: params.PackageId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var p = packageResp.AdPackage
|
||||
if p == nil {
|
||||
this.NotFound("adPackage", params.PackageId)
|
||||
return
|
||||
}
|
||||
this.Data["package"] = maps.Map{
|
||||
"id": p.Id,
|
||||
"protectionBandwidthSize": p.ProtectionBandwidthSize,
|
||||
"protectionBandwidthUnit": p.ProtectionBandwidthUnit,
|
||||
"serverBandwidthSize": p.ServerBandwidthSize,
|
||||
"serverBandwidthUnit": p.ServerBandwidthUnit,
|
||||
}
|
||||
|
||||
// 有效期选项
|
||||
periodsResp, err := this.RPC().ADPackagePeriodRPC().FindAllAvailableADPackagePeriods(this.AdminContext(), &pb.FindAllAvailableADPackagePeriodsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var periodMaps = []maps.Map{}
|
||||
for _, period := range periodsResp.AdPackagePeriods {
|
||||
periodMaps = append(periodMaps, maps.Map{
|
||||
"id": period.Id,
|
||||
"count": period.Count,
|
||||
"unit": period.Unit,
|
||||
"name": types.String(period.Count) + userconfigs.ADPackagePeriodUnitName(period.Unit),
|
||||
})
|
||||
}
|
||||
this.Data["periods"] = periodMaps
|
||||
|
||||
// 所有价格
|
||||
pricesResp, err := this.RPC().ADPackagePriceRPC().FindADPackagePrices(this.AdminContext(), &pb.FindADPackagePricesRequest{AdPackageId: params.PackageId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var priceMap = map[string]float64{} // periodIdString => price
|
||||
for _, price := range pricesResp.AdPackagePrices {
|
||||
priceMap[types.String(price.AdPackagePeriodId)] = price.Price
|
||||
}
|
||||
|
||||
this.Data["prices"] = priceMap
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package userinstances
|
||||
|
||||
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/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
// 高防产品
|
||||
var allPackageMap = map[int64]*pb.ADPackage{} // packageId => *pb.ADPackage
|
||||
packagesResp, err := this.RPC().ADPackageRPC().FindAllIdleADPackages(this.AdminContext(), &pb.FindAllIdleADPackagesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for _, p := range packagesResp.AdPackages {
|
||||
allPackageMap[p.Id] = p
|
||||
}
|
||||
|
||||
// 价格
|
||||
pricesResp, err := this.RPC().ADPackagePriceRPC().FindAllADPackagePrices(this.AdminContext(), &pb.FindAllADPackagePricesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var priceMaps = []maps.Map{}
|
||||
for _, price := range pricesResp.AdPackagePrices {
|
||||
if price.Price > 0 {
|
||||
var packageId = price.AdPackageId
|
||||
var periodId = price.AdPackagePeriodId
|
||||
|
||||
p, ok := allPackageMap[packageId]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
var networkId = p.AdNetworkId
|
||||
var countIdleInstances = p.CountIdleADPackageInstances
|
||||
|
||||
if packageId > 0 && periodId > 0 && networkId > 0 && countIdleInstances > 0 {
|
||||
priceMaps = append(priceMaps, maps.Map{
|
||||
"networkId": networkId,
|
||||
"packageId": packageId,
|
||||
"protectionBandwidth": types.String(p.ProtectionBandwidthSize) + userconfigs.ADPackageSizeFullUnit(p.ProtectionBandwidthUnit),
|
||||
"serverBandwidth": types.String(p.ServerBandwidthSize) + userconfigs.ADPackageSizeFullUnit(p.ServerBandwidthUnit),
|
||||
"periodId": periodId,
|
||||
"price": price.Price,
|
||||
"maxInstances": countIdleInstances,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Data["prices"] = priceMaps
|
||||
|
||||
// 重新处理防护带宽和服务带宽
|
||||
var allProtectionBandwidthSizes = []string{}
|
||||
var allServerBandwidthSizes = []string{}
|
||||
for _, p := range packagesResp.AdPackages {
|
||||
var protectionSize = types.String(p.ProtectionBandwidthSize) + userconfigs.ADPackageSizeFullUnit(p.ProtectionBandwidthUnit)
|
||||
var serverSize = types.String(p.ServerBandwidthSize) + userconfigs.ADPackageSizeFullUnit(p.ServerBandwidthUnit)
|
||||
if !lists.ContainsString(allProtectionBandwidthSizes, protectionSize) {
|
||||
var found = false
|
||||
for _, price := range priceMaps {
|
||||
if types.String(price["protectionBandwidth"]) == protectionSize {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if found {
|
||||
allProtectionBandwidthSizes = append(allProtectionBandwidthSizes, protectionSize)
|
||||
}
|
||||
}
|
||||
if !lists.ContainsString(allServerBandwidthSizes, serverSize) {
|
||||
var found = false
|
||||
for _, price := range priceMaps {
|
||||
if types.String(price["serverBandwidth"]) == serverSize {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if found {
|
||||
allServerBandwidthSizes = append(allServerBandwidthSizes, serverSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Data["allProtectionBandwidthSizes"] = allProtectionBandwidthSizes
|
||||
this.Data["allServerBandwidthSizes"] = allServerBandwidthSizes
|
||||
|
||||
// 线路
|
||||
var networkMaps = []maps.Map{}
|
||||
networkResp, err := this.RPC().ADNetworkRPC().FindAllAvailableADNetworks(this.AdminContext(), &pb.FindAllAvailableADNetworksRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for _, network := range networkResp.AdNetworks {
|
||||
var found = false
|
||||
for _, price := range priceMaps {
|
||||
if types.Int64(price["networkId"]) == network.Id {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if found {
|
||||
networkMaps = append(networkMaps, maps.Map{
|
||||
"id": network.Id,
|
||||
"name": network.Name,
|
||||
"description": network.Description,
|
||||
})
|
||||
}
|
||||
}
|
||||
this.Data["allNetworks"] = networkMaps
|
||||
|
||||
// 周期
|
||||
var periodMaps = []maps.Map{}
|
||||
periodResp, err := this.RPC().ADPackagePeriodRPC().FindAllAvailableADPackagePeriods(this.AdminContext(), &pb.FindAllAvailableADPackagePeriodsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for _, period := range periodResp.AdPackagePeriods {
|
||||
var found = false
|
||||
for _, price := range priceMaps {
|
||||
if types.Int64(price["periodId"]) == period.Id {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if found {
|
||||
periodMaps = append(periodMaps, maps.Map{
|
||||
"id": period.Id,
|
||||
"count": period.Count,
|
||||
"unit": period.Unit,
|
||||
"unitName": userconfigs.ADPackagePeriodUnitName(period.Unit),
|
||||
})
|
||||
}
|
||||
}
|
||||
this.Data["allPeriods"] = periodMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
UserId int64
|
||||
PackageId int64
|
||||
PeriodId int64
|
||||
Count int32
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.ADPackagePrice_LogCreateADPackagePrice, params.UserId, params.PackageId, params.PeriodId, params.Count)
|
||||
|
||||
if params.UserId <= 0 {
|
||||
this.Fail("请选择用户")
|
||||
return
|
||||
}
|
||||
|
||||
if params.PackageId <= 0 {
|
||||
this.Fail("请选择高防产品")
|
||||
return
|
||||
}
|
||||
|
||||
if params.PeriodId <= 0 {
|
||||
this.Fail("请选择有效期")
|
||||
return
|
||||
}
|
||||
|
||||
if params.Count <= 0 {
|
||||
this.Fail("请选择实例数量")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := this.RPC().ADPackagePriceRPC().FindADPackagePrice(this.AdminContext(), &pb.FindADPackagePriceRequest{
|
||||
AdPackageId: params.PackageId,
|
||||
AdPackagePeriodId: params.PeriodId,
|
||||
Count: params.Count,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if resp.Price == 0 {
|
||||
this.Fail("当前所选条件下的高防实例不可用")
|
||||
return
|
||||
}
|
||||
|
||||
_, err = this.RPC().UserADInstanceRPC().CreateUserADInstance(this.AdminContext(), &pb.CreateUserADInstanceRequest{
|
||||
UserId: params.UserId,
|
||||
AdPackageId: params.PackageId,
|
||||
AdPackagePeriodId: params.PeriodId,
|
||||
Count: params.Count,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package userinstances
|
||||
|
||||
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 {
|
||||
UserInstanceId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.UserADInstance_LogDeleteUserADInstance, params.UserInstanceId)
|
||||
|
||||
_, err := this.RPC().UserADInstanceRPC().DeleteUserADInstance(this.AdminContext(), &pb.DeleteUserADInstanceRequest{UserADInstanceId: params.UserInstanceId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package userinstances
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/dateutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "userPackage")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
UserId int64
|
||||
NetworkId int64
|
||||
PeriodId int64
|
||||
}) {
|
||||
countResp, err := this.RPC().UserADInstanceRPC().CountUserADInstances(this.AdminContext(), &pb.CountUserADInstancesRequest{
|
||||
AdNetworkId: params.NetworkId,
|
||||
UserId: params.UserId,
|
||||
ExpiresDay: "",
|
||||
AdPackagePeriodId: params.PeriodId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
userInstancesResp, err := this.RPC().UserADInstanceRPC().ListUserADInstances(this.AdminContext(), &pb.ListUserADInstancesRequest{
|
||||
AdNetworkId: params.NetworkId,
|
||||
UserId: params.UserId,
|
||||
AdPackagePeriodId: params.PeriodId,
|
||||
ExpiresDay: "",
|
||||
AvailableOnly: false,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var userInstanceMaps = []maps.Map{}
|
||||
for _, userInstance := range userInstancesResp.UserADInstances {
|
||||
// 用户
|
||||
var userMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if userInstance.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": userInstance.User.Id,
|
||||
"fullname": userInstance.User.Fullname,
|
||||
"username": userInstance.User.Username,
|
||||
}
|
||||
}
|
||||
|
||||
// 实例
|
||||
var instanceMap = maps.Map{
|
||||
"id": 0,
|
||||
"userInstanceId": 0,
|
||||
}
|
||||
if userInstance.AdPackageInstance != nil {
|
||||
instanceMap = maps.Map{
|
||||
"id": userInstance.AdPackageInstance.Id,
|
||||
"userInstanceId": userInstance.AdPackageInstance.UserInstanceId,
|
||||
}
|
||||
}
|
||||
|
||||
// 产品
|
||||
var packageMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if userInstance.AdPackageInstance != nil && userInstance.AdPackageInstance.AdPackage != nil {
|
||||
packageMap = maps.Map{
|
||||
"id": userInstance.AdPackageInstance.AdPackage.Id,
|
||||
"summary": userInstance.AdPackageInstance.AdPackage.Summary,
|
||||
}
|
||||
}
|
||||
|
||||
// 实例
|
||||
var ipAddresses = []string{}
|
||||
if userInstance.AdPackageInstance != nil && len(userInstance.AdPackageInstance.IpAddresses) > 0 {
|
||||
ipAddresses = userInstance.AdPackageInstance.IpAddresses
|
||||
}
|
||||
|
||||
userInstanceMaps = append(userInstanceMaps, maps.Map{
|
||||
"id": userInstance.Id,
|
||||
"dayFrom": dateutils.SplitYmd(userInstance.DayFrom),
|
||||
"dayTo": dateutils.SplitYmd(userInstance.DayTo),
|
||||
"user": userMap,
|
||||
"instance": instanceMap,
|
||||
"package": packageMap,
|
||||
"ipAddresses": ipAddresses,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", userInstance.CreatedAt),
|
||||
"periodCount": userInstance.AdPackagePeriodCount,
|
||||
"periodUnitName": userconfigs.ADPackagePeriodUnitName(userInstance.AdPackagePeriodUnit),
|
||||
"canDelete": userInstance.CanDelete,
|
||||
"isExpired": userInstance.DayTo < timeutil.Format("Ymd"),
|
||||
"isAvailable": userInstance.IsAvailable,
|
||||
"countObjects": userInstance.CountObjects,
|
||||
})
|
||||
}
|
||||
this.Data["userInstances"] = userInstanceMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package userinstances
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
type PriceAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *PriceAction) RunPost(params struct {
|
||||
PackageId int64
|
||||
PeriodId int64
|
||||
Count int32
|
||||
}) {
|
||||
if params.PackageId <= 0 || params.PeriodId <= 0 || params.Count <= 0 {
|
||||
this.Data["price"] = 0
|
||||
this.Data["amount"] = 0
|
||||
this.Success()
|
||||
return
|
||||
}
|
||||
|
||||
// 数量
|
||||
countInstancesResp, err := this.RPC().ADPackageInstanceRPC().CountIdleADPackageInstances(this.AdminContext(), &pb.CountIdleADPackageInstancesRequest{AdPackageId: params.PackageId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var countInstances = types.Int32(countInstancesResp.Count)
|
||||
if countInstances < params.Count {
|
||||
this.Data["price"] = 0
|
||||
this.Data["amount"] = 0
|
||||
this.Success()
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := this.RPC().ADPackagePriceRPC().FindADPackagePrice(this.AdminContext(), &pb.FindADPackagePriceRequest{
|
||||
AdPackageId: params.PackageId,
|
||||
AdPackagePeriodId: params.PeriodId,
|
||||
Count: params.Count,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["price"] = resp.Price
|
||||
this.Data["amount"] = resp.Amount
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package userinstances
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/dateutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type RenewPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *RenewPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *RenewPopupAction) RunGet(params struct {
|
||||
UserInstanceId int64
|
||||
}) {
|
||||
userInstanceResp, err := this.RPC().UserADInstanceRPC().FindUserADInstance(this.AdminContext(), &pb.FindUserADInstanceRequest{UserADInstanceId: params.UserInstanceId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var userInstance = userInstanceResp.UserADInstance
|
||||
if userInstance == nil {
|
||||
this.NotFound("userInstance", params.UserInstanceId)
|
||||
return
|
||||
}
|
||||
|
||||
// 用户
|
||||
var userMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if userInstance.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": userInstance.User.Id,
|
||||
"fullname": userInstance.User.Fullname,
|
||||
"username": userInstance.User.Username,
|
||||
}
|
||||
}
|
||||
|
||||
// 实例
|
||||
var instanceMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if userInstance.AdPackageInstance != nil {
|
||||
if userInstance.AdPackageInstance.IpAddresses == nil {
|
||||
userInstance.AdPackageInstance.IpAddresses = []string{}
|
||||
}
|
||||
instanceMap = maps.Map{
|
||||
"id": userInstance.AdPackageInstance.Id,
|
||||
"ipAddresses": userInstance.AdPackageInstance.IpAddresses,
|
||||
}
|
||||
}
|
||||
|
||||
// 产品
|
||||
var packageMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
var packageId int64
|
||||
if userInstance.AdPackageInstance != nil && userInstance.AdPackageInstance.AdPackage != nil {
|
||||
packageId = userInstance.AdPackageInstance.AdPackage.Id
|
||||
packageMap = maps.Map{
|
||||
"id": userInstance.AdPackageInstance.AdPackage.Id,
|
||||
"summary": userInstance.AdPackageInstance.AdPackage.Summary,
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["userInstance"] = maps.Map{
|
||||
"id": userInstance.Id,
|
||||
"periodId": userInstance.AdPackagePeriodId,
|
||||
"dayTo": dateutils.SplitYmd(userInstance.DayTo),
|
||||
"today": timeutil.Format("Y-m-d"),
|
||||
"isExpired": len(userInstance.DayTo) == 0 || userInstance.DayTo < timeutil.Format("Ymd"),
|
||||
"isAvailable": userInstance.IsAvailable,
|
||||
"user": userMap,
|
||||
"instance": instanceMap,
|
||||
"package": packageMap,
|
||||
}
|
||||
|
||||
// 价格选项
|
||||
if packageId > 0 {
|
||||
pricesResp, err := this.RPC().ADPackagePriceRPC().FindADPackagePrices(this.AdminContext(), &pb.FindADPackagePricesRequest{AdPackageId: packageId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var priceMaps = []maps.Map{}
|
||||
var allValidPeriodIds = []int64{}
|
||||
for _, price := range pricesResp.AdPackagePrices {
|
||||
allValidPeriodIds = append(allValidPeriodIds, price.AdPackagePeriodId)
|
||||
priceMaps = append(priceMaps, maps.Map{
|
||||
"periodId": price.AdPackagePeriodId,
|
||||
"price": price.Price,
|
||||
})
|
||||
}
|
||||
this.Data["prices"] = priceMaps
|
||||
|
||||
// 有效期选项
|
||||
var periodMaps = []maps.Map{}
|
||||
periodResp, err := this.RPC().ADPackagePeriodRPC().FindAllAvailableADPackagePeriods(this.AdminContext(), &pb.FindAllAvailableADPackagePeriodsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for _, period := range periodResp.AdPackagePeriods {
|
||||
if !lists.ContainsInt64(allValidPeriodIds, period.Id) {
|
||||
continue
|
||||
}
|
||||
periodMaps = append(periodMaps, maps.Map{
|
||||
"id": period.Id,
|
||||
"count": period.Count,
|
||||
"unit": period.Unit,
|
||||
"unitName": userconfigs.ADPackagePeriodUnitName(period.Unit),
|
||||
})
|
||||
}
|
||||
this.Data["allPeriods"] = periodMaps
|
||||
} else {
|
||||
this.Data["allPeriods"] = []maps.Map{}
|
||||
this.Data["prices"] = []maps.Map{}
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *RenewPopupAction) RunPost(params struct {
|
||||
UserInstanceId int64
|
||||
PeriodId int64
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.UserADInstance_LogRenewUserADInstance, params.UserInstanceId)
|
||||
|
||||
_, err := this.RPC().UserADInstanceRPC().RenewUserADInstance(this.AdminContext(), &pb.RenewUserADInstanceRequest{
|
||||
UserADInstanceId: params.UserInstanceId,
|
||||
AdPackagePeriodId: params.PeriodId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package userinstances
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/dateutils"
|
||||
"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"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type UpdateObjectsPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateObjectsPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdateObjectsPopupAction) RunGet(params struct {
|
||||
UserInstanceId int64
|
||||
}) {
|
||||
userInstanceResp, err := this.RPC().UserADInstanceRPC().FindUserADInstance(this.AdminContext(), &pb.FindUserADInstanceRequest{UserADInstanceId: params.UserInstanceId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var userInstance = userInstanceResp.UserADInstance
|
||||
if userInstance == nil {
|
||||
this.NotFound("userInstance", params.UserInstanceId)
|
||||
return
|
||||
}
|
||||
var objectMaps = []maps.Map{}
|
||||
if len(userInstance.ObjectsJSON) > 0 {
|
||||
err = json.Unmarshal(userInstance.ObjectsJSON, &objectMaps)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 用户
|
||||
var userMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if userInstance.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": userInstance.User.Id,
|
||||
"fullname": userInstance.User.Fullname,
|
||||
"username": userInstance.User.Username,
|
||||
}
|
||||
}
|
||||
|
||||
// 实例
|
||||
var instanceMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if userInstance.AdPackageInstance != nil {
|
||||
if userInstance.AdPackageInstance.IpAddresses == nil {
|
||||
userInstance.AdPackageInstance.IpAddresses = []string{}
|
||||
}
|
||||
instanceMap = maps.Map{
|
||||
"id": userInstance.AdPackageInstance.Id,
|
||||
"ipAddresses": userInstance.AdPackageInstance.IpAddresses,
|
||||
}
|
||||
}
|
||||
|
||||
// 产品
|
||||
var packageMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if userInstance.AdPackageInstance != nil && userInstance.AdPackageInstance.AdPackage != nil {
|
||||
packageMap = maps.Map{
|
||||
"id": userInstance.AdPackageInstance.AdPackage.Id,
|
||||
"summary": userInstance.AdPackageInstance.AdPackage.Summary,
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["userInstance"] = maps.Map{
|
||||
"id": userInstance.Id,
|
||||
"periodId": userInstance.AdPackagePeriodId,
|
||||
"isAvailable": userInstance.IsAvailable,
|
||||
"objects": objectMaps,
|
||||
"dayTo": dateutils.SplitYmd(userInstance.DayTo),
|
||||
"today": timeutil.Format("Y-m-d"),
|
||||
"isExpired": len(userInstance.DayTo) == 0 || userInstance.DayTo < timeutil.Format("Ymd"),
|
||||
"user": userMap,
|
||||
"instance": instanceMap,
|
||||
"package": packageMap,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdateObjectsPopupAction) RunPost(params struct {
|
||||
UserInstanceId int64
|
||||
ObjectCodesJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.UserADInstance_LogUpdateUserADInstanceObjects, params.UserInstanceId)
|
||||
|
||||
var objectCodes = []string{}
|
||||
if len(params.ObjectCodesJSON) > 0 {
|
||||
err := json.Unmarshal(params.ObjectCodesJSON, &objectCodes)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 检查有没有超出最大防护对象数量
|
||||
|
||||
_, err := this.RPC().UserADInstanceRPC().UpdateUserADInstanceObjects(this.AdminContext(), &pb.UpdateUserADInstanceObjectsRequest{
|
||||
UserADInstanceId: params.UserInstanceId,
|
||||
ObjectCodes: objectCodes,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package userinstances
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UserServersAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UserServersAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UserServersAction) RunPost(params struct {
|
||||
UserId int64
|
||||
Page int32
|
||||
}) {
|
||||
var size int64 = 10
|
||||
|
||||
// 数量
|
||||
countResp, err := this.RPC().ServerRPC().CountAllEnabledServersMatch(this.AdminContext(), &pb.CountAllEnabledServersMatchRequest{
|
||||
UserId: params.UserId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count, size)
|
||||
|
||||
// 列表
|
||||
serversResp, err := this.RPC().ServerRPC().ListEnabledServersMatch(this.AdminContext(), &pb.ListEnabledServersMatchRequest{
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
UserId: params.UserId,
|
||||
IgnoreServerNames: true,
|
||||
IgnoreSSLCerts: true,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var serverMaps = []maps.Map{}
|
||||
for _, server := range serversResp.Servers {
|
||||
serverMaps = append(serverMaps, maps.Map{
|
||||
"id": server.Id,
|
||||
"name": server.Name,
|
||||
})
|
||||
}
|
||||
this.Data["servers"] = serverMaps
|
||||
this.Data["page"] = maps.Map{
|
||||
"max": page.Max,
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user