add remote address to transfer and commands logs

This commit is contained in:
Nicola Murino 2021-06-01 22:28:43 +02:00
parent 969c992bfd
commit 575bcf1f03
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB
22 changed files with 134 additions and 122 deletions

View file

@ -188,7 +188,7 @@ func TestPreDeleteAction(t *testing.T) {
user.Permissions = make(map[string][]string) user.Permissions = make(map[string][]string)
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
fs := vfs.NewOsFs("id", homeDir, "") fs := vfs.NewOsFs("id", homeDir, "")
c := NewBaseConnection("id", ProtocolSFTP, user) c := NewBaseConnection("id", ProtocolSFTP, "", user)
testfile := filepath.Join(user.HomeDir, "testfile") testfile := filepath.Join(user.HomeDir, "testfile")
err = os.WriteFile(testfile, []byte("test"), os.ModePerm) err = os.WriteFile(testfile, []byte("test"), os.ModePerm)

View file

@ -239,7 +239,7 @@ func TestMaxConnections(t *testing.T) {
Config.MaxPerHostConnections = perHost Config.MaxPerHostConnections = perHost
assert.True(t, Connections.IsNewConnectionAllowed(ipAddr)) assert.True(t, Connections.IsNewConnectionAllowed(ipAddr))
c := NewBaseConnection("id", ProtocolSFTP, dataprovider.User{}) c := NewBaseConnection("id", ProtocolSFTP, "", dataprovider.User{})
fakeConn := &fakeConnection{ fakeConn := &fakeConnection{
BaseConnection: c, BaseConnection: c,
} }
@ -310,7 +310,7 @@ func TestIdleConnections(t *testing.T) {
user := dataprovider.User{ user := dataprovider.User{
Username: username, Username: username,
} }
c := NewBaseConnection(sshConn1.id+"_1", ProtocolSFTP, user) c := NewBaseConnection(sshConn1.id+"_1", ProtocolSFTP, "", user)
c.lastActivity = time.Now().Add(-24 * time.Hour).UnixNano() c.lastActivity = time.Now().Add(-24 * time.Hour).UnixNano()
fakeConn := &fakeConnection{ fakeConn := &fakeConnection{
BaseConnection: c, BaseConnection: c,
@ -322,7 +322,7 @@ func TestIdleConnections(t *testing.T) {
Connections.AddSSHConnection(sshConn1) Connections.AddSSHConnection(sshConn1)
Connections.Add(fakeConn) Connections.Add(fakeConn)
assert.Equal(t, Connections.GetActiveSessions(username), 1) assert.Equal(t, Connections.GetActiveSessions(username), 1)
c = NewBaseConnection(sshConn2.id+"_1", ProtocolSSH, user) c = NewBaseConnection(sshConn2.id+"_1", ProtocolSSH, "", user)
fakeConn = &fakeConnection{ fakeConn = &fakeConnection{
BaseConnection: c, BaseConnection: c,
} }
@ -330,7 +330,7 @@ func TestIdleConnections(t *testing.T) {
Connections.Add(fakeConn) Connections.Add(fakeConn)
assert.Equal(t, Connections.GetActiveSessions(username), 2) assert.Equal(t, Connections.GetActiveSessions(username), 2)
cFTP := NewBaseConnection("id2", ProtocolFTP, dataprovider.User{}) cFTP := NewBaseConnection("id2", ProtocolFTP, "", dataprovider.User{})
cFTP.lastActivity = time.Now().UnixNano() cFTP.lastActivity = time.Now().UnixNano()
fakeConn = &fakeConnection{ fakeConn = &fakeConnection{
BaseConnection: cFTP, BaseConnection: cFTP,
@ -370,7 +370,7 @@ func TestIdleConnections(t *testing.T) {
} }
func TestCloseConnection(t *testing.T) { func TestCloseConnection(t *testing.T) {
c := NewBaseConnection("id", ProtocolSFTP, dataprovider.User{}) c := NewBaseConnection("id", ProtocolSFTP, "", dataprovider.User{})
fakeConn := &fakeConnection{ fakeConn := &fakeConnection{
BaseConnection: c, BaseConnection: c,
} }
@ -386,7 +386,7 @@ func TestCloseConnection(t *testing.T) {
} }
func TestSwapConnection(t *testing.T) { func TestSwapConnection(t *testing.T) {
c := NewBaseConnection("id", ProtocolFTP, dataprovider.User{}) c := NewBaseConnection("id", ProtocolFTP, "", dataprovider.User{})
fakeConn := &fakeConnection{ fakeConn := &fakeConnection{
BaseConnection: c, BaseConnection: c,
} }
@ -394,7 +394,7 @@ func TestSwapConnection(t *testing.T) {
if assert.Len(t, Connections.GetStats(), 1) { if assert.Len(t, Connections.GetStats(), 1) {
assert.Equal(t, "", Connections.GetStats()[0].Username) assert.Equal(t, "", Connections.GetStats()[0].Username)
} }
c = NewBaseConnection("id", ProtocolFTP, dataprovider.User{ c = NewBaseConnection("id", ProtocolFTP, "", dataprovider.User{
Username: userTestUsername, Username: userTestUsername,
}) })
fakeConn = &fakeConnection{ fakeConn = &fakeConnection{
@ -431,7 +431,7 @@ func TestConnectionStatus(t *testing.T) {
Username: username, Username: username,
} }
fs := vfs.NewOsFs("", os.TempDir(), "") fs := vfs.NewOsFs("", os.TempDir(), "")
c1 := NewBaseConnection("id1", ProtocolSFTP, user) c1 := NewBaseConnection("id1", ProtocolSFTP, "", user)
fakeConn1 := &fakeConnection{ fakeConn1 := &fakeConnection{
BaseConnection: c1, BaseConnection: c1,
} }
@ -439,12 +439,12 @@ func TestConnectionStatus(t *testing.T) {
t1.BytesReceived = 123 t1.BytesReceived = 123
t2 := NewBaseTransfer(nil, c1, nil, "/p2", "/p2", "/r2", TransferDownload, 0, 0, 0, true, fs) t2 := NewBaseTransfer(nil, c1, nil, "/p2", "/p2", "/r2", TransferDownload, 0, 0, 0, true, fs)
t2.BytesSent = 456 t2.BytesSent = 456
c2 := NewBaseConnection("id2", ProtocolSSH, user) c2 := NewBaseConnection("id2", ProtocolSSH, "", user)
fakeConn2 := &fakeConnection{ fakeConn2 := &fakeConnection{
BaseConnection: c2, BaseConnection: c2,
command: "md5sum", command: "md5sum",
} }
c3 := NewBaseConnection("id3", ProtocolWebDAV, user) c3 := NewBaseConnection("id3", ProtocolWebDAV, "", user)
fakeConn3 := &fakeConnection{ fakeConn3 := &fakeConnection{
BaseConnection: c3, BaseConnection: c3,
command: "PROPFIND", command: "PROPFIND",
@ -677,7 +677,7 @@ func TestCachedFs(t *testing.T) {
user := dataprovider.User{ user := dataprovider.User{
HomeDir: filepath.Clean(os.TempDir()), HomeDir: filepath.Clean(os.TempDir()),
} }
conn := NewBaseConnection("id", ProtocolSFTP, user) conn := NewBaseConnection("id", ProtocolSFTP, "", user)
// changing the user should not affect the connection // changing the user should not affect the connection
user.HomeDir = filepath.Join(os.TempDir(), "temp") user.HomeDir = filepath.Join(os.TempDir(), "temp")
err := os.Mkdir(user.HomeDir, os.ModePerm) err := os.Mkdir(user.HomeDir, os.ModePerm)

View file

@ -30,13 +30,14 @@ type BaseConnection struct {
// start time for this connection // start time for this connection
startTime time.Time startTime time.Time
protocol string protocol string
remoteAddr string
sync.RWMutex sync.RWMutex
transferID uint64 transferID uint64
activeTransfers []ActiveTransfer activeTransfers []ActiveTransfer
} }
// NewBaseConnection returns a new BaseConnection // 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 connID := id
if utils.IsStringInSlice(protocol, supportedProtocols) { if utils.IsStringInSlice(protocol, supportedProtocols) {
connID = fmt.Sprintf("%v_%v", protocol, id) connID = fmt.Sprintf("%v_%v", protocol, id)
@ -46,6 +47,7 @@ func NewBaseConnection(id, protocol string, user dataprovider.User) *BaseConnect
User: user, User: user,
startTime: time.Now(), startTime: time.Now(),
protocol: protocol, protocol: protocol,
remoteAddr: remoteAddr,
lastActivity: time.Now().UnixNano(), lastActivity: time.Now().UnixNano(),
transferID: 0, transferID: 0,
} }
@ -238,7 +240,7 @@ func (c *BaseConnection) CreateDir(virtualPath string) error {
} }
vfs.SetPathPermissions(fs, fsPath, c.User.GetUID(), c.User.GetGID()) 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 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 { if info.Mode()&os.ModeSymlink == 0 {
vfolder, err := c.User.GetVirtualFolderForPath(path.Dir(virtualPath)) vfolder, err := c.User.GetVirtualFolderForPath(path.Dir(virtualPath))
if err == nil { if err == nil {
@ -342,7 +344,7 @@ func (c *BaseConnection) RemoveDir(virtualPath string) error {
return c.GetFsError(fs, err) 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 return nil
} }
@ -402,7 +404,7 @@ func (c *BaseConnection) Rename(virtualSourcePath, virtualTargetPath string) err
vfs.SetPathPermissions(fsDst, fsTargetPath, c.User.GetUID(), c.User.GetGID()) vfs.SetPathPermissions(fsDst, fsTargetPath, c.User.GetUID(), c.User.GetGID())
c.updateQuotaAfterRename(fsDst, virtualSourcePath, virtualTargetPath, fsTargetPath, initialSize) //nolint:errcheck c.updateQuotaAfterRename(fsDst, virtualSourcePath, virtualTargetPath, fsTargetPath, initialSize) //nolint:errcheck
logger.CommandLog(renameLogSender, fsSourcePath, fsTargetPath, c.User.Username, "", c.ID, c.protocol, -1, -1, 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) ExecuteActionNotification(&c.User, operationRename, fsSourcePath, virtualSourcePath, fsTargetPath, "", c.protocol, 0, nil)
return 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) c.Log(logger.LevelWarn, "failed to create symlink %#v -> %#v: %+v", fsSourcePath, fsTargetPath, err)
return c.GetFsError(fs, 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 return nil
} }
@ -504,7 +507,7 @@ func (c *BaseConnection) handleChmod(fs vfs.Fs, fsPath, pathForPerms string, att
return c.GetFsError(fs, err) return c.GetFsError(fs, err)
} }
logger.CommandLog(chmodLogSender, fsPath, "", c.User.Username, attributes.Mode.String(), c.ID, c.protocol, logger.CommandLog(chmodLogSender, fsPath, "", c.User.Username, attributes.Mode.String(), c.ID, c.protocol,
-1, -1, "", "", "", -1) -1, -1, "", "", "", -1, c.remoteAddr)
return nil return nil
} }
@ -521,7 +524,7 @@ func (c *BaseConnection) handleChown(fs vfs.Fs, fsPath, pathForPerms string, att
return c.GetFsError(fs, err) return c.GetFsError(fs, err)
} }
logger.CommandLog(chownLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, attributes.UID, attributes.GID, logger.CommandLog(chownLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, attributes.UID, attributes.GID,
"", "", "", -1) "", "", "", -1, c.remoteAddr)
return nil return nil
} }
@ -540,7 +543,7 @@ func (c *BaseConnection) handleChtimes(fs vfs.Fs, fsPath, pathForPerms string, a
accessTimeString := attributes.Atime.Format(chtimesFormat) accessTimeString := attributes.Atime.Format(chtimesFormat)
modificationTimeString := attributes.Mtime.Format(chtimesFormat) modificationTimeString := attributes.Mtime.Format(chtimesFormat)
logger.CommandLog(chtimesLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1, logger.CommandLog(chtimesLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1,
accessTimeString, modificationTimeString, "", -1) accessTimeString, modificationTimeString, "", -1, c.remoteAddr)
return nil 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) c.Log(logger.LevelWarn, "failed to truncate path %#v, size: %v, err: %+v", fsPath, attributes.Size, err)
return c.GetFsError(fs, 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 return nil

View file

@ -62,7 +62,7 @@ func TestRemoveErrors(t *testing.T) {
user.Permissions = make(map[string][]string) user.Permissions = make(map[string][]string)
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
fs := vfs.NewOsFs("", os.TempDir(), "") fs := vfs.NewOsFs("", os.TempDir(), "")
conn := NewBaseConnection("", ProtocolFTP, user) conn := NewBaseConnection("", ProtocolFTP, "", user)
err := conn.IsRemoveDirAllowed(fs, mappedPath, "/virtualpath1") err := conn.IsRemoveDirAllowed(fs, mappedPath, "/virtualpath1")
if assert.Error(t, err) { if assert.Error(t, err) {
assert.Contains(t, err.Error(), "permission denied") assert.Contains(t, err.Error(), "permission denied")
@ -83,7 +83,7 @@ func TestSetStatMode(t *testing.T) {
user.Permissions = make(map[string][]string) user.Permissions = make(map[string][]string)
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
fs := newMockOsFs(true, "", user.GetHomeDir()) fs := newMockOsFs(true, "", user.GetHomeDir())
conn := NewBaseConnection("", ProtocolWebDAV, user) conn := NewBaseConnection("", ProtocolWebDAV, "", user)
err := conn.handleChmod(fs, fakePath, fakePath, nil) err := conn.handleChmod(fs, fakePath, fakePath, nil)
assert.NoError(t, err) assert.NoError(t, err)
err = conn.handleChown(fs, fakePath, fakePath, nil) err = conn.handleChown(fs, fakePath, fakePath, nil)
@ -100,14 +100,14 @@ func TestSetStatMode(t *testing.T) {
func TestRecursiveRenameWalkError(t *testing.T) { func TestRecursiveRenameWalkError(t *testing.T) {
fs := vfs.NewOsFs("", os.TempDir(), "") fs := vfs.NewOsFs("", os.TempDir(), "")
conn := NewBaseConnection("", ProtocolWebDAV, dataprovider.User{}) conn := NewBaseConnection("", ProtocolWebDAV, "", dataprovider.User{})
err := conn.checkRecursiveRenameDirPermissions(fs, fs, "/source", "/target") err := conn.checkRecursiveRenameDirPermissions(fs, fs, "/source", "/target")
assert.ErrorIs(t, err, os.ErrNotExist) assert.ErrorIs(t, err, os.ErrNotExist)
} }
func TestCrossRenameFsErrors(t *testing.T) { func TestCrossRenameFsErrors(t *testing.T) {
fs := vfs.NewOsFs("", os.TempDir(), "") fs := vfs.NewOsFs("", os.TempDir(), "")
conn := NewBaseConnection("", ProtocolWebDAV, dataprovider.User{}) conn := NewBaseConnection("", ProtocolWebDAV, "", dataprovider.User{})
res := conn.hasSpaceForCrossRename(fs, vfs.QuotaCheckResult{}, 1, "missingsource") res := conn.hasSpaceForCrossRename(fs, vfs.QuotaCheckResult{}, 1, "missingsource")
assert.False(t, res) assert.False(t, res)
if runtime.GOOS != osWindows { if runtime.GOOS != osWindows {
@ -138,7 +138,7 @@ func TestRenameVirtualFolders(t *testing.T) {
VirtualPath: vdir, VirtualPath: vdir,
}) })
fs := vfs.NewOsFs("", os.TempDir(), "") fs := vfs.NewOsFs("", os.TempDir(), "")
conn := NewBaseConnection("", ProtocolFTP, u) conn := NewBaseConnection("", ProtocolFTP, "", u)
res := conn.isRenamePermitted(fs, fs, "source", "target", vdir, "vdirtarget", nil) res := conn.isRenamePermitted(fs, fs, "source", "target", vdir, "vdirtarget", nil)
assert.False(t, res) assert.False(t, res)
} }
@ -173,7 +173,7 @@ func TestUpdateQuotaAfterRename(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
fs, err := user.GetFilesystem("id") fs, err := user.GetFilesystem("id")
assert.NoError(t, err) assert.NoError(t, err)
c := NewBaseConnection("", ProtocolSFTP, user) c := NewBaseConnection("", ProtocolSFTP, "", user)
request := sftp.NewRequest("Rename", "/testfile") request := sftp.NewRequest("Rename", "/testfile")
if runtime.GOOS != osWindows { if runtime.GOOS != osWindows {
request.Filepath = "/dir" request.Filepath = "/dir"
@ -218,7 +218,7 @@ func TestUpdateQuotaAfterRename(t *testing.T) {
func TestErrorsMapping(t *testing.T) { func TestErrorsMapping(t *testing.T) {
fs := vfs.NewOsFs("", os.TempDir(), "") fs := vfs.NewOsFs("", os.TempDir(), "")
conn := NewBaseConnection("", ProtocolSFTP, dataprovider.User{HomeDir: os.TempDir()}) conn := NewBaseConnection("", ProtocolSFTP, "", dataprovider.User{HomeDir: os.TempDir()})
for _, protocol := range supportedProtocols { for _, protocol := range supportedProtocols {
conn.SetProtocol(protocol) conn.SetProtocol(protocol)
err := conn.GetFsError(fs, os.ErrNotExist) err := conn.GetFsError(fs, os.ErrNotExist)
@ -280,7 +280,7 @@ func TestMaxWriteSize(t *testing.T) {
} }
fs, err := user.GetFilesystem("123") fs, err := user.GetFilesystem("123")
assert.NoError(t, err) assert.NoError(t, err)
conn := NewBaseConnection("", ProtocolFTP, user) conn := NewBaseConnection("", ProtocolFTP, "", user)
quotaResult := vfs.QuotaCheckResult{ quotaResult := vfs.QuotaCheckResult{
HasSpace: true, HasSpace: true,
} }

View file

@ -1926,7 +1926,7 @@ func TestFsPermissionErrors(t *testing.T) {
func TestResolvePathError(t *testing.T) { func TestResolvePathError(t *testing.T) {
u := getTestUser() u := getTestUser()
u.HomeDir = "relative_path" u.HomeDir = "relative_path"
conn := common.NewBaseConnection("", common.ProtocolFTP, u) conn := common.NewBaseConnection("", common.ProtocolFTP, "", u)
testPath := "apath" testPath := "apath"
_, err := conn.ListDir(testPath) _, err := conn.ListDir(testPath)
assert.Error(t, err) assert.Error(t, err)
@ -2399,16 +2399,16 @@ func TestSFTPLoopError(t *testing.T) {
user1.VirtualFolders[0].FsConfig.SFTPConfig.Password = kms.NewPlainSecret(defaultPassword) user1.VirtualFolders[0].FsConfig.SFTPConfig.Password = kms.NewPlainSecret(defaultPassword)
user2.FsConfig.SFTPConfig.Password = kms.NewPlainSecret(defaultPassword) user2.FsConfig.SFTPConfig.Password = kms.NewPlainSecret(defaultPassword)
conn := common.NewBaseConnection("", common.ProtocolWebDAV, user1) conn := common.NewBaseConnection("", common.ProtocolWebDAV, "", user1)
_, _, err = conn.GetFsAndResolvedPath(user1.VirtualFolders[0].VirtualPath) _, _, err = conn.GetFsAndResolvedPath(user1.VirtualFolders[0].VirtualPath)
assert.ErrorIs(t, err, os.ErrPermission) assert.ErrorIs(t, err, os.ErrPermission)
conn = common.NewBaseConnection("", common.ProtocolSFTP, user1) conn = common.NewBaseConnection("", common.ProtocolSFTP, "", user1)
_, _, err = conn.GetFsAndResolvedPath(user1.VirtualFolders[0].VirtualPath) _, _, err = conn.GetFsAndResolvedPath(user1.VirtualFolders[0].VirtualPath)
if assert.Error(t, err) { if assert.Error(t, err) {
assert.Contains(t, err.Error(), "SFTP loop") assert.Contains(t, err.Error(), "SFTP loop")
} }
conn = common.NewBaseConnection("", common.ProtocolFTP, user1) conn = common.NewBaseConnection("", common.ProtocolFTP, "", user1)
_, _, err = conn.GetFsAndResolvedPath(user1.VirtualFolders[0].VirtualPath) _, _, err = conn.GetFsAndResolvedPath(user1.VirtualFolders[0].VirtualPath)
if assert.Error(t, err) { if assert.Error(t, err) {
assert.Contains(t, err.Error(), "SFTP loop") assert.Contains(t, err.Error(), "SFTP loop")
@ -2639,7 +2639,7 @@ func TestProxyProtocol(t *testing.T) {
} }
func TestSetProtocol(t *testing.T) { func TestSetProtocol(t *testing.T) {
conn := common.NewBaseConnection("id", "sshd_exec", dataprovider.User{HomeDir: os.TempDir()}) conn := common.NewBaseConnection("id", "sshd_exec", "", dataprovider.User{HomeDir: os.TempDir()})
conn.SetProtocol(common.ProtocolSCP) conn.SetProtocol(common.ProtocolSCP)
require.Equal(t, "SCP_id", conn.GetID()) require.Equal(t, "SCP_id", conn.GetID())
} }
@ -2649,7 +2649,7 @@ func TestGetFsError(t *testing.T) {
u.FsConfig.Provider = vfs.GCSFilesystemProvider u.FsConfig.Provider = vfs.GCSFilesystemProvider
u.FsConfig.GCSConfig.Bucket = "test" u.FsConfig.GCSConfig.Bucket = "test"
u.FsConfig.GCSConfig.Credentials = kms.NewPlainSecret("invalid JSON for credentials") u.FsConfig.GCSConfig.Credentials = kms.NewPlainSecret("invalid JSON for credentials")
conn := common.NewBaseConnection("", common.ProtocolFTP, u) conn := common.NewBaseConnection("", common.ProtocolFTP, "", u)
_, _, err := conn.GetFsAndResolvedPath("/vpath") _, _, err := conn.GetFsAndResolvedPath("/vpath")
assert.Error(t, err) assert.Error(t, err)
} }

View file

@ -236,7 +236,7 @@ func (t *BaseTransfer) Close() error {
elapsed := time.Since(t.start).Nanoseconds() / 1000000 elapsed := time.Since(t.start).Nanoseconds() / 1000000
if t.transferType == TransferDownload { if t.transferType == TransferDownload {
logger.TransferLog(downloadLogSender, t.fsPath, elapsed, atomic.LoadInt64(&t.BytesSent), t.Connection.User.Username, logger.TransferLog(downloadLogSender, t.fsPath, elapsed, atomic.LoadInt64(&t.BytesSent), t.Connection.User.Username,
t.Connection.ID, t.Connection.protocol) t.Connection.ID, t.Connection.protocol, t.Connection.remoteAddr)
ExecuteActionNotification(&t.Connection.User, operationDownload, t.fsPath, t.requestPath, "", "", t.Connection.protocol, ExecuteActionNotification(&t.Connection.User, operationDownload, t.fsPath, t.requestPath, "", "", t.Connection.protocol,
atomic.LoadInt64(&t.BytesSent), t.ErrTransfer) atomic.LoadInt64(&t.BytesSent), t.ErrTransfer)
} else { } else {
@ -247,7 +247,7 @@ func (t *BaseTransfer) Close() error {
t.Connection.Log(logger.LevelDebug, "uploaded file size %v", fileSize) t.Connection.Log(logger.LevelDebug, "uploaded file size %v", fileSize)
t.updateQuota(numFiles, fileSize) t.updateQuota(numFiles, fileSize)
logger.TransferLog(uploadLogSender, t.fsPath, elapsed, atomic.LoadInt64(&t.BytesReceived), t.Connection.User.Username, logger.TransferLog(uploadLogSender, t.fsPath, elapsed, atomic.LoadInt64(&t.BytesReceived), t.Connection.User.Username,
t.Connection.ID, t.Connection.protocol) t.Connection.ID, t.Connection.protocol, t.Connection.remoteAddr)
ExecuteActionNotification(&t.Connection.User, operationUpload, t.fsPath, t.requestPath, "", "", t.Connection.protocol, fileSize, ExecuteActionNotification(&t.Connection.User, operationUpload, t.fsPath, t.requestPath, "", "", t.Connection.protocol, fileSize,
t.ErrTransfer) t.ErrTransfer)
} }

View file

@ -16,7 +16,7 @@ import (
) )
func TestTransferUpdateQuota(t *testing.T) { func TestTransferUpdateQuota(t *testing.T) {
conn := NewBaseConnection("", ProtocolSFTP, dataprovider.User{}) conn := NewBaseConnection("", ProtocolSFTP, "", dataprovider.User{})
transfer := BaseTransfer{ transfer := BaseTransfer{
Connection: conn, Connection: conn,
transferType: TransferUpload, transferType: TransferUpload,
@ -61,7 +61,7 @@ func TestTransferThrottling(t *testing.T) {
// some tolerance // some tolerance
wantedUploadElapsed -= wantedDownloadElapsed / 10 wantedUploadElapsed -= wantedDownloadElapsed / 10
wantedDownloadElapsed -= wantedDownloadElapsed / 10 wantedDownloadElapsed -= wantedDownloadElapsed / 10
conn := NewBaseConnection("id", ProtocolSCP, u) conn := NewBaseConnection("id", ProtocolSCP, "", u)
transfer := NewBaseTransfer(nil, conn, nil, "", "", "", TransferUpload, 0, 0, 0, true, fs) transfer := NewBaseTransfer(nil, conn, nil, "", "", "", TransferUpload, 0, 0, 0, true, fs)
transfer.BytesReceived = testFileSize transfer.BytesReceived = testFileSize
transfer.Connection.UpdateLastActivity() transfer.Connection.UpdateLastActivity()
@ -95,7 +95,7 @@ func TestRealPath(t *testing.T) {
u.Permissions["/"] = []string{dataprovider.PermAny} u.Permissions["/"] = []string{dataprovider.PermAny}
file, err := os.Create(testFile) file, err := os.Create(testFile)
require.NoError(t, err) require.NoError(t, err)
conn := NewBaseConnection(fs.ConnectionID(), ProtocolSFTP, u) conn := NewBaseConnection(fs.ConnectionID(), ProtocolSFTP, "", u)
transfer := NewBaseTransfer(file, conn, nil, testFile, testFile, "/transfer_test_file", TransferUpload, 0, 0, 0, true, fs) transfer := NewBaseTransfer(file, conn, nil, testFile, testFile, "/transfer_test_file", TransferUpload, 0, 0, 0, true, fs)
rPath := transfer.GetRealFsPath(testFile) rPath := transfer.GetRealFsPath(testFile)
assert.Equal(t, testFile, rPath) assert.Equal(t, testFile, rPath)
@ -130,7 +130,7 @@ func TestTruncate(t *testing.T) {
} }
_, err = file.Write([]byte("hello")) _, err = file.Write([]byte("hello"))
assert.NoError(t, err) assert.NoError(t, err)
conn := NewBaseConnection(fs.ConnectionID(), ProtocolSFTP, u) conn := NewBaseConnection(fs.ConnectionID(), ProtocolSFTP, "", u)
transfer := NewBaseTransfer(file, conn, nil, testFile, testFile, "/transfer_test_file", TransferUpload, 0, 5, 100, false, fs) transfer := NewBaseTransfer(file, conn, nil, testFile, testFile, "/transfer_test_file", TransferUpload, 0, 5, 100, false, fs)
err = conn.SetStat("/transfer_test_file", &StatAttributes{ err = conn.SetStat("/transfer_test_file", &StatAttributes{
@ -192,7 +192,7 @@ func TestTransferErrors(t *testing.T) {
if !assert.NoError(t, err) { if !assert.NoError(t, err) {
assert.FailNow(t, "unable to open test file") assert.FailNow(t, "unable to open test file")
} }
conn := NewBaseConnection("id", ProtocolSFTP, u) conn := NewBaseConnection("id", ProtocolSFTP, "", u)
transfer := NewBaseTransfer(file, conn, nil, testFile, testFile, "/transfer_test_file", TransferUpload, 0, 0, 0, true, fs) transfer := NewBaseTransfer(file, conn, nil, testFile, testFile, "/transfer_test_file", TransferUpload, 0, 0, 0, true, fs)
assert.Nil(t, transfer.cancelFn) assert.Nil(t, transfer.cancelFn)
assert.Equal(t, testFile, transfer.GetFsPath()) assert.Equal(t, testFile, transfer.GetFsPath())
@ -261,7 +261,7 @@ func TestRemovePartialCryptoFile(t *testing.T) {
Username: "test", Username: "test",
HomeDir: os.TempDir(), HomeDir: os.TempDir(),
} }
conn := NewBaseConnection(fs.ConnectionID(), ProtocolSFTP, u) conn := NewBaseConnection(fs.ConnectionID(), ProtocolSFTP, "", u)
transfer := NewBaseTransfer(nil, conn, nil, testFile, testFile, "/transfer_test_file", TransferUpload, 0, 0, 0, true, fs) transfer := NewBaseTransfer(nil, conn, nil, testFile, testFile, "/transfer_test_file", TransferUpload, 0, 0, 0, true, fs)
transfer.ErrTransfer = errors.New("test error") transfer.ErrTransfer = errors.New("test error")
_, err = transfer.getUploadFileSize() _, err = transfer.getUploadFileSize()

View file

@ -13,6 +13,7 @@ The logs can be divided into the following categories:
- `sender` string. `Upload` or `Download` - `sender` string. `Upload` or `Download`
- `time` string. Date/time with millisecond precision - `time` string. Date/time with millisecond precision
- `level` string - `level` string
- `remote_addr` string. IP and, optionally, port of the remote client. For example `127.0.0.1:1234` or `127.0.0.1`
- `elapsed_ms`, int64. Elapsed time, as milliseconds, for the upload/download - `elapsed_ms`, int64. Elapsed time, as milliseconds, for the upload/download
- `size_bytes`, int64. Size, as bytes, of the download/upload - `size_bytes`, int64. Size, as bytes, of the download/upload
- `username`, string - `username`, string
@ -22,6 +23,7 @@ The logs can be divided into the following categories:
- **"command logs"**, SFTP/SCP command logs: - **"command logs"**, SFTP/SCP command logs:
- `sender` string. `Rename`, `Rmdir`, `Mkdir`, `Symlink`, `Remove`, `Chmod`, `Chown`, `Chtimes`, `Truncate`, `SSHCommand` - `sender` string. `Rename`, `Rmdir`, `Mkdir`, `Symlink`, `Remove`, `Chmod`, `Chown`, `Chtimes`, `Truncate`, `SSHCommand`
- `level` string - `level` string
- `remote_addr` string. IP and, optionally, port of the remote client. For example `127.0.0.1:1234` or `127.0.0.1`
- `username`, string - `username`, string
- `file_path` string - `file_path` string
- `target_path` string - `target_path` string
@ -37,7 +39,7 @@ The logs can be divided into the following categories:
- **"http logs"**, REST API logs: - **"http logs"**, REST API logs:
- `sender` string. `httpd` - `sender` string. `httpd`
- `level` string - `level` string
- `remote_addr` string. IP and port of the remote client - `remote_addr` string. IP and, optionally, port of the remote client. For example `127.0.0.1:1234` or `127.0.0.1`
- `proto` string, for example `HTTP/1.1` - `proto` string, for example `HTTP/1.1`
- `method` string. HTTP method (`GET`, `POST`, `PUT`, `DELETE` etc.) - `method` string. HTTP method (`GET`, `POST`, `PUT`, `DELETE` etc.)
- `user_agent` string - `user_agent` string

View file

@ -513,7 +513,7 @@ func TestClientVersion(t *testing.T) {
connID := fmt.Sprintf("2_%v", mockCC.ID()) connID := fmt.Sprintf("2_%v", mockCC.ID())
user := dataprovider.User{} user := dataprovider.User{}
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, user), BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, "", user),
clientContext: mockCC, clientContext: mockCC,
} }
common.Connections.Add(connection) common.Connections.Add(connection)
@ -530,7 +530,7 @@ func TestDriverMethodsNotImplemented(t *testing.T) {
connID := fmt.Sprintf("2_%v", mockCC.ID()) connID := fmt.Sprintf("2_%v", mockCC.ID())
user := dataprovider.User{} user := dataprovider.User{}
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, user), BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, "", user),
clientContext: mockCC, clientContext: mockCC,
} }
_, err := connection.Create("") _, err := connection.Create("")
@ -555,7 +555,7 @@ func TestResolvePathErrors(t *testing.T) {
mockCC := mockFTPClientContext{} mockCC := mockFTPClientContext{}
connID := fmt.Sprintf("%v", mockCC.ID()) connID := fmt.Sprintf("%v", mockCC.ID())
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, user), BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, "", user),
clientContext: mockCC, clientContext: mockCC,
} }
err := connection.Mkdir("", os.ModePerm) err := connection.Mkdir("", os.ModePerm)
@ -618,7 +618,7 @@ func TestUploadFileStatError(t *testing.T) {
connID := fmt.Sprintf("%v", mockCC.ID()) connID := fmt.Sprintf("%v", mockCC.ID())
fs := vfs.NewOsFs(connID, user.HomeDir, "") fs := vfs.NewOsFs(connID, user.HomeDir, "")
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, user), BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, "", user),
clientContext: mockCC, clientContext: mockCC,
} }
testFile := filepath.Join(user.HomeDir, "test", "testfile") testFile := filepath.Join(user.HomeDir, "test", "testfile")
@ -646,7 +646,7 @@ func TestAVBLErrors(t *testing.T) {
mockCC := mockFTPClientContext{} mockCC := mockFTPClientContext{}
connID := fmt.Sprintf("%v", mockCC.ID()) connID := fmt.Sprintf("%v", mockCC.ID())
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, user), BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, "", user),
clientContext: mockCC, clientContext: mockCC,
} }
_, err := connection.GetAvailableSpace("/") _, err := connection.GetAvailableSpace("/")
@ -667,7 +667,7 @@ func TestUploadOverwriteErrors(t *testing.T) {
connID := fmt.Sprintf("%v", mockCC.ID()) connID := fmt.Sprintf("%v", mockCC.ID())
fs := newMockOsFs(nil, nil, false, connID, user.GetHomeDir()) fs := newMockOsFs(nil, nil, false, connID, user.GetHomeDir())
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, user), BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, "", user),
clientContext: mockCC, clientContext: mockCC,
} }
flags := 0 flags := 0
@ -721,7 +721,7 @@ func TestTransferErrors(t *testing.T) {
connID := fmt.Sprintf("%v", mockCC.ID()) connID := fmt.Sprintf("%v", mockCC.ID())
fs := newMockOsFs(nil, nil, false, connID, user.GetHomeDir()) fs := newMockOsFs(nil, nil, false, connID, user.GetHomeDir())
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, user), BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, "", user),
clientContext: mockCC, clientContext: mockCC,
} }
baseTransfer := common.NewBaseTransfer(file, connection.BaseConnection, nil, file.Name(), file.Name(), testfile, baseTransfer := common.NewBaseTransfer(file, connection.BaseConnection, nil, file.Name(), file.Name(), testfile,

View file

@ -155,7 +155,7 @@ func (s *Server) ClientConnected(cc ftpserver.ClientContext) (string, error) {
connID := fmt.Sprintf("%v_%v", s.ID, cc.ID()) connID := fmt.Sprintf("%v_%v", s.ID, cc.ID())
user := dataprovider.User{} user := dataprovider.User{}
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, user), BaseConnection: common.NewBaseConnection(connID, common.ProtocolFTP, cc.RemoteAddr().String(), user),
clientContext: cc, clientContext: cc,
} }
common.Connections.Add(connection) common.Connections.Add(connection)
@ -335,7 +335,7 @@ func (s *Server) validateUser(user dataprovider.User, cc ftpserver.ClientContext
return nil, err return nil, err
} }
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(fmt.Sprintf("%v_%v", s.ID, cc.ID()), common.ProtocolFTP, user), BaseConnection: common.NewBaseConnection(fmt.Sprintf("%v_%v", s.ID, cc.ID()), common.ProtocolFTP, remoteAddr, user),
clientContext: cc, clientContext: cc,
} }
err = common.Connections.Swap(connection) err = common.Connections.Swap(connection)

View file

@ -2540,7 +2540,7 @@ func TestCloseActiveConnection(t *testing.T) {
_, err := httpdtest.CloseConnection("non_existent_id", http.StatusNotFound) _, err := httpdtest.CloseConnection("non_existent_id", http.StatusNotFound)
assert.NoError(t, err) assert.NoError(t, err)
user := getTestUser() user := getTestUser()
c := common.NewBaseConnection("connID", common.ProtocolSFTP, user) c := common.NewBaseConnection("connID", common.ProtocolSFTP, "", user)
fakeConn := &fakeConnection{ fakeConn := &fakeConnection{
BaseConnection: c, BaseConnection: c,
} }
@ -2553,12 +2553,12 @@ func TestCloseActiveConnection(t *testing.T) {
func TestCloseConnectionAfterUserUpdateDelete(t *testing.T) { func TestCloseConnectionAfterUserUpdateDelete(t *testing.T) {
user, _, err := httpdtest.AddUser(getTestUser(), http.StatusCreated) user, _, err := httpdtest.AddUser(getTestUser(), http.StatusCreated)
assert.NoError(t, err) assert.NoError(t, err)
c := common.NewBaseConnection("connID", common.ProtocolFTP, user) c := common.NewBaseConnection("connID", common.ProtocolFTP, "", user)
fakeConn := &fakeConnection{ fakeConn := &fakeConnection{
BaseConnection: c, BaseConnection: c,
} }
common.Connections.Add(fakeConn) common.Connections.Add(fakeConn)
c1 := common.NewBaseConnection("connID1", common.ProtocolSFTP, user) c1 := common.NewBaseConnection("connID1", common.ProtocolSFTP, "", user)
fakeConn1 := &fakeConnection{ fakeConn1 := &fakeConnection{
BaseConnection: c1, BaseConnection: c1,
} }
@ -3236,7 +3236,7 @@ func TestLoaddataMode(t *testing.T) {
assert.Equal(t, int64(789), folder.LastQuotaUpdate) assert.Equal(t, int64(789), folder.LastQuotaUpdate)
assert.Len(t, folder.Users, 0) assert.Len(t, folder.Users, 0)
c := common.NewBaseConnection("connID", common.ProtocolFTP, user) c := common.NewBaseConnection("connID", common.ProtocolFTP, "", user)
fakeConn := &fakeConnection{ fakeConn := &fakeConnection{
BaseConnection: c, BaseConnection: c,
} }
@ -4628,7 +4628,7 @@ func TestWebClientMaxConnections(t *testing.T) {
// now add a fake connection // now add a fake connection
fs := vfs.NewOsFs("id", os.TempDir(), "") fs := vfs.NewOsFs("id", os.TempDir(), "")
connection := &httpd.Connection{ connection := &httpd.Connection{
BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolHTTP, user), BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolHTTP, "", user),
} }
common.Connections.Add(connection) common.Connections.Add(connection)
@ -4757,7 +4757,7 @@ func TestMaxSessions(t *testing.T) {
// now add a fake connection // now add a fake connection
fs := vfs.NewOsFs("id", os.TempDir(), "") fs := vfs.NewOsFs("id", os.TempDir(), "")
connection := &httpd.Connection{ connection := &httpd.Connection{
BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolHTTP, user), BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolHTTP, "", user),
} }
common.Connections.Add(connection) common.Connections.Add(connection)
_, err = getJWTWebClientTokenFromTestServer(defaultUsername, defaultPassword) _, err = getJWTWebClientTokenFromTestServer(defaultUsername, defaultPassword)

View file

@ -1146,7 +1146,7 @@ func TestCompressorAbortHandler(t *testing.T) {
}() }()
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(xid.New().String(), common.ProtocolHTTP, dataprovider.User{}), BaseConnection: common.NewBaseConnection(xid.New().String(), common.ProtocolHTTP, "", dataprovider.User{}),
request: nil, request: nil,
} }
renderCompressedFiles(&failingWriter{}, connection, "", nil) renderCompressedFiles(&failingWriter{}, connection, "", nil)
@ -1159,7 +1159,7 @@ func TestZipErrors(t *testing.T) {
user.Permissions = make(map[string][]string) user.Permissions = make(map[string][]string)
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(xid.New().String(), common.ProtocolHTTP, user), BaseConnection: common.NewBaseConnection(xid.New().String(), common.ProtocolHTTP, "", user),
request: nil, request: nil,
} }
@ -1371,7 +1371,7 @@ func TestConnection(t *testing.T) {
user.Permissions = make(map[string][]string) user.Permissions = make(map[string][]string)
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(xid.New().String(), common.ProtocolHTTP, user), BaseConnection: common.NewBaseConnection(xid.New().String(), common.ProtocolHTTP, "", user),
request: nil, request: nil,
} }
assert.Empty(t, connection.GetClientVersion()) assert.Empty(t, connection.GetClientVersion())
@ -1393,7 +1393,7 @@ func TestRenderDirError(t *testing.T) {
user.Permissions = make(map[string][]string) user.Permissions = make(map[string][]string)
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(xid.New().String(), common.ProtocolHTTP, user), BaseConnection: common.NewBaseConnection(xid.New().String(), common.ProtocolHTTP, "", user),
request: nil, request: nil,
} }
@ -1412,7 +1412,7 @@ func TestHTTPDFile(t *testing.T) {
user.Permissions = make(map[string][]string) user.Permissions = make(map[string][]string)
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(xid.New().String(), common.ProtocolHTTP, user), BaseConnection: common.NewBaseConnection(xid.New().String(), common.ProtocolHTTP, "", user),
request: nil, request: nil,
} }

View file

@ -286,7 +286,7 @@ func handleWebClientDownload(w http.ResponseWriter, r *http.Request) {
} }
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(xid.New().String(), common.ProtocolHTTP, user), BaseConnection: common.NewBaseConnection(xid.New().String(), common.ProtocolHTTP, r.RemoteAddr, user),
request: r, request: r,
} }
common.Connections.Add(connection) common.Connections.Add(connection)
@ -323,7 +323,7 @@ func handleClientGetDirContents(w http.ResponseWriter, r *http.Request) {
} }
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(xid.New().String(), common.ProtocolHTTP, user), BaseConnection: common.NewBaseConnection(xid.New().String(), common.ProtocolHTTP, r.RemoteAddr, user),
request: r, request: r,
} }
common.Connections.Add(connection) common.Connections.Add(connection)
@ -383,7 +383,7 @@ func handleClientGetFiles(w http.ResponseWriter, r *http.Request) {
return return
} }
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(connID, common.ProtocolHTTP, user), BaseConnection: common.NewBaseConnection(connID, common.ProtocolHTTP, r.RemoteAddr, user),
request: r, request: r,
} }
common.Connections.Add(connection) common.Connections.Add(connection)

View file

@ -237,10 +237,11 @@ func ErrorToConsole(format string, v ...interface{}) {
} }
// TransferLog logs uploads or downloads // TransferLog logs uploads or downloads
func TransferLog(operation string, path string, elapsed int64, size int64, user string, connectionID string, protocol string) { func TransferLog(operation, path string, elapsed int64, size int64, user, connectionID, protocol, remoteAddr string) {
logger.Info(). logger.Info().
Timestamp(). Timestamp().
Str("sender", operation). Str("sender", operation).
Str("remote_addr", remoteAddr).
Int64("elapsed_ms", elapsed). Int64("elapsed_ms", elapsed).
Int64("size_bytes", size). Int64("size_bytes", size).
Str("username", user). Str("username", user).
@ -252,10 +253,11 @@ func TransferLog(operation string, path string, elapsed int64, size int64, user
// CommandLog logs an SFTP/SCP/SSH command // CommandLog logs an SFTP/SCP/SSH command
func CommandLog(command, path, target, user, fileMode, connectionID, protocol string, uid, gid int, atime, mtime, func CommandLog(command, path, target, user, fileMode, connectionID, protocol string, uid, gid int, atime, mtime,
sshCommand string, size int64) { sshCommand string, size int64, remoteAddr string) {
logger.Info(). logger.Info().
Timestamp(). Timestamp().
Str("sender", command). Str("sender", command).
Str("remote_addr", remoteAddr).
Str("username", user). Str("username", user).
Str("file_path", path). Str("file_path", path).
Str("target_path", target). Str("target_path", target).

View file

@ -33,6 +33,9 @@ func (c *Connection) GetClientVersion() string {
// GetRemoteAddress return the connected client's address // GetRemoteAddress return the connected client's address
func (c *Connection) GetRemoteAddress() string { func (c *Connection) GetRemoteAddress() string {
if c.RemoteAddr == nil {
return ""
}
return c.RemoteAddr.String() return c.RemoteAddr.String()
} }

View file

@ -158,7 +158,7 @@ func TestUploadResumeInvalidOffset(t *testing.T) {
Username: "testuser", Username: "testuser",
} }
fs := vfs.NewOsFs("", os.TempDir(), "") fs := vfs.NewOsFs("", os.TempDir(), "")
conn := common.NewBaseConnection("", common.ProtocolSFTP, user) conn := common.NewBaseConnection("", common.ProtocolSFTP, "", user)
baseTransfer := common.NewBaseTransfer(file, conn, nil, file.Name(), file.Name(), testfile, common.TransferUpload, 10, 0, 0, false, fs) baseTransfer := common.NewBaseTransfer(file, conn, nil, file.Name(), file.Name(), testfile, common.TransferUpload, 10, 0, 0, false, fs)
transfer := newTransfer(baseTransfer, nil, nil, nil) transfer := newTransfer(baseTransfer, nil, nil, nil)
_, err = transfer.WriteAt([]byte("test"), 0) _, err = transfer.WriteAt([]byte("test"), 0)
@ -186,7 +186,7 @@ func TestReadWriteErrors(t *testing.T) {
Username: "testuser", Username: "testuser",
} }
fs := vfs.NewOsFs("", os.TempDir(), "") fs := vfs.NewOsFs("", os.TempDir(), "")
conn := common.NewBaseConnection("", common.ProtocolSFTP, user) conn := common.NewBaseConnection("", common.ProtocolSFTP, "", user)
baseTransfer := common.NewBaseTransfer(file, conn, nil, file.Name(), file.Name(), testfile, common.TransferDownload, 0, 0, 0, false, fs) baseTransfer := common.NewBaseTransfer(file, conn, nil, file.Name(), file.Name(), testfile, common.TransferDownload, 0, 0, 0, false, fs)
transfer := newTransfer(baseTransfer, nil, nil, nil) transfer := newTransfer(baseTransfer, nil, nil, nil)
err = file.Close() err = file.Close()
@ -234,7 +234,7 @@ func TestReadWriteErrors(t *testing.T) {
} }
func TestUnsupportedListOP(t *testing.T) { func TestUnsupportedListOP(t *testing.T) {
conn := common.NewBaseConnection("", common.ProtocolSFTP, dataprovider.User{}) conn := common.NewBaseConnection("", common.ProtocolSFTP, "", dataprovider.User{})
sftpConn := Connection{ sftpConn := Connection{
BaseConnection: conn, BaseConnection: conn,
} }
@ -255,7 +255,7 @@ func TestTransferCancelFn(t *testing.T) {
Username: "testuser", Username: "testuser",
} }
fs := vfs.NewOsFs("", os.TempDir(), "") fs := vfs.NewOsFs("", os.TempDir(), "")
conn := common.NewBaseConnection("", common.ProtocolSFTP, user) conn := common.NewBaseConnection("", common.ProtocolSFTP, "", user)
baseTransfer := common.NewBaseTransfer(file, conn, cancelFn, file.Name(), file.Name(), testfile, common.TransferDownload, 0, 0, 0, false, fs) baseTransfer := common.NewBaseTransfer(file, conn, cancelFn, file.Name(), file.Name(), testfile, common.TransferDownload, 0, 0, 0, false, fs)
transfer := newTransfer(baseTransfer, nil, nil, nil) transfer := newTransfer(baseTransfer, nil, nil, nil)
@ -279,7 +279,7 @@ func TestUploadFiles(t *testing.T) {
fs := vfs.NewOsFs("123", os.TempDir(), "") fs := vfs.NewOsFs("123", os.TempDir(), "")
u := dataprovider.User{} u := dataprovider.User{}
c := Connection{ c := Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, u), BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", u),
} }
var flags sftp.FileOpenFlags var flags sftp.FileOpenFlags
flags.Write = true flags.Write = true
@ -331,7 +331,7 @@ func TestWithInvalidHome(t *testing.T) {
fs, err := u.GetFilesystem("123") fs, err := u.GetFilesystem("123")
assert.NoError(t, err) assert.NoError(t, err)
c := Connection{ c := Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, u), BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", u),
} }
_, err = fs.ResolvePath("../upper_path") _, err = fs.ResolvePath("../upper_path")
assert.Error(t, err, "tested path is not a home subdir") assert.Error(t, err, "tested path is not a home subdir")
@ -366,7 +366,7 @@ func TestSFTPGetUsedQuota(t *testing.T) {
u.Permissions = make(map[string][]string) u.Permissions = make(map[string][]string)
u.Permissions["/"] = []string{dataprovider.PermAny} u.Permissions["/"] = []string{dataprovider.PermAny}
connection := Connection{ connection := Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, u), BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", u),
} }
quotaResult := connection.HasSpace(false, false, "/") quotaResult := connection.HasSpace(false, false, "/")
assert.False(t, quotaResult.HasSpace) assert.False(t, quotaResult.HasSpace)
@ -463,7 +463,7 @@ func TestSSHCommandErrors(t *testing.T) {
user.Permissions = make(map[string][]string) user.Permissions = make(map[string][]string)
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
connection := Connection{ connection := Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSSH, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSSH, "", user),
channel: &mockSSHChannel, channel: &mockSSHChannel,
} }
cmd := sshCommand{ cmd := sshCommand{
@ -601,7 +601,7 @@ func TestCommandsWithExtensionsFilter(t *testing.T) {
} }
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSSH, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSSH, "", user),
channel: &mockSSHChannel, channel: &mockSSHChannel,
} }
cmd := sshCommand{ cmd := sshCommand{
@ -662,7 +662,7 @@ func TestSSHCommandsRemoteFs(t *testing.T) {
}, },
} }
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", user),
channel: &mockSSHChannel, channel: &mockSSHChannel,
} }
cmd := sshCommand{ cmd := sshCommand{
@ -707,7 +707,7 @@ func TestSSHCmdGetFsErrors(t *testing.T) {
user.Permissions = map[string][]string{} user.Permissions = map[string][]string{}
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", user),
channel: &mockSSHChannel, channel: &mockSSHChannel,
} }
cmd := sshCommand{ cmd := sshCommand{
@ -758,7 +758,7 @@ func TestGitVirtualFolders(t *testing.T) {
HomeDir: os.TempDir(), HomeDir: os.TempDir(),
} }
conn := &Connection{ conn := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", user),
} }
cmd := sshCommand{ cmd := sshCommand{
command: "git-receive-pack", command: "git-receive-pack",
@ -804,7 +804,7 @@ func TestRsyncOptions(t *testing.T) {
HomeDir: os.TempDir(), HomeDir: os.TempDir(),
} }
conn := &Connection{ conn := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", user),
} }
sshCmd := sshCommand{ sshCmd := sshCommand{
command: "rsync", command: "rsync",
@ -821,7 +821,7 @@ func TestRsyncOptions(t *testing.T) {
user.Permissions = permissions user.Permissions = permissions
conn = &Connection{ conn = &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", user),
} }
sshCmd = sshCommand{ sshCmd = sshCommand{
command: "rsync", command: "rsync",
@ -853,7 +853,7 @@ func TestSystemCommandSizeForPath(t *testing.T) {
fs, err := user.GetFilesystem("123") fs, err := user.GetFilesystem("123")
assert.NoError(t, err) assert.NoError(t, err)
conn := &Connection{ conn := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", user),
} }
sshCmd := sshCommand{ sshCmd := sshCommand{
command: "rsync", command: "rsync",
@ -915,7 +915,7 @@ func TestSystemCommandErrors(t *testing.T) {
fs, err := user.GetFilesystem("123") fs, err := user.GetFilesystem("123")
assert.NoError(t, err) assert.NoError(t, err)
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", user),
channel: &mockSSHChannel, channel: &mockSSHChannel,
} }
var sshCmd sshCommand var sshCmd sshCommand
@ -991,7 +991,7 @@ func TestCommandGetFsError(t *testing.T) {
}, },
} }
conn := &Connection{ conn := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", user),
} }
sshCmd := sshCommand{ sshCmd := sshCommand{
command: "rsync", command: "rsync",
@ -1009,7 +1009,7 @@ func TestCommandGetFsError(t *testing.T) {
ReadError: nil, ReadError: nil,
} }
conn = &Connection{ conn = &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, "", user),
channel: &mockSSHChannel, channel: &mockSSHChannel,
} }
scpCommand := scpCommand{ scpCommand := scpCommand{
@ -1101,7 +1101,7 @@ func TestSCPUploadError(t *testing.T) {
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", user),
channel: &mockSSHChannel, channel: &mockSSHChannel,
} }
scpCommand := scpCommand{ scpCommand := scpCommand{
@ -1140,7 +1140,7 @@ func TestSCPInvalidEndDir(t *testing.T) {
StdErrBuffer: bytes.NewBuffer(stdErrBuf), StdErrBuffer: bytes.NewBuffer(stdErrBuf),
} }
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, dataprovider.User{ BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", dataprovider.User{
HomeDir: os.TempDir(), HomeDir: os.TempDir(),
}), }),
channel: &mockSSHChannel, channel: &mockSSHChannel,
@ -1166,7 +1166,7 @@ func TestSCPParseUploadMessage(t *testing.T) {
} }
fs := vfs.NewOsFs("", os.TempDir(), "") fs := vfs.NewOsFs("", os.TempDir(), "")
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, dataprovider.User{ BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", dataprovider.User{
HomeDir: os.TempDir(), HomeDir: os.TempDir(),
}), }),
channel: &mockSSHChannel, channel: &mockSSHChannel,
@ -1203,7 +1203,7 @@ func TestSCPProtocolMessages(t *testing.T) {
WriteError: writeErr, WriteError: writeErr,
} }
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, dataprovider.User{}), BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, "", dataprovider.User{}),
channel: &mockSSHChannel, channel: &mockSSHChannel,
} }
scpCommand := scpCommand{ scpCommand := scpCommand{
@ -1264,7 +1264,7 @@ func TestSCPTestDownloadProtocolMessages(t *testing.T) {
WriteError: writeErr, WriteError: writeErr,
} }
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, dataprovider.User{}), BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, "", dataprovider.User{}),
channel: &mockSSHChannel, channel: &mockSSHChannel,
} }
scpCommand := scpCommand{ scpCommand := scpCommand{
@ -1338,7 +1338,7 @@ func TestSCPCommandHandleErrors(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
}() }()
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, dataprovider.User{}), BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, "", dataprovider.User{}),
channel: &mockSSHChannel, channel: &mockSSHChannel,
} }
scpCommand := scpCommand{ scpCommand := scpCommand{
@ -1379,7 +1379,7 @@ func TestSCPErrorsMockFs(t *testing.T) {
}() }()
connection := &Connection{ connection := &Connection{
channel: &mockSSHChannel, channel: &mockSSHChannel,
BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, u), BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, "", u),
} }
scpCommand := scpCommand{ scpCommand := scpCommand{
sshCommand: sshCommand{ sshCommand: sshCommand{
@ -1421,7 +1421,7 @@ func TestSCPRecursiveDownloadErrors(t *testing.T) {
}() }()
fs := vfs.NewOsFs("123", os.TempDir(), "") fs := vfs.NewOsFs("123", os.TempDir(), "")
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, dataprovider.User{ BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, "", dataprovider.User{
HomeDir: os.TempDir(), HomeDir: os.TempDir(),
}), }),
channel: &mockSSHChannel, channel: &mockSSHChannel,
@ -1467,7 +1467,7 @@ func TestSCPRecursiveUploadErrors(t *testing.T) {
WriteError: writeErr, WriteError: writeErr,
} }
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, dataprovider.User{}), BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, "", dataprovider.User{}),
channel: &mockSSHChannel, channel: &mockSSHChannel,
} }
scpCommand := scpCommand{ scpCommand := scpCommand{
@ -1508,7 +1508,7 @@ func TestSCPCreateDirs(t *testing.T) {
fs, err := u.GetFilesystem("123") fs, err := u.GetFilesystem("123")
assert.NoError(t, err) assert.NoError(t, err)
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, u), BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, "", u),
channel: &mockSSHChannel, channel: &mockSSHChannel,
} }
scpCommand := scpCommand{ scpCommand := scpCommand{
@ -1542,7 +1542,7 @@ func TestSCPDownloadFileData(t *testing.T) {
} }
fs := vfs.NewOsFs("", os.TempDir(), "") fs := vfs.NewOsFs("", os.TempDir(), "")
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, dataprovider.User{HomeDir: os.TempDir()}), BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, "", dataprovider.User{HomeDir: os.TempDir()}),
channel: &mockSSHChannelReadErr, channel: &mockSSHChannelReadErr,
} }
scpCommand := scpCommand{ scpCommand := scpCommand{
@ -1592,7 +1592,7 @@ func TestSCPUploadFiledata(t *testing.T) {
} }
fs := vfs.NewOsFs("", os.TempDir(), "") fs := vfs.NewOsFs("", os.TempDir(), "")
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, "", user),
channel: &mockSSHChannel, channel: &mockSSHChannel,
} }
scpCommand := scpCommand{ scpCommand := scpCommand{
@ -1681,7 +1681,7 @@ func TestUploadError(t *testing.T) {
} }
fs := vfs.NewOsFs("", os.TempDir(), "") fs := vfs.NewOsFs("", os.TempDir(), "")
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSCP, "", user),
} }
testfile := "testfile" testfile := "testfile"
@ -1725,7 +1725,7 @@ func TestTransferFailingReader(t *testing.T) {
fs := newMockOsFs(nil, nil, true, "", os.TempDir()) fs := newMockOsFs(nil, nil, true, "", os.TempDir())
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", user),
} }
request := sftp.NewRequest("Open", "afile.txt") request := sftp.NewRequest("Open", "afile.txt")
@ -1884,7 +1884,7 @@ func TestRecursiveCopyErrors(t *testing.T) {
fs, err := user.GetFilesystem("123") fs, err := user.GetFilesystem("123")
assert.NoError(t, err) assert.NoError(t, err)
conn := &Connection{ conn := &Connection{
BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, user), BaseConnection: common.NewBaseConnection("", common.ProtocolSFTP, "", user),
} }
sshCmd := sshCommand{ sshCmd := sshCommand{
command: "sftpgo-copy", command: "sftpgo-copy",
@ -1933,7 +1933,7 @@ func TestRecoverer(t *testing.T) {
c.AcceptInboundConnection(nil, nil) c.AcceptInboundConnection(nil, nil)
connID := "connectionID" connID := "connectionID"
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(connID, common.ProtocolSFTP, dataprovider.User{}), BaseConnection: common.NewBaseConnection(connID, common.ProtocolSFTP, "", dataprovider.User{}),
} }
c.handleSftpConnection(nil, connection) c.handleSftpConnection(nil, connection)
sshCmd := sshCommand{ sshCmd := sshCommand{

View file

@ -460,7 +460,7 @@ func (c *Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Serve
if string(req.Payload[4:]) == "sftp" { if string(req.Payload[4:]) == "sftp" {
ok = true ok = true
connection := Connection{ connection := Connection{
BaseConnection: common.NewBaseConnection(connID, common.ProtocolSFTP, user), BaseConnection: common.NewBaseConnection(connID, common.ProtocolSFTP, conn.RemoteAddr().String(), user),
ClientVersion: string(sconn.ClientVersion()), ClientVersion: string(sconn.ClientVersion()),
RemoteAddr: conn.RemoteAddr(), RemoteAddr: conn.RemoteAddr(),
channel: channel, channel: channel,
@ -470,7 +470,7 @@ func (c *Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Serve
case "exec": case "exec":
// protocol will be set later inside processSSHCommand it could be SSH or SCP // protocol will be set later inside processSSHCommand it could be SSH or SCP
connection := Connection{ connection := Connection{
BaseConnection: common.NewBaseConnection(connID, "sshd_exec", user), BaseConnection: common.NewBaseConnection(connID, "sshd_exec", conn.RemoteAddr().String(), user),
ClientVersion: string(sconn.ClientVersion()), ClientVersion: string(sconn.ClientVersion()),
RemoteAddr: conn.RemoteAddr(), RemoteAddr: conn.RemoteAddr(),
channel: channel, channel: channel,

View file

@ -726,9 +726,6 @@ func (c *sshCommand) sendExitStatus(err error) {
status = uint32(1) status = uint32(1)
c.connection.Log(logger.LevelWarn, "command failed: %#v args: %v user: %v err: %v", c.connection.Log(logger.LevelWarn, "command failed: %#v args: %v user: %v err: %v",
c.command, c.args, c.connection.User.Username, err) c.command, c.args, c.connection.User.Username, err)
} else {
logger.CommandLog(sshCommandLogSender, cmdPath, targetPath, c.connection.User.Username, "", c.connection.ID,
common.ProtocolSSH, -1, -1, "", "", c.connection.command, -1)
} }
exitStatus := sshSubsystemExitStatus{ exitStatus := sshSubsystemExitStatus{
Status: status, Status: status,
@ -753,6 +750,10 @@ func (c *sshCommand) sendExitStatus(err error) {
} }
common.ExecuteActionNotification(&c.connection.User, common.OperationSSHCmd, cmdPath, c.getDestPath(), targetPath, c.command, common.ExecuteActionNotification(&c.connection.User, common.OperationSSHCmd, cmdPath, c.getDestPath(), targetPath, c.command,
common.ProtocolSSH, 0, err) common.ProtocolSSH, 0, err)
if err == nil {
logger.CommandLog(sshCommandLogSender, cmdPath, targetPath, c.connection.User.Username, "", c.connection.ID,
common.ProtocolSSH, -1, -1, "", "", c.connection.command, -1, c.connection.GetRemoteAddress())
}
} }
} }

View file

@ -46,7 +46,7 @@ func ServeSubSystemConnection(user *dataprovider.User, connectionID string, read
dataprovider.UpdateLastLogin(user) //nolint:errcheck dataprovider.UpdateLastLogin(user) //nolint:errcheck
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(connectionID, common.ProtocolSFTP, *user), BaseConnection: common.NewBaseConnection(connectionID, common.ProtocolSFTP, "", *user),
ClientVersion: "", ClientVersion: "",
RemoteAddr: &net.IPAddr{}, RemoteAddr: &net.IPAddr{},
channel: newSubsystemChannel(reader, writer), channel: newSubsystemChannel(reader, writer),

View file

@ -334,7 +334,7 @@ func TestOrderDirsToRemove(t *testing.T) {
user := dataprovider.User{} user := dataprovider.User{}
fs := vfs.NewOsFs("id", os.TempDir(), "") fs := vfs.NewOsFs("id", os.TempDir(), "")
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, user), BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, "", user),
request: nil, request: nil,
} }
dirsToRemove := []objectMapping{} dirsToRemove := []objectMapping{}
@ -498,7 +498,7 @@ func TestResolvePathErrors(t *testing.T) {
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
fs := vfs.NewOsFs("connID", user.HomeDir, "") fs := vfs.NewOsFs("connID", user.HomeDir, "")
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, user), BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, "", user),
} }
err := connection.Mkdir(ctx, "", os.ModePerm) err := connection.Mkdir(ctx, "", os.ModePerm)
@ -567,7 +567,7 @@ func TestFileAccessErrors(t *testing.T) {
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
fs := vfs.NewOsFs("connID", user.HomeDir, "") fs := vfs.NewOsFs("connID", user.HomeDir, "")
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, user), BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, "", user),
} }
missingPath := "missing path" missingPath := "missing path"
fsMissingPath := filepath.Join(user.HomeDir, missingPath) fsMissingPath := filepath.Join(user.HomeDir, missingPath)
@ -628,7 +628,7 @@ func TestRemoveDirTree(t *testing.T) {
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
fs := vfs.NewOsFs("connID", user.HomeDir, "") fs := vfs.NewOsFs("connID", user.HomeDir, "")
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, user), BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, "", user),
} }
vpath := path.Join("adir", "missing") vpath := path.Join("adir", "missing")
@ -679,7 +679,7 @@ func TestContentType(t *testing.T) {
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
fs := vfs.NewOsFs("connID", user.HomeDir, "") fs := vfs.NewOsFs("connID", user.HomeDir, "")
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, user), BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, "", user),
} }
testFilePath := filepath.Join(user.HomeDir, testFile) testFilePath := filepath.Join(user.HomeDir, testFile)
ctx := context.Background() ctx := context.Background()
@ -728,7 +728,7 @@ func TestTransferReadWriteErrors(t *testing.T) {
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
fs := vfs.NewOsFs("connID", user.HomeDir, "") fs := vfs.NewOsFs("connID", user.HomeDir, "")
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, user), BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, "", user),
} }
testFilePath := filepath.Join(user.HomeDir, testFile) testFilePath := filepath.Join(user.HomeDir, testFile)
baseTransfer := common.NewBaseTransfer(nil, connection.BaseConnection, nil, testFilePath, testFilePath, testFile, baseTransfer := common.NewBaseTransfer(nil, connection.BaseConnection, nil, testFilePath, testFilePath, testFile,
@ -821,7 +821,7 @@ func TestTransferSeek(t *testing.T) {
user.Permissions["/"] = []string{dataprovider.PermAny} user.Permissions["/"] = []string{dataprovider.PermAny}
fs := vfs.NewOsFs("connID", user.HomeDir, "") fs := vfs.NewOsFs("connID", user.HomeDir, "")
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, user), BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, "", user),
} }
testFilePath := filepath.Join(user.HomeDir, testFile) testFilePath := filepath.Join(user.HomeDir, testFile)
testFileContents := []byte("content") testFileContents := []byte("content")

View file

@ -204,7 +204,7 @@ func (s *webDavServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx = context.WithValue(ctx, requestStartKey, time.Now()) ctx = context.WithValue(ctx, requestStartKey, time.Now())
connection := &Connection{ connection := &Connection{
BaseConnection: common.NewBaseConnection(connectionID, common.ProtocolWebDAV, user), BaseConnection: common.NewBaseConnection(connectionID, common.ProtocolWebDAV, r.RemoteAddr, user),
request: r, request: r,
} }
common.Connections.Add(connection) common.Connections.Add(connection)

View file

@ -1029,7 +1029,7 @@ func TestMaxConnections(t *testing.T) {
// now add a fake connection // now add a fake connection
fs := vfs.NewOsFs("id", os.TempDir(), "") fs := vfs.NewOsFs("id", os.TempDir(), "")
connection := &webdavd.Connection{ connection := &webdavd.Connection{
BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, user), BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, "", user),
} }
common.Connections.Add(connection) common.Connections.Add(connection)
assert.Error(t, checkBasicFunc(client)) assert.Error(t, checkBasicFunc(client))
@ -1084,7 +1084,7 @@ func TestMaxSessions(t *testing.T) {
// now add a fake connection // now add a fake connection
fs := vfs.NewOsFs("id", os.TempDir(), "") fs := vfs.NewOsFs("id", os.TempDir(), "")
connection := &webdavd.Connection{ connection := &webdavd.Connection{
BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, user), BaseConnection: common.NewBaseConnection(fs.ConnectionID(), common.ProtocolWebDAV, "", user),
} }
common.Connections.Add(connection) common.Connections.Add(connection)
assert.Error(t, checkBasicFunc(client)) assert.Error(t, checkBasicFunc(client))