@@ -37,12 +37,12 @@ func init() {
3737 })
3838}
3939
40- // 初始化
40+ // Init 初始化
4141func (this * HTTPFirewallPolicyDAO ) Init () {
4242 _ = this .DAOObject .Init ()
4343}
4444
45- // 启用条目
45+ // EnableHTTPFirewallPolicy 启用条目
4646func (this * HTTPFirewallPolicyDAO ) EnableHTTPFirewallPolicy (tx * dbs.Tx , id int64 ) error {
4747 _ , err := this .Query (tx ).
4848 Pk (id ).
@@ -51,7 +51,7 @@ func (this *HTTPFirewallPolicyDAO) EnableHTTPFirewallPolicy(tx *dbs.Tx, id int64
5151 return err
5252}
5353
54- // 禁用条目
54+ // DisableHTTPFirewallPolicy 禁用条目
5555func (this * HTTPFirewallPolicyDAO ) DisableHTTPFirewallPolicy (tx * dbs.Tx , policyId int64 ) error {
5656 _ , err := this .Query (tx ).
5757 Pk (policyId ).
@@ -64,7 +64,7 @@ func (this *HTTPFirewallPolicyDAO) DisableHTTPFirewallPolicy(tx *dbs.Tx, policyI
6464 return this .NotifyUpdate (tx , policyId )
6565}
6666
67- // 查找启用中的条目
67+ // FindEnabledHTTPFirewallPolicy 查找启用中的条目
6868func (this * HTTPFirewallPolicyDAO ) FindEnabledHTTPFirewallPolicy (tx * dbs.Tx , id int64 ) (* HTTPFirewallPolicy , error ) {
6969 result , err := this .Query (tx ).
7070 Pk (id ).
@@ -76,15 +76,15 @@ func (this *HTTPFirewallPolicyDAO) FindEnabledHTTPFirewallPolicy(tx *dbs.Tx, id
7676 return result .(* HTTPFirewallPolicy ), err
7777}
7878
79- // 根据主键查找名称
79+ // FindHTTPFirewallPolicyName 根据主键查找名称
8080func (this * HTTPFirewallPolicyDAO ) FindHTTPFirewallPolicyName (tx * dbs.Tx , id int64 ) (string , error ) {
8181 return this .Query (tx ).
8282 Pk (id ).
8383 Result ("name" ).
8484 FindStringCol ("" )
8585}
8686
87- // 查找所有可用策略
87+ // FindAllEnabledFirewallPolicies 查找所有可用策略
8888func (this * HTTPFirewallPolicyDAO ) FindAllEnabledFirewallPolicies (tx * dbs.Tx ) (result []* HTTPFirewallPolicy , err error ) {
8989 _ , err = this .Query (tx ).
9090 State (HTTPFirewallPolicyStateEnabled ).
@@ -94,7 +94,7 @@ func (this *HTTPFirewallPolicyDAO) FindAllEnabledFirewallPolicies(tx *dbs.Tx) (r
9494 return
9595}
9696
97- // 创建策略
97+ // CreateFirewallPolicy 创建策略
9898func (this * HTTPFirewallPolicyDAO ) CreateFirewallPolicy (tx * dbs.Tx , userId int64 , serverId int64 , isOn bool , name string , description string , inboundJSON []byte , outboundJSON []byte ) (int64 , error ) {
9999 op := NewHTTPFirewallPolicyOperator ()
100100 op .UserId = userId
@@ -113,7 +113,7 @@ func (this *HTTPFirewallPolicyDAO) CreateFirewallPolicy(tx *dbs.Tx, userId int64
113113 return types .Int64 (op .Id ), err
114114}
115115
116- // 修改策略的Inbound和Outbound
116+ // UpdateFirewallPolicyInboundAndOutbound 修改策略的Inbound和Outbound
117117func (this * HTTPFirewallPolicyDAO ) UpdateFirewallPolicyInboundAndOutbound (tx * dbs.Tx , policyId int64 , inboundJSON []byte , outboundJSON []byte ) error {
118118 if policyId <= 0 {
119119 return errors .New ("invalid policyId" )
@@ -138,7 +138,7 @@ func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicyInboundAndOutbound(tx *db
138138 return this .NotifyUpdate (tx , policyId )
139139}
140140
141- // 修改策略的Inbound
141+ // UpdateFirewallPolicyInbound 修改策略的Inbound
142142func (this * HTTPFirewallPolicyDAO ) UpdateFirewallPolicyInbound (tx * dbs.Tx , policyId int64 , inboundJSON []byte ) error {
143143 if policyId <= 0 {
144144 return errors .New ("invalid policyId" )
@@ -158,7 +158,7 @@ func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicyInbound(tx *dbs.Tx, polic
158158 return this .NotifyUpdate (tx , policyId )
159159}
160160
161- // 修改策略
161+ // UpdateFirewallPolicy 修改策略
162162func (this * HTTPFirewallPolicyDAO ) UpdateFirewallPolicy (tx * dbs.Tx , policyId int64 , isOn bool , name string , description string , inboundJSON []byte , outboundJSON []byte , blockOptionsJSON []byte ) error {
163163 if policyId <= 0 {
164164 return errors .New ("invalid policyId" )
@@ -189,18 +189,28 @@ func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicy(tx *dbs.Tx, policyId int
189189 return this .NotifyUpdate (tx , policyId )
190190}
191191
192- // 计算所有可用的策略数量
193- func (this * HTTPFirewallPolicyDAO ) CountAllEnabledFirewallPolicies (tx * dbs.Tx ) (int64 , error ) {
194- return this .Query (tx ).
192+ // CountAllEnabledFirewallPolicies 计算所有可用的策略数量
193+ func (this * HTTPFirewallPolicyDAO ) CountAllEnabledFirewallPolicies (tx * dbs.Tx , keyword string ) (int64 , error ) {
194+ query := this .Query (tx )
195+ if len (keyword ) > 0 {
196+ query .Where ("(name LIKE :keyword)" ).
197+ Param ("keyword" , "%" + keyword + "%" )
198+ }
199+ return query .
195200 State (HTTPFirewallPolicyStateEnabled ).
196201 Attr ("userId" , 0 ).
197202 Attr ("serverId" , 0 ).
198203 Count ()
199204}
200205
201- // 列出单页的策略
202- func (this * HTTPFirewallPolicyDAO ) ListEnabledFirewallPolicies (tx * dbs.Tx , offset int64 , size int64 ) (result []* HTTPFirewallPolicy , err error ) {
203- _ , err = this .Query (tx ).
206+ // ListEnabledFirewallPolicies 列出单页的策略
207+ func (this * HTTPFirewallPolicyDAO ) ListEnabledFirewallPolicies (tx * dbs.Tx , keyword string , offset int64 , size int64 ) (result []* HTTPFirewallPolicy , err error ) {
208+ query := this .Query (tx )
209+ if len (keyword ) > 0 {
210+ query .Where ("(name LIKE :keyword)" ).
211+ Param ("keyword" , "%" + keyword + "%" )
212+ }
213+ _ , err = query .
204214 State (HTTPFirewallPolicyStateEnabled ).
205215 Attr ("userId" , 0 ).
206216 Attr ("serverId" , 0 ).
@@ -212,7 +222,7 @@ func (this *HTTPFirewallPolicyDAO) ListEnabledFirewallPolicies(tx *dbs.Tx, offse
212222 return
213223}
214224
215- // 组合策略配置
225+ // ComposeFirewallPolicy 组合策略配置
216226func (this * HTTPFirewallPolicyDAO ) ComposeFirewallPolicy (tx * dbs.Tx , policyId int64 ) (* firewallconfigs.HTTPFirewallPolicy , error ) {
217227 policy , err := this .FindEnabledHTTPFirewallPolicy (tx , policyId )
218228 if err != nil {
@@ -297,7 +307,7 @@ func (this *HTTPFirewallPolicyDAO) ComposeFirewallPolicy(tx *dbs.Tx, policyId in
297307 return config , nil
298308}
299309
300- // 检查用户防火墙策略
310+ // CheckUserFirewallPolicy 检查用户防火墙策略
301311func (this * HTTPFirewallPolicyDAO ) CheckUserFirewallPolicy (tx * dbs.Tx , userId int64 , firewallPolicyId int64 ) error {
302312 ok , err := this .Query (tx ).
303313 Pk (firewallPolicyId ).
@@ -315,7 +325,7 @@ func (this *HTTPFirewallPolicyDAO) CheckUserFirewallPolicy(tx *dbs.Tx, userId in
315325 return ErrNotFound
316326}
317327
318- // 查找包含某个IPList的所有策略
328+ // FindEnabledFirewallPolicyIdsWithIPListId 查找包含某个IPList的所有策略
319329func (this * HTTPFirewallPolicyDAO ) FindEnabledFirewallPolicyIdsWithIPListId (tx * dbs.Tx , ipListId int64 ) ([]int64 , error ) {
320330 ones , err := this .Query (tx ).
321331 ResultPk ().
@@ -333,7 +343,7 @@ func (this *HTTPFirewallPolicyDAO) FindEnabledFirewallPolicyIdsWithIPListId(tx *
333343 return result , nil
334344}
335345
336- // 查找包含某个规则分组的策略ID
346+ // FindEnabledFirewallPolicyIdWithRuleGroupId 查找包含某个规则分组的策略ID
337347func (this * HTTPFirewallPolicyDAO ) FindEnabledFirewallPolicyIdWithRuleGroupId (tx * dbs.Tx , ruleGroupId int64 ) (int64 , error ) {
338348 return this .Query (tx ).
339349 ResultPk ().
@@ -343,7 +353,7 @@ func (this *HTTPFirewallPolicyDAO) FindEnabledFirewallPolicyIdWithRuleGroupId(tx
343353 FindInt64Col (0 )
344354}
345355
346- // 设置某个策略所属的服务ID
356+ // UpdateFirewallPolicyServerId 设置某个策略所属的服务ID
347357func (this * HTTPFirewallPolicyDAO ) UpdateFirewallPolicyServerId (tx * dbs.Tx , policyId int64 , serverId int64 ) error {
348358 _ , err := this .Query (tx ).
349359 Pk (policyId ).
@@ -352,7 +362,7 @@ func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicyServerId(tx *dbs.Tx, poli
352362 return err
353363}
354364
355- // 通知更新
365+ // NotifyUpdate 通知更新
356366func (this * HTTPFirewallPolicyDAO ) NotifyUpdate (tx * dbs.Tx , policyId int64 ) error {
357367 webIds , err := SharedHTTPWebDAO .FindAllWebIdsWithHTTPFirewallPolicyId (tx , policyId )
358368 if err != nil {
0 commit comments