增加删除黑名单IP接口

pull/30/head
taoshihan1991 4 years ago
parent dd7ad61a5d
commit 0024d0ff4a

@ -23,6 +23,21 @@ func PostIpblack(c *gin.Context) {
"msg": "添加黑名单成功!",
})
}
func DelIpblack(c *gin.Context) {
ip := c.Query("ip")
if ip==""{
c.JSON(200, gin.H{
"code": 400,
"msg": "请输入IP!",
})
return
}
models.DeleteIpblackById(ip)
c.JSON(200, gin.H{
"code": 200,
"msg": "删除黑名单成功!",
})
}
func GetIpblacks(c *gin.Context) {
page,_:=strconv.Atoi(c.Query("page"))
count:=models.CountIps(nil,nil)

@ -10,6 +10,7 @@ func RbacAuth(c *gin.Context){
roleId, _ :=c.Get("role_id")
role:=models.FindRole(roleId)
var methodFlag bool
rPaths:=strings.Split(c.Request.RequestURI,"?")
if role.Method!="*"{
methods:=strings.Split(role.Method,",")
for _,m:=range methods{
@ -21,7 +22,7 @@ func RbacAuth(c *gin.Context){
if !methodFlag{
c.JSON(200, gin.H{
"code": 403,
"msg": "没有权限:"+c.Request.Method+","+c.Request.RequestURI,
"msg": "没有权限:"+c.Request.Method+","+rPaths[0],
})
c.Abort()
return
@ -31,7 +32,7 @@ func RbacAuth(c *gin.Context){
if role.Path!="*"{
paths:=strings.Split(role.Path,",")
for _,p:=range paths{
if c.Request.RequestURI==p{
if rPaths[0]==p{
flag=true
break
}
@ -39,7 +40,7 @@ func RbacAuth(c *gin.Context){
if !flag{
c.JSON(200, gin.H{
"code": 403,
"msg": "没有权限:"+c.Request.Method+","+c.Request.RequestURI,
"msg": "没有权限:"+rPaths[0],
})
c.Abort()
return

@ -17,6 +17,9 @@ func CreateIpblack(ip string,kefuId string)uint{
DB.Create(black)
return black.ID
}
func DeleteIpblackById(id string){
DB.Where("id = ?",id).Delete(Ipblack{})
}
func FindIp(ip string)Ipblack{
var ipblack Ipblack
DB.Where("ip = ?", ip).First(&ipblack)

@ -50,5 +50,6 @@ func InitApiRouter(engine *gin.Engine){
engine.DELETE("/notice",middleware.JwtApiMiddleware, controller.DelNotice)
engine.GET("/notices",middleware.JwtApiMiddleware, controller.GetNotices)
engine.POST("/ipblack",middleware.JwtApiMiddleware,controller.PostIpblack)
engine.POST("/ipblacks_all",middleware.JwtApiMiddleware,controller.GetIpblacks)
engine.DELETE("/ipblack",middleware.JwtApiMiddleware,controller.DelIpblack)
engine.GET("/ipblacks_all",middleware.JwtApiMiddleware,controller.GetIpblacks)
}
Loading…
Cancel
Save