mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-01 21:30:24 +08:00
WAF国家/地区封禁、省份封禁增加例外URL、限制URL
This commit is contained in:
@@ -163,47 +163,52 @@ func (this *HTTPRequest) checkWAFRequest(firewallPolicy *firewallconfigs.HTTPFir
|
|||||||
// 检查地区封禁
|
// 检查地区封禁
|
||||||
if firewallPolicy.Mode == firewallconfigs.FirewallModeDefend {
|
if firewallPolicy.Mode == firewallconfigs.FirewallModeDefend {
|
||||||
if firewallPolicy.Inbound.Region != nil && firewallPolicy.Inbound.Region.IsOn {
|
if firewallPolicy.Inbound.Region != nil && firewallPolicy.Inbound.Region.IsOn {
|
||||||
regionConfig := firewallPolicy.Inbound.Region
|
var regionConfig = firewallPolicy.Inbound.Region
|
||||||
if regionConfig.IsNotEmpty() {
|
if regionConfig.IsNotEmpty() {
|
||||||
for _, remoteAddr := range remoteAddrs {
|
for _, remoteAddr := range remoteAddrs {
|
||||||
var result = iplib.LookupIP(remoteAddr)
|
var result = iplib.LookupIP(remoteAddr)
|
||||||
if result != nil && result.IsOk() {
|
if result != nil && result.IsOk() {
|
||||||
// 检查国家/地区级别封禁
|
var currentURL = this.URL()
|
||||||
var countryId = result.CountryId()
|
if regionConfig.MatchCountryURL(currentURL) {
|
||||||
if countryId > 0 && lists.ContainsInt64(regionConfig.DenyCountryIds, countryId) {
|
// 检查国家/地区级别封禁
|
||||||
this.firewallPolicyId = firewallPolicy.Id
|
var countryId = result.CountryId()
|
||||||
|
if countryId > 0 && lists.ContainsInt64(regionConfig.DenyCountryIds, countryId) {
|
||||||
|
this.firewallPolicyId = firewallPolicy.Id
|
||||||
|
|
||||||
this.writeCode(http.StatusForbidden, "", "")
|
this.writeCode(http.StatusForbidden, "", "")
|
||||||
this.writer.Flush()
|
this.writer.Flush()
|
||||||
this.writer.Close()
|
this.writer.Close()
|
||||||
|
|
||||||
// 停止日志
|
// 停止日志
|
||||||
if !logDenying {
|
if !logDenying {
|
||||||
this.disableLog = true
|
this.disableLog = true
|
||||||
} else {
|
} else {
|
||||||
this.tags = append(this.tags, "denyCountry")
|
this.tags = append(this.tags, "denyCountry")
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查省份封禁
|
if regionConfig.MatchProvinceURL(currentURL) {
|
||||||
var provinceId = result.ProvinceId()
|
// 检查省份封禁
|
||||||
if provinceId > 0 && lists.ContainsInt64(regionConfig.DenyProvinceIds, provinceId) {
|
var provinceId = result.ProvinceId()
|
||||||
this.firewallPolicyId = firewallPolicy.Id
|
if provinceId > 0 && lists.ContainsInt64(regionConfig.DenyProvinceIds, provinceId) {
|
||||||
|
this.firewallPolicyId = firewallPolicy.Id
|
||||||
|
|
||||||
this.writeCode(http.StatusForbidden, "", "")
|
this.writeCode(http.StatusForbidden, "", "")
|
||||||
this.writer.Flush()
|
this.writer.Flush()
|
||||||
this.writer.Close()
|
this.writer.Close()
|
||||||
|
|
||||||
// 停止日志
|
// 停止日志
|
||||||
if !logDenying {
|
if !logDenying {
|
||||||
this.disableLog = true
|
this.disableLog = true
|
||||||
} else {
|
} else {
|
||||||
this.tags = append(this.tags, "denyProvince")
|
this.tags = append(this.tags, "denyProvince")
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user