diff --git a/internal/app/handlers.go b/internal/app/handlers.go index 48619617..e992643a 100644 --- a/internal/app/handlers.go +++ b/internal/app/handlers.go @@ -970,7 +970,7 @@ func (app *App) integrationsGetFile(c *gin.Context) { reader, size, err := integrationProvider.Download(fileID) if err != nil { - log.Error(err) + log.Errorf("cannot download file %s, %v", fileID, err) c.AbortWithStatus(http.StatusInternalServerError) return } diff --git a/internal/integrations/localfs.go b/internal/integrations/localfs.go index 2470903c..e31ea648 100644 --- a/internal/integrations/localfs.go +++ b/internal/integrations/localfs.go @@ -8,7 +8,7 @@ import ( "github.com/ddvk/rmfakecloud/internal/messages" "github.com/ddvk/rmfakecloud/internal/model" - "github.com/sirupsen/logrus" + log "github.com/sirupsen/logrus" ) const ( @@ -63,7 +63,7 @@ func (d *localFS) List(folder string, depth int) (*messages.IntegrationFolder, e startPath := path.Clean(folder) - logrus.Info("[localfs] query for: ", startPath, " depth: ", depth) + log.Infof("[localfs] query for '%s' depth %d: ", startPath, depth) err := visitDir(d.rootPath, startPath, depth, response, func(s string) ([]fs.FileInfo, error) { di, err := os.ReadDir(s) @@ -74,7 +74,7 @@ func (d *localFS) List(folder string, depth int) (*messages.IntegrationFolder, e for _, d := range di { fi, err := d.Info() if err != nil { - logrus.Warnf("[localfs] cant get fileinfo %v", err) + log.Warnf("[localfs] cant get fileinfo %v", err) continue } result = append(result, fi) @@ -95,6 +95,7 @@ func (d *localFS) Download(fileID string) (io.ReadCloser, int64, error) { } localPath := path.Join(d.rootPath, path.Clean(decoded)) + log.Infof("[localfs] getting local file %s", localPath) st, err := os.Stat(localPath) if err != nil { @@ -115,11 +116,11 @@ func (d *localFS) Upload(folderID, name, fileType string, reader io.ReadCloser) } //TODO: more cleanup and checks filePath := path.Clean(path.Join(folder, name+"."+fileType)) - logrus.Trace(loggerfs, "Cleaned: ", filePath) + log.Trace(loggerfs, "Cleaned: ", filePath) fullPath := path.Join(d.rootPath, filePath) - logrus.Trace(loggerfs, "Uploading to: ", fullPath) + log.Trace(loggerfs, "Uploading to: ", fullPath) writer, err := os.Create(fullPath) if err != nil { return diff --git a/internal/model/user.go b/internal/model/user.go index b736ab0f..2f63afc8 100644 --- a/internal/model/user.go +++ b/internal/model/user.go @@ -64,22 +64,22 @@ type IntegrationConfig struct { Name string // WebDav // FTP - Username string - Password string - Address string + Username string `yaml:"username,omitempty"` + Password string `yaml:"password,omitempty"` + Address string `yaml:"address,omitempty"` // FTP - ActiveTransfers bool + ActiveTransfers bool `yaml:"activetransfers,omitempty"` // Insecure ignore TLS cert errors - Insecure bool + Insecure bool `yaml:"insecure,omitempty"` // Dropbox - Accesstoken string + Accesstoken string `yaml:"accesstoken,omitempty"` // Localfs - //TODO: experimental, security blah blah - Path string + // really dangerous as it allows path traversal + Path string `yaml:"path,omitempty"` } // GenPassword generates a new random password diff --git a/internal/ui/handlers.go b/internal/ui/handlers.go index bfc72e9f..b6d90d5f 100644 --- a/internal/ui/handlers.go +++ b/internal/ui/handlers.go @@ -42,7 +42,7 @@ func (app *ReactAppWrapper) register(c *gin.Context) { if client != "localhost" && client != "::1" && client != "127.0.0.1" { - c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "Registrations are closed"}) + c.AbortWithStatusJSON(http.StatusForbidden, viewmodel.NewErrorResponse("Registrations are closed")) return } @@ -179,7 +179,7 @@ func (app *ReactAppWrapper) changePassword(c *gin.Context) { if user.ID != uid { log.Error("Trying to change password for a different user.") - c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "cant do that"}) + c.AbortWithStatusJSON(http.StatusBadRequest, viewmodel.NewErrorResponse("cant do that")) return } @@ -188,7 +188,7 @@ func (app *ReactAppWrapper) changePassword(c *gin.Context) { if err != nil { log.Error(err) } - c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "Invalid email or password"}) + c.AbortWithStatusJSON(http.StatusBadRequest, viewmodel.NewErrorResponse("Invalid email or password")) return } @@ -213,14 +213,14 @@ func (app *ReactAppWrapper) newCode(c *gin.Context) { user, err := app.userStorer.GetUser(uid) if err != nil { log.Error("Unable to find user: ", err) - c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + c.AbortWithStatusJSON(http.StatusInternalServerError, viewmodel.NewErrorResponse(err.Error())) return } code, err := app.codeConnector.NewCode(user.ID) if err != nil { log.Error("Unable to generate new device code: ", err) - c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "Unable to generate new code"}) + c.AbortWithStatusJSON(http.StatusInternalServerError, viewmodel.NewErrorResponse("Unable to generate new code")) return } @@ -389,7 +389,7 @@ func (app *ReactAppWrapper) getAppUsers(c *gin.Context) { if err != nil { log.Error(err) - c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "Unable to get users."}) + c.AbortWithStatusJSON(http.StatusInternalServerError, viewmodel.NewErrorResponse("Unable to get users.")) return } @@ -537,7 +537,8 @@ func warnLocalfsEdition(c *gin.Context, int *model.IntegrationConfig) { c.AbortWithStatus(http.StatusInternalServerError) return } - c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "To avoid security issues with local directory integration, you have to manually edit your .userprofile file:\n\n" + string(s)}) + c.AbortWithStatusJSON(http.StatusForbidden, + viewmodel.NewErrorResponse("To avoid security issues with local directory integration, you have to manually edit your .userprofile file:\n\n" + string(s))) } func (app *ReactAppWrapper) createIntegration(c *gin.Context) { diff --git a/internal/ui/ui.go b/internal/ui/ui.go index e71524ed..1b1cd5cd 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -121,5 +121,5 @@ func (w ReactAppWrapper) Open(filepath string) (http.File, error) { return f, err } func badReq(c *gin.Context, message string) { - c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": message}) + c.AbortWithStatusJSON(http.StatusBadRequest, viewmodel.NewErrorResponse(message)) } diff --git a/internal/ui/viewmodel/models.go b/internal/ui/viewmodel/models.go index c7080d69..cef87882 100644 --- a/internal/ui/viewmodel/models.go +++ b/internal/ui/viewmodel/models.go @@ -31,6 +31,16 @@ type ChangeEmailForm struct { CurrentPassword string `json:"currentPassword"` } +// ErrorResponse +type ErrorResponse struct { + Error string `json:"error"` +} +func NewErrorResponse(errormsg string) ErrorResponse { + return ErrorResponse { + Error: errormsg, + } +} + // DocumentTree a tree of documents type DocumentTree struct { Entries []Entry