Explorar el Código

sftpd stats: add file path for active upload/download

Nicola Murino hace 5 años
padre
commit
90607d4f86
Se han modificado 4 ficheros con 17 adiciones y 2 borrados
  1. 2 2
      README.md
  2. 3 0
      api/schema/openapi.yaml
  3. 10 0
      dataprovider/user.go
  4. 2 0
      sftpd/sftpd.go

+ 2 - 2
README.md

@@ -28,7 +28,7 @@ Regularly the test cases are manually executed and pass on Windows. Other UNIX v
 ## Requirements
 
 - Go 1.12 or higher
-- A suitable SQL server to use as data provider: PostreSQL (9+) or MySQL (4.1+) or SQLite 3.x
+- A suitable SQL server to use as data provider: PostreSQL (9+) or MySQL (5.6+) or SQLite 3.x
 
 ## Installation
 
@@ -89,7 +89,7 @@ If you don't configure any private host keys, the daemon will use `id_rsa` in th
 
 Before starting `sftpgo` a dataprovider must be configured.
 
-Sample SQL scripts to create the required database structure can be found insite the source tree [sql](https://github.com/drakkan/sftpgo/tree/master/sql "sql") directory. The SQL scripts filename's is, by convention, the date as `YYYYMMDD` and the suffix `.sql`. You need to apply all the SQL scripts for your database ordered by name, for example `20190706.sql` must be applied before `20190728.sql` and so on.
+Sample SQL scripts to create the required database structure can be found inside the source tree [sql](https://github.com/drakkan/sftpgo/tree/master/sql "sql") directory. The SQL scripts filename's is, by convention, the date as `YYYYMMDD` and the suffix `.sql`. You need to apply all the SQL scripts for your database ordered by name, for example `20190706.sql` must be applied before `20190728.sql` and so on.
 
 The `sftpgo` configuration file contains the following sections:
 

+ 3 - 0
api/schema/openapi.yaml

@@ -602,6 +602,9 @@ components:
           enum: 
             - upload
             - download
+        path:
+          type: string
+          description: SFTP file path for the upload/download
         start_time:
           type: integer
           format: int64

+ 10 - 0
dataprovider/user.go

@@ -110,3 +110,13 @@ func (u *User) GetHomeDir() string {
 func (u *User) HasQuotaRestrictions() bool {
 	return u.QuotaFiles > 0 || u.QuotaSize > 0
 }
+
+// GetRelativePath returns the path for a file relative to the user's home dir.
+// This is the path as seen by SFTP users
+func (u *User) GetRelativePath(path string) string {
+	rel, err := filepath.Rel(u.GetHomeDir(), path)
+	if err != nil {
+		return ""
+	}
+	return "/" + filepath.ToSlash(rel)
+}

+ 2 - 0
sftpd/sftpd.go

@@ -50,6 +50,7 @@ type connectionTransfer struct {
 	StartTime     int64  `json:"start_time"`
 	Size          int64  `json:"size"`
 	LastActivity  int64  `json:"last_activity"`
+	Path          string `json:"path"`
 }
 
 // ActiveQuotaScan defines an active quota scan
@@ -210,6 +211,7 @@ func GetConnectionsStats() []ConnectionStatus {
 					StartTime:     utils.GetTimeAsMsSinceEpoch(t.start),
 					Size:          size,
 					LastActivity:  utils.GetTimeAsMsSinceEpoch(t.lastActivity),
+					Path:          c.User.GetRelativePath(t.path),
 				}
 				conn.Transfers = append(conn.Transfers, connTransfer)
 			}