发送消息验证ip黑名单

pull/30/head
taoshihan1991 4 years ago
parent 4f548505d4
commit 2599bed3b1

@ -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;

@ -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
}
}

@ -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
}

@ -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)
//设置消息已读

@ -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)

@ -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="连接关闭!"

@ -36,6 +36,7 @@
<el-menu-item style="display:none" index="2-3" v-on:click="openUrl('/setting')">设置登陆账号</el-menu-item>
<el-menu-item style="display:none" index="2-4" v-on:click="openUrl('/setting_mysql')">设置mysql</el-menu-item>
<el-menu-item index="2-5" v-on:click="openUrl('/setting_deploy')">设置网页部署</el-menu-item>
<el-menu-item index="4-5" v-on:click="openUrl('/setting_ipblack')">IP黑名单</el-menu-item>
</el-menu-item-group>
</el-submenu>
</el-menu>

@ -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

Loading…
Cancel
Save