Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7763f26249 | ||
|
|
b7ae10e2d0 | ||
|
|
e54eddc961 | ||
|
|
93db9d4926 | ||
|
|
8c1af3e699 | ||
|
|
53c74553bc | ||
|
|
3eb9cade0e |
@@ -1,7 +1,7 @@
|
|||||||
package teaconst
|
package teaconst
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "0.3.5"
|
Version = "0.3.6"
|
||||||
|
|
||||||
ProductName = "Edge Node"
|
ProductName = "Edge Node"
|
||||||
ProcessName = "edge-node"
|
ProcessName = "edge-node"
|
||||||
|
|||||||
@@ -297,10 +297,13 @@ func (this *IPSetAction) runActionSingleIP(action string, listType IPListType, i
|
|||||||
case "deleteItem":
|
case "deleteItem":
|
||||||
args = append(args, "del")
|
args = append(args, "del")
|
||||||
}
|
}
|
||||||
|
|
||||||
args = append(args, listName, item.IpFrom)
|
args = append(args, listName, item.IpFrom)
|
||||||
timestamp := time.Now().Unix()
|
if action == "addItem" {
|
||||||
if item.ExpiredAt > timestamp {
|
timestamp := time.Now().Unix()
|
||||||
args = append(args, "timeout", strconv.FormatInt(item.ExpiredAt-timestamp, 10))
|
if item.ExpiredAt > timestamp {
|
||||||
|
args = append(args, "timeout", strconv.FormatInt(item.ExpiredAt-timestamp, 10))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
|
|||||||
@@ -86,13 +86,21 @@ type HTTPRequest struct {
|
|||||||
// 初始化
|
// 初始化
|
||||||
func (this *HTTPRequest) init() {
|
func (this *HTTPRequest) init() {
|
||||||
this.writer = NewHTTPWriter(this, this.RawWriter)
|
this.writer = NewHTTPWriter(this, this.RawWriter)
|
||||||
this.web = &serverconfigs.HTTPWebConfig{IsOn: true}
|
this.web = &serverconfigs.HTTPWebConfig{
|
||||||
|
IsOn: true,
|
||||||
|
}
|
||||||
|
|
||||||
// this.uri = this.RawReq.URL.RequestURI()
|
// this.uri = this.RawReq.URL.RequestURI()
|
||||||
// 之所以不使用RequestURI(),是不想让URL中的Path被Encode
|
// 之所以不使用RequestURI(),是不想让URL中的Path被Encode
|
||||||
|
var urlPath = this.RawReq.URL.Path
|
||||||
|
if this.Server.Web != nil && this.Server.Web.MergeSlashes {
|
||||||
|
urlPath = utils.CleanPath(urlPath)
|
||||||
|
this.web.MergeSlashes = true
|
||||||
|
}
|
||||||
if len(this.RawReq.URL.RawQuery) > 0 {
|
if len(this.RawReq.URL.RawQuery) > 0 {
|
||||||
this.uri = this.RawReq.URL.Path + "?" + this.RawReq.URL.RawQuery
|
this.uri = urlPath + "?" + this.RawReq.URL.RawQuery
|
||||||
} else {
|
} else {
|
||||||
this.uri = this.RawReq.URL.Path
|
this.uri = urlPath
|
||||||
}
|
}
|
||||||
|
|
||||||
this.rawURI = this.uri
|
this.rawURI = this.uri
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package nodes
|
package nodes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -8,7 +9,11 @@ import (
|
|||||||
|
|
||||||
// 主机地址快速跳转
|
// 主机地址快速跳转
|
||||||
func (this *HTTPRequest) doHostRedirect() (blocked bool) {
|
func (this *HTTPRequest) doHostRedirect() (blocked bool) {
|
||||||
fullURL := this.requestScheme() + "://" + this.Host + this.RawReq.URL.Path
|
var urlPath = this.RawReq.URL.Path
|
||||||
|
if this.web.MergeSlashes {
|
||||||
|
urlPath = utils.CleanPath(urlPath)
|
||||||
|
}
|
||||||
|
fullURL := this.requestScheme() + "://" + this.Host + urlPath
|
||||||
for _, u := range this.web.HostRedirects {
|
for _, u := range this.web.HostRedirects {
|
||||||
if !u.IsOn {
|
if !u.IsOn {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
// 清理Path中的多余的字符
|
// CleanPath 清理Path中的多余的字符
|
||||||
func CleanPath(path string) string {
|
func CleanPath(path string) string {
|
||||||
l := len(path)
|
l := len(path)
|
||||||
if l == 0 {
|
if l == 0 {
|
||||||
@@ -9,6 +9,10 @@ func CleanPath(path string) string {
|
|||||||
result := []byte{'/'}
|
result := []byte{'/'}
|
||||||
isSlash := true
|
isSlash := true
|
||||||
for i := 0; i < l; i++ {
|
for i := 0; i < l; i++ {
|
||||||
|
if path[i] == '?' {
|
||||||
|
result = append(result, path[i:]...)
|
||||||
|
break
|
||||||
|
}
|
||||||
if path[i] == '\\' || path[i] == '/' {
|
if path[i] == '\\' || path[i] == '/' {
|
||||||
if !isSlash {
|
if !isSlash {
|
||||||
isSlash = true
|
isSlash = true
|
||||||
@@ -21,4 +25,3 @@ func CleanPath(path string) string {
|
|||||||
}
|
}
|
||||||
return string(result)
|
return string(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ func TestCleanPath(t *testing.T) {
|
|||||||
a.IsTrue(CleanPath("/hello////world") == "/hello/world")
|
a.IsTrue(CleanPath("/hello////world") == "/hello/world")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCleanPath_Args(t *testing.T) {
|
||||||
|
a := assert.NewAssertion(t)
|
||||||
|
a.IsTrue(CleanPath("/hello/world?base=///////") == "/hello/world?base=///////")
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkCleanPath(b *testing.B) {
|
func BenchmarkCleanPath(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = CleanPath("/hello///world/very/long/very//long")
|
_ = CleanPath("/hello///world/very/long/very//long")
|
||||||
|
|||||||
@@ -10,8 +10,15 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
var SharedIPWhiteList = NewIPList()
|
var SharedIPWhiteList = NewIPList(IPListTypeAllow)
|
||||||
var SharedIPBlackList = NewIPList()
|
var SharedIPBlackList = NewIPList(IPListTypeDeny)
|
||||||
|
|
||||||
|
type IPListType = string
|
||||||
|
|
||||||
|
const (
|
||||||
|
IPListTypeAllow IPListType = "allow"
|
||||||
|
IPListTypeDeny IPListType = "deny"
|
||||||
|
)
|
||||||
|
|
||||||
const IPTypeAll = "*"
|
const IPTypeAll = "*"
|
||||||
|
|
||||||
@@ -20,16 +27,18 @@ type IPList struct {
|
|||||||
expireList *expires.List
|
expireList *expires.List
|
||||||
ipMap map[string]int64 // ip => id
|
ipMap map[string]int64 // ip => id
|
||||||
idMap map[int64]string // id => ip
|
idMap map[int64]string // id => ip
|
||||||
|
listType IPListType
|
||||||
|
|
||||||
id int64
|
id int64
|
||||||
locker sync.RWMutex
|
locker sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewIPList 获取新对象
|
// NewIPList 获取新对象
|
||||||
func NewIPList() *IPList {
|
func NewIPList(listType IPListType) *IPList {
|
||||||
var list = &IPList{
|
var list = &IPList{
|
||||||
ipMap: map[string]int64{},
|
ipMap: map[string]int64{},
|
||||||
idMap: map[int64]string{},
|
idMap: map[int64]string{},
|
||||||
|
listType: listType,
|
||||||
}
|
}
|
||||||
|
|
||||||
e := expires.NewList()
|
e := expires.NewList()
|
||||||
@@ -67,20 +76,22 @@ func (this *IPList) Add(ipType string, scope firewallconfigs.FirewallScope, serv
|
|||||||
func (this *IPList) RecordIP(ipType string, scope firewallconfigs.FirewallScope, serverId int64, ip string, expiresAt int64, policyId int64, groupId int64, setId int64) {
|
func (this *IPList) RecordIP(ipType string, scope firewallconfigs.FirewallScope, serverId int64, ip string, expiresAt int64, policyId int64, groupId int64, setId int64) {
|
||||||
this.Add(ipType, scope, serverId, ip, expiresAt)
|
this.Add(ipType, scope, serverId, ip, expiresAt)
|
||||||
|
|
||||||
select {
|
if this.listType == IPListTypeDeny {
|
||||||
case recordIPTaskChan <- &recordIPTask{
|
select {
|
||||||
ip: ip,
|
case recordIPTaskChan <- &recordIPTask{
|
||||||
listId: firewallconfigs.GlobalListId,
|
ip: ip,
|
||||||
expiredAt: expiresAt,
|
listId: firewallconfigs.GlobalListId,
|
||||||
level: firewallconfigs.DefaultEventLevel,
|
expiredAt: expiresAt,
|
||||||
serverId: serverId,
|
level: firewallconfigs.DefaultEventLevel,
|
||||||
sourceServerId: serverId,
|
serverId: serverId,
|
||||||
sourceHTTPFirewallPolicyId: policyId,
|
sourceServerId: serverId,
|
||||||
sourceHTTPFirewallRuleGroupId: groupId,
|
sourceHTTPFirewallPolicyId: policyId,
|
||||||
sourceHTTPFirewallRuleSetId: setId,
|
sourceHTTPFirewallRuleGroupId: groupId,
|
||||||
}:
|
sourceHTTPFirewallRuleSetId: setId,
|
||||||
default:
|
}:
|
||||||
|
default:
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user