From 2b33ec5f2516cfa59858e5ef8677a78149e26c2e Mon Sep 17 00:00:00 2001 From: Antonio Navarro Perez Date: Fri, 13 Nov 2020 12:06:33 +0100 Subject: [PATCH] Allow others fuse option. (#19) Signed-off-by: Antonio Navarro Perez --- README.md | 11 ++++++----- cmd/distribyted/main.go | 19 +++++++++++++------ config/model.go | 5 +++-- fuse/handler.go | 19 ++++++++++++++----- templates/config_template.yaml | 2 ++ 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index e833a94..241b0b4 100644 --- a/README.md +++ b/README.md @@ -84,17 +84,18 @@ Run the program: `./distribyted-[VERSION]-[OS]-[ARCH]` Defaults are good enough for starters, but you can change them. Here is the output of `./distribyted -help`: -``` +```text NAME: distribyted - Torrent client with on-demand file downloading as a filesystem. USAGE: - distribyted-v0.3.0-linux-amd64 [global options] [arguments...] + distribyted [global options] [arguments...] GLOBAL OPTIONS: - --config value YAML file containing distribyted configuration. (default: "./distribyted-data/config.yaml") [$DISTRIBYTED_CONFIG] - --http-port value http port for web interface (default: 4444) [$DISTRIBYTED_HTTP_PORT] - --help, -h show help (default: false) + --config value YAML file containing distribyted configuration. (default: "./distribyted-data/config.yaml") [$DISTRIBYTED_CONFIG] + --http-port value HTTP port for web interface (default: 4444) [$DISTRIBYTED_HTTP_PORT] + --fuse-allow-other Allow other users to acces to all fuse mountpoints. You need to add user_allow_other flag to /etc/fuse.conf file. (default: false) [$DISTRIBYTED_FUSE_ALLOW_OTHER] + --help, -h show help (default: false) ``` ### Prerequisites on windows diff --git a/cmd/distribyted/main.go b/cmd/distribyted/main.go index cfa1a15..f7df776 100644 --- a/cmd/distribyted/main.go +++ b/cmd/distribyted/main.go @@ -19,8 +19,9 @@ import ( ) const ( - configFlag = "config" - portFlag = "http-port" + configFlag = "config" + fuseAllowOther = "fuse-allow-other" + portFlag = "http-port" ) func main() { @@ -38,12 +39,18 @@ func main() { Name: portFlag, Value: 4444, EnvVars: []string{"DISTRIBYTED_HTTP_PORT"}, - Usage: "http port for web interface", + Usage: "HTTP port for web interface", + }, + &cli.BoolFlag{ + Name: fuseAllowOther, + Value: false, + EnvVars: []string{"DISTRIBYTED_FUSE_ALLOW_OTHER"}, + Usage: "Allow other users to access all fuse mountpoints. You need to add user_allow_other flag to /etc/fuse.conf file.", }, }, Action: func(c *cli.Context) error { - err := load(c.String(configFlag), c.Int(portFlag)) + err := load(c.String(configFlag), c.Int(portFlag), c.Bool(fuseAllowOther)) return err }, @@ -63,7 +70,7 @@ func newCache(folder string) (*filecache.Cache, error) { return filecache.NewCache(folder) } -func load(configPath string, port int) error { +func load(configPath string, port int, fuseAllowOther bool) error { ch := config.NewHandler(configPath) conf, err := ch.Get() @@ -84,7 +91,7 @@ func load(configPath string, port int) error { } ss := stats.NewTorrent() - mountService := fuse.NewHandler(c, ss) + mountService := fuse.NewHandler(c, ss, fuseAllowOther) sigChan := make(chan os.Signal) signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) diff --git a/config/model.go b/config/model.go index c98c91f..97c1bee 100644 --- a/config/model.go +++ b/config/model.go @@ -9,8 +9,9 @@ type Root struct { } type MountPoint struct { - Path string `yaml:"path"` - Torrents []struct { + AllowOther bool `yaml:"fuse-allow-other,omitempty"` + Path string `yaml:"path"` + Torrents []struct { MagnetURI string `yaml:"magnetUri,omitempty"` TorrentPath string `yaml:"torrentPath,omitempty"` FolderName string `yaml:"folderName,omitempty"` diff --git a/fuse/handler.go b/fuse/handler.go index 2b9c63b..6f2fc8a 100644 --- a/fuse/handler.go +++ b/fuse/handler.go @@ -18,14 +18,17 @@ type Handler struct { c *torrent.Client s *stats.Torrent + fuseAllowOther bool + hosts map[string]*fuse.FileSystemHost } -func NewHandler(c *torrent.Client, s *stats.Torrent) *Handler { +func NewHandler(c *torrent.Client, s *stats.Torrent, fuseAllowOther bool) *Handler { return &Handler{ - c: c, - s: s, - hosts: make(map[string]*fuse.FileSystemHost), + c: c, + s: s, + fuseAllowOther: fuseAllowOther, + hosts: make(map[string]*fuse.FileSystemHost), } } @@ -76,7 +79,13 @@ func (s *Handler) Mount(mpc *config.MountPoint, ef config.EventFunc) error { // TODO improve error handling here go func() { - ok := host.Mount(mpc.Path, nil) + var config []string + + if mpc.AllowOther || s.fuseAllowOther { + config = append(config, "-o", "allow_other") + } + + ok := host.Mount(mpc.Path, config) if !ok { log.WithField("path", mpc.Path).Error("error trying to mount filesystem") } diff --git a/templates/config_template.yaml b/templates/config_template.yaml index bc48595..c7633d5 100644 --- a/templates/config_template.yaml +++ b/templates/config_template.yaml @@ -9,6 +9,8 @@ mountPoints: # Example mountpoint containing some multimedia files # For windows users: You can set here also a disk letter like X: or Z: - path: ./distribyted-data/mountpoints/multimedia + # Add this flag if you want to allow other users to access this fuse mountpoint. You need to add user_allow_other flag to /etc/fuse.conf file. + # fuse-allow-other: true torrents: # - torrentPath: /path/to/torrent/file.torrent - magnetUri: "magnet:?xt=urn:btih:c9e15763f722f23e98a29decdfae341b98d53056&dn=Cosmos+Laundromat&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fcosmos-laundromat.torrent"