mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-08 03:00:27 +08:00
实现新的CC
This commit is contained in:
@@ -514,6 +514,12 @@ func (this *HTTPRequest) Format(source string) string {
|
|||||||
return this.requestRemoteUser()
|
return this.requestRemoteUser()
|
||||||
case "requestURI", "requestUri":
|
case "requestURI", "requestUri":
|
||||||
return this.rawURI
|
return this.rawURI
|
||||||
|
case "requestURL":
|
||||||
|
var scheme = "http"
|
||||||
|
if this.IsHTTPS {
|
||||||
|
scheme = "https"
|
||||||
|
}
|
||||||
|
return scheme + "://" + this.Host + this.rawURI
|
||||||
case "requestPath":
|
case "requestPath":
|
||||||
return this.requestPath()
|
return this.requestPath()
|
||||||
case "requestPathExtension":
|
case "requestPathExtension":
|
||||||
@@ -1201,7 +1207,7 @@ func (this *HTTPRequest) canIgnore(err error) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HTTP内部错误
|
// HTTP内部错误
|
||||||
if strings.HasPrefix(err.Error(), "http:") || strings.HasPrefix(err.Error(), "http2:") {
|
if strings.HasPrefix(err.Error(), "http:") || strings.HasPrefix(err.Error(), "http2:") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func (this *Piece) Add(key uint64, item *Item) () {
|
|||||||
func (this *Piece) IncreaseInt64(key uint64, delta int64, expiredAt int64) (result int64) {
|
func (this *Piece) IncreaseInt64(key uint64, delta int64, expiredAt int64) (result int64) {
|
||||||
this.locker.Lock()
|
this.locker.Lock()
|
||||||
item, ok := this.m[key]
|
item, ok := this.m[key]
|
||||||
if ok {
|
if ok && item.expiredAt > time.Now().Unix() {
|
||||||
result = types.Int64(item.Value) + delta
|
result = types.Int64(item.Value) + delta
|
||||||
item.Value = result
|
item.Value = result
|
||||||
item.expiredAt = expiredAt
|
item.expiredAt = expiredAt
|
||||||
|
|||||||
48
internal/waf/checkpoints/cc2.go
Normal file
48
internal/waf/checkpoints/cc2.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package checkpoints
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/ttlcache"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ccCache = ttlcache.NewCache(ttlcache.NewPiecesOption(32))
|
||||||
|
|
||||||
|
// CC2Checkpoint 新的CC
|
||||||
|
type CC2Checkpoint struct {
|
||||||
|
Checkpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CC2Checkpoint) RequestValue(req requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
|
var keys = options.GetSlice("keys")
|
||||||
|
var keyValues = []string{}
|
||||||
|
for _, key := range keys {
|
||||||
|
keyValues = append(keyValues, req.Format(types.String(key)))
|
||||||
|
}
|
||||||
|
if len(keyValues) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var period = options.GetInt64("period")
|
||||||
|
if period <= 0 {
|
||||||
|
period = 60
|
||||||
|
}
|
||||||
|
|
||||||
|
var threshold = options.GetInt64("threshold")
|
||||||
|
if threshold <= 0 {
|
||||||
|
threshold = 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
value = ccCache.IncreaseInt64("WAF-CC-"+strings.Join(keyValues, "@"), 1, time.Now().Unix()+period)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CC2Checkpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -185,12 +185,19 @@ var AllCheckpoints = []*CheckpointDefinition{
|
|||||||
Instance: new(RequestHeaderCheckpoint),
|
Instance: new(RequestHeaderCheckpoint),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "CC统计",
|
Name: "CC统计(旧)",
|
||||||
Prefix: "cc",
|
Prefix: "cc",
|
||||||
Description: "统计某段时间段内的请求信息",
|
Description: "统计某段时间段内的请求信息",
|
||||||
HasParams: true,
|
HasParams: true,
|
||||||
Instance: new(CCCheckpoint),
|
Instance: new(CCCheckpoint),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "CC统计(新)",
|
||||||
|
Prefix: "cc2",
|
||||||
|
Description: "统计某段时间段内的请求信息",
|
||||||
|
HasParams: true,
|
||||||
|
Instance: new(CC2Checkpoint),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "通用响应Header长度限制",
|
Name: "通用响应Header长度限制",
|
||||||
Prefix: "responseGeneralHeaderLength",
|
Prefix: "responseGeneralHeaderLength",
|
||||||
|
|||||||
@@ -25,4 +25,7 @@ type Request interface {
|
|||||||
|
|
||||||
// WAFServerId 服务ID
|
// WAFServerId 服务ID
|
||||||
WAFServerId() int64
|
WAFServerId() int64
|
||||||
|
|
||||||
|
// Format 格式化变量
|
||||||
|
Format(string) string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,3 +65,7 @@ func (this *TestRequest) WAFRestoreBody(data []byte) {
|
|||||||
func (this *TestRequest) WAFServerId() int64 {
|
func (this *TestRequest) WAFServerId() int64 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *TestRequest) Format(s string) string {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user