Merge pull request #437 from samwafgo/feat_batchdelete_436

Feat batchdelete 436
This commit is contained in:
samwafgo
2025-08-22 11:15:49 +08:00
committed by GitHub
45 changed files with 812 additions and 177 deletions

View File

@@ -8,6 +8,7 @@ import (
"SamWaf/model/request"
"SamWaf/model/spec"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
@@ -115,3 +116,62 @@ func (w *WafAllowIpApi) NotifyWaf(host_code string) {
}
global.GWAF_CHAN_MSG <- chanInfo
}
// BatchDelAllowIpApi 批量删除IP白名单
func (w *WafAllowIpApi) BatchDelAllowIpApi(c *gin.Context) {
var req request.WafAllowIpBatchDelReq
err := c.ShouldBindJSON(&req)
if err == nil {
// 先获取要删除的记录对应的HostCode用于后续通知WAF引擎
hostCodes, err := wafIpAllowService.GetHostCodesByIds(req.Ids)
if err != nil {
response.FailWithMessage("获取网站信息失败", c)
return
}
// 执行批量删除
err = wafIpAllowService.BatchDelApi(req)
if err != nil {
response.FailWithMessage("批量删除失败: "+err.Error(), c)
} else {
// 通知所有相关的网站更新配置
for _, hostCode := range hostCodes {
w.NotifyWaf(hostCode)
}
response.OkWithMessage(fmt.Sprintf("成功删除 %d 条记录", len(req.Ids)), c)
}
} else {
response.FailWithMessage("解析失败", c)
}
}
// DelAllAllowIpApi 删除指定网站的所有IP白名单
func (w *WafAllowIpApi) DelAllAllowIpApi(c *gin.Context) {
var req request.WafAllowIpDelAllReq
err := c.ShouldBindJSON(&req)
if err == nil {
// 先获取要删除的记录对应的HostCode用于后续通知WAF引擎
hostCodes, err := wafIpAllowService.GetHostCodes()
if err != nil {
response.FailWithMessage("获取网站信息失败", c)
return
}
err = wafIpAllowService.DelAllApi(req)
if err != nil {
response.FailWithMessage("全量删除失败: "+err.Error(), c)
} else {
// 通知所有相关的网站更新配置
for _, hostCode := range hostCodes {
w.NotifyWaf(hostCode)
}
if len(req.HostCode) > 0 {
response.OkWithMessage("成功删除该网站的所有IP白名单", c)
} else {
response.OkWithMessage("成功删除所有IP白名单", c)
}
}
} else {
response.FailWithMessage("解析失败", c)
}
}

View File

@@ -8,6 +8,7 @@ import (
"SamWaf/model/request"
"SamWaf/model/spec"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
@@ -115,3 +116,62 @@ func (w *WafAllowUrlApi) NotifyWaf(host_code string) {
}
global.GWAF_CHAN_MSG <- chanInfo
}
// 新增批量删除API
func (w *WafAllowUrlApi) BatchDelAllowUrlApi(c *gin.Context) {
var req request.WafAllowUrlBatchDelReq
err := c.ShouldBindJSON(&req)
if err == nil {
// 先获取要删除的记录对应的HostCode用于后续通知WAF引擎
hostCodes, err := wafUrlAllowService.GetHostCodesByIds(req.Ids)
if err != nil {
response.FailWithMessage("获取网站信息失败", c)
return
}
// 执行批量删除
err = wafUrlAllowService.BatchDelApi(req)
if err != nil {
response.FailWithMessage("批量删除失败: "+err.Error(), c)
} else {
// 通知所有相关的网站更新配置
for _, hostCode := range hostCodes {
w.NotifyWaf(hostCode)
}
response.OkWithMessage(fmt.Sprintf("成功删除 %d 条记录", len(req.Ids)), c)
}
} else {
response.FailWithMessage("解析失败", c)
}
}
// 新增全部删除API
func (w *WafAllowUrlApi) DelAllAllowUrlApi(c *gin.Context) {
var req request.WafAllowUrlDelAllReq
err := c.ShouldBindJSON(&req)
if err == nil {
// 先获取要删除的记录对应的HostCode用于后续通知WAF引擎
hostCodes, err := wafUrlAllowService.GetHostCodes()
if err != nil {
response.FailWithMessage("获取网站信息失败", c)
return
}
err = wafUrlAllowService.DelAllApi(req)
if err != nil {
response.FailWithMessage("全部删除失败: "+err.Error(), c)
} else {
// 通知所有相关的网站更新配置
for _, hostCode := range hostCodes {
w.NotifyWaf(hostCode)
}
if len(req.HostCode) > 0 {
response.OkWithMessage("成功删除该网站的所有URL白名单", c)
} else {
response.OkWithMessage("成功删除所有URL白名单", c)
}
}
} else {
response.FailWithMessage("解析失败", c)
}
}

View File

@@ -8,6 +8,7 @@ import (
"SamWaf/model/request"
"SamWaf/model/spec"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
@@ -115,3 +116,62 @@ func (w *WafBlockUrlApi) NotifyWaf(host_code string) {
}
global.GWAF_CHAN_MSG <- chanInfo
}
// BatchDelBlockUrlApi 批量删除URL黑名单
func (w *WafBlockUrlApi) BatchDelBlockUrlApi(c *gin.Context) {
var req request.WafBlockUrlBatchDelReq
err := c.ShouldBindJSON(&req)
if err == nil {
// 先获取要删除的记录对应的HostCode用于后续通知WAF引擎
hostCodes, err := wafUrlBlockService.GetHostCodesByIds(req.Ids)
if err != nil {
response.FailWithMessage("获取网站信息失败", c)
return
}
// 执行批量删除
err = wafUrlBlockService.BatchDelApi(req)
if err != nil {
response.FailWithMessage("批量删除失败: "+err.Error(), c)
} else {
// 通知所有相关的网站更新配置
for _, hostCode := range hostCodes {
w.NotifyWaf(hostCode)
}
response.OkWithMessage(fmt.Sprintf("成功删除 %d 条记录", len(req.Ids)), c)
}
} else {
response.FailWithMessage("解析失败", c)
}
}
// DelAllBlockUrlApi 删除指定网站的所有URL黑名单
func (w *WafBlockUrlApi) DelAllBlockUrlApi(c *gin.Context) {
var req request.WafBlockUrlDelAllReq
err := c.ShouldBindJSON(&req)
if err == nil {
// 先获取要删除的记录对应的HostCode用于后续通知WAF引擎
hostCodes, err := wafUrlBlockService.GetHostCodes()
if err != nil {
response.FailWithMessage("获取网站信息失败", c)
return
}
err = wafUrlBlockService.DelAllApi(req)
if err != nil {
response.FailWithMessage("全部删除失败: "+err.Error(), c)
} else {
// 通知所有相关的网站更新配置
for _, hostCode := range hostCodes {
w.NotifyWaf(hostCode)
}
if len(req.HostCode) > 0 {
response.OkWithMessage("成功删除该网站的所有URL黑名单", c)
} else {
response.OkWithMessage("成功删除所有URL黑名单", c)
}
}
} else {
response.FailWithMessage("解析失败", c)
}
}

View File

@@ -8,6 +8,7 @@ import (
"SamWaf/model/request"
"SamWaf/model/spec"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
@@ -115,3 +116,62 @@ func (w *WafLdpUrlApi) NotifyWaf(host_code string) {
}
global.GWAF_CHAN_MSG <- chanInfo
}
// BatchDelLdpUrlApi 批量删除隐私保护URL
func (w *WafLdpUrlApi) BatchDelLdpUrlApi(c *gin.Context) {
var req request.WafLdpUrlBatchDelReq
err := c.ShouldBindJSON(&req)
if err == nil {
// 先获取要删除的记录对应的HostCode用于后续通知WAF引擎
hostCodes, err := wafLdpUrlService.GetHostCodesByIds(req.Ids)
if err != nil {
response.FailWithMessage("获取网站信息失败", c)
return
}
// 执行批量删除
err = wafLdpUrlService.BatchDelApi(req)
if err != nil {
response.FailWithMessage("批量删除失败: "+err.Error(), c)
} else {
// 通知所有相关的网站更新配置
for _, hostCode := range hostCodes {
w.NotifyWaf(hostCode)
}
response.OkWithMessage(fmt.Sprintf("成功删除 %d 条记录", len(req.Ids)), c)
}
} else {
response.FailWithMessage("解析失败", c)
}
}
// DelAllLdpUrlApi 删除指定网站的所有隐私保护URL
func (w *WafLdpUrlApi) DelAllLdpUrlApi(c *gin.Context) {
var req request.WafLdpUrlDelAllReq
err := c.ShouldBindJSON(&req)
if err == nil {
// 先获取要删除的记录对应的HostCode用于后续通知WAF引擎
hostCodes, err := wafLdpUrlService.GetHostCodes()
if err != nil {
response.FailWithMessage("获取网站信息失败", c)
return
}
err = wafLdpUrlService.DelAllApi(req)
if err != nil {
response.FailWithMessage("全部删除失败: "+err.Error(), c)
} else {
// 通知所有相关的网站更新配置
for _, hostCode := range hostCodes {
w.NotifyWaf(hostCode)
}
if len(req.HostCode) > 0 {
response.OkWithMessage("成功删除该网站的所有隐私保护URL", c)
} else {
response.OkWithMessage("成功删除所有隐私保护URL", c)
}
}
} else {
response.FailWithMessage("解析失败", c)
}
}

View File

@@ -217,3 +217,62 @@ func (w *WafRuleAPi) NotifyWaf(host_code string) {
}
global.GWAF_CHAN_MSG <- chanInfo
}
// BatchDelRuleApi 批量删除规则
func (w *WafRuleAPi) BatchDelRuleApi(c *gin.Context) {
var req request.WafRuleBatchDelReq
err := c.ShouldBindJSON(&req)
if err == nil {
// 先获取要删除的记录对应的HostCode用于后续通知WAF引擎
hostCodes, err := wafRuleService.GetHostCodesByCodes(req.Codes)
if err != nil {
response.FailWithMessage("获取网站信息失败", c)
return
}
// 执行批量删除
err = wafRuleService.BatchDelApi(req)
if err != nil {
response.FailWithMessage("批量删除失败: "+err.Error(), c)
} else {
// 通知所有相关的网站更新配置
for _, hostCode := range hostCodes {
w.NotifyWaf(hostCode)
}
response.OkWithMessage(fmt.Sprintf("成功删除 %d 条记录", len(req.Codes)), c)
}
} else {
response.FailWithMessage("解析失败", c)
}
}
// DelAllRuleApi 删除指定网站的所有规则
func (w *WafRuleAPi) DelAllRuleApi(c *gin.Context) {
var req request.WafRuleDelAllReq
err := c.ShouldBindJSON(&req)
if err == nil {
// 先获取要删除的记录对应的HostCode用于后续通知WAF引擎
hostCodes, err := wafRuleService.GetHostCodes()
if err != nil {
response.FailWithMessage("获取网站信息失败", c)
return
}
err = wafRuleService.DelAllApi(req)
if err != nil {
response.FailWithMessage("全部删除失败: "+err.Error(), c)
} else {
// 通知所有相关的网站更新配置
for _, hostCode := range hostCodes {
w.NotifyWaf(hostCode)
}
if len(req.HostCode) > 0 {
response.OkWithMessage("成功删除该网站的所有规则", c)
} else {
response.OkWithMessage("成功删除所有规则", c)
}
}
} else {
response.FailWithMessage("解析失败", c)
}
}

View File

@@ -1,7 +0,0 @@
package request
type WafAllowIpAddReq struct {
HostCode string `json:"host_code"` //网站唯一码(主要键)
Ip string `json:"ip"` //白名单ip
Remarks string `json:"remarks"` //备注
}

View File

@@ -1,5 +0,0 @@
package request
type WafAllowIpDelReq struct {
Id string `json:"id" form:"id"` //白名单IP唯一键
}

View File

@@ -1,5 +0,0 @@
package request
type WafAllowIpDetailReq struct {
Id string `json:"id" form:"id"` //白名单IP唯一键
}

View File

@@ -1,8 +0,0 @@
package request
type WafAllowIpEditReq struct {
Id string `json:"id"` //白名单IP唯一键
HostCode string `json:"host_code"` //网站唯一码(主要键)
Ip string `json:"ip"` //白名单ip
Remarks string `json:"remarks"` //备注
}

View File

@@ -0,0 +1,34 @@
package request
import "SamWaf/model/common/request"
type WafAllowIpAddReq struct {
HostCode string `json:"host_code"` //网站唯一码(主要键)
Ip string `json:"ip"` //白名单ip
Remarks string `json:"remarks"` //备注
}
type WafAllowIpDelReq struct {
Id string `json:"id" form:"id"` //白名单IP唯一键
}
type WafAllowIpDetailReq struct {
Id string `json:"id" form:"id"` //白名单IP唯一键
}
type WafAllowIpEditReq struct {
Id string `json:"id"` //白名单IP唯一键
HostCode string `json:"host_code"` //网站唯一码(主要键)
Ip string `json:"ip"` //白名单ip
Remarks string `json:"remarks"` //备注
}
type WafAllowIpSearchReq struct {
HostCode string `json:"host_code" ` //主机码
Ip string `json:"ip"` //白名单ip
request.PageInfo
}
type WafAllowIpBatchDelReq struct {
Ids []string `json:"ids" binding:"required"` //白名单IP唯一键数组
}
type WafAllowIpDelAllReq struct {
HostCode string `json:"host_code" form:"host_code"` //网站唯一码,为空则删除所有
}

View File

@@ -1,9 +0,0 @@
package request
import "SamWaf/model/common/request"
type WafAllowIpSearchReq struct {
HostCode string `json:"host_code" ` //主机码
Ip string `json:"ip"` //白名单ip
request.PageInfo
}

View File

@@ -1,8 +0,0 @@
package request
type WafAllowUrlAddReq struct {
HostCode string `json:"host_code"` //网站唯一码(主要键)
CompareType string `json:"compare_type" form:"compare_type"` //对比方式
Url string `json:"url"` //白名单url
Remarks string `json:"remarks"` //备注
}

View File

@@ -1,5 +0,0 @@
package request
type WafAllowUrlDelReq struct {
Id string `json:"id" form:"id"` //白名单url唯一键
}

View File

@@ -1,5 +0,0 @@
package request
type WafAllowUrlDetailReq struct {
Id string `json:"id" form:"id"` //白名单Url唯一键
}

View File

@@ -1,9 +0,0 @@
package request
type WafAllowUrlEditReq struct {
Id string `json:"id"` //白名单url唯一键
HostCode string `json:"host_code"` //网站唯一码(主要键)
CompareType string `json:"compare_type" form:"compare_type"` //对比方式
Url string `json:"url"` //白名单url
Remarks string `json:"remarks"` //备注
}

View File

@@ -0,0 +1,38 @@
package request
import "SamWaf/model/common/request"
type WafAllowUrlAddReq struct {
HostCode string `json:"host_code"` //网站唯一码(主要键)
CompareType string `json:"compare_type" form:"compare_type"` //对比方式
Url string `json:"url"` //白名单url
Remarks string `json:"remarks"` //备注
}
type WafAllowUrlDelReq struct {
Id string `json:"id" form:"id"` //白名单url唯一键
}
type WafAllowUrlDetailReq struct {
Id string `json:"id" form:"id"` //白名单Url唯一键
}
type WafAllowUrlEditReq struct {
Id string `json:"id"` //白名单url唯一键
HostCode string `json:"host_code"` //网站唯一码(主要键)
CompareType string `json:"compare_type" form:"compare_type"` //对比方式
Url string `json:"url"` //白名单url
Remarks string `json:"remarks"` //备注
}
type WafAllowUrlSearchReq struct {
HostCode string `json:"host_code" ` //主机码
Url string `json:"url"` //白名单url
request.PageInfo
}
type WafAllowUrlBatchDelReq struct {
Ids []string `json:"ids" form:"ids"` //白名单url唯一键数组
}
type WafAllowUrlDelAllReq struct {
HostCode string `json:"host_code" form:"host_code"` //网站唯一码
}

View File

@@ -1,9 +0,0 @@
package request
import "SamWaf/model/common/request"
type WafAllowUrlSearchReq struct {
HostCode string `json:"host_code" ` //主机码
Url string `json:"url"` //白名单url
request.PageInfo
}

View File

@@ -1,8 +0,0 @@
package request
type WafBlockUrlAddReq struct {
HostCode string `json:"host_code"` //网站唯一码(主要键)
CompareType string `json:"compare_type" form:"compare_type"` //对比方式
Url string `json:"url"` //Block url
Remarks string `json:"remarks"` //备注
}

View File

@@ -1,5 +0,0 @@
package request
type WafBlockUrlDelReq struct {
Id string `json:"id" form:"id"` //Block url唯一键
}

View File

@@ -1,5 +0,0 @@
package request
type WafBlockUrlDetailReq struct {
Id string `json:"id" form:"id"` //Block Url唯一键
}

View File

@@ -1,9 +0,0 @@
package request
type WafBlockUrlEditReq struct {
Id string `json:"id"` //Block url唯一键
HostCode string `json:"host_code"` //网站唯一码(主要键)
CompareType string `json:"compare_type" form:"compare_type"` //对比方式
Url string `json:"url"` //Block url
Remarks string `json:"remarks"` //备注
}

View File

@@ -0,0 +1,39 @@
package request
import "SamWaf/model/common/request"
type WafBlockUrlAddReq struct {
HostCode string `json:"host_code"` //网站唯一码(主要键)
CompareType string `json:"compare_type" form:"compare_type"` //对比方式
Url string `json:"url"` //Block url
Remarks string `json:"remarks"` //备注
}
type WafBlockUrlSearchReq struct {
HostCode string `json:"host_code" ` //主机码
Url string `json:"url"` //Block url
request.PageInfo
}
type WafBlockUrlDelReq struct {
Id string `json:"id" form:"id"` //Block url唯一键
}
type WafBlockUrlDetailReq struct {
Id string `json:"id" form:"id"` //Block Url唯一键
}
type WafBlockUrlEditReq struct {
Id string `json:"id"` //Block url唯一键
HostCode string `json:"host_code"` //网站唯一码(主要键)
CompareType string `json:"compare_type" form:"compare_type"` //对比方式
Url string `json:"url"` //Block url
Remarks string `json:"remarks"` //备注
}
// 批量删除请求结构体
type WafBlockUrlBatchDelReq struct {
Ids []string `json:"ids" binding:"required"` // 要删除的ID列表
}
// 全部删除请求结构体
type WafBlockUrlDelAllReq struct {
HostCode string `json:"host_code"` // 网站唯一码,为空则删除所有
}

View File

@@ -1,9 +0,0 @@
package request
import "SamWaf/model/common/request"
type WafBlockUrlSearchReq struct {
HostCode string `json:"host_code" ` //主机码
Url string `json:"url"` //Block url
request.PageInfo
}

View File

@@ -1,8 +0,0 @@
package request
type WafLdpUrlAddReq struct {
HostCode string `json:"host_code"` //网站唯一码(主要键)
CompareType string `json:"compare_type"` //对比方式
Url string `json:"url"` //加隐私保护的url
Remarks string `json:"remarks"` //备注
}

View File

@@ -1,5 +0,0 @@
package request
type WafLdpUrlDelReq struct {
Id string `json:"id" form:"id"` //隐私保护url唯一键
}

View File

@@ -1,5 +0,0 @@
package request
type WafLdpUrlDetailReq struct {
Id string `json:"id" form:"id"` //隐私保护Url唯一键
}

View File

@@ -1,9 +0,0 @@
package request
type WafLdpUrlEditReq struct {
Id string `json:"id"` //隐私保护url唯一键
HostCode string `json:"host_code"` //网站唯一码(主要键)
CompareType string `json:"compare_type"` //对比方式
Url string `json:"url"` //隐私保护url
Remarks string `json:"remarks"` //备注
}

View File

@@ -0,0 +1,35 @@
package request
import "SamWaf/model/common/request"
type WafLdpUrlAddReq struct {
HostCode string `json:"host_code"` //网站唯一码(主要键)
CompareType string `json:"compare_type"` //对比方式
Url string `json:"url"` //加隐私保护的url
Remarks string `json:"remarks"` //备注
}
type WafLdpUrlDelReq struct {
Id string `json:"id" form:"id"` //隐私保护url唯一键
}
type WafLdpUrlDetailReq struct {
Id string `json:"id" form:"id"` //隐私保护Url唯一键
}
type WafLdpUrlEditReq struct {
Id string `json:"id"` //隐私保护url唯一键
HostCode string `json:"host_code"` //网站唯一码(主要键)
CompareType string `json:"compare_type"` //对比方式
Url string `json:"url"` //隐私保护url
Remarks string `json:"remarks"` //备注
}
type WafLdpUrlSearchReq struct {
HostCode string `json:"host_code" ` //主机码
Url string `json:"url"` //隐私保护url
request.PageInfo
}
type WafLdpUrlBatchDelReq struct {
Ids []string `json:"ids" binding:"required"` //隐私保护URL唯一键数组
}
type WafLdpUrlDelAllReq struct {
HostCode string `json:"host_code" form:"host_code"` //网站唯一码,为空则删除所有
}

View File

@@ -1,9 +0,0 @@
package request
import "SamWaf/model/common/request"
type WafLdpUrlSearchReq struct {
HostCode string `json:"host_code" ` //主机码
Url string `json:"url"` //隐私保护url
request.PageInfo
}

View File

@@ -1,8 +0,0 @@
package request
type WafRuleAddReq struct {
RuleCode string `json:"rule_code"` //规则编号v4
RuleJson string
IsManualRule int `json:"is_manual_rule"`
RuleContent string `json:"rule_content"` //规则内容
}

View File

@@ -1,5 +0,0 @@
package request
type WafRuleDelReq struct {
CODE string `json:"code"`
}

View File

@@ -1,5 +0,0 @@
package request
type WafRuleDetailReq struct {
CODE string `json:"code"`
}

View File

@@ -1,8 +0,0 @@
package request
type WafRuleEditReq struct {
CODE string `json:"code"`
RuleJson string `json:"rulejson"`
IsManualRule int `json:"is_manual_rule"`
RuleContent string `json:"rule_content"` //规则内容
}

View File

@@ -0,0 +1,34 @@
package request
import "SamWaf/model/common/request"
type WafRuleAddReq struct {
RuleCode string `json:"rule_code"` //规则编号v4
RuleJson string
IsManualRule int `json:"is_manual_rule"`
RuleContent string `json:"rule_content"` //规则内容
}
type WafRuleDelReq struct {
CODE string `json:"code"`
}
type WafRuleDetailReq struct {
CODE string `json:"code"`
}
type WafRuleEditReq struct {
CODE string `json:"code"`
RuleJson string `json:"rulejson"`
IsManualRule int `json:"is_manual_rule"`
RuleContent string `json:"rule_content"` //规则内容
}
type WafRuleSearchReq struct {
HostCode string `json:"host_code" form:"host_code"` //主机码
RuleName string `json:"rule_name" form:"rule_name"` //规则名
request.PageInfo
}
type WafRuleBatchDelReq struct {
Codes []string `json:"codes" binding:"required"` //规则编码数组
}
type WafRuleDelAllReq struct {
HostCode string `json:"host_code" form:"host_code"` //网站唯一码,为空则删除所有
}

View File

@@ -1,9 +0,0 @@
package request
import "SamWaf/model/common/request"
type WafRuleSearchReq struct {
HostCode string `json:"host_code" form:"host_code"` //主机码
RuleName string `json:"rule_name" form:"rule_name"` //规则名
request.PageInfo
}

View File

@@ -16,4 +16,7 @@ func (receiver *AllowIpRouter) InitAllowIpRouter(group *gin.RouterGroup) {
allowIpRouter.POST("/samwaf/wafhost/ipwhite/add", AllowIpRouterApi.AddApi)
allowIpRouter.GET("/samwaf/wafhost/ipwhite/del", AllowIpRouterApi.DelAllowIpApi)
allowIpRouter.POST("/samwaf/wafhost/ipwhite/edit", AllowIpRouterApi.ModifyAllowIpApi)
allowIpRouter.POST("/samwaf/wafhost/ipwhite/batchdel", AllowIpRouterApi.BatchDelAllowIpApi)
allowIpRouter.POST("/samwaf/wafhost/ipwhite/delall", AllowIpRouterApi.DelAllAllowIpApi)
}

View File

@@ -16,4 +16,8 @@ func (receiver *AllowUrlRouter) InitAllowUrlRouter(group *gin.RouterGroup) {
allowUrlRouter.POST("/samwaf/wafhost/urlwhite/add", AllowUrlRouterApi.AddApi)
allowUrlRouter.GET("/samwaf/wafhost/urlwhite/del", AllowUrlRouterApi.DelAllowUrlApi)
allowUrlRouter.POST("/samwaf/wafhost/urlwhite/edit", AllowUrlRouterApi.ModifyAllowUrlApi)
// 新增批量删除路由
allowUrlRouter.POST("/samwaf/wafhost/urlwhite/batchdel", AllowUrlRouterApi.BatchDelAllowUrlApi)
// 新增全部删除路由
allowUrlRouter.POST("/samwaf/wafhost/urlwhite/delall", AllowUrlRouterApi.DelAllAllowUrlApi)
}

View File

@@ -16,4 +16,6 @@ func (receiver *BlockUrlRouter) InitBlockUrlRouter(group *gin.RouterGroup) {
router.POST("/samwaf/wafhost/urlblock/add", api.AddApi)
router.GET("/samwaf/wafhost/urlblock/del", api.DelBlockUrlApi)
router.POST("/samwaf/wafhost/urlblock/edit", api.ModifyBlockUrlApi)
router.POST("/samwaf/wafhost/urlblock/batchdel", api.BatchDelBlockUrlApi)
router.POST("/samwaf/wafhost/urlblock/delall", api.DelAllBlockUrlApi)
}

View File

@@ -16,4 +16,6 @@ func (receiver *LdpUrlRouter) InitLdpUrlRouter(group *gin.RouterGroup) {
ldpUrlRouter.POST("/samwaf/wafhost/ldpurl/add", LdpUrlRouterApi.AddApi)
ldpUrlRouter.GET("/samwaf/wafhost/ldpurl/del", LdpUrlRouterApi.DelLdpUrlApi)
ldpUrlRouter.POST("/samwaf/wafhost/ldpurl/edit", LdpUrlRouterApi.ModifyLdpUrlApi)
ldpUrlRouter.POST("/samwaf/wafhost/ldpurl/batchdel", LdpUrlRouterApi.BatchDelLdpUrlApi)
ldpUrlRouter.POST("/samwaf/wafhost/ldpurl/delall", LdpUrlRouterApi.DelAllLdpUrlApi)
}

View File

@@ -16,4 +16,6 @@ func (receiver *RuleRouter) InitRuleRouter(group *gin.RouterGroup) {
wafRuleRouter.POST("/samwaf/wafhost/rule/add", ruleApi.AddApi)
wafRuleRouter.GET("/samwaf/wafhost/rule/del", ruleApi.DelRuleApi)
wafRuleRouter.POST("/samwaf/wafhost/rule/edit", ruleApi.ModifyRuleApi)
wafRuleRouter.POST("/samwaf/wafhost/rule/batchdel", ruleApi.BatchDelRuleApi)
wafRuleRouter.POST("/samwaf/wafhost/rule/delall", ruleApi.DelAllRuleApi)
}

View File

@@ -110,3 +110,68 @@ func (receiver *WafWhiteIpService) DelApi(req request.WafAllowIpDelReq) error {
err = global.GWAF_LOCAL_DB.Where("id = ?", req.Id).Delete(model.IPAllowList{}).Error
return err
}
// BatchDelApi 批量删除指定ID的IP白名单
func (receiver *WafWhiteIpService) BatchDelApi(req request.WafAllowIpBatchDelReq) error {
if len(req.Ids) == 0 {
return errors.New("删除ID列表不能为空")
}
// 先检查所有ID是否存在
var count int64
err := global.GWAF_LOCAL_DB.Model(&model.IPAllowList{}).Where("id IN ?", req.Ids).Count(&count).Error
if err != nil {
return err
}
if count != int64(len(req.Ids)) {
return errors.New("部分ID不存在")
}
// 执行批量删除
err = global.GWAF_LOCAL_DB.Where("id IN ?", req.Ids).Delete(&model.IPAllowList{}).Error
return err
}
// DelAllApi 删除指定网站的所有IP白名单
func (receiver *WafWhiteIpService) DelAllApi(req request.WafAllowIpDelAllReq) error {
var whereCondition string
var whereValues []interface{}
if len(req.HostCode) > 0 {
whereCondition = "host_code = ? AND user_code = ? AND tenant_id = ?"
whereValues = append(whereValues, req.HostCode, global.GWAF_USER_CODE, global.GWAF_TENANT_ID)
} else {
whereCondition = "user_code = ? AND tenant_id = ?"
whereValues = append(whereValues, global.GWAF_USER_CODE, global.GWAF_TENANT_ID)
}
// 先检查是否存在记录
var count int64
err := global.GWAF_LOCAL_DB.Model(&model.IPAllowList{}).Where(whereCondition, whereValues...).Count(&count).Error
if err != nil {
return err
}
if count == 0 {
return errors.New("没有IP白名单记录")
}
// 执行删除
err = global.GWAF_LOCAL_DB.Where(whereCondition, whereValues...).Delete(&model.IPAllowList{}).Error
return err
}
// GetHostCodesByIds 根据ID数组获取对应的HostCode列表
func (receiver *WafWhiteIpService) GetHostCodesByIds(ids []string) ([]string, error) {
var hostCodes []string
err := global.GWAF_LOCAL_DB.Model(&model.IPAllowList{}).Where("id IN ?", ids).Distinct("host_code").Pluck("host_code", &hostCodes).Error
return hostCodes, err
}
// GetHostCodes 获取所有HostCode列表
func (receiver *WafWhiteIpService) GetHostCodes() ([]string, error) {
var hostCodes []string
err := global.GWAF_LOCAL_DB.Model(&model.IPAllowList{}).Where("user_code = ? AND tenant_id = ?", global.GWAF_USER_CODE, global.GWAF_TENANT_ID).Distinct("host_code").Pluck("host_code", &hostCodes).Error
return hostCodes, err
}

View File

@@ -107,3 +107,53 @@ func (receiver *WafWhiteUrlService) DelApi(req request.WafAllowUrlDelReq) error
err = global.GWAF_LOCAL_DB.Where("id = ?", req.Id).Delete(model.URLAllowList{}).Error
return err
}
// 批量删除方法
func (receiver *WafWhiteUrlService) BatchDelApi(req request.WafAllowUrlBatchDelReq) error {
// 添加用户和租户验证
err := global.GWAF_LOCAL_DB.Where("id IN ? AND user_code = ? AND tenant_id = ?", req.Ids, global.GWAF_USER_CODE, global.GWAF_TENANT_ID).Delete(&model.URLAllowList{}).Error
return err
}
// 全部删除方法
func (receiver *WafWhiteUrlService) DelAllApi(req request.WafAllowUrlDelAllReq) error {
var whereCondition string
var whereValues []interface{}
if len(req.HostCode) > 0 {
whereCondition = "host_code = ? AND user_code = ? AND tenant_id = ?"
whereValues = append(whereValues, req.HostCode, global.GWAF_USER_CODE, global.GWAF_TENANT_ID)
} else {
whereCondition = "user_code = ? AND tenant_id = ?"
whereValues = append(whereValues, global.GWAF_USER_CODE, global.GWAF_TENANT_ID)
}
// 先检查是否存在记录
var count int64
err := global.GWAF_LOCAL_DB.Model(&model.URLAllowList{}).Where(whereCondition, whereValues...).Count(&count).Error
if err != nil {
return err
}
if count == 0 {
return errors.New("没有URL白名单记录")
}
// 执行删除
err = global.GWAF_LOCAL_DB.Where(whereCondition, whereValues...).Delete(&model.URLAllowList{}).Error
return err
}
// GetHostCodesByIds 根据ID数组获取对应的HostCode列表
func (receiver *WafWhiteUrlService) GetHostCodesByIds(ids []string) ([]string, error) {
var hostCodes []string
err := global.GWAF_LOCAL_DB.Model(&model.URLAllowList{}).Where("id IN ?", ids).Distinct("host_code").Pluck("host_code", &hostCodes).Error
return hostCodes, err
}
// GetHostCodes 获取所有HostCode列表
func (receiver *WafWhiteUrlService) GetHostCodes() ([]string, error) {
var hostCodes []string
err := global.GWAF_LOCAL_DB.Model(&model.URLAllowList{}).Where("user_code = ? AND tenant_id = ?", global.GWAF_USER_CODE, global.GWAF_TENANT_ID).Distinct("host_code").Pluck("host_code", &hostCodes).Error
return hostCodes, err
}

View File

@@ -107,3 +107,68 @@ func (receiver *WafBlockUrlService) DelApi(req request.WafBlockUrlDelReq) error
err = global.GWAF_LOCAL_DB.Where("id = ?", req.Id).Delete(model.URLBlockList{}).Error
return err
}
// BatchDelApi 批量删除指定ID的URL黑名单
func (receiver *WafBlockUrlService) BatchDelApi(req request.WafBlockUrlBatchDelReq) error {
if len(req.Ids) == 0 {
return errors.New("删除ID列表不能为空")
}
// 先检查所有ID是否存在
var count int64
err := global.GWAF_LOCAL_DB.Model(&model.URLBlockList{}).Where("id IN ? AND user_code = ? AND tenant_id = ?", req.Ids, global.GWAF_USER_CODE, global.GWAF_TENANT_ID).Count(&count).Error
if err != nil {
return err
}
if count != int64(len(req.Ids)) {
return errors.New("部分ID不存在")
}
// 执行批量删除
err = global.GWAF_LOCAL_DB.Where("id IN ? AND user_code = ? AND tenant_id = ?", req.Ids, global.GWAF_USER_CODE, global.GWAF_TENANT_ID).Delete(&model.URLBlockList{}).Error
return err
}
// DelAllApi 删除指定网站的所有URL黑名单
func (receiver *WafBlockUrlService) DelAllApi(req request.WafBlockUrlDelAllReq) error {
var whereCondition string
var whereValues []interface{}
if len(req.HostCode) > 0 {
whereCondition = "host_code = ? AND user_code = ? AND tenant_id = ?"
whereValues = append(whereValues, req.HostCode, global.GWAF_USER_CODE, global.GWAF_TENANT_ID)
} else {
whereCondition = "user_code = ? AND tenant_id = ?"
whereValues = append(whereValues, global.GWAF_USER_CODE, global.GWAF_TENANT_ID)
}
// 先检查是否存在记录
var count int64
err := global.GWAF_LOCAL_DB.Model(&model.URLBlockList{}).Where(whereCondition, whereValues...).Count(&count).Error
if err != nil {
return err
}
if count == 0 {
return errors.New("没有URL黑名单记录")
}
// 执行删除
err = global.GWAF_LOCAL_DB.Where(whereCondition, whereValues...).Delete(&model.URLBlockList{}).Error
return err
}
// GetHostCodesByIds 根据ID数组获取对应的HostCode列表
func (receiver *WafBlockUrlService) GetHostCodesByIds(ids []string) ([]string, error) {
var hostCodes []string
err := global.GWAF_LOCAL_DB.Model(&model.URLBlockList{}).Where("id IN ?", ids).Distinct("host_code").Pluck("host_code", &hostCodes).Error
return hostCodes, err
}
// GetHostCodes 获取所有HostCode列表
func (receiver *WafBlockUrlService) GetHostCodes() ([]string, error) {
var hostCodes []string
err := global.GWAF_LOCAL_DB.Model(&model.URLBlockList{}).Where("user_code = ? AND tenant_id = ?", global.GWAF_USER_CODE, global.GWAF_TENANT_ID).Distinct("host_code").Pluck("host_code", &hostCodes).Error
return hostCodes, err
}

View File

@@ -108,3 +108,68 @@ func (receiver *WafLdpUrlService) DelApi(req request.WafLdpUrlDelReq) error {
err = global.GWAF_LOCAL_DB.Where("id = ?", req.Id).Delete(model.LDPUrl{}).Error
return err
}
// BatchDelApi 批量删除指定ID的隐私保护URL
func (receiver *WafLdpUrlService) BatchDelApi(req request.WafLdpUrlBatchDelReq) error {
if len(req.Ids) == 0 {
return errors.New("删除ID列表不能为空")
}
// 先检查所有ID是否存在
var count int64
err := global.GWAF_LOCAL_DB.Model(&model.LDPUrl{}).Where("id IN ? AND user_code = ? AND tenant_id = ?", req.Ids, global.GWAF_USER_CODE, global.GWAF_TENANT_ID).Count(&count).Error
if err != nil {
return err
}
if count != int64(len(req.Ids)) {
return errors.New("部分ID不存在")
}
// 执行批量删除
err = global.GWAF_LOCAL_DB.Where("id IN ? AND user_code = ? AND tenant_id = ?", req.Ids, global.GWAF_USER_CODE, global.GWAF_TENANT_ID).Delete(&model.LDPUrl{}).Error
return err
}
// DelAllApi 删除指定网站的所有隐私保护URL
func (receiver *WafLdpUrlService) DelAllApi(req request.WafLdpUrlDelAllReq) error {
var whereCondition string
var whereValues []interface{}
if len(req.HostCode) > 0 {
whereCondition = "host_code = ? AND user_code = ? AND tenant_id = ?"
whereValues = append(whereValues, req.HostCode, global.GWAF_USER_CODE, global.GWAF_TENANT_ID)
} else {
whereCondition = "user_code = ? AND tenant_id = ?"
whereValues = append(whereValues, global.GWAF_USER_CODE, global.GWAF_TENANT_ID)
}
// 先检查是否存在记录
var count int64
err := global.GWAF_LOCAL_DB.Model(&model.LDPUrl{}).Where(whereCondition, whereValues...).Count(&count).Error
if err != nil {
return err
}
if count == 0 {
return errors.New("没有隐私保护URL记录")
}
// 执行删除
err = global.GWAF_LOCAL_DB.Where(whereCondition, whereValues...).Delete(&model.LDPUrl{}).Error
return err
}
// GetHostCodesByIds 根据ID列表获取HostCode列表
func (receiver *WafLdpUrlService) GetHostCodesByIds(ids []string) ([]string, error) {
var hostCodes []string
err := global.GWAF_LOCAL_DB.Model(&model.LDPUrl{}).Where("id IN ?", ids).Pluck("host_code", &hostCodes).Error
return hostCodes, err
}
// GetHostCodes 获取所有HostCode列表
func (receiver *WafLdpUrlService) GetHostCodes() ([]string, error) {
var hostCodes []string
err := global.GWAF_LOCAL_DB.Model(&model.LDPUrl{}).Pluck("host_code", &hostCodes).Error
return hostCodes, err
}

View File

@@ -159,3 +159,78 @@ func (receiver *WafRuleService) DelRuleApi(req request.WafRuleDelReq) error {
}
return nil
}
// BatchDelApi 批量删除指定编码的规则
func (receiver *WafRuleService) BatchDelApi(req request.WafRuleBatchDelReq) error {
if len(req.Codes) == 0 {
return errors.New("删除编码列表不能为空")
}
// 先检查所有编码是否存在
var count int64
err := global.GWAF_LOCAL_DB.Model(&model.Rules{}).Where("rule_code IN ? AND user_code = ? AND tenant_id = ? AND rule_status <> 999", req.Codes, global.GWAF_USER_CODE, global.GWAF_TENANT_ID).Count(&count).Error
if err != nil {
return err
}
if count != int64(len(req.Codes)) {
return errors.New("部分规则编码不存在")
}
// 执行批量删除(软删除)
ruleMap := map[string]interface{}{
"RuleStatus": "999",
"RuleVersion": 999999,
"UPDATE_TIME": customtype.JsonTime(time.Now()),
}
err = global.GWAF_LOCAL_DB.Model(&model.Rules{}).Where("rule_code IN ? AND user_code = ? AND tenant_id = ?", req.Codes, global.GWAF_USER_CODE, global.GWAF_TENANT_ID).Updates(ruleMap).Error
return err
}
// DelAllApi 删除指定网站的所有规则
func (receiver *WafRuleService) DelAllApi(req request.WafRuleDelAllReq) error {
var whereCondition string
var whereValues []interface{}
if len(req.HostCode) > 0 {
whereCondition = "host_code = ? AND user_code = ? AND tenant_id = ? AND rule_status <> 999"
whereValues = append(whereValues, req.HostCode, global.GWAF_USER_CODE, global.GWAF_TENANT_ID)
} else {
whereCondition = "user_code = ? AND tenant_id = ? AND rule_status <> 999"
whereValues = append(whereValues, global.GWAF_USER_CODE, global.GWAF_TENANT_ID)
}
// 先检查是否存在记录
var count int64
err := global.GWAF_LOCAL_DB.Model(&model.Rules{}).Where(whereCondition, whereValues...).Count(&count).Error
if err != nil {
return err
}
if count == 0 {
return errors.New("没有规则记录")
}
// 执行删除(软删除)
ruleMap := map[string]interface{}{
"RuleStatus": "999",
"RuleVersion": 999999,
"UPDATE_TIME": customtype.JsonTime(time.Now()),
}
err = global.GWAF_LOCAL_DB.Model(&model.Rules{}).Where(whereCondition, whereValues...).Updates(ruleMap).Error
return err
}
// GetHostCodesByCodes 根据规则编码列表获取HostCode列表
func (receiver *WafRuleService) GetHostCodesByCodes(codes []string) ([]string, error) {
var hostCodes []string
err := global.GWAF_LOCAL_DB.Model(&model.Rules{}).Where("rule_code IN ? AND rule_status <> 999", codes).Pluck("host_code", &hostCodes).Error
return hostCodes, err
}
// GetHostCodes 获取所有HostCode列表
func (receiver *WafRuleService) GetHostCodes() ([]string, error) {
var hostCodes []string
err := global.GWAF_LOCAL_DB.Model(&model.Rules{}).Where("rule_status <> 999").Pluck("host_code", &hostCodes).Error
return hostCodes, err
}