From 75a88de55c8bee555b6f0595736a43b2e8204a60 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 4 Nov 2018 11:34:16 +0000 Subject: [PATCH] rc/rcserver: with --rc-files if auth set, pass on to URL opened If `--rc-user` or `--rc-pass` is set then the URL that is opened with `--rc-files` will have the authorization in the URL in the `http://user:pass@localhost/` style. --- docs/content/rc.md | 4 ++++ fs/rc/rcserver/rcserver.go | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/content/rc.md b/docs/content/rc.md index c2a4ca7e5..9aeaaea27 100644 --- a/docs/content/rc.md +++ b/docs/content/rc.md @@ -79,6 +79,10 @@ If this is set then rclone will serve the files in that directory. It will also open the root in the web browser if specified. This is for implementing browser based GUIs for rclone functions. +If `--rc-user` or `--rc-pass` is set then the URL that is opened will +have the authorization in the URL in the `http://user:pass@localhost/` +style. + Default Off. ### --rc-no-auth diff --git a/fs/rc/rcserver/rcserver.go b/fs/rc/rcserver/rcserver.go index e8d187031..b52718e2f 100644 --- a/fs/rc/rcserver/rcserver.go +++ b/fs/rc/rcserver/rcserver.go @@ -69,7 +69,16 @@ func (s *Server) Serve() error { fs.Logf(nil, "Serving remote control on %s", s.URL()) // Open the files in the browser if set if s.files != nil { - _ = open.Start(s.URL()) + openURL, err := url.Parse(s.URL()) + if err != nil { + return errors.Wrap(err, "invalid serving URL") + } + // Add username, password into the URL if they are set + user, pass := s.opt.HTTPOptions.BasicUser, s.opt.HTTPOptions.BasicPass + if user != "" || pass != "" { + openURL.User = url.UserPassword(user, pass) + } + _ = open.Start(openURL.String()) } return nil }