Commit aab2db68 authored by qunfeng qiu's avatar qunfeng qiu
Browse files

proxy service

parent 99afe61b
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
ARG TARGETARCH
WORKDIR /app
COPY ./ ./
RUN go env -w GOPROXY='https://goproxy.cn,direct' && GOOS=linux GOARCH=$TARGETARCH go build -a -o ./dist/waf-api-server gitlab.com/tensorsecurity-rd/waf-console/cmd/api-server
FROM ubuntu:22.04
#FROM alpine
# ARG MIRROR_SOURCE=mirrors.aliyun.com
WORKDIR /
# ADD dist/waf-console /
COPY config/waf_detection_index_template.json /
COPY --from=builder /app/dist/waf-api-server /waf-api-server
# RUN ls -l /waf-api-server
ENTRYPOINT ["/waf-api-server"]
\ No newline at end of file
......@@ -337,7 +337,7 @@ func (c *WafController) ListAttackLogs(ctx *gin.Context) {
id := ctx.Query("serviceId")
filter.ServiceId, _ = strconv.ParseInt(id, 10, 64)
filter.Limit, filter.Offset, _ = getLimitAndOffset(ctx)
filter.Cluster = ctx.Query("cluster")
filter.Cluster = ctx.Query("region_code")
filter.AttackUrl = ctx.Query("attackAddr")
filter.AttackIp = ctx.Query("attackIp")
filter.AttackType = ctx.Query("attackType")
......@@ -371,6 +371,10 @@ func (c *WafController) ListAttackLogs(ctx *gin.Context) {
}, nil)
}
func (c *WafController) CountAttackLogs(ctx *gin.Context) {
}
// getLimitAndOffset extracts pagination parameters from the context
// Returns limit, offset, and error
func getLimitAndOffset(ctx *gin.Context) (int, int, error) {
......
......@@ -30,4 +30,5 @@ type Service interface {
GetBlackWhiteLists(ctx context.Context, query *MatchExprQueryOption, limit int, offset int) ([]MatcherExpr, int, error)
ListListenerHistory(ctx context.Context, query *WafListenerHistoryOption, limit, offset int) ([]model.WafListenerHistory, int, error)
ListAttackClasses(ctx context.Context, lang string) []AttackClasses
CountAttackLogs(ctx context.Context, serviceID uint32) int64
}
type SimpleProxy struct {
regionUrlMap map[string]string
}
\ No newline at end of file
......@@ -151,6 +151,29 @@ func (s *wafService) GetWaf(ctx context.Context, regionCode, namespace, gatewayN
}, nil
}
func (s *wafService) CountAttackLogs(ctx context.Context, serviceID uint32) int64 {
now := time.Now()
startOfDay := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
endOfDay := startOfDay.Add(24 * time.Hour)
boolQuery := elastic.NewBoolQuery()
boolQuery.Must(elastic.NewTermQuery("service_id", serviceID))
boolQuery.Filter(elastic.NewRangeQuery("attack_time").
Gte(startOfDay.UnixMilli()).
Lt(endOfDay.UnixMilli()))
boolQuery.Filter(elastic.NewBoolQuery().MustNot(elastic.NewTermQuery("action", "pass")))
result, err := s.elasticClient.Count("waf-detections*").
Query(boolQuery).
Do(ctx)
if err != nil {
log.Err(fmt.Errorf("failed to count attack logs: %v", err))
return 0
}
return result
}
func (s *wafService) ListWafs(ctx context.Context) ([]WafService, error) {
var wafs []WafService
if err := s.db.Model(&model.WafService{}).Find(&wafs).Error; err != nil {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment