(msg []byte, filePath string, c *websocket.Conn, mt int)
| 17 | ) |
| 18 | |
| 19 | func processWebSocketMessage(msg []byte, filePath string, c *websocket.Conn, mt int) error { |
| 20 | var message types.EditorChange |
| 21 | var account types.Account = c.Locals("account").(types.Account) |
| 22 | |
| 23 | if err := json.Unmarshal(msg, &message); err != nil { |
| 24 | return err |
| 25 | } |
| 26 | |
| 27 | switch message.Type { |
| 28 | case "editor-change": |
| 29 | if !account.Permissions.Change { |
| 30 | permissionError, _ := json.Marshal(fiber.Map{ |
| 31 | "type": "error", |
| 32 | "error": "You don't have permission to change!", |
| 33 | }) |
| 34 | |
| 35 | c.WriteMessage(mt, permissionError) |
| 36 | return nil // Server doesn't care about permission errors |
| 37 | } |
| 38 | |
| 39 | utils.ScheduleDebouncedLog(account.Username, filePath) |
| 40 | |
| 41 | utils.SendToAllExclude(filePath, mt, msg, c) |
| 42 | return applyEditorChange(filePath, message.Change, &account) |
| 43 | case "change-path": |
| 44 | if !account.Permissions.ReadDirectories { |
| 45 | permissionError, _ := json.Marshal(fiber.Map{ |
| 46 | "type": "error", |
| 47 | "error": "You don't have permission to read-directories!", |
| 48 | }) |
| 49 | |
| 50 | c.WriteMessage(mt, permissionError) |
| 51 | return nil |
| 52 | } |
| 53 | |
| 54 | path := config.Config.GetScopedFolder(account.Scope) + "/" + message.Path |
| 55 | |
| 56 | if !utils.IsSafePath(path) { |
| 57 | c.Close() |
| 58 | return fmt.Errorf("path traversal security issue") |
| 59 | } |
| 60 | |
| 61 | fileStat, err := os.Stat(path) |
| 62 | if err != nil { |
| 63 | c.Close() |
| 64 | return fmt.Errorf("unknown error") |
| 65 | } |
| 66 | |
| 67 | return utils.ChangePath(c, path, fileStat.IsDir()) |
| 68 | case "unzip": |
| 69 | if !account.Permissions.Extract { |
| 70 | permissionError, _ := json.Marshal(fiber.Map{ |
| 71 | "type": "error", |
| 72 | "error": "You don't have permission to unzip!", |
| 73 | }) |
| 74 | |
| 75 | c.WriteMessage(mt, permissionError) |
| 76 | return nil // Server doesn't care about permission errors |
no test coverage detected