138 lines
3.6 KiB
Go
138 lines
3.6 KiB
Go
// 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()
|
|
}
|