2020-10-08 15:06:42 +08:00
|
|
|
package checkpoints
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
2022-04-08 16:11:05 +08:00
|
|
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
2020-11-18 19:35:38 +08:00
|
|
|
"github.com/iwind/TeaGo/maps"
|
2020-10-08 15:06:42 +08:00
|
|
|
)
|
|
|
|
|
|
2021-07-18 15:51:49 +08:00
|
|
|
// RequestAllCheckpoint ${requestAll}
|
2020-10-08 15:06:42 +08:00
|
|
|
type RequestAllCheckpoint struct {
|
|
|
|
|
Checkpoint
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-18 15:51:49 +08:00
|
|
|
func (this *RequestAllCheckpoint) RequestValue(req requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
2020-10-08 15:06:42 +08:00
|
|
|
valueBytes := []byte{}
|
2021-07-18 15:51:49 +08:00
|
|
|
if len(req.WAFRaw().RequestURI) > 0 {
|
|
|
|
|
valueBytes = append(valueBytes, req.WAFRaw().RequestURI...)
|
|
|
|
|
} else if req.WAFRaw().URL != nil {
|
|
|
|
|
valueBytes = append(valueBytes, req.WAFRaw().URL.RequestURI()...)
|
2020-10-08 15:06:42 +08:00
|
|
|
}
|
|
|
|
|
|
2022-03-16 17:06:26 +08:00
|
|
|
if this.RequestBodyIsEmpty(req) {
|
|
|
|
|
value = valueBytes
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-18 15:51:49 +08:00
|
|
|
if req.WAFRaw().Body != nil {
|
2020-10-08 15:06:42 +08:00
|
|
|
valueBytes = append(valueBytes, ' ')
|
|
|
|
|
|
2021-07-18 15:51:49 +08:00
|
|
|
var bodyData = req.WAFGetCacheBody()
|
|
|
|
|
if len(bodyData) == 0 {
|
2022-04-08 16:11:05 +08:00
|
|
|
data, err := req.WAFReadBody(utils.MaxBodySize) // read body
|
2020-10-08 15:06:42 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return "", err, nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-18 15:51:49 +08:00
|
|
|
bodyData = data
|
|
|
|
|
req.WAFSetCacheBody(data)
|
|
|
|
|
req.WAFRestoreBody(data)
|
2020-10-08 15:06:42 +08:00
|
|
|
}
|
2021-07-18 15:51:49 +08:00
|
|
|
valueBytes = append(valueBytes, bodyData...)
|
2020-10-08 15:06:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value = valueBytes
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-18 15:51:49 +08:00
|
|
|
func (this *RequestAllCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
2020-10-08 15:06:42 +08:00
|
|
|
value = ""
|
|
|
|
|
if this.IsRequest() {
|
|
|
|
|
return this.RequestValue(req, param, options)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|