package controller import ( "fmt" "github.com/gin-gonic/gin" "kefu/models" "strconv" ) func PostIpblack(c *gin.Context) { entId, _ := c.Get("ent_id") ip := c.PostForm("ip") name := c.PostForm("name") if ip == "" { c.JSON(200, gin.H{ "code": 400, "msg": "请输入IP!", }) return } if ip == c.ClientIP() { c.JSON(200, gin.H{ "code": 400, "msg": "不能拉黑自己的IP!", }) return } kefuId, _ := c.Get("kefu_name") models.CreateIpblack(ip, kefuId.(string), name, entId.(string)) logContent := fmt.Sprintf("'%s'添加IP黑名单'%s'", kefuId, ip) go models.CreateFlyLog(entId.(string), c.ClientIP(), logContent, "ipblack") c.JSON(200, gin.H{ "code": 200, "msg": "添加IP黑名单成功!", }) } func PostSystemIpblack(c *gin.Context) { entId := "" ip := c.PostForm("ip") name := c.PostForm("name") if ip == "" { c.JSON(200, gin.H{ "code": 400, "msg": "请输入IP!", }) return } kefuId, _ := c.Get("kefu_name") models.CreateIpblack(ip, kefuId.(string), name, entId) logContent := fmt.Sprintf("'%s'添加IP黑名单'%s'", kefuId, ip) go models.CreateFlyLog(entId, c.ClientIP(), logContent, "ipblack") c.JSON(200, gin.H{ "code": 200, "msg": "添加IP黑名单成功!", }) } func DelIpblack(c *gin.Context) { ip := c.Query("ip") if ip == "" { c.JSON(200, gin.H{ "code": 400, "msg": "请输入IP!", }) return } models.DeleteIpblackByIp(ip) c.JSON(200, gin.H{ "code": 200, "msg": "删除黑名单成功!", }) } func GetIpblacks(c *gin.Context) { //分页处理 page, _ := strconv.Atoi(c.Query("page")) if page <= 0 { page = 1 } pagesize, _ := strconv.Atoi(c.Query("pagesize")) if pagesize <= 0 { pagesize = 10 } count := models.CountIps(nil, nil) list := models.FindIps(nil, nil, uint(page), uint(pagesize)) c.JSON(200, gin.H{ "code": 200, "msg": "ok", "result": gin.H{ "list": list, "count": count, "pagesize": pagesize, "page": page, }, }) } func GetIpblacksByKefuId(c *gin.Context) { kefuId, _ := c.Get("kefu_name") list := models.FindIpsByKefuId(kefuId.(string)) c.JSON(200, gin.H{ "code": 200, "msg": "ok", "result": list, }) }