mirror of
https://github.com/Li4n0/revsuit.git
synced 2026-09-21 22:30:46 +08:00
feat(ftp): support receive ftp connection (#6)
Co-authored-by: E99p1ant <[email protected]>
This commit is contained in:
+8
-7
@@ -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)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user