WAF规则集中增加“允许搜索引擎”选项,可以快速允许搜索引擎访问

This commit is contained in:
刘祥超
2024-05-08 16:45:28 +08:00
parent f1b3a7463d
commit 731f213310
4 changed files with 78 additions and 27 deletions

View File

@@ -1,8 +1,10 @@
package utils
import (
"github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/re"
"github.com/TeaOSLab/EdgeNode/internal/utils/agents"
"github.com/TeaOSLab/EdgeNode/internal/utils/cachehits"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
"github.com/TeaOSLab/EdgeNode/internal/utils/ttlcache"
@@ -100,3 +102,30 @@ func MatchBytesCache(regex *re.Regexp, byteSlice []byte, cacheLife CacheLife) bo
func ComposeIPType(setId int64, req requests.Request) string {
return "set:" + types.String(setId) + "@" + stringutil.Md5(req.WAFRaw().UserAgent())
}
var searchEngineProviderMap = map[string]bool{
"谷歌": true,
"雅虎": true,
"脸书": true,
"百度": true,
"Facebook": true,
"Yandex": true,
}
// CheckSearchEngine check if ip is from search engines
func CheckSearchEngine(ip string) bool {
if len(ip) == 0 {
return false
}
if agents.SharedManager.ContainsIP(ip) {
return true
}
var result = iplibrary.LookupIP(ip)
if result == nil {
return false
}
return searchEngineProviderMap[result.ProviderName()]
}