Allow others fuse option. (#19)

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
This commit is contained in:
Antonio Navarro Perez 2020-11-13 12:06:33 +01:00 committed by GitHub
parent bd81446da6
commit 2b33ec5f25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 18 deletions

View file

@ -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

View file

@ -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)

View file

@ -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"`

View file

@ -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")
}

View file

@ -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"