浏览代码

Merge branch 'ftp-record' of tmp/arozos into master

TC 4 年之前
父节点
当前提交
b70d9af859
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7 1
      mod/storage/ftp/drivers.go

+ 7 - 1
mod/storage/ftp/drivers.go

@@ -5,6 +5,7 @@ import (
 	"errors"
 	"log"
 	"os"
+	"time"
 
 	ftp "github.com/fclairamb/ftpserverlib"
 )
@@ -60,6 +61,8 @@ func (m mainDriver) AuthUser(cc ftp.ClientContext, user string, pass string) (ft
 		accessOK := userinfo.UserIsInOneOfTheGroupOf(allowedPgs)
 
 		if !accessOK {
+			//log the signin request
+			m.userHandler.GetAuthAgent().Logger.LogAuthByRequestInfo(user, cc.RemoteAddr().String(), time.Now().Unix(), false, "ftp")
 			//Disconnect this user as he is not in the group that is allowed to access ftp
 			log.Println(userinfo.Username + " tries to access FTP endpoint with invalid permission settings.")
 			return nil, errors.New("User " + userinfo.Username + " has no permission to access FTP endpoint")
@@ -71,13 +74,16 @@ func (m mainDriver) AuthUser(cc ftp.ClientContext, user string, pass string) (ft
 
 		//Record username into connected user list
 		m.connectedUserList.Store(cc.ID(), userinfo.Username)
-
+		//log the signin request
+		m.userHandler.GetAuthAgent().Logger.LogAuthByRequestInfo(userinfo.Username, cc.RemoteAddr().String(), time.Now().Unix(), true, "ftp")
 		//Return the aofs object
 		return aofs{
 			userinfo:  userinfo,
 			tmpFolder: tmpFolder,
 		}, nil
 	} else {
+		//log the signin request
+		m.userHandler.GetAuthAgent().Logger.LogAuthByRequestInfo(user, cc.RemoteAddr().String(), time.Now().Unix(), false, "ftp")
 		return nil, errors.New("Invalid username or password")
 	}
 }