parent
224151e814
commit
713e564a6e
2
file.go
2
file.go
|
@ -42,7 +42,7 @@ func getInfo(url *url.URL, c *FileManager, u *User) (*fileInfo, error) {
|
|||
var err error
|
||||
|
||||
i := &fileInfo{URL: c.PrefixURL + url.Path}
|
||||
i.VirtualPath = strings.Replace(url.Path, c.baseURL, "", 1)
|
||||
i.VirtualPath = strings.Replace(url.Path, c.BaseURL, "", 1)
|
||||
i.VirtualPath = strings.TrimPrefix(i.VirtualPath, "/")
|
||||
i.VirtualPath = "/" + i.VirtualPath
|
||||
|
||||
|
|
|
@ -22,13 +22,15 @@ type FileManager struct {
|
|||
Assets *assets
|
||||
|
||||
// BaseURL is the path where the GUI will be accessible. It musn't end with
|
||||
// a trailing slash and mustn't contain PrefixURL, if set.
|
||||
baseURL string
|
||||
// a trailing slash and mustn't contain PrefixURL, if set. Despite being
|
||||
// exported, it should only be manipulated using SetBaseURL function.
|
||||
BaseURL string
|
||||
|
||||
// WebDavURL is the path where the WebDAV will be accessible. It can be set to ""
|
||||
// in order to override the GUI and only use the WebDAV. It musn't end with
|
||||
// a trailing slash.
|
||||
webDavURL string
|
||||
// a trailing slash. Despite being exported, it should only be manipulated
|
||||
// using SetWebDavURL function.
|
||||
WebDavURL string
|
||||
|
||||
// PrefixURL is a part of the URL that is trimmed from the http.Request.URL before
|
||||
// it arrives to our handlers. It may be useful when using FileManager as a middleware
|
||||
|
@ -129,13 +131,13 @@ func New(scope string) *FileManager {
|
|||
// AbsoluteURL returns the actual URL where
|
||||
// File Manager interface can be accessed.
|
||||
func (m FileManager) AbsoluteURL() string {
|
||||
return m.PrefixURL + m.baseURL
|
||||
return m.PrefixURL + m.BaseURL
|
||||
}
|
||||
|
||||
// AbsoluteWebDavURL returns the actual URL
|
||||
// where WebDAV can be accessed.
|
||||
func (m FileManager) AbsoluteWebDavURL() string {
|
||||
return m.PrefixURL + m.webDavURL
|
||||
return m.PrefixURL + m.WebDavURL
|
||||
}
|
||||
|
||||
// SetBaseURL updates the BaseURL of a File Manager
|
||||
|
@ -144,7 +146,7 @@ func (m *FileManager) SetBaseURL(url string) {
|
|||
url = strings.TrimPrefix(url, "/")
|
||||
url = strings.TrimSuffix(url, "/")
|
||||
url = "/" + url
|
||||
m.baseURL = strings.TrimSuffix(url, "/")
|
||||
m.BaseURL = strings.TrimSuffix(url, "/")
|
||||
}
|
||||
|
||||
// SetWebDavURL updates the WebDavURL of a File Manager
|
||||
|
@ -153,11 +155,11 @@ func (m *FileManager) SetWebDavURL(url string) {
|
|||
url = strings.TrimPrefix(url, "/")
|
||||
url = strings.TrimSuffix(url, "/")
|
||||
|
||||
m.webDavURL = m.baseURL + "/" + url
|
||||
m.WebDavURL = m.BaseURL + "/" + url
|
||||
|
||||
// update base user webdav handler
|
||||
m.handler = &webdav.Handler{
|
||||
Prefix: m.webDavURL,
|
||||
Prefix: m.WebDavURL,
|
||||
FileSystem: m.fileSystem,
|
||||
LockSystem: webdav.NewMemLS(),
|
||||
}
|
||||
|
@ -166,7 +168,7 @@ func (m *FileManager) SetWebDavURL(url string) {
|
|||
// the new URL
|
||||
for _, u := range m.Users {
|
||||
u.handler = &webdav.Handler{
|
||||
Prefix: m.webDavURL,
|
||||
Prefix: m.WebDavURL,
|
||||
FileSystem: u.fileSystem,
|
||||
LockSystem: webdav.NewMemLS(),
|
||||
}
|
||||
|
@ -192,7 +194,7 @@ func (m *FileManager) SetScope(scope string, username string) error {
|
|||
u.fileSystem = webdav.Dir(u.scope)
|
||||
|
||||
u.handler = &webdav.Handler{
|
||||
Prefix: m.webDavURL,
|
||||
Prefix: m.WebDavURL,
|
||||
FileSystem: u.fileSystem,
|
||||
LockSystem: webdav.NewMemLS(),
|
||||
}
|
||||
|
|
10
http.go
10
http.go
|
@ -25,7 +25,7 @@ func (m *FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, er
|
|||
|
||||
// Checks if the URL matches the Assets URL. Returns the asset if the
|
||||
// method is GET and Status Forbidden otherwise.
|
||||
if matchURL(r.URL.Path, m.baseURL+assetsURL) {
|
||||
if matchURL(r.URL.Path, m.BaseURL+assetsURL) {
|
||||
if r.Method == http.MethodGet {
|
||||
return serveAssets(w, r, m)
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ func (m *FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, er
|
|||
}
|
||||
|
||||
// Checks if the request URL is for the WebDav server
|
||||
if matchURL(r.URL.Path, m.webDavURL) {
|
||||
if matchURL(r.URL.Path, m.WebDavURL) {
|
||||
return serveWebDAV(w, r, m, u)
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ func (m *FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, er
|
|||
w.Header().Set("x-xss-protection", "1; mode=block")
|
||||
|
||||
// Checks if the User is allowed to access this file
|
||||
if !u.Allowed(strings.TrimPrefix(r.URL.Path, m.baseURL)) {
|
||||
if !u.Allowed(strings.TrimPrefix(r.URL.Path, m.BaseURL)) {
|
||||
if r.Method == http.MethodGet {
|
||||
return htmlError(
|
||||
w, http.StatusForbidden,
|
||||
|
@ -119,7 +119,7 @@ func serveWebDAV(w http.ResponseWriter, r *http.Request, m *FileManager, u *User
|
|||
var err error
|
||||
|
||||
// Checks for user permissions relatively to this path.
|
||||
if !u.Allowed(strings.TrimPrefix(r.URL.Path, m.webDavURL)) {
|
||||
if !u.Allowed(strings.TrimPrefix(r.URL.Path, m.WebDavURL)) {
|
||||
return http.StatusForbidden, nil
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ func serveWebDAV(w http.ResponseWriter, r *http.Request, m *FileManager, u *User
|
|||
//
|
||||
// It was decided on https://github.com/hacdias/caddy-filemanager/issues/85
|
||||
// that GET, for collections, will return the same as PROPFIND method.
|
||||
path := strings.Replace(r.URL.Path, m.webDavURL, "", 1)
|
||||
path := strings.Replace(r.URL.Path, m.WebDavURL, "", 1)
|
||||
path = u.scope + "/" + path
|
||||
path = filepath.Clean(path)
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ const assetsURL = "/_internal"
|
|||
// Serve provides the needed assets for the front-end
|
||||
func serveAssets(w http.ResponseWriter, r *http.Request, m *FileManager) (int, error) {
|
||||
// gets the filename to be used with Assets function
|
||||
filename := strings.Replace(r.URL.Path, m.baseURL+assetsURL, "", 1)
|
||||
filename := strings.Replace(r.URL.Path, m.BaseURL+assetsURL, "", 1)
|
||||
|
||||
var file []byte
|
||||
var err error
|
||||
|
|
|
@ -77,7 +77,7 @@ func command(w http.ResponseWriter, r *http.Request, c *FileManager, u *User) (i
|
|||
}
|
||||
|
||||
// Gets the path and initializes a buffer.
|
||||
path := strings.Replace(r.URL.Path, c.baseURL, c.scope, 1)
|
||||
path := strings.Replace(r.URL.Path, c.BaseURL, c.scope, 1)
|
||||
path = filepath.Clean(path)
|
||||
buff := new(bytes.Buffer)
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ func serveListing(w http.ResponseWriter, r *http.Request, c *FileManager, u *Use
|
|||
URL: r.URL,
|
||||
}
|
||||
|
||||
cookieScope := c.baseURL
|
||||
cookieScope := c.BaseURL
|
||||
if cookieScope == "" {
|
||||
cookieScope = "/"
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ func search(w http.ResponseWriter, r *http.Request, c *FileManager, u *User) (in
|
|||
}
|
||||
|
||||
search = parseSearch(value)
|
||||
scope := strings.Replace(r.URL.Path, c.baseURL, "", 1)
|
||||
scope := strings.Replace(r.URL.Path, c.BaseURL, "", 1)
|
||||
scope = strings.TrimPrefix(scope, "/")
|
||||
scope = "/" + scope
|
||||
scope = u.scope + scope
|
||||
|
|
Loading…
Reference in New Issue