mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
add back-end flags to #19
This commit is contained in:
parent
c1290b149a
commit
87de0ae1be
@ -21,6 +21,7 @@ type Config struct {
|
|||||||
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
|
||||||
Users map[string]*UserConfig
|
Users map[string]*UserConfig
|
||||||
|
CurrentUser *UserConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserConfig contains the configuration for each user
|
// UserConfig contains the configuration for each user
|
||||||
|
@ -170,17 +170,6 @@ func (i *Info) serveSingleFile(w http.ResponseWriter, r *http.Request, c *config
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the current User
|
|
||||||
user, _, ok := r.BasicAuth()
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
page.Info.User = c.UserConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := c.Users[user]; ok {
|
|
||||||
page.Info.User = c.Users[user]
|
|
||||||
}
|
|
||||||
|
|
||||||
if CanBeEdited(i.Name) {
|
if CanBeEdited(i.Name) {
|
||||||
editor, err := i.GetEditor()
|
editor, err := i.GetEditor()
|
||||||
|
|
||||||
@ -261,17 +250,6 @@ func (i *Info) serveListing(w http.ResponseWriter, r *http.Request, c *config.Co
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the current User
|
|
||||||
user, _, ok := r.BasicAuth()
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
page.Info.User = c.UserConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := c.Users[user]; ok {
|
|
||||||
page.Info.User = c.Users[user]
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.Header.Get("Minimal") == "true" {
|
if r.Header.Get("Minimal") == "true" {
|
||||||
page.Minimal = true
|
page.Minimal = true
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,20 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
|
|||||||
code int
|
code int
|
||||||
err error
|
err error
|
||||||
serveAssets bool
|
serveAssets bool
|
||||||
|
user *config.UserConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Set the current User
|
||||||
|
username, _, ok := r.BasicAuth()
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
user = c.UserConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := c.Users[username]; ok {
|
||||||
|
user = c.Users[username]
|
||||||
|
}
|
||||||
|
|
||||||
for i := range f.Configs {
|
for i := range f.Configs {
|
||||||
if httpserver.Path(r.URL.Path).Matches(f.Configs[i].BaseURL) {
|
if httpserver.Path(r.URL.Path).Matches(f.Configs[i].BaseURL) {
|
||||||
c = &f.Configs[i]
|
c = &f.Configs[i]
|
||||||
@ -102,11 +114,20 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
|
|||||||
if fi.IsDir {
|
if fi.IsDir {
|
||||||
return http.StatusNotAcceptable, nil
|
return http.StatusNotAcceptable, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !user.AllowEdit {
|
||||||
|
return http.StatusUnauthorized, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Update a file
|
// Update a file
|
||||||
return fi.Update(w, r, c)
|
return fi.Update(w, r, c)
|
||||||
case http.MethodPost:
|
case http.MethodPost:
|
||||||
// Upload a new file
|
// Upload a new file
|
||||||
if r.Header.Get("Upload") == "true" {
|
if r.Header.Get("Upload") == "true" {
|
||||||
|
if !user.AllowNew {
|
||||||
|
return http.StatusUnauthorized, nil
|
||||||
|
}
|
||||||
|
|
||||||
return upload(w, r, c)
|
return upload(w, r, c)
|
||||||
}
|
}
|
||||||
// Search and git commands
|
// Search and git commands
|
||||||
@ -115,14 +136,26 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
|
|||||||
}
|
}
|
||||||
// VCS commands
|
// VCS commands
|
||||||
if r.Header.Get("Command") != "" {
|
if r.Header.Get("Command") != "" {
|
||||||
|
if !user.AllowCommands {
|
||||||
|
return http.StatusUnauthorized, nil
|
||||||
|
}
|
||||||
|
|
||||||
return vcsCommand(w, r, c)
|
return vcsCommand(w, r, c)
|
||||||
}
|
}
|
||||||
// Creates a new folder
|
// Creates a new folder
|
||||||
return newDirectory(w, r, c)
|
return newDirectory(w, r, c)
|
||||||
case http.MethodDelete:
|
case http.MethodDelete:
|
||||||
|
if !user.AllowEdit {
|
||||||
|
return http.StatusUnauthorized, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Delete a file or a directory
|
// Delete a file or a directory
|
||||||
return fi.Delete()
|
return fi.Delete()
|
||||||
case http.MethodPatch:
|
case http.MethodPatch:
|
||||||
|
if !user.AllowEdit {
|
||||||
|
return http.StatusUnauthorized, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Rename a file or directory
|
// Rename a file or directory
|
||||||
return fi.Rename(w, r)
|
return fi.Rename(w, r)
|
||||||
default:
|
default:
|
||||||
|
@ -25,7 +25,6 @@ type Info struct {
|
|||||||
Path string
|
Path string
|
||||||
IsDir bool
|
IsDir bool
|
||||||
Config *config.Config
|
Config *config.Config
|
||||||
User *config.UserConfig
|
|
||||||
Data interface{}
|
Data interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user