feat(ftp): support receive ftp connection (#6)

Co-authored-by: E99p1ant <[email protected]>
This commit is contained in:
Li4n0
2021-04-25 13:39:27 +08:00
committed by GitHub
co-authored by E99p1ant
parent 5e24f9530d
commit 26755351f7
36 changed files with 1446 additions and 141 deletions
+8 -7
View File
@@ -49,11 +49,12 @@ func (s *Server) updateRules() error {
func (s *Server) handleConnection(conn net.Conn) {
defer conn.Close()
ip, port, _ := net.SplitHostPort(conn.RemoteAddr().String())
if err := conn.SetDeadline(time.Now().Add(time.Second * 30)); err != nil {
log.Error("RMI set connection deadline error:%v", err.Error())
}
ip, port, _ := net.SplitHostPort(conn.RemoteAddr().String())
buf := make([]byte, 1024)
_, err := conn.Read(buf)
if err != nil {
@@ -94,7 +95,7 @@ func (s *Server) handleConnection(conn net.Conn) {
path := strings.TrimRight(string(frags[len(frags)-1][2:]), "\x00")
for _, _rule := range s.getRules() {
flag, flagGroup := _rule.Match(path)
flag, flagGroup, _ := _rule.Match(path)
if flag == "" {
continue
}
@@ -104,10 +105,10 @@ func (s *Server) handleConnection(conn net.Conn) {
// create new record
r, err := NewRecord(_rule, flag, path, ip, area)
if err != nil {
log.Error("RMI record(rule_id:%d) created failed :%s", _rule.ID, err.Error())
log.Error("RMI record[rule_id:%d] created failed :%s", _rule.ID, err.Error())
return
}
log.Info("RMI record(id:%d,rule:%s,remote_ip:%s) has been created", r.ID, _rule.Name, ip)
log.Info("RMI 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 {
@@ -116,18 +117,18 @@ func (s *Server) handleConnection(conn net.Conn) {
database.DB.Where("rule_name=? and raw like ?", _rule.Name, "%"+flagGroup+"%").Model(&Record{}).Count(&count)
if count <= 1 {
r.PushToClient()
log.Trace("RMI record(id:%d) has been put to client message queue", r.ID)
log.Trace("RMI record[id%d] has been put to client message queue", r.ID)
}
}
r.PushToClient()
log.Trace("RMI record(id:%d) has been put to client message queue", r.ID)
log.Trace("RMI record[id%d] has been put to client message queue", r.ID)
}
//send notice
if _rule.Notice {
go func() {
r.Notice()
log.Trace("RMI record(id:%d) notice has been sent", r.ID)
log.Trace("RMI record[id%d] notice has been sent", r.ID)
}()
}
}