mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2026-11-02 11:11:47 +08:00
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package wafenginecore
|
|
|
|
import (
|
|
"SamWaf/global"
|
|
"SamWaf/innerbean"
|
|
"SamWaf/model/detection"
|
|
"SamWaf/model/wafenginmodel"
|
|
"SamWaf/utils"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
/*
|
|
*
|
|
检测白名单 ip
|
|
*/
|
|
func (waf *WafEngine) CheckAllowIP(r *http.Request, weblogbean *innerbean.WebLog, formValue url.Values, hostTarget *wafenginmodel.HostSafe, globalHostTarget *wafenginmodel.HostSafe) detection.Result {
|
|
result := detection.Result{
|
|
JumpGuardResult: false,
|
|
IsBlock: false,
|
|
Title: "",
|
|
Content: "",
|
|
}
|
|
clientIp := weblogbean.SRC_IP
|
|
if global.GCONFIG_RECORD_PROXY_HEADER == "" {
|
|
clientIp = weblogbean.NetSrcIp
|
|
}
|
|
|
|
//ip白名单策略(局部)
|
|
if hostTarget.IPWhiteLists != nil {
|
|
for i := 0; i < len(hostTarget.IPWhiteLists); i++ {
|
|
if utils.CheckIPInCIDR(clientIp, hostTarget.IPWhiteLists[i].Ip) {
|
|
result.JumpGuardResult = true
|
|
break
|
|
}
|
|
}
|
|
}
|
|
//ip白名单策略(全局)
|
|
if waf.HostTarget[global.GWAF_GLOBAL_HOST_NAME].Host.GUARD_STATUS == 1 && waf.HostTarget[global.GWAF_GLOBAL_HOST_NAME].IPWhiteLists != nil {
|
|
for i := 0; i < len(waf.HostTarget[global.GWAF_GLOBAL_HOST_NAME].IPWhiteLists); i++ {
|
|
if utils.CheckIPInCIDR(clientIp, waf.HostTarget[global.GWAF_GLOBAL_HOST_NAME].IPWhiteLists[i].Ip) {
|
|
result.JumpGuardResult = true
|
|
break
|
|
}
|
|
}
|
|
}
|
|
return result
|
|
}
|