Track file upload activity

This commit is contained in:
DaneEveritt 2022-07-24 17:12:47 -04:00
parent c18e844689
commit e3ab241d7f
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
3 changed files with 8 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package router
import ( import (
"bufio" "bufio"
"context" "context"
"github.com/pterodactyl/wings/internal/models"
"io" "io"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
@ -600,6 +601,11 @@ func postServerUploadFiles(c *gin.Context) {
if err := handleFileUpload(p, s, header); err != nil { if err := handleFileUpload(p, s, header); err != nil {
NewServerError(err, s).Abort(c) NewServerError(err, s).Abort(c)
return return
} else {
s.SaveActivity(s.NewRequestActivity(token.UserUuid, c.Request.RemoteAddr), server.ActivityFileUploaded, models.ActivityMeta{
"file": header.Filename,
"directory": filepath.Clean(directory),
})
} }
} }
} }
@ -617,6 +623,5 @@ func handleFileUpload(p string, s *server.Server, header *multipart.FileHeader)
if err := s.Filesystem().Writefile(p, file); err != nil { if err := s.Filesystem().Writefile(p, file); err != nil {
return err return err
} }
return nil return nil
} }

View File

@ -8,6 +8,7 @@ type UploadPayload struct {
jwt.Payload jwt.Payload
ServerUuid string `json:"server_uuid"` ServerUuid string `json:"server_uuid"`
UserUuid string `json:"user_uuid"`
UniqueId string `json:"unique_id"` UniqueId string `json:"unique_id"`
} }

View File

@ -17,6 +17,7 @@ const (
ActivitySftpCreateDirectory = models.Event("server:sftp.create-directory") ActivitySftpCreateDirectory = models.Event("server:sftp.create-directory")
ActivitySftpRename = models.Event("server:sftp.rename") ActivitySftpRename = models.Event("server:sftp.rename")
ActivitySftpDelete = models.Event("server:sftp.delete") ActivitySftpDelete = models.Event("server:sftp.delete")
ActivityFileUploaded = models.Event("server:file.uploaded")
) )
// RequestActivity is a wrapper around a LoggedEvent that is able to track additional request // RequestActivity is a wrapper around a LoggedEvent that is able to track additional request