actions: add pre-download and pre-upload

Downloads and uploads can be denied based on hook response
This commit is contained in:
Nicola Murino
2021-05-26 07:48:37 +02:00
parent 600268ebb8
commit 25a44030f9
24 changed files with 710 additions and 176 deletions

View File

@@ -74,17 +74,17 @@ func (c *Connection) ReadDir(name string) ([]os.FileInfo, error) {
return c.ListDir(name)
}
func (c *Connection) getFileReader(name string, offset int64) (io.ReadCloser, error) {
func (c *Connection) getFileReader(name string, offset int64, method string) (io.ReadCloser, error) {
c.UpdateLastActivity()
name = utils.CleanPath(name)
if !c.User.HasPerm(dataprovider.PermDownload, path.Dir(name)) {
return nil, os.ErrPermission
return nil, c.GetPermissionDeniedError()
}
if !c.User.IsFileAllowed(name) {
c.Log(logger.LevelWarn, "reading file %#v is not allowed", name)
return nil, os.ErrPermission
return nil, c.GetPermissionDeniedError()
}
fs, p, err := c.GetFsAndResolvedPath(name)
@@ -92,6 +92,13 @@ func (c *Connection) getFileReader(name string, offset int64) (io.ReadCloser, er
return nil, err
}
if method != http.MethodHead {
if err := common.ExecutePreAction(&c.User, common.OperationPreDownload, p, name, c.GetProtocol(), 0); err != nil {
c.Log(logger.LevelDebug, "download for file %#v denied by pre action: %v", name, err)
return nil, c.GetPermissionDeniedError()
}
}
file, r, cancelFn, err := fs.Open(p, offset)
if err != nil {
c.Log(logger.LevelWarn, "could not open file %#v for reading: %+v", p, err)