mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-12 02:06:37 +08:00
前端优化
This commit is contained in:
@@ -695,6 +695,11 @@ func buildIPGroup(group *model.OpenFlareWAFIPGroup, input IPGroupInput) (*model.
|
||||
group.Type = groupType
|
||||
group.Enabled = input.Enabled
|
||||
group.IPList = string(ipListJSON)
|
||||
if groupType == wafIPGroupTypeAutomatic {
|
||||
if err := pruneIPGroupExtIPs(group, normalizedIPs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
group.AutoConfig = autoConfig
|
||||
group.SubscriptionURL = subscriptionURL
|
||||
group.SubscriptionFormat = subscriptionFormat
|
||||
@@ -785,6 +790,34 @@ func loadIPGroupReferenceCounts(ctx context.Context) (map[uint]int, error) {
|
||||
return counts, nil
|
||||
}
|
||||
|
||||
func pruneIPGroupExtIPs(group *model.OpenFlareWAFIPGroup, ipList []string) error {
|
||||
if group == nil {
|
||||
return nil
|
||||
}
|
||||
allowed := make(map[string]struct{}, len(ipList))
|
||||
for _, ip := range ipList {
|
||||
allowed[ip] = struct{}{}
|
||||
}
|
||||
var extIPs []ipGroupExtIP
|
||||
if group.ExtIPs != "" && group.ExtIPs != "[]" {
|
||||
if err := json.Unmarshal([]byte(group.ExtIPs), &extIPs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
pruned := make([]ipGroupExtIP, 0, len(extIPs))
|
||||
for _, extIP := range extIPs {
|
||||
if _, ok := allowed[extIP.IP]; ok {
|
||||
pruned = append(pruned, extIP)
|
||||
}
|
||||
}
|
||||
extIPsJSON, err := json.Marshal(pruned)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
group.ExtIPs = string(extIPsJSON)
|
||||
return nil
|
||||
}
|
||||
|
||||
func normalizeIPList(items []string) ([]string, error) {
|
||||
normalized := make([]string, 0, len(items))
|
||||
for _, raw := range items {
|
||||
|
||||
Reference in New Issue
Block a user