waf.go 2.63 KB
Newer Older
qiuqunfeng's avatar
qiuqunfeng committed
1 2 3 4
package api

import (
	"github.com/gin-gonic/gin"
5
	"github.com/olivere/elastic/v7"
qiuqunfeng's avatar
qiuqunfeng committed
6
	"gitlab.com/tensorsecurity-rd/waf-console/internal/controller"
qiuqunfeng's avatar
qiuqunfeng committed
7
	"gitlab.com/tensorsecurity-rd/waf-console/internal/utils"
qiuqunfeng's avatar
qiuqunfeng committed
8 9 10
	"gorm.io/gorm"
)

11
func SetWafRouter(e *gin.Engine, clusterClientManager *utils.ClusterClientManager, db *gorm.DB, gatewayUrl string, elasticClient *elastic.Client, regionUrlMap map[string]string) {
qiuqunfeng's avatar
qiuqunfeng committed
12
	v1 := e.Group("v1/api/waf")
qiuqunfeng's avatar
qiuqunfeng committed
13

14
	wafController := controller.NewWafController(clusterClientManager, db, gatewayUrl, elasticClient)
qiuqunfeng's avatar
qiuqunfeng committed
15
	v1.GET("", wafController.Waf)
16
	v1.GET("list", wafController.ListWafs)
qiuqunfeng's avatar
qiuqunfeng committed
17
	v1.POST("/", wafController.CreateWaf)
qiuqunfeng's avatar
commit  
qiuqunfeng committed
18
	v1.PUT("mode", wafController.UpdateMode)
qiuqunfeng's avatar
qiuqunfeng committed
19 20 21
	v1.PUT("rules", wafController.UpdateRule)
	v1.PUT("listener/enable", wafController.EnableListenerWaf)
	v1.PUT("gateway/enable", wafController.EnableGatewayWaf)
22
	v1.POST("listeners/enable", wafController.EnableListenerWafs)
qiuqunfeng's avatar
qiuqunfeng committed
23 24
	v1.DELETE("listener/:region_code/:namespace/:gateway_name/:port", wafController.DeleteListenerWaf)
	v1.DELETE("gateway/:region_code/:namespace/:gateway_name", wafController.DeleteGatewayWaf)
qiuqunfeng's avatar
commit  
qiuqunfeng committed
25
	v1.POST("debug/savecatagory", wafController.SaveRuleCategoryToDB)
26
	v1.GET("listener/history", wafController.ListListenerHistory)
27 28

	v2 := e.Group("api/v2/containerSec/waf")
29
	wafLogController := controller.NewWafLogController(regionUrlMap)
30 31 32
	v2.GET("attack/log/list", wafLogController.WafLogProxy)
	v2.GET("attack/log/details", wafLogController.WafLogProxy)
	v2.GET("attack/log/rspPkg", wafLogController.WafLogProxy)
33 34 35
	// v2.GET("attack/log/list", wafController.ListAttackLogs)
	// v2.GET("attack/log/details", wafController.GetAttackLogDetails)
	// v2.GET("attack/log/rspPkg", wafController.GetAttackLogRsp)
36

37 38
	v2.GET("rules", wafController.ListRules)
	v2.PUT("rules", wafController.UpdateRule)
39 40 41
	v2.POST("blackwhitelist", wafController.CreateBlackWhiteList)
	v2.PUT("blackwhitelist", wafController.UpdateBlackWhiteList)
	v2.PUT("blackwhitelist/enabling", wafController.EnableBlackWhiteList)
qiuqunfeng's avatar
debug  
qiuqunfeng committed
42
	v2.DELETE("blackwhitelist/:id", wafController.DeleteBlackWhiteList)
43
	v2.GET("blackwhitelists", wafController.GetBlackWhiteLists)
44
	v2.GET("services", wafController.ListWafsV2)
45
	v2.GET("attack/classes", wafController.AttackClassesList)
46

qiuqunfeng's avatar
qiuqunfeng committed
47
}
48 49 50 51 52 53 54 55 56

func SetApiWafRouter(e *gin.Engine, clusterClientManager *utils.ClusterClientManager, db *gorm.DB, gatewayUrl string, elasticClient *elastic.Client) {
	v1 := e.Group("api/v2/waf")

	wafController := controller.NewWafController(clusterClientManager, db, gatewayUrl, elasticClient)
	v1.GET("attack/log/list", wafController.ListAttackLogs)
	v1.GET("attack/log/details", wafController.GetAttackLogDetails)
	v1.GET("attack/log/rspPkg", wafController.GetAttackLogRsp)
}