From ec47fc560c1de6adec317b0c3a90deaa9ec9b0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 21 Jan 2021 11:00:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=BA=9B=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E3=80=81=E6=B5=8B=E8=AF=95=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/iplibrary/manager_ip_list.go | 2 +- internal/nodes/http_request.go | 1 + internal/nodes/http_request_waf.go | 2 ++ internal/utils/ip_test.go | 9 +++++++++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 internal/utils/ip_test.go diff --git a/internal/iplibrary/manager_ip_list.go b/internal/iplibrary/manager_ip_list.go index 917d823..017cf97 100644 --- a/internal/iplibrary/manager_ip_list.go +++ b/internal/iplibrary/manager_ip_list.go @@ -49,7 +49,7 @@ func (this *IPListManager) Start() { remotelogs.Println("IP_LIST_MANAGER", err.Error()) } - ticker := time.NewTicker(60 * time.Second) // TODO 未来改成可以手动触发IP变更事件 + ticker := time.NewTicker(60 * time.Second) events.On(events.EventQuit, func() { ticker.Stop() }) diff --git a/internal/nodes/http_request.go b/internal/nodes/http_request.go index db035ad..5a538a3 100644 --- a/internal/nodes/http_request.go +++ b/internal/nodes/http_request.go @@ -853,6 +853,7 @@ func (this *HTTPRequest) requestServerPort() int { // 设置代理相关头部信息 // 参考:https://tools.ietf.org/html/rfc7239 +// TODO X-Forwarded-* 系列做成可选项,避免有些源站屏蔽此项 func (this *HTTPRequest) setForwardHeaders(header http.Header) { if this.RawReq.Header.Get("Connection") == "close" { this.RawReq.Header.Set("Connection", "keep-alive") diff --git a/internal/nodes/http_request_waf.go b/internal/nodes/http_request_waf.go index e90c566..5f04bb0 100644 --- a/internal/nodes/http_request_waf.go +++ b/internal/nodes/http_request_waf.go @@ -84,6 +84,7 @@ func (this *HTTPRequest) checkWAFRequest(firewallPolicy *firewallconfigs.HTTPFir countryId := iplibrary.SharedCountryManager.Lookup(result.Country) if countryId > 0 && lists.ContainsInt64(regionConfig.DenyCountryIds, countryId) { // TODO 可以配置对封禁的处理方式等 + // TODO 需要记录日志信息 this.writer.WriteHeader(http.StatusForbidden) this.writer.Close() @@ -99,6 +100,7 @@ func (this *HTTPRequest) checkWAFRequest(firewallPolicy *firewallconfigs.HTTPFir provinceId := iplibrary.SharedProvinceManager.Lookup(result.Province) if provinceId > 0 && lists.ContainsInt64(regionConfig.DenyProvinceIds, provinceId) { // TODO 可以配置对封禁的处理方式等 + // TODO 需要记录日志信息 this.writer.WriteHeader(http.StatusForbidden) this.writer.Close() diff --git a/internal/utils/ip_test.go b/internal/utils/ip_test.go new file mode 100644 index 0000000..132b4aa --- /dev/null +++ b/internal/utils/ip_test.go @@ -0,0 +1,9 @@ +package utils + +import "testing" + +func TestIP2Long(t *testing.T) { + t.Log(IP2Long("0.0.0.0")) + t.Log(IP2Long("1.0.0.0")) + t.Log(IP2Long("0.0.0.0.0")) +}