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 -->
|
<!-- SCRIPTS -->
|
||||||
<!-- User Data and Permissions; WebDavURL -->
|
<!-- 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="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/form2js.js"></script>
|
||||||
<script src="{{ .Config.AbsoluteURL }}/_filemanagerinternal/js/application.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.
|
// Config is a configuration for browsing in a particular path.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
*User
|
*User
|
||||||
|
PrefixURL string
|
||||||
BaseURL string
|
BaseURL string
|
||||||
AbsoluteURL string
|
|
||||||
AddrPath string
|
AddrPath string
|
||||||
Token string // Anti CSRF token
|
Token string // Anti CSRF token
|
||||||
HugoEnabled bool // Enables the Hugo plugin for File Manager
|
HugoEnabled bool // Enables the Hugo plugin for File Manager
|
||||||
@ -26,8 +26,8 @@ type Config struct {
|
|||||||
CurrentUser *User
|
CurrentUser *User
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) FullWebDavURL() string {
|
func (c Config) AbsoluteURL() string {
|
||||||
return c.AbsoluteURL + c.WebDavURL
|
return c.PrefixURL + c.BaseURL
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rule is a dissalow/allow rule
|
// Rule is a dissalow/allow rule
|
||||||
@ -235,13 +235,12 @@ func Parse(c *caddy.Controller) ([]Config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
caddyConf := httpserver.GetConfig(c)
|
caddyConf := httpserver.GetConfig(c)
|
||||||
cfg.AbsoluteURL = strings.TrimSuffix(caddyConf.Addr.Path, "/") + "/" + cfg.BaseURL
|
|
||||||
cfg.AbsoluteURL = strings.Replace(cfg.AbsoluteURL, "//", "/", -1)
|
cfg.PrefixURL = strings.TrimSuffix(caddyConf.Addr.Path, "/")
|
||||||
cfg.AbsoluteURL = strings.TrimSuffix(cfg.AbsoluteURL, "/")
|
|
||||||
cfg.AddrPath = strings.TrimSuffix(caddyConf.Addr.Path, "/")
|
cfg.AddrPath = strings.TrimSuffix(caddyConf.Addr.Path, "/")
|
||||||
cfg.WebDavURL = "/" + strings.TrimPrefix(cfg.WebDavURL, "/")
|
cfg.WebDavURL = "/" + strings.TrimPrefix(cfg.WebDavURL, "/")
|
||||||
cfg.Handler = &webdav.Handler{
|
cfg.Handler = &webdav.Handler{
|
||||||
Prefix: cfg.WebDavURL,
|
Prefix: cfg.BaseURL + cfg.WebDavURL,
|
||||||
FileSystem: cfg.FileSystem,
|
FileSystem: cfg.FileSystem,
|
||||||
LockSystem: webdav.NewMemLS(),
|
LockSystem: webdav.NewMemLS(),
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ package filemanager
|
|||||||
import (
|
import (
|
||||||
e "errors"
|
e "errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-filemanager/assets"
|
"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
|
// 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
|
// 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
|
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
|
// Preprocess the PUT request if it's the case
|
||||||
if r.Method == http.MethodPut {
|
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 {
|
if handlers.PreProccessPUT(w, r, c, user, fi) != nil {
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ func ServeListing(w http.ResponseWriter, r *http.Request, c *config.Config, u *c
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Loads the content of the directory
|
// 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 {
|
if err != nil {
|
||||||
return errors.ErrorToHTTPCode(err, true), err
|
return errors.ErrorToHTTPCode(err, true), err
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,8 @@ func PreProccessPUT(
|
|||||||
i *file.Info,
|
i *file.Info,
|
||||||
) (err error) {
|
) (err error) {
|
||||||
var (
|
var (
|
||||||
data map[string]interface{}
|
data = map[string]interface{}{}
|
||||||
file []byte
|
file = []byte{}
|
||||||
kind string
|
kind string
|
||||||
rawBuffer = new(bytes.Buffer)
|
rawBuffer = new(bytes.Buffer)
|
||||||
)
|
)
|
||||||
@ -43,7 +43,7 @@ func PreProccessPUT(
|
|||||||
|
|
||||||
switch kind {
|
switch kind {
|
||||||
case "frontmatter-only":
|
case "frontmatter-only":
|
||||||
if file, err = ParseFrontMatterOnlyFile(data, i.Name()); err != nil {
|
if file, err = ParseFrontMatterOnlyFile(data, i.FileInfo.Name()); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "content-only":
|
case "content-only":
|
||||||
|
@ -67,10 +67,10 @@ func (i Info) BreadcrumbMap() map[string]string {
|
|||||||
func (i Info) PreviousLink() string {
|
func (i Info) PreviousLink() string {
|
||||||
path := strings.TrimSuffix(i.Path, "/")
|
path := strings.TrimSuffix(i.Path, "/")
|
||||||
path = strings.TrimPrefix(path, "/")
|
path = strings.TrimPrefix(path, "/")
|
||||||
path = i.Config.AbsoluteURL + "/" + path
|
path = i.Config.AbsoluteURL() + "/" + path
|
||||||
path = path[0 : len(path)-len(i.Name)]
|
path = path[0 : len(path)-len(i.Name)]
|
||||||
|
|
||||||
if len(path) < len(i.Config.AbsoluteURL+"/") {
|
if len(path) < len(i.Config.AbsoluteURL()+"/") {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user