1.4.5.2
This commit is contained in:
@@ -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