mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 23:00:55 +03:00
add remote address to transfer and commands logs
This commit is contained in:
@@ -28,15 +28,16 @@ type BaseConnection struct {
|
||||
// user associated with this connection if any
|
||||
User dataprovider.User
|
||||
// start time for this connection
|
||||
startTime time.Time
|
||||
protocol string
|
||||
startTime time.Time
|
||||
protocol string
|
||||
remoteAddr string
|
||||
sync.RWMutex
|
||||
transferID uint64
|
||||
activeTransfers []ActiveTransfer
|
||||
}
|
||||
|
||||
// NewBaseConnection returns a new BaseConnection
|
||||
func NewBaseConnection(id, protocol string, user dataprovider.User) *BaseConnection {
|
||||
func NewBaseConnection(id, protocol, remoteAddr string, user dataprovider.User) *BaseConnection {
|
||||
connID := id
|
||||
if utils.IsStringInSlice(protocol, supportedProtocols) {
|
||||
connID = fmt.Sprintf("%v_%v", protocol, id)
|
||||
@@ -46,6 +47,7 @@ func NewBaseConnection(id, protocol string, user dataprovider.User) *BaseConnect
|
||||
User: user,
|
||||
startTime: time.Now(),
|
||||
protocol: protocol,
|
||||
remoteAddr: remoteAddr,
|
||||
lastActivity: time.Now().UnixNano(),
|
||||
transferID: 0,
|
||||
}
|
||||
@@ -238,7 +240,7 @@ func (c *BaseConnection) CreateDir(virtualPath string) error {
|
||||
}
|
||||
vfs.SetPathPermissions(fs, fsPath, c.User.GetUID(), c.User.GetGID())
|
||||
|
||||
logger.CommandLog(mkdirLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1, "", "", "", -1)
|
||||
logger.CommandLog(mkdirLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1, "", "", "", -1, c.remoteAddr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -271,7 +273,7 @@ func (c *BaseConnection) RemoveFile(fs vfs.Fs, fsPath, virtualPath string, info
|
||||
}
|
||||
}
|
||||
|
||||
logger.CommandLog(removeLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1, "", "", "", -1)
|
||||
logger.CommandLog(removeLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1, "", "", "", -1, c.remoteAddr)
|
||||
if info.Mode()&os.ModeSymlink == 0 {
|
||||
vfolder, err := c.User.GetVirtualFolderForPath(path.Dir(virtualPath))
|
||||
if err == nil {
|
||||
@@ -342,7 +344,7 @@ func (c *BaseConnection) RemoveDir(virtualPath string) error {
|
||||
return c.GetFsError(fs, err)
|
||||
}
|
||||
|
||||
logger.CommandLog(rmdirLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1, "", "", "", -1)
|
||||
logger.CommandLog(rmdirLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1, "", "", "", -1, c.remoteAddr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -402,7 +404,7 @@ func (c *BaseConnection) Rename(virtualSourcePath, virtualTargetPath string) err
|
||||
vfs.SetPathPermissions(fsDst, fsTargetPath, c.User.GetUID(), c.User.GetGID())
|
||||
c.updateQuotaAfterRename(fsDst, virtualSourcePath, virtualTargetPath, fsTargetPath, initialSize) //nolint:errcheck
|
||||
logger.CommandLog(renameLogSender, fsSourcePath, fsTargetPath, c.User.Username, "", c.ID, c.protocol, -1, -1,
|
||||
"", "", "", -1)
|
||||
"", "", "", -1, c.remoteAddr)
|
||||
ExecuteActionNotification(&c.User, operationRename, fsSourcePath, virtualSourcePath, fsTargetPath, "", c.protocol, 0, nil)
|
||||
|
||||
return nil
|
||||
@@ -438,7 +440,8 @@ func (c *BaseConnection) CreateSymlink(virtualSourcePath, virtualTargetPath stri
|
||||
c.Log(logger.LevelWarn, "failed to create symlink %#v -> %#v: %+v", fsSourcePath, fsTargetPath, err)
|
||||
return c.GetFsError(fs, err)
|
||||
}
|
||||
logger.CommandLog(symlinkLogSender, fsSourcePath, fsTargetPath, c.User.Username, "", c.ID, c.protocol, -1, -1, "", "", "", -1)
|
||||
logger.CommandLog(symlinkLogSender, fsSourcePath, fsTargetPath, c.User.Username, "", c.ID, c.protocol, -1, -1, "",
|
||||
"", "", -1, c.remoteAddr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -504,7 +507,7 @@ func (c *BaseConnection) handleChmod(fs vfs.Fs, fsPath, pathForPerms string, att
|
||||
return c.GetFsError(fs, err)
|
||||
}
|
||||
logger.CommandLog(chmodLogSender, fsPath, "", c.User.Username, attributes.Mode.String(), c.ID, c.protocol,
|
||||
-1, -1, "", "", "", -1)
|
||||
-1, -1, "", "", "", -1, c.remoteAddr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -521,7 +524,7 @@ func (c *BaseConnection) handleChown(fs vfs.Fs, fsPath, pathForPerms string, att
|
||||
return c.GetFsError(fs, err)
|
||||
}
|
||||
logger.CommandLog(chownLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, attributes.UID, attributes.GID,
|
||||
"", "", "", -1)
|
||||
"", "", "", -1, c.remoteAddr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -540,7 +543,7 @@ func (c *BaseConnection) handleChtimes(fs vfs.Fs, fsPath, pathForPerms string, a
|
||||
accessTimeString := attributes.Atime.Format(chtimesFormat)
|
||||
modificationTimeString := attributes.Mtime.Format(chtimesFormat)
|
||||
logger.CommandLog(chtimesLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1,
|
||||
accessTimeString, modificationTimeString, "", -1)
|
||||
accessTimeString, modificationTimeString, "", -1, c.remoteAddr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -573,7 +576,8 @@ func (c *BaseConnection) SetStat(virtualPath string, attributes *StatAttributes)
|
||||
c.Log(logger.LevelWarn, "failed to truncate path %#v, size: %v, err: %+v", fsPath, attributes.Size, err)
|
||||
return c.GetFsError(fs, err)
|
||||
}
|
||||
logger.CommandLog(truncateLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1, "", "", "", attributes.Size)
|
||||
logger.CommandLog(truncateLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1, "", "",
|
||||
"", attributes.Size, c.remoteAddr)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user