mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-11 22:00:25 +08:00
实现UA名单功能
This commit is contained in:
@@ -237,6 +237,14 @@ func (this *HTTPRequest) Do() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UA名单
|
||||||
|
if !this.isSubRequest && this.web.UserAgent != nil && this.web.UserAgent.IsOn {
|
||||||
|
if this.doCheckUserAgent() {
|
||||||
|
this.doEnd()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 访问控制
|
// 访问控制
|
||||||
if !this.isSubRequest && this.web.Auth != nil && this.web.Auth.IsOn {
|
if !this.isSubRequest && this.web.Auth != nil && this.web.Auth.IsOn {
|
||||||
if this.doAuth() {
|
if this.doAuth() {
|
||||||
@@ -526,6 +534,11 @@ func (this *HTTPRequest) configureWeb(web *serverconfigs.HTTPWebConfig, isTop bo
|
|||||||
this.web.Referers = web.Referers
|
this.web.Referers = web.Referers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// user agent
|
||||||
|
if web.UserAgent != nil && (web.UserAgent.IsPrior || isTop) {
|
||||||
|
this.web.UserAgent = web.UserAgent
|
||||||
|
}
|
||||||
|
|
||||||
// request limit
|
// request limit
|
||||||
if web.RequestLimit != nil && (web.RequestLimit.IsPrior || isTop) {
|
if web.RequestLimit != nil && (web.RequestLimit.IsPrior || isTop) {
|
||||||
this.web.RequestLimit = web.RequestLimit
|
this.web.RequestLimit = web.RequestLimit
|
||||||
|
|||||||
24
internal/nodes/http_request_user_agent.go
Normal file
24
internal/nodes/http_request_user_agent.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package nodes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (this *HTTPRequest) doCheckUserAgent() (shouldStop bool) {
|
||||||
|
if this.web.UserAgent == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const cacheSeconds = "3600" // 时间不能过长,防止修改设置后长期无法生效
|
||||||
|
|
||||||
|
if !this.web.UserAgent.AllowRequest(this.RawReq) {
|
||||||
|
this.tags = append(this.tags, "userAgentCheck")
|
||||||
|
this.writer.Header().Set("Cache-Control", "max-age="+cacheSeconds)
|
||||||
|
this.writeCode(http.StatusForbidden, "The User-Agent has been blocked.", "当前访问已被UA名单拦截。")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user