diff --git a/api/entrance.go b/api/entrance.go index 896e705..16e5106 100644 --- a/api/entrance.go +++ b/api/entrance.go @@ -8,8 +8,8 @@ type APIGroup struct { WafLogAPi WafRuleAPi WafEngineApi - WafWhiteIpApi - WafWhiteUrlApi + WafAllowIpApi + WafAllowUrlApi WafLdpUrlApi WafAntiCCApi WafBlockIpApi @@ -33,8 +33,8 @@ var ( wafLogService = waf_service.WafLogServiceApp wafStatService = waf_service.WafStatServiceApp wafRuleService = waf_service.WafRuleServiceApp - wafIpWhiteService = waf_service.WafWhiteIpServiceApp - wafUrlWhiteService = waf_service.WafWhiteUrlServiceApp + wafIpAllowService = waf_service.WafWhiteIpServiceApp + wafUrlAllowService = waf_service.WafWhiteUrlServiceApp wafLdpUrlService = waf_service.WafLdpUrlServiceApp wafAntiCCService = waf_service.WafAntiCCServiceApp diff --git a/api/waf_white_ip.go b/api/waf_allow_ip.go similarity index 63% rename from api/waf_white_ip.go rename to api/waf_allow_ip.go index 9ea5742..eac1890 100644 --- a/api/waf_white_ip.go +++ b/api/waf_allow_ip.go @@ -12,16 +12,16 @@ import ( "gorm.io/gorm" ) -type WafWhiteIpApi struct { +type WafAllowIpApi struct { } -func (w *WafWhiteIpApi) AddApi(c *gin.Context) { - var req request.WafWhiteIpAddReq +func (w *WafAllowIpApi) AddApi(c *gin.Context) { + var req request.WafAllowIpAddReq err := c.ShouldBindJSON(&req) if err == nil { - err = wafIpWhiteService.CheckIsExistApi(req) + err = wafIpAllowService.CheckIsExistApi(req) if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { - err = wafIpWhiteService.AddApi(req) + err = wafIpAllowService.AddApi(req) if err == nil { w.NotifyWaf(req.HostCode) response.OkWithMessage("添加成功", c) @@ -39,21 +39,21 @@ func (w *WafWhiteIpApi) AddApi(c *gin.Context) { response.FailWithMessage("解析失败", c) } } -func (w *WafWhiteIpApi) GetDetailApi(c *gin.Context) { - var req request.WafWhiteIpDetailReq +func (w *WafAllowIpApi) GetDetailApi(c *gin.Context) { + var req request.WafAllowIpDetailReq err := c.ShouldBind(&req) if err == nil { - bean := wafIpWhiteService.GetDetailApi(req) + bean := wafIpAllowService.GetDetailApi(req) response.OkWithDetailed(bean, "获取成功", c) } else { response.FailWithMessage("解析失败", c) } } -func (w *WafWhiteIpApi) GetListApi(c *gin.Context) { - var req request.WafWhiteIpSearchReq +func (w *WafAllowIpApi) GetListApi(c *gin.Context) { + var req request.WafAllowIpSearchReq err := c.ShouldBindJSON(&req) if err == nil { - wafIpWhites, total, _ := wafIpWhiteService.GetListApi(req) + wafIpWhites, total, _ := wafIpAllowService.GetListApi(req) response.OkWithDetailed(response.PageResult{ List: wafIpWhites, Total: total, @@ -64,12 +64,12 @@ func (w *WafWhiteIpApi) GetListApi(c *gin.Context) { response.FailWithMessage("解析失败", c) } } -func (w *WafWhiteIpApi) DelWhiteIpApi(c *gin.Context) { - var req request.WafWhiteIpDelReq +func (w *WafAllowIpApi) DelAllowIpApi(c *gin.Context) { + var req request.WafAllowIpDelReq err := c.ShouldBind(&req) if err == nil { - bean := wafIpWhiteService.GetDetailByIdApi(req.Id) - err = wafIpWhiteService.DelApi(req) + bean := wafIpAllowService.GetDetailByIdApi(req.Id) + err = wafIpAllowService.DelApi(req) if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { response.FailWithMessage("请检测参数", c) } else if err != nil { @@ -84,19 +84,11 @@ func (w *WafWhiteIpApi) DelWhiteIpApi(c *gin.Context) { } } -func (w *WafWhiteIpApi) ModifyWhiteIpApi(c *gin.Context) { - /*rawBody, err := c.GetRawData() - if err != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read raw body"}) - c.Abort() - return - } - - fmt.Println("落地 Raw body:", string(rawBody))*/ - var req request.WafWhiteIpEditReq +func (w *WafAllowIpApi) ModifyAllowIpApi(c *gin.Context) { + var req request.WafAllowIpEditReq err := c.ShouldBindJSON(&req) if err == nil { - err = wafIpWhiteService.ModifyApi(req) + err = wafIpAllowService.ModifyApi(req) if err != nil { response.FailWithMessage("编辑发生错误", c) } else { @@ -113,12 +105,12 @@ func (w *WafWhiteIpApi) ModifyWhiteIpApi(c *gin.Context) { * 通知到waf引擎实时生效 */ -func (w *WafWhiteIpApi) NotifyWaf(host_code string) { - var ipWhites []model.IPWhiteList +func (w *WafAllowIpApi) NotifyWaf(host_code string) { + var ipWhites []model.IPAllowList global.GWAF_LOCAL_DB.Where("host_code = ? ", host_code).Find(&ipWhites) var chanInfo = spec.ChanCommonHost{ HostCode: host_code, - Type: enums.ChanTypeWhiteIP, + Type: enums.ChanTypeAllowIP, Content: ipWhites, } global.GWAF_CHAN_MSG <- chanInfo diff --git a/api/waf_white_url.go b/api/waf_allow_url.go similarity index 67% rename from api/waf_white_url.go rename to api/waf_allow_url.go index 2f26d9c..bd45292 100644 --- a/api/waf_white_url.go +++ b/api/waf_allow_url.go @@ -12,16 +12,16 @@ import ( "gorm.io/gorm" ) -type WafWhiteUrlApi struct { +type WafAllowUrlApi struct { } -func (w *WafWhiteUrlApi) AddApi(c *gin.Context) { - var req request.WafWhiteUrlAddReq +func (w *WafAllowUrlApi) AddApi(c *gin.Context) { + var req request.WafAllowUrlAddReq err := c.ShouldBindJSON(&req) if err == nil { - err = wafUrlWhiteService.CheckIsExistApi(req) + err = wafUrlAllowService.CheckIsExistApi(req) if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { - err = wafUrlWhiteService.AddApi(req) + err = wafUrlAllowService.AddApi(req) if err == nil { w.NotifyWaf(req.HostCode) response.OkWithMessage("添加成功", c) @@ -39,21 +39,21 @@ func (w *WafWhiteUrlApi) AddApi(c *gin.Context) { response.FailWithMessage("解析失败", c) } } -func (w *WafWhiteUrlApi) GetDetailApi(c *gin.Context) { - var req request.WafWhiteUrlDetailReq +func (w *WafAllowUrlApi) GetDetailApi(c *gin.Context) { + var req request.WafAllowUrlDetailReq err := c.ShouldBind(&req) if err == nil { - bean := wafUrlWhiteService.GetDetailApi(req) + bean := wafUrlAllowService.GetDetailApi(req) response.OkWithDetailed(bean, "获取成功", c) } else { response.FailWithMessage("解析失败", c) } } -func (w *WafWhiteUrlApi) GetListApi(c *gin.Context) { - var req request.WafWhiteUrlSearchReq +func (w *WafAllowUrlApi) GetListApi(c *gin.Context) { + var req request.WafAllowUrlSearchReq err := c.ShouldBindJSON(&req) if err == nil { - beans, total, _ := wafUrlWhiteService.GetListApi(req) + beans, total, _ := wafUrlAllowService.GetListApi(req) response.OkWithDetailed(response.PageResult{ List: beans, Total: total, @@ -64,12 +64,12 @@ func (w *WafWhiteUrlApi) GetListApi(c *gin.Context) { response.FailWithMessage("解析失败", c) } } -func (w *WafWhiteUrlApi) DelWhiteUrlApi(c *gin.Context) { - var req request.WafWhiteUrlDelReq +func (w *WafAllowUrlApi) DelAllowUrlApi(c *gin.Context) { + var req request.WafAllowUrlDelReq err := c.ShouldBind(&req) if err == nil { - bean := wafUrlWhiteService.GetDetailByIdApi(req.Id) - err = wafUrlWhiteService.DelApi(req) + bean := wafUrlAllowService.GetDetailByIdApi(req.Id) + err = wafUrlAllowService.DelApi(req) if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { response.FailWithMessage("请检测参数", c) } else if err != nil { @@ -84,11 +84,11 @@ func (w *WafWhiteUrlApi) DelWhiteUrlApi(c *gin.Context) { } } -func (w *WafWhiteUrlApi) ModifyWhiteUrlApi(c *gin.Context) { - var req request.WafWhiteUrlEditReq +func (w *WafAllowUrlApi) ModifyAllowUrlApi(c *gin.Context) { + var req request.WafAllowUrlEditReq err := c.ShouldBindJSON(&req) if err == nil { - err = wafUrlWhiteService.ModifyApi(req) + err = wafUrlAllowService.ModifyApi(req) if err != nil { response.FailWithMessage("编辑发生错误", c) } else { @@ -105,12 +105,12 @@ func (w *WafWhiteUrlApi) ModifyWhiteUrlApi(c *gin.Context) { * 通知到waf引擎实时生效 */ -func (w *WafWhiteUrlApi) NotifyWaf(host_code string) { - var urlWhites []model.URLWhiteList +func (w *WafAllowUrlApi) NotifyWaf(host_code string) { + var urlWhites []model.URLAllowList global.GWAF_LOCAL_DB.Where("host_code = ? ", host_code).Find(&urlWhites) var chanInfo = spec.ChanCommonHost{ HostCode: host_code, - Type: enums.ChanTypeWhiteURL, + Type: enums.ChanTypeAllowURL, Content: urlWhites, } global.GWAF_CHAN_MSG <- chanInfo diff --git a/enums/chan_enum.go b/enums/chan_enum.go index 3f199e4..1a0615b 100644 --- a/enums/chan_enum.go +++ b/enums/chan_enum.go @@ -5,8 +5,8 @@ const ( ChanTypeRule ChanTypeAnticc ChanTypeLdp - ChanTypeWhiteIP - ChanTypeWhiteURL + ChanTypeAllowIP + ChanTypeAllowURL ChanTypeBlockIP ChanTypeBlockURL ChanTypeDelHost diff --git a/main.go b/main.go index ed47e40..9fce2d1 100644 --- a/main.go +++ b/main.go @@ -317,16 +317,16 @@ func (m *wafSystenService) run() { case msg := <-global.GWAF_CHAN_MSG: if globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostTarget[globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostCode[msg.HostCode]] != nil && globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostCode[msg.HostCode] != "" { switch msg.Type { - case enums.ChanTypeWhiteIP: + case enums.ChanTypeAllowIP: globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostTarget[globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostCode[msg.HostCode]].Mux.Lock() - globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostTarget[globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostCode[msg.HostCode]].IPWhiteLists = msg.Content.([]model.IPWhiteList) - zlog.Debug("远程配置", zap.Any("IPWhiteLists", msg.Content.([]model.IPWhiteList))) + globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostTarget[globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostCode[msg.HostCode]].IPWhiteLists = msg.Content.([]model.IPAllowList) + zlog.Debug("远程配置", zap.Any("IPWhiteLists", msg.Content.([]model.IPAllowList))) globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostTarget[globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostCode[msg.HostCode]].Mux.Unlock() break - case enums.ChanTypeWhiteURL: + case enums.ChanTypeAllowURL: globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostTarget[globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostCode[msg.HostCode]].Mux.Lock() - globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostTarget[globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostCode[msg.HostCode]].UrlWhiteLists = msg.Content.([]model.URLWhiteList) - zlog.Debug("远程配置", zap.Any("UrlWhiteLists", msg.Content.([]model.URLWhiteList))) + globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostTarget[globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostCode[msg.HostCode]].UrlWhiteLists = msg.Content.([]model.URLAllowList) + zlog.Debug("远程配置", zap.Any("UrlWhiteLists", msg.Content.([]model.URLAllowList))) globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostTarget[globalobj.GWAF_RUNTIME_OBJ_WAF_ENGINE.HostCode[msg.HostCode]].Mux.Unlock() break case enums.ChanTypeBlockIP: diff --git a/model/whitelist.go b/model/allowlist.go similarity index 90% rename from model/whitelist.go rename to model/allowlist.go index 031b643..ae5b6ca 100644 --- a/model/whitelist.go +++ b/model/allowlist.go @@ -4,13 +4,13 @@ import ( "SamWaf/model/baseorm" ) -type IPWhiteList struct { +type IPAllowList struct { baseorm.BaseOrm HostCode string `json:"host_code"` //网站唯一码(主要键) Ip string `json:"ip"` //白名单ip Remarks string `json:"remarks"` //备注 } -type URLWhiteList struct { +type URLAllowList struct { baseorm.BaseOrm HostCode string `json:"host_code"` //网站唯一码(主要键) CompareType string `json:"compare_type"` //判断类型,包含、开始、结束、完全匹配 diff --git a/model/request/waf_white_ip_add_req.go b/model/request/waf_allow_ip_add_req.go similarity index 85% rename from model/request/waf_white_ip_add_req.go rename to model/request/waf_allow_ip_add_req.go index c159298..7b13cae 100644 --- a/model/request/waf_white_ip_add_req.go +++ b/model/request/waf_allow_ip_add_req.go @@ -1,6 +1,6 @@ package request -type WafWhiteIpAddReq struct { +type WafAllowIpAddReq struct { HostCode string `json:"host_code"` //网站唯一码(主要键) Ip string `json:"ip"` //白名单ip Remarks string `json:"remarks"` //备注 diff --git a/model/request/waf_white_ip_del_req.go b/model/request/waf_allow_ip_del_req.go similarity index 71% rename from model/request/waf_white_ip_del_req.go rename to model/request/waf_allow_ip_del_req.go index 5185a0d..0c75efe 100644 --- a/model/request/waf_white_ip_del_req.go +++ b/model/request/waf_allow_ip_del_req.go @@ -1,5 +1,5 @@ package request -type WafWhiteIpDelReq struct { +type WafAllowIpDelReq struct { Id string `json:"id" form:"id"` //白名单IP唯一键 } diff --git a/model/request/waf_white_ip_detail_req.go b/model/request/waf_allow_ip_detail_req.go similarity index 69% rename from model/request/waf_white_ip_detail_req.go rename to model/request/waf_allow_ip_detail_req.go index 7c4ea0a..dab2a8d 100644 --- a/model/request/waf_white_ip_detail_req.go +++ b/model/request/waf_allow_ip_detail_req.go @@ -1,5 +1,5 @@ package request -type WafWhiteIpDetailReq struct { +type WafAllowIpDetailReq struct { Id string `json:"id" form:"id"` //白名单IP唯一键 } diff --git a/model/request/waf_white_ip_edit_req.go b/model/request/waf_allow_ip_edit_req.go similarity index 88% rename from model/request/waf_white_ip_edit_req.go rename to model/request/waf_allow_ip_edit_req.go index 5e33c8f..75f63c7 100644 --- a/model/request/waf_white_ip_edit_req.go +++ b/model/request/waf_allow_ip_edit_req.go @@ -1,6 +1,6 @@ package request -type WafWhiteIpEditReq struct { +type WafAllowIpEditReq struct { Id string `json:"id"` //白名单IP唯一键 HostCode string `json:"host_code"` //网站唯一码(主要键) Ip string `json:"ip"` //白名单ip diff --git a/model/request/waf_white_ip_search.go b/model/request/waf_allow_ip_search.go similarity index 83% rename from model/request/waf_white_ip_search.go rename to model/request/waf_allow_ip_search.go index 5bf2c9a..c6bc1b6 100644 --- a/model/request/waf_white_ip_search.go +++ b/model/request/waf_allow_ip_search.go @@ -2,7 +2,7 @@ package request import "SamWaf/model/common/request" -type WafWhiteIpSearchReq struct { +type WafAllowIpSearchReq struct { HostCode string `json:"host_code" ` //主机码 Ip string `json:"ip"` //白名单ip request.PageInfo diff --git a/model/request/waf_white_url_add_req.go b/model/request/waf_allow_url_add_req.go similarity index 91% rename from model/request/waf_white_url_add_req.go rename to model/request/waf_allow_url_add_req.go index 9e304e6..b8055cd 100644 --- a/model/request/waf_white_url_add_req.go +++ b/model/request/waf_allow_url_add_req.go @@ -1,6 +1,6 @@ package request -type WafWhiteUrlAddReq struct { +type WafAllowUrlAddReq struct { HostCode string `json:"host_code"` //网站唯一码(主要键) CompareType string `json:"compare_type" form:"compare_type"` //对比方式 Url string `json:"url"` //白名单url diff --git a/model/request/waf_white_url_del_req.go b/model/request/waf_allow_url_del_req.go similarity index 70% rename from model/request/waf_white_url_del_req.go rename to model/request/waf_allow_url_del_req.go index 9edee19..2fd0a32 100644 --- a/model/request/waf_white_url_del_req.go +++ b/model/request/waf_allow_url_del_req.go @@ -1,5 +1,5 @@ package request -type WafWhiteUrlDelReq struct { +type WafAllowUrlDelReq struct { Id string `json:"id" form:"id"` //白名单url唯一键 } diff --git a/model/request/waf_white_url_detail_req.go b/model/request/waf_allow_url_detail_req.go similarity index 68% rename from model/request/waf_white_url_detail_req.go rename to model/request/waf_allow_url_detail_req.go index 3002ac9..90c3e71 100644 --- a/model/request/waf_white_url_detail_req.go +++ b/model/request/waf_allow_url_detail_req.go @@ -1,5 +1,5 @@ package request -type WafWhiteUrlDetailReq struct { +type WafAllowUrlDetailReq struct { Id string `json:"id" form:"id"` //白名单Url唯一键 } diff --git a/model/request/waf_white_url_edit_req.go b/model/request/waf_allow_url_edit_req.go similarity index 92% rename from model/request/waf_white_url_edit_req.go rename to model/request/waf_allow_url_edit_req.go index ce13642..27c31b6 100644 --- a/model/request/waf_white_url_edit_req.go +++ b/model/request/waf_allow_url_edit_req.go @@ -1,6 +1,6 @@ package request -type WafWhiteUrlEditReq struct { +type WafAllowUrlEditReq struct { Id string `json:"id"` //白名单url唯一键 HostCode string `json:"host_code"` //网站唯一码(主要键) CompareType string `json:"compare_type" form:"compare_type"` //对比方式 diff --git a/model/request/waf_white_url_search.go b/model/request/waf_allow_url_search.go similarity index 83% rename from model/request/waf_white_url_search.go rename to model/request/waf_allow_url_search.go index 25a2874..3c863b6 100644 --- a/model/request/waf_white_url_search.go +++ b/model/request/waf_allow_url_search.go @@ -2,7 +2,7 @@ package request import "SamWaf/model/common/request" -type WafWhiteUrlSearchReq struct { +type WafAllowUrlSearchReq struct { HostCode string `json:"host_code" ` //主机码 Url string `json:"url"` //白名单url request.PageInfo diff --git a/router/entrance.go b/router/entrance.go index d0103e3..1b6f915 100644 --- a/router/entrance.go +++ b/router/entrance.go @@ -6,8 +6,8 @@ type ApiGroup struct { RuleRouter EngineRouter StatRouter - WhiteIpRouter - WhiteUrlRouter + AllowIpRouter + AllowUrlRouter LdpUrlRouter AntiCCRouter BlockIpRouter diff --git a/router/waf_allow_ip.go b/router/waf_allow_ip.go new file mode 100644 index 0000000..b0795ad --- /dev/null +++ b/router/waf_allow_ip.go @@ -0,0 +1,19 @@ +package router + +import ( + "SamWaf/api" + "github.com/gin-gonic/gin" +) + +type AllowIpRouter struct { +} + +func (receiver *AllowIpRouter) InitAllowIpRouter(group *gin.RouterGroup) { + AllowIpRouterApi := api.APIGroupAPP.WafAllowIpApi + allowIpRouter := group.Group("") + allowIpRouter.POST("/samwaf/wafhost/ipwhite/list", AllowIpRouterApi.GetListApi) + allowIpRouter.GET("/samwaf/wafhost/ipwhite/detail", AllowIpRouterApi.GetDetailApi) + allowIpRouter.POST("/samwaf/wafhost/ipwhite/add", AllowIpRouterApi.AddApi) + allowIpRouter.GET("/samwaf/wafhost/ipwhite/del", AllowIpRouterApi.DelAllowIpApi) + allowIpRouter.POST("/samwaf/wafhost/ipwhite/edit", AllowIpRouterApi.ModifyAllowIpApi) +} diff --git a/router/waf_allow_url.go b/router/waf_allow_url.go new file mode 100644 index 0000000..73ebe40 --- /dev/null +++ b/router/waf_allow_url.go @@ -0,0 +1,19 @@ +package router + +import ( + "SamWaf/api" + "github.com/gin-gonic/gin" +) + +type AllowUrlRouter struct { +} + +func (receiver *AllowUrlRouter) InitAllowUrlRouter(group *gin.RouterGroup) { + AllowUrlRouterApi := api.APIGroupAPP.WafAllowUrlApi + allowUrlRouter := group.Group("") + allowUrlRouter.POST("/samwaf/wafhost/urlwhite/list", AllowUrlRouterApi.GetListApi) + allowUrlRouter.GET("/samwaf/wafhost/urlwhite/detail", AllowUrlRouterApi.GetDetailApi) + allowUrlRouter.POST("/samwaf/wafhost/urlwhite/add", AllowUrlRouterApi.AddApi) + allowUrlRouter.GET("/samwaf/wafhost/urlwhite/del", AllowUrlRouterApi.DelAllowUrlApi) + allowUrlRouter.POST("/samwaf/wafhost/urlwhite/edit", AllowUrlRouterApi.ModifyAllowUrlApi) +} diff --git a/router/waf_ldp_url.go b/router/waf_ldp_url.go index 87c8291..b9ec861 100644 --- a/router/waf_ldp_url.go +++ b/router/waf_ldp_url.go @@ -8,7 +8,7 @@ import ( type LdpUrlRouter struct { } -func (receiver *WhiteUrlRouter) InitLdpUrlRouter(group *gin.RouterGroup) { +func (receiver *LdpUrlRouter) InitLdpUrlRouter(group *gin.RouterGroup) { LdpUrlRouterApi := api.APIGroupAPP.WafLdpUrlApi ldpUrlRouter := group.Group("") ldpUrlRouter.POST("/samwaf/wafhost/ldpurl/list", LdpUrlRouterApi.GetListApi) diff --git a/router/waf_white_ip.go b/router/waf_white_ip.go deleted file mode 100644 index 4da2959..0000000 --- a/router/waf_white_ip.go +++ /dev/null @@ -1,19 +0,0 @@ -package router - -import ( - "SamWaf/api" - "github.com/gin-gonic/gin" -) - -type WhiteIpRouter struct { -} - -func (receiver *WhiteIpRouter) InitWhiteIpRouter(group *gin.RouterGroup) { - WhiteIpRouterApi := api.APIGroupAPP.WafWhiteIpApi - whiteIpRouter := group.Group("") - whiteIpRouter.POST("/samwaf/wafhost/ipwhite/list", WhiteIpRouterApi.GetListApi) - whiteIpRouter.GET("/samwaf/wafhost/ipwhite/detail", WhiteIpRouterApi.GetDetailApi) - whiteIpRouter.POST("/samwaf/wafhost/ipwhite/add", WhiteIpRouterApi.AddApi) - whiteIpRouter.GET("/samwaf/wafhost/ipwhite/del", WhiteIpRouterApi.DelWhiteIpApi) - whiteIpRouter.POST("/samwaf/wafhost/ipwhite/edit", WhiteIpRouterApi.ModifyWhiteIpApi) -} diff --git a/router/waf_white_url.go b/router/waf_white_url.go deleted file mode 100644 index 8c47894..0000000 --- a/router/waf_white_url.go +++ /dev/null @@ -1,19 +0,0 @@ -package router - -import ( - "SamWaf/api" - "github.com/gin-gonic/gin" -) - -type WhiteUrlRouter struct { -} - -func (receiver *WhiteUrlRouter) InitWhiteUrlRouter(group *gin.RouterGroup) { - WhiteUrlRouterApi := api.APIGroupAPP.WafWhiteUrlApi - whiteUrlRouter := group.Group("") - whiteUrlRouter.POST("/samwaf/wafhost/urlwhite/list", WhiteUrlRouterApi.GetListApi) - whiteUrlRouter.GET("/samwaf/wafhost/urlwhite/detail", WhiteUrlRouterApi.GetDetailApi) - whiteUrlRouter.POST("/samwaf/wafhost/urlwhite/add", WhiteUrlRouterApi.AddApi) - whiteUrlRouter.GET("/samwaf/wafhost/urlwhite/del", WhiteUrlRouterApi.DelWhiteUrlApi) - whiteUrlRouter.POST("/samwaf/wafhost/urlwhite/edit", WhiteUrlRouterApi.ModifyWhiteUrlApi) -} diff --git a/service/waf_service/waf_white_ip.go b/service/waf_service/waf_allow_ip.go similarity index 75% rename from service/waf_service/waf_white_ip.go rename to service/waf_service/waf_allow_ip.go index 34c3a21..34637c4 100644 --- a/service/waf_service/waf_white_ip.go +++ b/service/waf_service/waf_allow_ip.go @@ -15,8 +15,8 @@ type WafWhiteIpService struct{} var WafWhiteIpServiceApp = new(WafWhiteIpService) -func (receiver *WafWhiteIpService) AddApi(wafWhiteIpAddReq request.WafWhiteIpAddReq) error { - var wafHost = &model.IPWhiteList{ +func (receiver *WafWhiteIpService) AddApi(wafWhiteIpAddReq request.WafAllowIpAddReq) error { + var wafHost = &model.IPAllowList{ BaseOrm: baseorm.BaseOrm{ Id: uuid.NewV4().String(), USER_CODE: global.GWAF_USER_CODE, @@ -32,12 +32,12 @@ func (receiver *WafWhiteIpService) AddApi(wafWhiteIpAddReq request.WafWhiteIpAdd return nil } -func (receiver *WafWhiteIpService) CheckIsExistApi(wafWhiteIpAddReq request.WafWhiteIpAddReq) error { - return global.GWAF_LOCAL_DB.First(&model.IPWhiteList{}, "host_code = ? and ip= ?", wafWhiteIpAddReq.HostCode, +func (receiver *WafWhiteIpService) CheckIsExistApi(wafWhiteIpAddReq request.WafAllowIpAddReq) error { + return global.GWAF_LOCAL_DB.First(&model.IPAllowList{}, "host_code = ? and ip= ?", wafWhiteIpAddReq.HostCode, wafWhiteIpAddReq.Ip).Error } -func (receiver *WafWhiteIpService) ModifyApi(wafWhiteIpEditReq request.WafWhiteIpEditReq) error { - var ipWhite model.IPWhiteList +func (receiver *WafWhiteIpService) ModifyApi(wafWhiteIpEditReq request.WafAllowIpEditReq) error { + var ipWhite model.IPAllowList global.GWAF_LOCAL_DB.Where("host_code = ? and ip= ?", wafWhiteIpEditReq.HostCode, wafWhiteIpEditReq.Ip).Find(&ipWhite) if ipWhite.Id != "" && ipWhite.Ip != wafWhiteIpEditReq.Ip { @@ -49,22 +49,22 @@ func (receiver *WafWhiteIpService) ModifyApi(wafWhiteIpEditReq request.WafWhiteI "Remarks": wafWhiteIpEditReq.Remarks, "UPDATE_TIME": customtype.JsonTime(time.Now()), } - err := global.GWAF_LOCAL_DB.Model(model.IPWhiteList{}).Where("id = ?", wafWhiteIpEditReq.Id).Updates(ipWhiteMap).Error + err := global.GWAF_LOCAL_DB.Model(model.IPAllowList{}).Where("id = ?", wafWhiteIpEditReq.Id).Updates(ipWhiteMap).Error return err } -func (receiver *WafWhiteIpService) GetDetailApi(req request.WafWhiteIpDetailReq) model.IPWhiteList { - var ipWhite model.IPWhiteList +func (receiver *WafWhiteIpService) GetDetailApi(req request.WafAllowIpDetailReq) model.IPAllowList { + var ipWhite model.IPAllowList global.GWAF_LOCAL_DB.Where("id=?", req.Id).Find(&ipWhite) return ipWhite } -func (receiver *WafWhiteIpService) GetDetailByIdApi(id string) model.IPWhiteList { - var ipWhite model.IPWhiteList +func (receiver *WafWhiteIpService) GetDetailByIdApi(id string) model.IPAllowList { + var ipWhite model.IPAllowList global.GWAF_LOCAL_DB.Where("id=?", id).Find(&ipWhite) return ipWhite } -func (receiver *WafWhiteIpService) GetListApi(req request.WafWhiteIpSearchReq) ([]model.IPWhiteList, int64, error) { - var ipWhites []model.IPWhiteList +func (receiver *WafWhiteIpService) GetListApi(req request.WafAllowIpSearchReq) ([]model.IPAllowList, int64, error) { + var ipWhites []model.IPAllowList var total int64 = 0 /*where条件*/ var whereField = "" @@ -91,17 +91,17 @@ func (receiver *WafWhiteIpService) GetListApi(req request.WafWhiteIpSearchReq) ( whereValues = append(whereValues, req.Ip) } - global.GWAF_LOCAL_DB.Model(&model.IPWhiteList{}).Where(whereField, whereValues...).Limit(req.PageSize).Offset(req.PageSize * (req.PageIndex - 1)).Find(&ipWhites) - global.GWAF_LOCAL_DB.Model(&model.IPWhiteList{}).Where(whereField, whereValues...).Count(&total) + global.GWAF_LOCAL_DB.Model(&model.IPAllowList{}).Where(whereField, whereValues...).Limit(req.PageSize).Offset(req.PageSize * (req.PageIndex - 1)).Find(&ipWhites) + global.GWAF_LOCAL_DB.Model(&model.IPAllowList{}).Where(whereField, whereValues...).Count(&total) return ipWhites, total, nil } -func (receiver *WafWhiteIpService) DelApi(req request.WafWhiteIpDelReq) error { - var ipWhite model.IPWhiteList +func (receiver *WafWhiteIpService) DelApi(req request.WafAllowIpDelReq) error { + var ipWhite model.IPAllowList err := global.GWAF_LOCAL_DB.Where("id = ?", req.Id).First(&ipWhite).Error if err != nil { return err } - err = global.GWAF_LOCAL_DB.Where("id = ?", req.Id).Delete(model.IPWhiteList{}).Error + err = global.GWAF_LOCAL_DB.Where("id = ?", req.Id).Delete(model.IPAllowList{}).Error return err } diff --git a/service/waf_service/waf_white_url.go b/service/waf_service/waf_allow_url.go similarity index 73% rename from service/waf_service/waf_white_url.go rename to service/waf_service/waf_allow_url.go index dd57a8f..8e88c3f 100644 --- a/service/waf_service/waf_white_url.go +++ b/service/waf_service/waf_allow_url.go @@ -15,8 +15,8 @@ type WafWhiteUrlService struct{} var WafWhiteUrlServiceApp = new(WafWhiteUrlService) -func (receiver *WafWhiteUrlService) AddApi(req request.WafWhiteUrlAddReq) error { - var bean = &model.URLWhiteList{ +func (receiver *WafWhiteUrlService) AddApi(req request.WafAllowUrlAddReq) error { + var bean = &model.URLAllowList{ BaseOrm: baseorm.BaseOrm{ Id: uuid.NewV4().String(), USER_CODE: global.GWAF_USER_CODE, @@ -33,12 +33,12 @@ func (receiver *WafWhiteUrlService) AddApi(req request.WafWhiteUrlAddReq) error return nil } -func (receiver *WafWhiteUrlService) CheckIsExistApi(req request.WafWhiteUrlAddReq) error { - return global.GWAF_LOCAL_DB.First(&model.URLWhiteList{}, "host_code = ? and url= ?", req.HostCode, +func (receiver *WafWhiteUrlService) CheckIsExistApi(req request.WafAllowUrlAddReq) error { + return global.GWAF_LOCAL_DB.First(&model.URLAllowList{}, "host_code = ? and url= ?", req.HostCode, req.Url).Error } -func (receiver *WafWhiteUrlService) ModifyApi(req request.WafWhiteUrlEditReq) error { - var ipWhite model.URLWhiteList +func (receiver *WafWhiteUrlService) ModifyApi(req request.WafAllowUrlEditReq) error { + var ipWhite model.URLAllowList global.GWAF_LOCAL_DB.Where("host_code = ? and url= ?", req.HostCode, req.Url).Find(&ipWhite) if ipWhite.Id != "" && ipWhite.Url != req.Url { @@ -51,22 +51,22 @@ func (receiver *WafWhiteUrlService) ModifyApi(req request.WafWhiteUrlEditReq) er "Remarks": req.Remarks, "UPDATE_TIME": customtype.JsonTime(time.Now()), } - err := global.GWAF_LOCAL_DB.Model(model.URLWhiteList{}).Where("id = ?", req.Id).Updates(ipWhiteMap).Error + err := global.GWAF_LOCAL_DB.Model(model.URLAllowList{}).Where("id = ?", req.Id).Updates(ipWhiteMap).Error return err } -func (receiver *WafWhiteUrlService) GetDetailApi(req request.WafWhiteUrlDetailReq) model.URLWhiteList { - var bean model.URLWhiteList +func (receiver *WafWhiteUrlService) GetDetailApi(req request.WafAllowUrlDetailReq) model.URLAllowList { + var bean model.URLAllowList global.GWAF_LOCAL_DB.Where("id=?", req.Id).Find(&bean) return bean } -func (receiver *WafWhiteUrlService) GetDetailByIdApi(id string) model.URLWhiteList { - var bean model.URLWhiteList +func (receiver *WafWhiteUrlService) GetDetailByIdApi(id string) model.URLAllowList { + var bean model.URLAllowList global.GWAF_LOCAL_DB.Where("id=?", id).Find(&bean) return bean } -func (receiver *WafWhiteUrlService) GetListApi(req request.WafWhiteUrlSearchReq) ([]model.URLWhiteList, int64, error) { - var list []model.URLWhiteList +func (receiver *WafWhiteUrlService) GetListApi(req request.WafAllowUrlSearchReq) ([]model.URLAllowList, int64, error) { + var list []model.URLAllowList var total int64 = 0 /*where条件*/ var whereField = "" @@ -93,17 +93,17 @@ func (receiver *WafWhiteUrlService) GetListApi(req request.WafWhiteUrlSearchReq) whereValues = append(whereValues, req.Url) } - global.GWAF_LOCAL_DB.Model(&model.URLWhiteList{}).Where(whereField, whereValues...).Limit(req.PageSize).Offset(req.PageSize * (req.PageIndex - 1)).Find(&list) - global.GWAF_LOCAL_DB.Model(&model.URLWhiteList{}).Where(whereField, whereValues...).Count(&total) + global.GWAF_LOCAL_DB.Model(&model.URLAllowList{}).Where(whereField, whereValues...).Limit(req.PageSize).Offset(req.PageSize * (req.PageIndex - 1)).Find(&list) + global.GWAF_LOCAL_DB.Model(&model.URLAllowList{}).Where(whereField, whereValues...).Count(&total) return list, total, nil } -func (receiver *WafWhiteUrlService) DelApi(req request.WafWhiteUrlDelReq) error { - var ipWhite model.URLWhiteList +func (receiver *WafWhiteUrlService) DelApi(req request.WafAllowUrlDelReq) error { + var ipWhite model.URLAllowList err := global.GWAF_LOCAL_DB.Where("id = ?", req.Id).First(&ipWhite).Error if err != nil { return err } - err = global.GWAF_LOCAL_DB.Where("id = ?", req.Id).Delete(model.URLWhiteList{}).Error + err = global.GWAF_LOCAL_DB.Where("id = ?", req.Id).Delete(model.URLAllowList{}).Error return err } diff --git a/wafdb/localdb.go b/wafdb/localdb.go index 9be1538..23594ba 100644 --- a/wafdb/localdb.go +++ b/wafdb/localdb.go @@ -101,8 +101,8 @@ func InitCoreDb(currentDir string) { db.AutoMigrate(&model.LDPUrl{}) //白名单处理 - db.AutoMigrate(&model.IPWhiteList{}) - db.AutoMigrate(&model.URLWhiteList{}) + db.AutoMigrate(&model.IPAllowList{}) + db.AutoMigrate(&model.URLAllowList{}) //限制处理 db.AutoMigrate(&model.IPBlockList{}) diff --git a/wafmangeweb/localserver.go b/wafmangeweb/localserver.go index c32eceb..6bc79ea 100644 --- a/wafmangeweb/localserver.go +++ b/wafmangeweb/localserver.go @@ -34,8 +34,8 @@ func (web *WafWebManager) initRouter(r *gin.Engine) { router.ApiGroupApp.InitRuleRouter(RouterGroup) router.ApiGroupApp.InitEngineRouter(RouterGroup) router.ApiGroupApp.InitStatRouter(RouterGroup) - router.ApiGroupApp.InitWhiteIpRouter(RouterGroup) - router.ApiGroupApp.InitWhiteUrlRouter(RouterGroup) + router.ApiGroupApp.InitAllowIpRouter(RouterGroup) + router.ApiGroupApp.InitAllowUrlRouter(RouterGroup) router.ApiGroupApp.InitLdpUrlRouter(RouterGroup) router.ApiGroupApp.InitAntiCCRouter(RouterGroup) router.ApiGroupApp.InitBlockIpRouter(RouterGroup)