unexport baseURL and webDavURL
							parent
							
								
									e6492286db
								
							
						
					
					
						commit
						b93158b291
					
				|  | @ -17,7 +17,7 @@ func handler(w http.ResponseWriter, r *http.Request) { | |||
| } | ||||
| 
 | ||||
| func main() { | ||||
| 	m = filemanager.New() | ||||
| 	m = filemanager.New("D:\\TEST") | ||||
| 	http.HandleFunc("/", handler) | ||||
| 	http.ListenAndServe(":8080", nil) | ||||
| } | ||||
|  |  | |||
|  | @ -20,19 +20,19 @@ type FileManager struct { | |||
| 	*user | ||||
| 	Assets *assets | ||||
| 
 | ||||
| 	// 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
 | ||||
| 	// such as in caddy-filemanager plugin. It musn't end with a trailing slash.
 | ||||
| 	PrefixURL string | ||||
| 
 | ||||
| 	// 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 | ||||
| 	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 | ||||
| 	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
 | ||||
| 	// such as in caddy-filemanager plugin. It musn't end with a trailing slash.
 | ||||
| 	PrefixURL string | ||||
| 
 | ||||
| 	// Users is a map with the different configurations for each user.
 | ||||
| 	Users map[string]*user | ||||
|  | @ -126,13 +126,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
 | ||||
|  | @ -141,7 +141,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
 | ||||
|  | @ -150,11 +150,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(), | ||||
| 	} | ||||
|  | @ -163,7 +163,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(), | ||||
| 		} | ||||
|  | @ -189,7 +189,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
								
								
								
								
							|  | @ -26,7 +26,7 @@ func (c *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, c.BaseURL+AssetsURL) { | ||||
| 	if matchURL(r.URL.Path, c.baseURL+AssetsURL) { | ||||
| 		if r.Method == http.MethodGet { | ||||
| 			return serveAssets(w, r, c) | ||||
| 		} | ||||
|  | @ -42,9 +42,9 @@ func (c *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, c.WebDavURL) { | ||||
| 	if matchURL(r.URL.Path, c.webDavURL) { | ||||
| 		// Checks for user permissions relatively to this PATH
 | ||||
| 		if !user.Allowed(strings.TrimPrefix(r.URL.Path, c.WebDavURL)) { | ||||
| 		if !user.Allowed(strings.TrimPrefix(r.URL.Path, c.webDavURL)) { | ||||
| 			return http.StatusForbidden, nil | ||||
| 		} | ||||
| 
 | ||||
|  | @ -58,7 +58,7 @@ func (c *FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, er | |||
| 			//
 | ||||
| 			// 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, c.WebDavURL, "", 1) | ||||
| 			path := strings.Replace(r.URL.Path, c.webDavURL, "", 1) | ||||
| 			path = user.scope + "/" + path | ||||
| 			path = filepath.Clean(path) | ||||
| 
 | ||||
|  | @ -110,7 +110,7 @@ func (c *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 !user.Allowed(strings.TrimPrefix(r.URL.Path, c.BaseURL)) { | ||||
| 	if !user.Allowed(strings.TrimPrefix(r.URL.Path, c.baseURL)) { | ||||
| 		if r.Method == http.MethodGet { | ||||
| 			return htmlError( | ||||
| 				w, http.StatusForbidden, | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
							
								
								
									
										2
									
								
								info.go
								
								
								
								
							
							
						
						
									
										2
									
								
								info.go
								
								
								
								
							|  | @ -37,7 +37,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 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Henrique Dias
						Henrique Dias