@@ -18,11 +18,17 @@ import (
1818func (h * Server ) registerTraffic (group * gin.RouterGroup ) {
1919 group .POST ("/capture" , h .TrafficCapture )
2020 group .POST ("/replay" , h .TrafficReplay )
21- group .POST ("/cancel" , h .TrafficStop )
21+ group .POST ("/cancel" , h .TrafficCancel )
2222 group .GET ("/show" , h .TrafficShow )
2323}
2424
2525func (h * Server ) TrafficCapture (c * gin.Context ) {
26+ globalCfg := h .mgr .CfgMgr .GetConfig ()
27+ if ! globalCfg .EnableTrafficReplay {
28+ c .String (http .StatusBadRequest , "traffic capture is disabled" )
29+ return
30+ }
31+
2632 cfg := capture.CaptureConfig {}
2733 cfg .Output = c .PostForm ("output" )
2834 if durationStr := c .PostForm ("duration" ); durationStr != "" {
@@ -44,7 +50,7 @@ func (h *Server) TrafficCapture(c *gin.Context) {
4450 }
4551 }
4652 cfg .Compress = compress
47- cfg .KeyFile = h . mgr . CfgMgr . GetConfig () .Security .Encryption .KeyPath
53+ cfg .KeyFile = globalCfg .Security .Encryption .KeyPath
4854 if startTimeStr := c .PostForm ("start-time" ); startTimeStr != "" {
4955 startTime , err := time .Parse (time .RFC3339 , startTimeStr )
5056 if err != nil {
@@ -64,6 +70,12 @@ func (h *Server) TrafficCapture(c *gin.Context) {
6470}
6571
6672func (h * Server ) TrafficReplay (c * gin.Context ) {
73+ globalCfg := h .mgr .CfgMgr .GetConfig ()
74+ if ! globalCfg .EnableTrafficReplay {
75+ c .String (http .StatusBadRequest , "traffic replay is disabled" )
76+ return
77+ }
78+
6779 cfg := replay.ReplayConfig {}
6880 cfg .Input = c .PostForm ("input" )
6981 if speedStr := c .PostForm ("speed" ); speedStr != "" {
@@ -87,7 +99,7 @@ func (h *Server) TrafficReplay(c *gin.Context) {
8799 cfg .Username = c .PostForm ("username" )
88100 cfg .Password = c .PostForm ("password" )
89101 cfg .ReadOnly = strings .EqualFold (c .PostForm ("readonly" ), "true" )
90- cfg .KeyFile = h . mgr . CfgMgr . GetConfig () .Security .Encryption .KeyPath
102+ cfg .KeyFile = globalCfg .Security .Encryption .KeyPath
91103
92104 if err := h .mgr .ReplayJobMgr .StartReplay (cfg ); err != nil {
93105 c .String (http .StatusInternalServerError , err .Error ())
@@ -96,12 +108,24 @@ func (h *Server) TrafficReplay(c *gin.Context) {
96108 c .String (http .StatusOK , "replay started" )
97109}
98110
99- func (h * Server ) TrafficStop (c * gin.Context ) {
111+ func (h * Server ) TrafficCancel (c * gin.Context ) {
112+ globalCfg := h .mgr .CfgMgr .GetConfig ()
113+ if ! globalCfg .EnableTrafficReplay {
114+ c .String (http .StatusBadRequest , "traffic cancel is disabled" )
115+ return
116+ }
117+
100118 result := h .mgr .ReplayJobMgr .Stop ()
101119 c .String (http .StatusOK , result )
102120}
103121
104122func (h * Server ) TrafficShow (c * gin.Context ) {
123+ globalCfg := h .mgr .CfgMgr .GetConfig ()
124+ if ! globalCfg .EnableTrafficReplay {
125+ c .String (http .StatusBadRequest , "traffic show is disabled" )
126+ return
127+ }
128+
105129 result := h .mgr .ReplayJobMgr .Jobs ()
106130 c .String (http .StatusOK , result )
107131}
0 commit comments