mirror of
https://github.com/Li4n0/revsuit.git
synced 2026-09-26 08:31:52 +08:00
feat(ftp): support receive ftp connection (#6)
Co-authored-by: E99p1ant <[email protected]>
This commit is contained in:
+22
-14
@@ -65,8 +65,9 @@ func (s *Server) NewConnection(c *vmysql.Conn) {
|
||||
)
|
||||
|
||||
for _, _rule := range s.getRules() {
|
||||
flag, _ := _rule.Match(user + schema)
|
||||
if flag == "" {
|
||||
userFlag, _, _ := _rule.Match(user)
|
||||
schemaFlag, _, _ := _rule.Match(schema)
|
||||
if userFlag == "" && schemaFlag == "" {
|
||||
continue
|
||||
}
|
||||
s.connRulePool.Store(c.ConnectionID, _rule)
|
||||
@@ -81,8 +82,6 @@ func (s *Server) NewConnection(c *vmysql.Conn) {
|
||||
if strings.Contains(c.ConnAttrs["_client_name"], "MySQL Connector") {
|
||||
c.IsJdbcClient = true
|
||||
c.SupportLoadDataLocal = true
|
||||
// 测试发现只有 pymysql 和原生命令行会对这个 flag 真正进行修改
|
||||
// 而且 Connector/J 默认值为 False, 所以这里做特殊兼容
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,21 +89,30 @@ func (s *Server) NewConnection(c *vmysql.Conn) {
|
||||
// ConnectionClosed is part of the mysql.Handler interface.
|
||||
func (s *Server) ConnectionClosed(c *vmysql.Conn) {
|
||||
log.Trace("MySQL Client leaved, ID [%d]", c.ConnectionID)
|
||||
|
||||
var (
|
||||
user = c.User
|
||||
clientName string
|
||||
clientOS string
|
||||
supportLoadLocalData = c.SupportLoadDataLocal
|
||||
cr, ok = s.connRulePool.Load(c.ConnectionID)
|
||||
user = c.User
|
||||
schema = c.SchemaName
|
||||
supportLoadLocalData = c.SupportLoadDataLocal
|
||||
cr, ok = s.connRulePool.Load(c.ConnectionID)
|
||||
clientName, clientOS, flag, flagGroup string
|
||||
)
|
||||
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
_rule := cr.(*Rule)
|
||||
flag, flagGroup := _rule.Match(user)
|
||||
for _, s := range []string{user, schema} {
|
||||
flag, flagGroup, _ = _rule.Match(s)
|
||||
if flag != "" {
|
||||
break
|
||||
}
|
||||
}
|
||||
if flag == "" {
|
||||
log.Error("MySQL Connection rule(%d) not match flag", c.ConnectionID)
|
||||
}
|
||||
|
||||
if c.ConnAttrs != nil {
|
||||
clientName = c.ConnAttrs["_client_name"] + " " + c.ConnAttrs["_client_version"]
|
||||
clientOS = c.ConnAttrs["_os"] + " " + c.ConnAttrs["_platform"]
|
||||
@@ -125,7 +133,7 @@ func (s *Server) ConnectionClosed(c *vmysql.Conn) {
|
||||
log.Error("MySQL record(rule_id:%s) created failed :%s", _rule.Name, err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("MySQL record(id:%d,rule:%s,remote_ip:%s) has been created", r.ID, _rule.Name, ip)
|
||||
log.Info("MySQL record[id:%d rule:%s remote_ip:%s] has been created", r.ID, _rule.Name, ip)
|
||||
|
||||
//only send to client when this connection recorded first time.
|
||||
if _rule.PushToClient {
|
||||
@@ -134,11 +142,11 @@ func (s *Server) ConnectionClosed(c *vmysql.Conn) {
|
||||
database.DB.Where("rule_name=? and domain like ?", _rule.Name, "%"+flagGroup+"%").Model(&Record{}).Count(&count)
|
||||
if count <= 1 {
|
||||
r.PushToClient()
|
||||
log.Trace("MySQL record(id:%d) has been put to client message queue", r.ID)
|
||||
log.Trace("MySQL record[id%d] has been put to client message queue", r.ID)
|
||||
}
|
||||
} else {
|
||||
r.PushToClient()
|
||||
log.Trace("MySQL record(id:%d) has been put to client message queue", r.ID)
|
||||
log.Trace("MySQL record[id%d] has been put to client message queue", r.ID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +154,7 @@ func (s *Server) ConnectionClosed(c *vmysql.Conn) {
|
||||
if _rule.Notice {
|
||||
go func() {
|
||||
r.Notice()
|
||||
log.Trace("MySQL record(id:%d) notice has been sent", r.ID)
|
||||
log.Trace("MySQL record[id%d] notice has been sent", r.ID)
|
||||
}()
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,13 @@ func ListRecords(c *gin.Context) {
|
||||
if mysqlRecord.ClientName != "" {
|
||||
db.Where("client_name like ?", "%"+mysqlRecord.ClientName)
|
||||
}
|
||||
if c.Query("load_local_data") != "" {
|
||||
if c.Query("load_local_data") == "true" {
|
||||
db.Where("load_local_data = ?", true)
|
||||
} else {
|
||||
db.Where("load_local_data = ?", false)
|
||||
}
|
||||
}
|
||||
|
||||
page, err := strconv.Atoi(c.Query("page"))
|
||||
if err != nil {
|
||||
|
||||
+3
-3
@@ -140,9 +140,9 @@ func UpsertRules(c *gin.Context) {
|
||||
}
|
||||
|
||||
if update {
|
||||
log.Trace("MySQL rule(id:%d) has been updated", mysqlRule.ID)
|
||||
log.Trace("MySQL rule[id%d] has been updated", mysqlRule.ID)
|
||||
} else {
|
||||
log.Trace("MySQL rule(id:%d) has been created", mysqlRule.ID)
|
||||
log.Trace("MySQL rule[id%d] has been created", mysqlRule.ID)
|
||||
}
|
||||
|
||||
c.JSON(200, gin.H{
|
||||
@@ -174,7 +174,7 @@ func DeleteRules(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Trace("MySQL rule(id:%d) has been deleted", mysqlRule.ID)
|
||||
log.Trace("MySQL rule[id%d] has been deleted", mysqlRule.ID)
|
||||
|
||||
c.JSON(200, gin.H{
|
||||
"status": "succeed",
|
||||
|
||||
Reference in New Issue
Block a user