mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2025-12-06 06:58:54 +08:00
feat:change word
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -5,8 +5,8 @@ const (
|
||||
ChanTypeRule
|
||||
ChanTypeAnticc
|
||||
ChanTypeLdp
|
||||
ChanTypeWhiteIP
|
||||
ChanTypeWhiteURL
|
||||
ChanTypeAllowIP
|
||||
ChanTypeAllowURL
|
||||
ChanTypeBlockIP
|
||||
ChanTypeBlockURL
|
||||
ChanTypeDelHost
|
||||
|
||||
12
main.go
12
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:
|
||||
|
||||
@@ -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"` //判断类型,包含、开始、结束、完全匹配
|
||||
@@ -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"` //备注
|
||||
@@ -1,5 +1,5 @@
|
||||
package request
|
||||
|
||||
type WafWhiteIpDelReq struct {
|
||||
type WafAllowIpDelReq struct {
|
||||
Id string `json:"id" form:"id"` //白名单IP唯一键
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
package request
|
||||
|
||||
type WafWhiteIpDetailReq struct {
|
||||
type WafAllowIpDetailReq struct {
|
||||
Id string `json:"id" form:"id"` //白名单IP唯一键
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -1,5 +1,5 @@
|
||||
package request
|
||||
|
||||
type WafWhiteUrlDelReq struct {
|
||||
type WafAllowUrlDelReq struct {
|
||||
Id string `json:"id" form:"id"` //白名单url唯一键
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
package request
|
||||
|
||||
type WafWhiteUrlDetailReq struct {
|
||||
type WafAllowUrlDetailReq struct {
|
||||
Id string `json:"id" form:"id"` //白名单Url唯一键
|
||||
}
|
||||
@@ -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"` //对比方式
|
||||
@@ -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
|
||||
@@ -6,8 +6,8 @@ type ApiGroup struct {
|
||||
RuleRouter
|
||||
EngineRouter
|
||||
StatRouter
|
||||
WhiteIpRouter
|
||||
WhiteUrlRouter
|
||||
AllowIpRouter
|
||||
AllowUrlRouter
|
||||
LdpUrlRouter
|
||||
AntiCCRouter
|
||||
BlockIpRouter
|
||||
|
||||
19
router/waf_allow_ip.go
Normal file
19
router/waf_allow_ip.go
Normal file
@@ -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)
|
||||
}
|
||||
19
router/waf_allow_url.go
Normal file
19
router/waf_allow_url.go
Normal file
@@ -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)
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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{})
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user