mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
Hopefully fix #
This commit is contained in:
parent
e03fa7eb0c
commit
5cb16ed8ae
@ -113,7 +113,7 @@
|
||||
|
||||
<!-- SCRIPTS -->
|
||||
<!-- User Data and Permissions; WebDavURL -->
|
||||
<script>var user = JSON.parse('{{ Marshal .User }}'), webdavURL = "{{.Config.FullWebDavURL}}", baseURL = "{{.Config.AbsoluteURL}}";</script>
|
||||
<script>var user = JSON.parse('{{ Marshal .User }}'), webdavURL = "{{.Config.AbsoluteURL}}{{.Config.WebDavURL}}", baseURL = "{{.Config.AbsoluteURL}}";</script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ace.js"></script>
|
||||
<script src="{{ .Config.AbsoluteURL }}/_filemanagerinternal/js/form2js.js"></script>
|
||||
<script src="{{ .Config.AbsoluteURL }}/_filemanagerinternal/js/application.js"></script>
|
||||
|
@ -16,8 +16,8 @@ import (
|
||||
// Config is a configuration for browsing in a particular path.
|
||||
type Config struct {
|
||||
*User
|
||||
PrefixURL string
|
||||
BaseURL string
|
||||
AbsoluteURL string
|
||||
AddrPath string
|
||||
Token string // Anti CSRF token
|
||||
HugoEnabled bool // Enables the Hugo plugin for File Manager
|
||||
@ -26,8 +26,8 @@ type Config struct {
|
||||
CurrentUser *User
|
||||
}
|
||||
|
||||
func (c Config) FullWebDavURL() string {
|
||||
return c.AbsoluteURL + c.WebDavURL
|
||||
func (c Config) AbsoluteURL() string {
|
||||
return c.PrefixURL + c.BaseURL
|
||||
}
|
||||
|
||||
// Rule is a dissalow/allow rule
|
||||
@ -235,13 +235,12 @@ func Parse(c *caddy.Controller) ([]Config, error) {
|
||||
}
|
||||
|
||||
caddyConf := httpserver.GetConfig(c)
|
||||
cfg.AbsoluteURL = strings.TrimSuffix(caddyConf.Addr.Path, "/") + "/" + cfg.BaseURL
|
||||
cfg.AbsoluteURL = strings.Replace(cfg.AbsoluteURL, "//", "/", -1)
|
||||
cfg.AbsoluteURL = strings.TrimSuffix(cfg.AbsoluteURL, "/")
|
||||
|
||||
cfg.PrefixURL = strings.TrimSuffix(caddyConf.Addr.Path, "/")
|
||||
cfg.AddrPath = strings.TrimSuffix(caddyConf.Addr.Path, "/")
|
||||
cfg.WebDavURL = "/" + strings.TrimPrefix(cfg.WebDavURL, "/")
|
||||
cfg.Handler = &webdav.Handler{
|
||||
Prefix: cfg.WebDavURL,
|
||||
Prefix: cfg.BaseURL + cfg.WebDavURL,
|
||||
FileSystem: cfg.FileSystem,
|
||||
LockSystem: webdav.NewMemLS(),
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ package filemanager
|
||||
import (
|
||||
e "errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/hacdias/caddy-filemanager/assets"
|
||||
@ -64,7 +65,7 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
|
||||
}
|
||||
|
||||
// Checks if the request URL is for the WebDav server
|
||||
if httpserver.Path(r.URL.Path).Matches(c.WebDavURL) {
|
||||
if httpserver.Path(r.URL.Path).Matches(c.BaseURL + c.WebDavURL) {
|
||||
// Checks for user permissions relatively to this PATH
|
||||
if !user.Allowed(strings.TrimPrefix(r.URL.Path, c.WebDavURL)) {
|
||||
return http.StatusForbidden, nil
|
||||
@ -83,6 +84,17 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
|
||||
|
||||
// Preprocess the PUT request if it's the case
|
||||
if r.Method == http.MethodPut {
|
||||
var urlp *url.URL
|
||||
urlp, err = url.Parse(strings.Replace(r.URL.String(), c.WebDavURL, "", 1))
|
||||
if err != nil {
|
||||
return code, err
|
||||
}
|
||||
|
||||
fi, code, err = file.GetInfo(urlp, c, user)
|
||||
if err != nil {
|
||||
return code, err
|
||||
}
|
||||
|
||||
if handlers.PreProccessPUT(w, r, c, user, fi) != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ func ServeListing(w http.ResponseWriter, r *http.Request, c *config.Config, u *c
|
||||
var err error
|
||||
|
||||
// Loads the content of the directory
|
||||
listing, err := file.GetListing(u, i.VirtualPath, c.AbsoluteURL+r.URL.Path)
|
||||
listing, err := file.GetListing(u, i.VirtualPath, c.PrefixURL+r.URL.Path)
|
||||
if err != nil {
|
||||
return errors.ErrorToHTTPCode(err, true), err
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ func PreProccessPUT(
|
||||
i *file.Info,
|
||||
) (err error) {
|
||||
var (
|
||||
data map[string]interface{}
|
||||
file []byte
|
||||
data = map[string]interface{}{}
|
||||
file = []byte{}
|
||||
kind string
|
||||
rawBuffer = new(bytes.Buffer)
|
||||
)
|
||||
@ -43,7 +43,7 @@ func PreProccessPUT(
|
||||
|
||||
switch kind {
|
||||
case "frontmatter-only":
|
||||
if file, err = ParseFrontMatterOnlyFile(data, i.Name()); err != nil {
|
||||
if file, err = ParseFrontMatterOnlyFile(data, i.FileInfo.Name()); err != nil {
|
||||
return
|
||||
}
|
||||
case "content-only":
|
||||
|
@ -67,10 +67,10 @@ func (i Info) BreadcrumbMap() map[string]string {
|
||||
func (i Info) PreviousLink() string {
|
||||
path := strings.TrimSuffix(i.Path, "/")
|
||||
path = strings.TrimPrefix(path, "/")
|
||||
path = i.Config.AbsoluteURL + "/" + path
|
||||
path = i.Config.AbsoluteURL() + "/" + path
|
||||
path = path[0 : len(path)-len(i.Name)]
|
||||
|
||||
if len(path) < len(i.Config.AbsoluteURL+"/") {
|
||||
if len(path) < len(i.Config.AbsoluteURL()+"/") {
|
||||
return ""
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user