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.
This commit is contained in:
Nick Craig-Wood 2018-11-04 11:34:16 +00:00
parent 2466f4d152
commit 75a88de55c
2 changed files with 14 additions and 1 deletions

View File

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

View File

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