mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-05 01:20:25 +08:00
增加若干API
This commit is contained in:
@@ -444,6 +444,7 @@ func (this *HTTPFirewallPolicyDAO) ComposeFirewallPolicy(tx *dbs.Tx, policyId in
|
|||||||
|
|
||||||
var config = &firewallconfigs.HTTPFirewallPolicy{}
|
var config = &firewallconfigs.HTTPFirewallPolicy{}
|
||||||
config.Id = int64(policy.Id)
|
config.Id = int64(policy.Id)
|
||||||
|
config.ServerId = int64(policy.ServerId)
|
||||||
config.IsOn = policy.IsOn
|
config.IsOn = policy.IsOn
|
||||||
config.Name = policy.Name
|
config.Name = policy.Name
|
||||||
config.Description = policy.Description
|
config.Description = policy.Description
|
||||||
@@ -667,6 +668,19 @@ func (this *HTTPFirewallPolicyDAO) FindFirewallPolicyIdsWithServerId(tx *dbs.Tx,
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindServerIdWithFirewallPolicyId 根据策略查找网站ID
|
||||||
|
func (this *HTTPFirewallPolicyDAO) FindServerIdWithFirewallPolicyId(tx *dbs.Tx, policyId int64) (serverId int64, err error) {
|
||||||
|
if policyId <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
serverId, err = this.Query(tx).
|
||||||
|
Pk(policyId).
|
||||||
|
Result("serverId").
|
||||||
|
FindInt64Col(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// NotifyUpdate 通知更新
|
// NotifyUpdate 通知更新
|
||||||
func (this *HTTPFirewallPolicyDAO) NotifyUpdate(tx *dbs.Tx, policyId int64) error {
|
func (this *HTTPFirewallPolicyDAO) NotifyUpdate(tx *dbs.Tx, policyId int64) error {
|
||||||
webIds, err := SharedHTTPWebDAO.FindAllWebIdsWithHTTPFirewallPolicyId(tx, policyId)
|
webIds, err := SharedHTTPWebDAO.FindAllWebIdsWithHTTPFirewallPolicyId(tx, policyId)
|
||||||
|
|||||||
@@ -339,3 +339,16 @@ func (this *IPListDAO) NotifyUpdate(tx *dbs.Tx, listId int64, taskType NodeTaskT
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindServerIdWithListId 查找IP名单对应的网站ID
|
||||||
|
func (this *IPListDAO) FindServerIdWithListId(tx *dbs.Tx, listId int64) (serverId int64, err error) {
|
||||||
|
if listId <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
serverId, err = this.Query(tx).
|
||||||
|
Pk(listId).
|
||||||
|
Result("serverId").
|
||||||
|
FindInt64Col(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const (
|
|||||||
PlanField_ClusterId dbs.FieldName = "clusterId" // 集群ID
|
PlanField_ClusterId dbs.FieldName = "clusterId" // 集群ID
|
||||||
PlanField_TrafficLimit dbs.FieldName = "trafficLimit" // 流量限制
|
PlanField_TrafficLimit dbs.FieldName = "trafficLimit" // 流量限制
|
||||||
PlanField_Features dbs.FieldName = "features" // 允许的功能
|
PlanField_Features dbs.FieldName = "features" // 允许的功能
|
||||||
|
PlanField_HasFullFeatures dbs.FieldName = "hasFullFeatures" // 是否有完整的功能
|
||||||
PlanField_TrafficPrice dbs.FieldName = "trafficPrice" // 流量价格设定
|
PlanField_TrafficPrice dbs.FieldName = "trafficPrice" // 流量价格设定
|
||||||
PlanField_BandwidthPrice dbs.FieldName = "bandwidthPrice" // 带宽价格
|
PlanField_BandwidthPrice dbs.FieldName = "bandwidthPrice" // 带宽价格
|
||||||
PlanField_MonthlyPrice dbs.FieldName = "monthlyPrice" // 月付
|
PlanField_MonthlyPrice dbs.FieldName = "monthlyPrice" // 月付
|
||||||
@@ -34,6 +35,7 @@ type Plan struct {
|
|||||||
ClusterId uint32 `field:"clusterId"` // 集群ID
|
ClusterId uint32 `field:"clusterId"` // 集群ID
|
||||||
TrafficLimit dbs.JSON `field:"trafficLimit"` // 流量限制
|
TrafficLimit dbs.JSON `field:"trafficLimit"` // 流量限制
|
||||||
Features dbs.JSON `field:"features"` // 允许的功能
|
Features dbs.JSON `field:"features"` // 允许的功能
|
||||||
|
HasFullFeatures bool `field:"hasFullFeatures"` // 是否有完整的功能
|
||||||
TrafficPrice dbs.JSON `field:"trafficPrice"` // 流量价格设定
|
TrafficPrice dbs.JSON `field:"trafficPrice"` // 流量价格设定
|
||||||
BandwidthPrice dbs.JSON `field:"bandwidthPrice"` // 带宽价格
|
BandwidthPrice dbs.JSON `field:"bandwidthPrice"` // 带宽价格
|
||||||
MonthlyPrice float64 `field:"monthlyPrice"` // 月付
|
MonthlyPrice float64 `field:"monthlyPrice"` // 月付
|
||||||
@@ -58,6 +60,7 @@ type PlanOperator struct {
|
|||||||
ClusterId any // 集群ID
|
ClusterId any // 集群ID
|
||||||
TrafficLimit any // 流量限制
|
TrafficLimit any // 流量限制
|
||||||
Features any // 允许的功能
|
Features any // 允许的功能
|
||||||
|
HasFullFeatures any // 是否有完整的功能
|
||||||
TrafficPrice any // 流量价格设定
|
TrafficPrice any // 流量价格设定
|
||||||
BandwidthPrice any // 带宽价格
|
BandwidthPrice any // 带宽价格
|
||||||
MonthlyPrice any // 月付
|
MonthlyPrice any // 月付
|
||||||
|
|||||||
@@ -862,3 +862,29 @@ func (this *HTTPFirewallPolicyService) CheckHTTPFirewallPolicyIPStatus(ctx conte
|
|||||||
RegionProvince: nil,
|
RegionProvince: nil,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindServerIdWithHTTPFirewallPolicyId 获取防火墙对应的网站ID
|
||||||
|
func (this *HTTPFirewallPolicyService) FindServerIdWithHTTPFirewallPolicyId(ctx context.Context, req *pb.FindServerIdWithHTTPFirewallPolicyIdRequest) (*pb.FindServerIdWithHTTPFirewallPolicyIdResponse, error) {
|
||||||
|
_, userId, err := this.ValidateAdminAndUser(ctx, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
serverId, err := models.SharedHTTPFirewallPolicyDAO.FindServerIdWithFirewallPolicyId(tx, req.HttpFirewallPolicyId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// check user
|
||||||
|
if serverId > 0 && userId > 0 {
|
||||||
|
err = models.SharedServerDAO.CheckUserServer(tx, userId, serverId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.FindServerIdWithHTTPFirewallPolicyIdResponse{
|
||||||
|
ServerId: serverId,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -782,3 +782,38 @@ func (this *IPItemService) UpdateIPItemsRead(ctx context.Context, req *pb.Update
|
|||||||
}
|
}
|
||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindServerIdWithIPItemId 查找IP对应的名单所属网站ID
|
||||||
|
func (this *IPItemService) FindServerIdWithIPItemId(ctx context.Context, req *pb.FindServerIdWithIPItemIdRequest) (*pb.FindServerIdWithIPItemIdResponse, error) {
|
||||||
|
_, userId, err := this.ValidateAdminAndUser(ctx, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
listId, err := models.SharedIPItemDAO.FindItemListId(tx, req.IpItemId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if listId > 0 {
|
||||||
|
var serverId int64
|
||||||
|
serverId, err = models.SharedIPListDAO.FindServerIdWithListId(tx, listId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if serverId > 0 {
|
||||||
|
// check user
|
||||||
|
if userId > 0 {
|
||||||
|
err = models.SharedServerDAO.CheckUserServer(tx, userId, serverId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &pb.FindServerIdWithIPItemIdResponse{ServerId: serverId}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.FindServerIdWithIPItemIdResponse{ServerId: 0}, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -224,3 +224,29 @@ func (this *IPListService) FindEnabledIPListContainsIP(ctx context.Context, req
|
|||||||
}
|
}
|
||||||
return &pb.FindEnabledIPListContainsIPResponse{IpLists: pbLists}, nil
|
return &pb.FindEnabledIPListContainsIPResponse{IpLists: pbLists}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindServerIdWithIPListId 查找IP名单对应的网站ID
|
||||||
|
func (this *IPListService) FindServerIdWithIPListId(ctx context.Context, req *pb.FindServerIdWithIPListIdRequest) (*pb.FindServerIdWithIPListIdResponse, error) {
|
||||||
|
_, userId, err := this.ValidateAdminAndUser(ctx, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
serverId, err := models.SharedIPListDAO.FindServerIdWithListId(tx, req.IpListId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// check user
|
||||||
|
if serverId > 0 && userId > 0 {
|
||||||
|
err = models.SharedServerDAO.CheckUserServer(tx, userId, serverId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.FindServerIdWithIPListIdResponse{
|
||||||
|
ServerId: serverId,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -2890,6 +2890,7 @@ func (this *ServerService) FindServerUserPlan(ctx context.Context, req *pb.FindS
|
|||||||
User: nil,
|
User: nil,
|
||||||
Plan: &pb.Plan{
|
Plan: &pb.Plan{
|
||||||
Id: int64(plan.Id),
|
Id: int64(plan.Id),
|
||||||
|
IsOn: plan.IsOn,
|
||||||
Name: plan.Name,
|
Name: plan.Name,
|
||||||
PriceType: plan.PriceType,
|
PriceType: plan.PriceType,
|
||||||
TrafficPriceJSON: plan.TrafficPrice,
|
TrafficPriceJSON: plan.TrafficPrice,
|
||||||
@@ -2897,6 +2898,8 @@ func (this *ServerService) FindServerUserPlan(ctx context.Context, req *pb.FindS
|
|||||||
TotalServers: types.Int32(plan.TotalServers),
|
TotalServers: types.Int32(plan.TotalServers),
|
||||||
TotalServerNames: types.Int32(plan.TotalServerNames),
|
TotalServerNames: types.Int32(plan.TotalServerNames),
|
||||||
TotalServerNamesPerServer: types.Int32(plan.TotalServerNamesPerServer),
|
TotalServerNamesPerServer: types.Int32(plan.TotalServerNamesPerServer),
|
||||||
|
HasFullFeatures: plan.HasFullFeatures,
|
||||||
|
FeaturesJSON: plan.Features,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
|||||||
@@ -618,31 +618,6 @@ func (this *UserService) UpdateAllUsersFeatures(ctx context.Context, req *pb.Upd
|
|||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindUserFeatures 获取用户所有的功能列表
|
|
||||||
func (this *UserService) FindUserFeatures(ctx context.Context, req *pb.FindUserFeaturesRequest) (*pb.FindUserFeaturesResponse, error) {
|
|
||||||
_, userId, err := this.ValidateAdminAndUser(ctx, false)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if userId > 0 {
|
|
||||||
req.UserId = userId
|
|
||||||
}
|
|
||||||
|
|
||||||
var tx = this.NullTx()
|
|
||||||
|
|
||||||
features, err := models.SharedUserDAO.FindUserFeatures(tx, req.UserId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result := []*pb.UserFeature{}
|
|
||||||
for _, feature := range features {
|
|
||||||
result = append(result, feature.ToPB())
|
|
||||||
}
|
|
||||||
|
|
||||||
return &pb.FindUserFeaturesResponse{Features: result}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// FindAllUserFeatureDefinitions 获取所有的功能定义
|
// FindAllUserFeatureDefinitions 获取所有的功能定义
|
||||||
func (this *UserService) FindAllUserFeatureDefinitions(ctx context.Context, req *pb.FindAllUserFeatureDefinitionsRequest) (*pb.FindAllUserFeatureDefinitionsResponse, error) {
|
func (this *UserService) FindAllUserFeatureDefinitions(ctx context.Context, req *pb.FindAllUserFeatureDefinitionsRequest) (*pb.FindAllUserFeatureDefinitionsResponse, error) {
|
||||||
_, err := this.ValidateAdmin(ctx)
|
_, err := this.ValidateAdmin(ctx)
|
||||||
@@ -650,8 +625,8 @@ func (this *UserService) FindAllUserFeatureDefinitions(ctx context.Context, req
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
features := userconfigs.FindAllUserFeatures()
|
var features = userconfigs.FindAllUserFeatures()
|
||||||
result := []*pb.UserFeature{}
|
var result = []*pb.UserFeature{}
|
||||||
for _, feature := range features {
|
for _, feature := range features {
|
||||||
result = append(result, feature.ToPB())
|
result = append(result, feature.ToPB())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,3 +89,28 @@ func (this *UserService) RegisterUser(ctx context.Context, req *pb.RegisterUserR
|
|||||||
RequireEmailVerification: requireEmailVerification,
|
RequireEmailVerification: requireEmailVerification,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindUserFeatures 获取用户所有的功能列表
|
||||||
|
func (this *UserService) FindUserFeatures(ctx context.Context, req *pb.FindUserFeaturesRequest) (*pb.FindUserFeaturesResponse, error) {
|
||||||
|
_, userId, err := this.ValidateAdminAndUser(ctx, false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if userId > 0 {
|
||||||
|
req.UserId = userId
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
|
||||||
|
features, err := models.SharedUserDAO.FindUserFeatures(tx, req.UserId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := []*pb.UserFeature{}
|
||||||
|
for _, feature := range features {
|
||||||
|
result = append(result, feature.ToPB())
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.FindUserFeaturesResponse{Features: result}, nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user