mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2026-02-13 05:05:38 +08:00
支持更多的分组全局设置功能
This commit is contained in:
@@ -96,9 +96,10 @@ func (this *HTTPFirewallPolicyDAO) FindAllEnabledFirewallPolicies(tx *dbs.Tx) (r
|
||||
}
|
||||
|
||||
// CreateFirewallPolicy 创建策略
|
||||
func (this *HTTPFirewallPolicyDAO) CreateFirewallPolicy(tx *dbs.Tx, userId int64, serverId int64, isOn bool, name string, description string, inboundJSON []byte, outboundJSON []byte) (int64, error) {
|
||||
func (this *HTTPFirewallPolicyDAO) CreateFirewallPolicy(tx *dbs.Tx, userId int64, serverGroupId int64, serverId int64, isOn bool, name string, description string, inboundJSON []byte, outboundJSON []byte) (int64, error) {
|
||||
op := NewHTTPFirewallPolicyOperator()
|
||||
op.UserId = userId
|
||||
op.GroupId = serverGroupId
|
||||
op.ServerId = serverId
|
||||
op.State = HTTPFirewallPolicyStateEnabled
|
||||
op.IsOn = isOn
|
||||
@@ -116,7 +117,7 @@ func (this *HTTPFirewallPolicyDAO) CreateFirewallPolicy(tx *dbs.Tx, userId int64
|
||||
|
||||
// CreateDefaultFirewallPolicy 创建默认的WAF策略
|
||||
func (this *HTTPFirewallPolicyDAO) CreateDefaultFirewallPolicy(tx *dbs.Tx, name string) (int64, error) {
|
||||
policyId, err := this.CreateFirewallPolicy(tx, 0, 0, true, "\""+name+"\"WAF策略", "默认创建的WAF策略", nil, nil)
|
||||
policyId, err := this.CreateFirewallPolicy(tx, 0, 0, 0, true, "\""+name+"\"WAF策略", "默认创建的WAF策略", nil, nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ type HTTPFirewallPolicy struct {
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
ServerId uint32 `field:"serverId"` // 服务ID
|
||||
GroupId uint32 `field:"groupId"` // 服务分组ID
|
||||
State uint8 `field:"state"` // 状态
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
IsOn uint8 `field:"isOn"` // 是否启用
|
||||
@@ -24,6 +25,7 @@ type HTTPFirewallPolicyOperator struct {
|
||||
AdminId interface{} // 管理员ID
|
||||
UserId interface{} // 用户ID
|
||||
ServerId interface{} // 服务ID
|
||||
GroupId interface{} // 服务分组ID
|
||||
State interface{} // 状态
|
||||
CreatedAt interface{} // 创建时间
|
||||
IsOn interface{} // 是否启用
|
||||
|
||||
@@ -966,6 +966,39 @@ func (this *HTTPWebDAO) FindWebServerId(tx *dbs.Tx, webId int64) (serverId int64
|
||||
return this.FindWebServerId(tx, webId)
|
||||
}
|
||||
|
||||
// FindWebServerGroupId 查找使用此Web的分组ID
|
||||
func (this *HTTPWebDAO) FindWebServerGroupId(tx *dbs.Tx, webId int64) (groupId int64, err error) {
|
||||
if webId <= 0 {
|
||||
return 0, nil
|
||||
}
|
||||
groupId, err = SharedServerGroupDAO.FindEnabledGroupIdWithWebId(tx, webId)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if groupId > 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// web在Location中的情况
|
||||
locationId, err := SharedHTTPLocationDAO.FindEnabledLocationIdWithWebId(tx, webId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if locationId == 0 {
|
||||
return
|
||||
}
|
||||
webId, err = this.FindEnabledWebIdWithLocationId(tx, locationId)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if webId <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// 第二轮查找
|
||||
return this.FindWebServerGroupId(tx, webId)
|
||||
}
|
||||
|
||||
// CheckUserWeb 检查用户权限
|
||||
func (this *HTTPWebDAO) CheckUserWeb(tx *dbs.Tx, userId int64, webId int64) error {
|
||||
serverId, err := this.FindWebServerId(tx, webId)
|
||||
@@ -1015,12 +1048,23 @@ func (this *HTTPWebDAO) FindWebHostRedirects(tx *dbs.Tx, webId int64) ([]byte, e
|
||||
|
||||
// NotifyUpdate 通知更新
|
||||
func (this *HTTPWebDAO) NotifyUpdate(tx *dbs.Tx, webId int64) error {
|
||||
// server
|
||||
serverId, err := this.FindWebServerId(tx, webId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if serverId == 0 {
|
||||
return nil
|
||||
if serverId > 0 {
|
||||
return SharedServerDAO.NotifyUpdate(tx, serverId)
|
||||
}
|
||||
return SharedServerDAO.NotifyUpdate(tx, serverId)
|
||||
|
||||
// group
|
||||
groupId, err := this.FindWebServerGroupId(tx, webId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if groupId > 0 {
|
||||
return SharedServerGroupDAO.NotifyUpdate(tx, groupId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -224,6 +224,48 @@ func (this *ServerGroupDAO) UpdateUDPReverseProxy(tx *dbs.Tx, groupId int64, con
|
||||
return this.NotifyUpdate(tx, groupId)
|
||||
}
|
||||
|
||||
// FindGroupWebId 查找分组WebId
|
||||
func (this *ServerGroupDAO) FindGroupWebId(tx *dbs.Tx, groupId int64) (webId int64, err error) {
|
||||
return this.Query(tx).
|
||||
Pk(groupId).
|
||||
Result("webId").
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// FindEnabledGroupIdWithWebId 根据WebId查找分组
|
||||
func (this *ServerGroupDAO) FindEnabledGroupIdWithWebId(tx *dbs.Tx, webId int64) (int64, error) {
|
||||
if webId <= 0 {
|
||||
return 0, nil
|
||||
}
|
||||
return this.Query(tx).
|
||||
State(ServerGroupStateEnabled).
|
||||
ResultPk().
|
||||
Attr("webId", webId).
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// InitGroupWeb 初始化Web配置
|
||||
func (this *ServerGroupDAO) InitGroupWeb(tx *dbs.Tx, groupId int64) (int64, error) {
|
||||
if groupId <= 0 {
|
||||
return 0, errors.New("invalid groupId")
|
||||
}
|
||||
|
||||
webId, err := SharedHTTPWebDAO.CreateWeb(tx, 0, 0, nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
err = this.Query(tx).
|
||||
Pk(groupId).
|
||||
Set("webId", webId).
|
||||
UpdateQuickly()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return webId, nil
|
||||
}
|
||||
|
||||
// ComposeGroupConfig 组合配置
|
||||
func (this *ServerGroupDAO) ComposeGroupConfig(tx *dbs.Tx, groupId int64, cacheMap maps.Map) (*serverconfigs.ServerGroupConfig, error) {
|
||||
if cacheMap == nil {
|
||||
@@ -312,6 +354,17 @@ func (this *ServerGroupDAO) ComposeGroupConfig(tx *dbs.Tx, groupId int64, cacheM
|
||||
}
|
||||
}
|
||||
|
||||
// web
|
||||
if group.WebId > 0 {
|
||||
webConfig, err := SharedHTTPWebDAO.ComposeWebConfig(tx, int64(group.WebId), cacheMap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if webConfig != nil {
|
||||
config.Web = webConfig
|
||||
}
|
||||
}
|
||||
|
||||
cacheMap[cacheKey] = config
|
||||
|
||||
return config, nil
|
||||
@@ -327,7 +380,6 @@ func (this *ServerGroupDAO) FindEnabledGroupIdWithReverseProxyId(tx *dbs.Tx, rev
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
|
||||
// NotifyUpdate 通知更新
|
||||
func (this *ServerGroupDAO) NotifyUpdate(tx *dbs.Tx, groupId int64) error {
|
||||
serverIds, err := SharedServerDAO.FindAllEnabledServerIdsWithGroupId(tx, groupId)
|
||||
|
||||
Reference in New Issue
Block a user