mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-23 15:10:25 +08:00
WAF规则集中增加“允许搜索引擎”选项,可以快速允许搜索引擎访问
This commit is contained in:
@@ -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()]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user