Initial commit (code only without large binaries)
This commit is contained in:
@@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user