diff --git a/config/go-fly.sql b/config/go-fly.sql index c850e8d..d5a97b6 100644 --- a/config/go-fly.sql +++ b/config/go-fly.sql @@ -93,5 +93,6 @@ CREATE TABLE `ipblack` ( `ip` varchar(100) NOT NULL DEFAULT '', `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `kefu_id` varchar(100) NOT NULL DEFAULT '', - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + UNIQUE KEY `ip` (`ip`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/middleware/ipblack.go b/middleware/ipblack.go new file mode 100644 index 0000000..5d84159 --- /dev/null +++ b/middleware/ipblack.go @@ -0,0 +1,19 @@ +package middleware + +import ( + "github.com/gin-gonic/gin" + "github.com/taoshihan1991/imaptool/models" +) + +func Ipblack(c *gin.Context){ + ip:=c.ClientIP() + ipblack:=models.FindIp(ip) + if ipblack.IP!=""{ + c.JSON(200, gin.H{ + "code": 400, + "msg": "IP已被加入黑名单", + }) + c.Abort() + return + } +} diff --git a/models/ipblacks.go b/models/ipblacks.go index fa0c444..f7a305e 100644 --- a/models/ipblacks.go +++ b/models/ipblacks.go @@ -16,4 +16,9 @@ func CreateIpblack(ip string,kefuId string)uint{ } DB.Create(black) return black.ID +} +func FindIp(ip string)Ipblack{ + var ipblack Ipblack + DB.Where("ip = ?", ip).First(&ipblack) + return ipblack } \ No newline at end of file diff --git a/router/api.go b/router/api.go index d508c9d..f52a426 100644 --- a/router/api.go +++ b/router/api.go @@ -16,9 +16,9 @@ func InitApiRouter(engine *gin.Engine){ //获取消息 engine.GET("/messages", controller.GetVisitorMessage) //发送单条消息 - engine.POST("/message",controller.SendMessage) + engine.POST("/message",middleware.Ipblack,controller.SendMessage) //上传文件 - engine.POST("/uploadimg",controller.UploadImg) + engine.POST("/uploadimg",middleware.Ipblack,controller.UploadImg) //获取未读消息数 engine.GET("/message_status",controller.GetVisitorMessage) //设置消息已读 diff --git a/router/view.go b/router/view.go index 6408f35..d00389b 100644 --- a/router/view.go +++ b/router/view.go @@ -18,6 +18,7 @@ func InitViewRouter(engine *gin.Engine){ engine.GET("/setting_welcome", tmpl.PageSettingWelcome) engine.GET("/setting_deploy", tmpl.PageSettingDeploy) engine.GET("/setting_kefu_list",tmpl.PageKefuList) + engine.GET("/setting_ipblack",tmpl.PageIpblack) engine.GET("/mail_list", tmpl.PageMailList) engine.GET("/roles_list", tmpl.PageRoleList) engine.GET("/webjs", tmpl.PageWebJs) diff --git a/static/html/chat_page.html b/static/html/chat_page.html index 3d0a3ff..bf00a7d 100644 --- a/static/html/chat_page.html +++ b/static/html/chat_page.html @@ -237,19 +237,27 @@ mes.from_id = guest.id; mes.to_id = guest.to_id; mes.content = this.messageContent; - $.post("/message",mes,function(){ + //发送消息 + $.post("/message",mes,function(res){ + if(res.code!=200){ + _this.$message({ + message: res.msg, + type: 'error' + }); + return; + } _this.messageContent = ""; + let content = {} + content.avator=guest.avator; + content.content = replaceContent(this.messageContent); + content.name = guest.name; + content.is_kefu = true; + content.time = this.getNowDate(); + this.msgList.push(content); + this.saveHistory(content); + this.scrollBottom(); }); - let content = {} - content.avator=guest.avator; - content.content = replaceContent(this.messageContent); - content.name = guest.name; - content.is_kefu = true; - content.time = this.getNowDate(); - this.msgList.push(content); - this.saveHistory(content); - this.scrollBottom(); }, OnClose() { this.chatTitle="连接关闭!" diff --git a/static/html/setting_left.html b/static/html/setting_left.html index e81e282..e68daa8 100644 --- a/static/html/setting_left.html +++ b/static/html/setting_left.html @@ -36,6 +36,7 @@ 设置登陆账号 设置mysql 设置网页部署 + IP黑名单 diff --git a/tmpl/setting.go b/tmpl/setting.go index ecd6429..d956c4f 100644 --- a/tmpl/setting.go +++ b/tmpl/setting.go @@ -53,6 +53,13 @@ func PageRoleList(c *gin.Context) { "action":"roles_list", }) } +//角色列表 +func PageIpblack(c *gin.Context) { + c.HTML(http.StatusOK, "setting_ipblack.html", gin.H{ + "tab_index":"4-5", + "action":"setting_ipblack", + }) +} type SettingHtml struct { *CommonHtml Username, Password string