Compare commits

...

12 Commits

Author SHA1 Message Date
Henrique Dias
f014828ee6 chore: version 1.7.1
Former-commit-id: 5b1b7642b56050a35dd06e020fe666d54ac4608b [formerly 3f64b131efb30db09461791b0bcce8a45cde2fd7] [formerly 31799922e187b67442ca8d024304dbdfa37b76f8 [formerly a8c589172d]]
Former-commit-id: c034e606c858c02346bd6de223a8dae1c35cde6f [formerly d9ee0ae17078a3510552541b26ba50d4c1d48806]
Former-commit-id: f94753f8d2de4ef2c99c0e5a19a863c8e5c464fe
2018-05-20 14:56:25 +01:00
Equim
bab6b7760b fix name_template for arm arch
Former-commit-id: a6c02bbd245beec733e61853c0a2446d464779fb [formerly 0399fb8fd0458ca804df6786f2f2013dc92155ed] [formerly a4fb29cb77d6448beef4c6bba88c93f70ac1bd75 [formerly 347122153b]]
Former-commit-id: d7b0611d1e2d2c76f4b04a9faf681947b9973e52 [formerly fff496e7d33c0b9b81467a33c7398dc962efe941]
Former-commit-id: c7d63e5908af2541d7cf4444bdf1730eefe23c5a
2018-04-26 22:38:15 +08:00
1138-4EB
e278dbba65 Rename manager to browser (#406)
* rename File Manager to File Browser

* rename fm to fb


Former-commit-id: 82cd461b7efa992114a6cb6a3bb7fbae53558f42 [formerly 18b0295100462d2c798177086ddc3f615c50ca71] [formerly 5927828ac67268438cc6de00fcaf9140a8620794 [formerly 7643b0c4e3]]
Former-commit-id: 3661e0339db83f5e4e3afa9bcb1015401afb611d [formerly 50eb65db9848c8db82115913fb58399fc371d990]
Former-commit-id: 03e42a5b429a3f0a83c88799e086a4c51c5e031d
2018-04-23 22:42:52 +01:00
Henrique Dias
5a8c28fa6d Update package.json
Former-commit-id: 0481ae202a800cc772ecc73f2df6c34c7cd3c440 [formerly 39f2f5644324def07a26aeaba413009785edd01e] [formerly 1d8a679709a764eb3485cc235e78ea102f1eb2b1 [formerly cd0ab77388]]
Former-commit-id: 0539911bdb06bafddd89d01235444397653dfbdd [formerly cea0a516383ad638738b6bc4d0a12509cdc9daf8]
Former-commit-id: 4eeca9fed79ddce64b6c1da7dead970601541733
2018-04-23 20:29:16 +01:00
1138-4EB
e7e2edf76c fix #311, fix #312 (see filebrowser/frontend#7) (#405)
Former-commit-id: 2a2fe8e441a30073ff9dbb4ba4f6c6235709f158 [formerly 75aa9ca68f6fe2e20ff01d027c9c18e49fe75739] [formerly 371c60a517b81399929f520abc25462f7a271083 [formerly c6eb4fbac5]]
Former-commit-id: e501e318c908fd83ffe7a4984ea732385116aa97 [formerly c5a2a983c3960e2af98915b89a6abb3f2ae3bbde]
Former-commit-id: 90dd43012239882bf72855df4f538fa59f699d64
2018-04-23 20:21:18 +01:00
1138-4EB
dd2d02e492 fix309: merge CMD in the dockerfile to ENTRYPOINT (#397)
Former-commit-id: ca81d11e477ac00abf2998b69425f00a0fa9bfd3 [formerly 262790d3b7ddd904b38fc926658e275531ced99b] [formerly 7d2d31e627d5df0d2f78362a43a27d80725dd4be [formerly f7fdd6cc92]]
Former-commit-id: 097da2311051673f5bea9f851f1451938a7d1935 [formerly b7922bd40d932e03493345cdaca0541150d9a44e]
Former-commit-id: 6b915b5d648575b857d51dc885de675616509d18
2018-04-18 11:53:22 +01:00
Michael Lawson
735e74a858 Fix typo preventing "--allow-edit" from being set (#392)
Former-commit-id: 3762a51ff4883a37b27ba5f859c0633f46d9d7f6 [formerly e125c2f788f5c04c4546ddfc6d86fff1d6624142] [formerly 2d696d4c1857621a9f8ae8c0637a5f43d783c2a5 [formerly 54d0845212]]
Former-commit-id: b063d159d13c5024b79d7dd7bbb5770732efd7e7 [formerly d75479c0c17ca461e36930501ee415a4b8863319]
Former-commit-id: b4a1f4516594d07ff22894384713b0fcb5ba15d8
2018-04-06 05:24:32 +08:00
Henrique Dias
7fc2414476 chore: add more architectures and arm versions (#379)
closes #357

Former-commit-id: 3ee5cc7ba30971665983f9e4a6ff9c25736c02db [formerly a804a698af9226856a76451dc78b756ce9d97dcc] [formerly e1ec927e96a80c90d039efd85a706135f6d4725a [formerly 281339337d]]
Former-commit-id: 6cdd27c4d9ecdb019b99228cbe5641949efc71d6 [formerly dac19ea15f5c7fa6d4b5eaad1c3a5267ae561900]
Former-commit-id: 2a263d999de61788373209667fa8c67a4e3850ad
2018-03-11 22:05:57 +08:00
Henrique Dias
822b8f8e05 chore: setting untracked version [ci skip]
Former-commit-id: 1bf9470ebe3331bcf61f1335de88b4298d253d3c [formerly 360a3ff78b73dadb59a78dc96a4708a4e8e7669b] [formerly c09ce1961737ed92aa22960025e25c0c63847f3e [formerly 5facaf219f]]
Former-commit-id: 4716a43b6e1a3a107d9f9b586376c726e4362ebf [formerly 4ff2f3a2b977b0f1ccaf7eb7ebc8fd4b57f459a9]
Former-commit-id: d0dd7a8e05f6495882493978ed3507aefbdcbd25
2018-03-10 13:25:56 +00:00
Henrique Dias
2d63c288e4 chore: version 1.7.0
Former-commit-id: fad547009e94abcf390a7a9a5fbda912890f5558 [formerly 38266b3eac1f5b6f45d12fdfa83afcf7daa98e60] [formerly e36ec6f4c2b25002be967b4a5dc9566749ac8d42 [formerly 97d26e2348]]
Former-commit-id: 59730ce4eac5932e9d52ffd5dbe810f52f69f548 [formerly 327efa168ad4669b585228fd6b7ced76b261e1f7]
Former-commit-id: d325631f00a18d8fc6009f571b66192809cb8875
2018-03-10 13:25:46 +00:00
Henrique Dias
218a96eebd chore: update dependencies
Former-commit-id: 17c4e043823582d827f3de6a50fc48f2c60250a7 [formerly b1783b936da0e7ede97e128c0d73d20c4c0f5c1b] [formerly b170eca4528721f3269451f6fabeffa54d08fcb9 [formerly fbf49d61d6]]
Former-commit-id: b34516564cf6520f8c21693e287c092bc65b76e9 [formerly b45a4f2367831aee0e5def4096e34b6afb4b8a83]
Former-commit-id: b06ebe48ba6311fa50488aa26b0cc74118d4dfd7
2018-03-10 13:25:11 +00:00
Henrique Dias
4fbef557ee chore: setting untracked version [ci skip]
Former-commit-id: 0fbfd17b4531b45f781fb8517eb155ec953a98f2 [formerly 3a6821e11c979bc638eeb1d31458f1ff7605f69e] [formerly 0ecb209c4172fc504860f25325e03d78f4a12408 [formerly dc97fb7dc6]]
Former-commit-id: 18dc494d9c4b250dc451316ee6c342e0bc26a5e0 [formerly e375068391bba6b1e4c477895bcf054574c7865a]
Former-commit-id: eed4fd2cddeb199b22843a293e8471cb3a40ab0a
2018-03-10 09:00:56 +00:00
21 changed files with 250 additions and 240 deletions

View File

@@ -1,24 +1,24 @@
### Instructions (remove before submitting):
1. Are you asking for help with using Caddy or File Manager? Please use our forum instead: https://forum.caddyserver.com.
2. If you are filing a bug report, please answer the following questions.
3. If your issue is not a bug report, you do not need to use this template.
4. If not using with Caddy, ignore questions 1 and 2.
### 1. Have you downloaded File Manager from caddyserver.com? If yes, when have you done that? If no, and you are running a custom build, which is the revision of File Manager's repository?
### 2. What is your entire Caddyfile?
```text
(Put Caddyfile here)
```
### 3. What are you trying to do?
### 4. What did you expect to see?
### 5. What did you see instead (give full error messages and/or log)?
### 6. How can someone who is starting from scratch reproduce this behaviour as minimally as possible?
### Instructions (remove before submitting):
1. Are you asking for help with using Caddy or File Browser? Please use our forum instead: https://forum.caddyserver.com.
2. If you are filing a bug report, please answer the following questions.
3. If your issue is not a bug report, you do not need to use this template.
4. If not using with Caddy, ignore questions 1 and 2.
### 1. Have you downloaded File Browser from caddyserver.com? If yes, when have you done that? If no, and you are running a custom build, which is the revision of File Browser's repository?
### 2. What is your entire Caddyfile?
```text
(Put Caddyfile here)
```
### 3. What are you trying to do?
### 4. What did you expect to see?
### 5. What did you see instead (give full error messages and/or log)?
### 6. How can someone who is starting from scratch reproduce this behaviour as minimally as possible?

View File

@@ -15,18 +15,28 @@ build:
- 386
- arm
- arm64
- mips
- mips64
- mipsle
- mips64le
goarm:
- 5
- 6
- 7
ignore:
- goos: darwin
goarch: 386
- goos: openbsd
goarch: arm
goarm: 6
- goos: freebsd
goarch: arm
goarm: 6
- goos: linux
goarch: arm64
- goos: netbsd
goarch: arm
- goos: solaris
goarch: arm
archive:
name_template: "{{.Os}}-{{.Arch}}-{{ .ProjectName }}"
name_template: "{{.Os}}-{{.Arch}}{{if .Arm}}v{{.Arm}}{{end}}-{{ .ProjectName }}"
format: tar.gz
format_overrides:
- goos: windows

View File

@@ -21,5 +21,4 @@ EXPOSE 80
COPY Docker.json /config.json
ENTRYPOINT ["/filebrowser"]
CMD ["--config", "/config.json"]
ENTRYPOINT ["/filebrowser", "--config", "/config.json"]

150
README.md
View File

@@ -1,75 +1,75 @@
![Preview](https://user-images.githubusercontent.com/5447088/28537288-39be4288-70a2-11e7-8ce9-0813d59f46b7.gif)
# filebrowser
[![CircleCI](https://img.shields.io/circleci/project/github/filebrowser/filebrowser.svg?style=flat-square)](https://circleci.com/gh/filebrowser/filebrowser)
[![Go Report Card](https://goreportcard.com/badge/github.com/filebrowser/filebrowser?style=flat-square)](https://goreportcard.com/report/github.com/filebrowser/filebrowser)
[![Documentation](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](http://godoc.org/github.com/filebrowser/filebrowser)
[![Version](https://img.shields.io/github/release/filebrowser/filebrowser.svg?style=flat-square)](https://github.com/filebrowser/filebrowser/releases/latest)
filebrowser provides a file managing interface within a specified directory and it can be used to upload, delete, preview, rename and edit your files. It allows the creation of multiple users and each user can have its own directory. It can be used as a standalone app or as a middleware.
# Table of contents
+ [Getting started](#getting-started)
+ [Features](#features)
- [Users](#users)
- [Search](#search)
+ [Contributing](#contributing)
+ [Donate](#donate)
# Getting started
You can find the Getting Started guide on the [documentation](https://filebrowser.github.io/quick-start/).
# Features
Easy login system.
![Login Page](https://user-images.githubusercontent.com/5447088/28432382-975493dc-6d7f-11e7-9190-23f8037159dc.jpg)
Listings of your files, available in two styles: mosaic and list. You can delete, move, rename, upload and create new files, as well as directories. Single files can be downloaded directly, and multiple files as *.zip*, *.tar*, *.tar.gz*, *.tar.bz2* or *.tar.xz*.
![Mosaic Listing](https://user-images.githubusercontent.com/5447088/28432384-9771bb4c-6d7f-11e7-8564-3a9bd6a3ce3a.jpg)
File Manager editor is powered by [Codemirror](https://codemirror.net/) and if you're working with markdown files with metadata, both parts will be separated from each other so you can focus on the content.
![Markdown Editor](https://user-images.githubusercontent.com/5447088/28432383-9756fdac-6d7f-11e7-8e58-fec49470d15f.jpg)
On the settings page, a regular user can set its own custom CSS to personalize the experience and change its password. For admins, they can manage the permissions of each user, set commands which can be executed when certain events are triggered (such as before saving and after saving) and change plugin's settings.
![Settings](https://user-images.githubusercontent.com/5447088/28432385-9776ec66-6d7f-11e7-90a5-891bacd4d02f.jpg)
We also allow the users to search in the directories and execute commands if allowed.
## Users
We support multiple users and each user can have its own scope and custom stylesheet. The administrator is able to choose which permissions should be given to the users, as well as the commands they can execute. Each user also have a set of rules, in which he can be prevented or allowed to access some directories (regular expressions included!).
![Users](https://user-images.githubusercontent.com/5447088/28432386-977f388a-6d7f-11e7-9006-87d16f05f1f8.jpg)
## Search
File Browser allows you to search through your files and it has some options. By default, your search will be something like this:
```
this are keywords
```
If you search for that it will look at every file that contains "this", "are" or "keywords" on their name. If you want to search for an exact term, you should surround your search by double quotes:
```
"this is the name"
```
That will search for any file that contains "this is the name" on its name. It won't search for each separated term this time.
By default, every search will be case sensitive. Although, you can make a case insensitive search by adding `case:insensitive` to the search terms, like this:
```
this are keywords case:insensitive
```
# Contributing
The contributing guidelines can be found [here](https://github.com/filebrowser/community).
![Preview](https://user-images.githubusercontent.com/5447088/28537288-39be4288-70a2-11e7-8ce9-0813d59f46b7.gif)
# filebrowser
[![CircleCI](https://img.shields.io/circleci/project/github/filebrowser/filebrowser.svg?style=flat-square)](https://circleci.com/gh/filebrowser/filebrowser)
[![Go Report Card](https://goreportcard.com/badge/github.com/filebrowser/filebrowser?style=flat-square)](https://goreportcard.com/report/github.com/filebrowser/filebrowser)
[![Documentation](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](http://godoc.org/github.com/filebrowser/filebrowser)
[![Version](https://img.shields.io/github/release/filebrowser/filebrowser.svg?style=flat-square)](https://github.com/filebrowser/filebrowser/releases/latest)
filebrowser provides a file managing interface within a specified directory and it can be used to upload, delete, preview, rename and edit your files. It allows the creation of multiple users and each user can have its own directory. It can be used as a standalone app or as a middleware.
# Table of contents
+ [Getting started](#getting-started)
+ [Features](#features)
- [Users](#users)
- [Search](#search)
+ [Contributing](#contributing)
+ [Donate](#donate)
# Getting started
You can find the Getting Started guide on the [documentation](https://filebrowser.github.io/quick-start/).
# Features
Easy login system.
![Login Page](https://user-images.githubusercontent.com/5447088/28432382-975493dc-6d7f-11e7-9190-23f8037159dc.jpg)
Listings of your files, available in two styles: mosaic and list. You can delete, move, rename, upload and create new files, as well as directories. Single files can be downloaded directly, and multiple files as *.zip*, *.tar*, *.tar.gz*, *.tar.bz2* or *.tar.xz*.
![Mosaic Listing](https://user-images.githubusercontent.com/5447088/28432384-9771bb4c-6d7f-11e7-8564-3a9bd6a3ce3a.jpg)
File Browser editor is powered by [Codemirror](https://codemirror.net/) and if you're working with markdown files with metadata, both parts will be separated from each other so you can focus on the content.
![Markdown Editor](https://user-images.githubusercontent.com/5447088/28432383-9756fdac-6d7f-11e7-8e58-fec49470d15f.jpg)
On the settings page, a regular user can set its own custom CSS to personalize the experience and change its password. For admins, they can manage the permissions of each user, set commands which can be executed when certain events are triggered (such as before saving and after saving) and change plugin's settings.
![Settings](https://user-images.githubusercontent.com/5447088/28432385-9776ec66-6d7f-11e7-90a5-891bacd4d02f.jpg)
We also allow the users to search in the directories and execute commands if allowed.
## Users
We support multiple users and each user can have its own scope and custom stylesheet. The administrator is able to choose which permissions should be given to the users, as well as the commands they can execute. Each user also have a set of rules, in which he can be prevented or allowed to access some directories (regular expressions included!).
![Users](https://user-images.githubusercontent.com/5447088/28432386-977f388a-6d7f-11e7-9006-87d16f05f1f8.jpg)
## Search
File Browser allows you to search through your files and it has some options. By default, your search will be something like this:
```
this are keywords
```
If you search for that it will look at every file that contains "this", "are" or "keywords" on their name. If you want to search for an exact term, you should surround your search by double quotes:
```
"this is the name"
```
That will search for any file that contains "this is the name" on its name. It won't search for each separated term this time.
By default, every search will be case sensitive. Although, you can make a case insensitive search by adding `case:insensitive` to the search terms, like this:
```
this are keywords case:insensitive
```
# Contributing
The contributing guidelines can be found [here](https://github.com/filebrowser/community).

View File

@@ -2,7 +2,7 @@ package bolt
import (
"github.com/asdine/storm"
fm "github.com/filebrowser/filebrowser"
fb "github.com/filebrowser/filebrowser"
)
// ConfigStore is a configuration store.
@@ -14,7 +14,7 @@ type ConfigStore struct {
func (c ConfigStore) Get(name string, to interface{}) error {
err := c.DB.Get("config", name, to)
if err == storm.ErrNotFound {
return fm.ErrNotExist
return fb.ErrNotExist
}
return err

View File

@@ -3,7 +3,7 @@ package bolt
import (
"github.com/asdine/storm"
"github.com/asdine/storm/q"
fm "github.com/filebrowser/filebrowser"
fb "github.com/filebrowser/filebrowser"
)
// ShareStore is a shareable links store.
@@ -12,55 +12,55 @@ type ShareStore struct {
}
// Get gets a Share Link from an hash.
func (s ShareStore) Get(hash string) (*fm.ShareLink, error) {
var v fm.ShareLink
func (s ShareStore) Get(hash string) (*fb.ShareLink, error) {
var v fb.ShareLink
err := s.DB.One("Hash", hash, &v)
if err == storm.ErrNotFound {
return nil, fm.ErrNotExist
return nil, fb.ErrNotExist
}
return &v, err
}
// GetPermanent gets the permanent link from a path.
func (s ShareStore) GetPermanent(path string) (*fm.ShareLink, error) {
var v fm.ShareLink
func (s ShareStore) GetPermanent(path string) (*fb.ShareLink, error) {
var v fb.ShareLink
err := s.DB.Select(q.Eq("Path", path), q.Eq("Expires", false)).First(&v)
if err == storm.ErrNotFound {
return nil, fm.ErrNotExist
return nil, fb.ErrNotExist
}
return &v, err
}
// GetByPath gets all the links for a specific path.
func (s ShareStore) GetByPath(hash string) ([]*fm.ShareLink, error) {
var v []*fm.ShareLink
func (s ShareStore) GetByPath(hash string) ([]*fb.ShareLink, error) {
var v []*fb.ShareLink
err := s.DB.Find("Path", hash, &v)
if err == storm.ErrNotFound {
return v, fm.ErrNotExist
return v, fb.ErrNotExist
}
return v, err
}
// Gets retrieves all the shareable links.
func (s ShareStore) Gets() ([]*fm.ShareLink, error) {
var v []*fm.ShareLink
func (s ShareStore) Gets() ([]*fb.ShareLink, error) {
var v []*fb.ShareLink
err := s.DB.All(&v)
if err == storm.ErrNotFound {
return v, fm.ErrNotExist
return v, fb.ErrNotExist
}
return v, err
}
// Save stores a Share Link on the database.
func (s ShareStore) Save(l *fm.ShareLink) error {
func (s ShareStore) Save(l *fb.ShareLink) error {
return s.DB.Save(l)
}
// Delete deletes a Share Link from the database.
func (s ShareStore) Delete(hash string) error {
return s.DB.DeleteStruct(&fm.ShareLink{Hash: hash})
return s.DB.DeleteStruct(&fb.ShareLink{Hash: hash})
}

View File

@@ -100,7 +100,7 @@ func setupViper() {
viper.BindPFlag("Commands", flag.Lookup("commands"))
viper.BindPFlag("AllowCommands", flag.Lookup("allow-commands"))
viper.BindPFlag("AllowEdit", flag.Lookup("allow-edit"))
viper.BindPFlag("AlowNew", flag.Lookup("allow-new"))
viper.BindPFlag("AllowNew", flag.Lookup("allow-new"))
viper.BindPFlag("AllowPublish", flag.Lookup("allow-publish"))
viper.BindPFlag("Locale", flag.Lookup("locale"))
viper.BindPFlag("StaticGen", flag.Lookup("staticgen"))

8
doc.go
View File

@@ -1,7 +1,7 @@
/*
Package filebrowser provides a web interface to access your files
wherever you are. To use this package as a middleware for your app,
you'll need to import both File Manager and File Manager HTTP packages.
you'll need to import both File Browser and File Browser HTTP packages.
import (
fm "github.com/filebrowser/filebrowser"
@@ -49,11 +49,11 @@ functions:
m.SetPrefixURL("/")
The Prefix URL is a part of the path that is already stripped from the
r.URL.Path variable before the request arrives to File Manager's handler.
r.URL.Path variable before the request arrives to File Browser's handler.
This is a function that will rarely be used. You can see one example on Caddy
filemanager plugin.
The Base URL is the URL path where you want File Manager to be available in. If
The Base URL is the URL path where you want File Browser to be available in. If
you want to be available at the root path, you should call:
m.SetBaseURL("/")
@@ -62,7 +62,7 @@ But if you want to access it at '/admin', you would call:
m.SetBaseURL("/admin")
Now, that you already have a File Manager instance created, you just need to
Now, that you already have a File Browser instance created, you just need to
add it to your handlers using m.ServeHTTP which is compatible to http.Handler.
We also have a m.ServeWithErrorsHTTP that returns the status code and an error.

View File

@@ -22,8 +22,8 @@ import (
)
const (
// Version is the current File Manager version.
Version = "1.6.0"
// Version is the current File Browser version.
Version = "1.7.1"
ListViewMode = "list"
MosaicViewMode = "mosaic"
@@ -58,7 +58,7 @@ type FileBrowser struct {
Store *Store
// PrefixURL is a part of the URL that is already trimmed from the request URL before it
// arrives to our handlers. It may be useful when using File Manager as a middleware
// arrives to our handlers. It may be useful when using File Browser as a middleware
// such as in caddy-filemanager plugin. It is only useful in certain situations.
PrefixURL string
@@ -115,9 +115,9 @@ type FSBuilder func(scope string) FileSystem
// Setup loads the configuration from the database and configures
// the Assets and the Cron job. It must always be run after
// creating a File Manager object.
// creating a File Browser object.
func (m *FileBrowser) Setup() error {
// Creates a new File Manager instance with the Users
// Creates a new File Browser instance with the Users
// map and Assets box.
m.Assets = rice.MustFindBox("./node_modules/filebrowser-frontend/dist")
m.Cron = cron.New()
@@ -221,7 +221,7 @@ func (m *FileBrowser) Setup() error {
}
// RootURL returns the actual URL where
// File Manager interface can be accessed.
// File Browser interface can be accessed.
func (m FileBrowser) RootURL() string {
return m.PrefixURL + m.BaseURL
}
@@ -235,7 +235,7 @@ func (m *FileBrowser) SetPrefixURL(url string) {
m.PrefixURL = strings.TrimSuffix(url, "/")
}
// SetBaseURL updates the baseURL of a File Manager
// SetBaseURL updates the baseURL of a File Browser
// object.
func (m *FileBrowser) SetBaseURL(url string) {
url = strings.TrimPrefix(url, "/")
@@ -244,7 +244,7 @@ func (m *FileBrowser) SetBaseURL(url string) {
m.BaseURL = strings.TrimSuffix(url, "/")
}
// Attach attaches a static generator to the current File Manager.
// Attach attaches a static generator to the current File Browser.
func (m *FileBrowser) Attach(s StaticGen) error {
if reflect.TypeOf(s).Kind() != reflect.Ptr {
return errors.New("data should be a pointer to interface, not interface")
@@ -290,7 +290,7 @@ func (m FileBrowser) ShareCleaner() {
func (m FileBrowser) Runner(event string, path string, destination string, user *User) error {
commands := []string{}
// Get the commands from the File Manager instance itself.
// Get the commands from the File Browser instance itself.
if val, ok := m.Commands[event]; ok {
commands = append(commands, val...)
}

View File

@@ -9,7 +9,7 @@ import (
"github.com/dgrijalva/jwt-go"
"github.com/dgrijalva/jwt-go/request"
fm "github.com/filebrowser/filebrowser"
fb "github.com/filebrowser/filebrowser"
)
const reCaptchaAPI = "/recaptcha/api/siteverify"
@@ -50,7 +50,7 @@ func reCaptcha(host, secret, response string) (bool, error) {
}
// authHandler processes the authentication for the user.
func authHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func authHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// NoAuth instances shouldn't call this method.
if c.NoAuth {
return 0, nil
@@ -86,7 +86,7 @@ func authHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, er
}
// Checks if the password is correct.
if !fm.CheckPasswordHash(cred.Password, u.Password) {
if !fb.CheckPasswordHash(cred.Password, u.Password) {
return http.StatusForbidden, nil
}
@@ -96,7 +96,7 @@ func authHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, er
// renewAuthHandler is used when the front-end already has a JWT token
// and is checking if it is up to date. If so, updates its info.
func renewAuthHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func renewAuthHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
ok, u := validateAuth(c, r)
if !ok {
return http.StatusForbidden, nil
@@ -108,15 +108,15 @@ func renewAuthHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in
// claims is the JWT claims.
type claims struct {
fm.User
fb.User
jwt.StandardClaims
}
// printToken prints the final JWT token to the user.
func printToken(c *fm.Context, w http.ResponseWriter) (int, error) {
func printToken(c *fb.Context, w http.ResponseWriter) (int, error) {
// Creates a copy of the user and removes it password
// hash so it never arrives to the user.
u := fm.User{}
u := fb.User{}
u = *c.User
u.Password = ""
@@ -125,7 +125,7 @@ func printToken(c *fm.Context, w http.ResponseWriter) (int, error) {
u,
jwt.StandardClaims{
ExpiresAt: time.Now().Add(time.Hour * 24).Unix(),
Issuer: "File Manager",
Issuer: "File Browser",
},
}
@@ -165,7 +165,7 @@ func (e extractor) ExtractToken(r *http.Request) (string, error) {
// validateAuth is used to validate the authentication and returns the
// User if it is valid.
func validateAuth(c *fm.Context, r *http.Request) (bool, *fm.User) {
func validateAuth(c *fb.Context, r *http.Request) (bool, *fb.User) {
if c.NoAuth {
c.User = c.DefaultUser
return true, c.User

View File

@@ -7,14 +7,14 @@ import (
"path/filepath"
"strings"
fm "github.com/filebrowser/filebrowser"
fb "github.com/filebrowser/filebrowser"
"github.com/hacdias/fileutils"
"github.com/mholt/archiver"
)
// downloadHandler creates an archive in one of the supported formats (zip, tar,
// tar.gz or tar.bz2) and sends it to be downloaded.
func downloadHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func downloadHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// If the file isn't a directory, serve it using http.ServeFile. We display it
// inline if it is requested.
if !c.File.IsDir {
@@ -77,7 +77,7 @@ func downloadHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int
return 0, err
}
func downloadFileHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func downloadFileHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
file, err := os.Open(c.File.Path)
defer file.Close()

View File

@@ -10,13 +10,13 @@ import (
"strings"
"time"
fm "github.com/filebrowser/filebrowser"
fb "github.com/filebrowser/filebrowser"
)
// Handler returns a function compatible with http.HandleFunc.
func Handler(m *fm.FileBrowser) http.Handler {
func Handler(m *fb.FileBrowser) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
code, err := serve(&fm.Context{
code, err := serve(&fb.Context{
FileBrowser: m,
User: nil,
File: nil,
@@ -37,9 +37,9 @@ func Handler(m *fm.FileBrowser) http.Handler {
}
// serve is the main entry point of this HTML application.
func serve(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func serve(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// Checks if the URL contains the baseURL and strips it. Otherwise, it just
// returns a 404 fm.Error because we're not supposed to be here!
// returns a 404 fb.Error because we're not supposed to be here!
p := strings.TrimPrefix(r.URL.Path, c.BaseURL)
if len(p) >= len(r.URL.Path) && c.BaseURL != "" {
@@ -93,7 +93,7 @@ func serve(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
}
// staticHandler handles the static assets path.
func staticHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func staticHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
if r.URL.Path != "/static/manifest.json" {
http.FileServer(c.Assets.HTTPBox()).ServeHTTP(w, r)
return 0, nil
@@ -103,7 +103,7 @@ func staticHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int,
}
// apiHandler is the main entry point for the /api endpoint.
func apiHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func apiHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
if r.URL.Path == "/auth/get" {
return authHandler(c, w, r)
}
@@ -139,7 +139,7 @@ func apiHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, err
if c.Router == "checksum" || c.Router == "download" {
var err error
c.File, err = fm.GetInfo(r.URL, c.FileBrowser, c.User)
c.File, err = fb.GetInfo(r.URL, c.FileBrowser, c.User)
if err != nil {
return ErrorToHTTP(err, false), err
}
@@ -173,11 +173,11 @@ func apiHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, err
}
// serveChecksum calculates the hash of a file. Supports MD5, SHA1, SHA256 and SHA512.
func checksumHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func checksumHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
query := r.URL.Query().Get("algo")
val, err := c.File.Checksum(query)
if err == fm.ErrInvalidOption {
if err == fb.ErrInvalidOption {
return http.StatusBadRequest, err
} else if err != nil {
return http.StatusInternalServerError, err
@@ -205,7 +205,7 @@ func splitURL(path string) (string, string) {
}
// renderFile renders a file using a template with some needed variables.
func renderFile(c *fm.Context, w http.ResponseWriter, file string) (int, error) {
func renderFile(c *fb.Context, w http.ResponseWriter, file string) (int, error) {
tpl := template.Must(template.New("file").Parse(c.Assets.MustString(file)))
var contentType string
@@ -225,7 +225,7 @@ func renderFile(c *fm.Context, w http.ResponseWriter, file string) (int, error)
data := map[string]interface{}{
"BaseURL": c.RootURL(),
"NoAuth": c.NoAuth,
"Version": fm.Version,
"Version": fb.Version,
"CSS": template.CSS(c.CSS),
"ReCaptcha": c.ReCaptchaKey != "" && c.ReCaptchaSecret != "",
"ReCaptchaHost": c.ReCaptchaHost,
@@ -246,9 +246,9 @@ func renderFile(c *fm.Context, w http.ResponseWriter, file string) (int, error)
}
// sharePage build the share page.
func sharePage(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func sharePage(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
s, err := c.Store.Share.Get(r.URL.Path)
if err == fm.ErrNotExist {
if err == fb.ErrNotExist {
w.WriteHeader(http.StatusNotFound)
return renderFile(c, w, "static/share/404.html")
}
@@ -271,7 +271,7 @@ func sharePage(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, erro
return ErrorToHTTP(err, false), err
}
c.File = &fm.File{
c.File = &fb.File{
Path: s.Path,
Name: info.Name(),
ModTime: info.ModTime(),

View File

@@ -13,7 +13,7 @@ import (
"strings"
"time"
fm "github.com/filebrowser/filebrowser"
fb "github.com/filebrowser/filebrowser"
"github.com/hacdias/fileutils"
)
@@ -27,7 +27,7 @@ func sanitizeURL(url string) string {
return path
}
func resourceHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func resourceHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
r.URL.Path = sanitizeURL(r.URL.Path)
switch r.Method {
@@ -62,9 +62,9 @@ func resourceHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int
return http.StatusNotImplemented, nil
}
func resourceGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func resourceGetHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// Gets the information of the directory/file.
f, err := fm.GetInfo(r.URL, c.FileBrowser, c.User)
f, err := fb.GetInfo(r.URL, c.FileBrowser, c.User)
if err != nil {
return ErrorToHTTP(err, false), err
}
@@ -104,7 +104,7 @@ func resourceGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (
return renderJSON(w, f)
}
func listingHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func listingHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
f := c.File
f.Kind = "listing"
@@ -133,7 +133,7 @@ func listingHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int,
return renderJSON(w, f)
}
func resourceDeleteHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func resourceDeleteHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// Prevent the removal of the root directory.
if r.URL.Path == "/" || !c.User.AllowEdit {
return http.StatusForbidden, nil
@@ -158,7 +158,7 @@ func resourceDeleteHandler(c *fm.Context, w http.ResponseWriter, r *http.Request
return http.StatusOK, nil
}
func resourcePostPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func resourcePostPutHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
if !c.User.AllowNew && r.Method == http.MethodPost {
return http.StatusForbidden, nil
}
@@ -240,7 +240,7 @@ func resourcePostPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Reques
return http.StatusOK, nil
}
func resourcePublishSchedule(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func resourcePublishSchedule(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
publish := r.Header.Get("Publish")
schedule := r.Header.Get("Schedule")
@@ -271,7 +271,7 @@ func resourcePublishSchedule(c *fm.Context, w http.ResponseWriter, r *http.Reque
return http.StatusOK, nil
}
func resourcePublish(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func resourcePublish(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
path := filepath.Join(c.User.Scope, r.URL.Path)
// Before save command handler.
@@ -293,7 +293,7 @@ func resourcePublish(c *fm.Context, w http.ResponseWriter, r *http.Request) (int
}
// resourcePatchHandler is the entry point for resource handler.
func resourcePatchHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func resourcePatchHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
if !c.User.AllowEdit {
return http.StatusForbidden, nil
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
"reflect"
fm "github.com/filebrowser/filebrowser"
fb "github.com/filebrowser/filebrowser"
"github.com/mitchellh/mapstructure"
)
@@ -28,7 +28,7 @@ type option struct {
func parsePutSettingsRequest(r *http.Request) (*modifySettingsRequest, error) {
// Checks if the request body is empty.
if r.Body == nil {
return nil, fm.ErrEmptyRequest
return nil, fb.ErrEmptyRequest
}
// Parses the request body and checks if it's well formed.
@@ -40,13 +40,13 @@ func parsePutSettingsRequest(r *http.Request) (*modifySettingsRequest, error) {
// Checks if the request type is right.
if mod.What != "settings" {
return nil, fm.ErrWrongDataType
return nil, fb.ErrWrongDataType
}
return mod, nil
}
func settingsHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func settingsHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
if r.URL.Path != "" && r.URL.Path != "/" {
return http.StatusNotFound, nil
}
@@ -67,7 +67,7 @@ type settingsGetRequest struct {
StaticGen []option `json:"staticGen"`
}
func settingsGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func settingsGetHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
if !c.User.Admin {
return http.StatusForbidden, nil
}
@@ -97,7 +97,7 @@ func settingsGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (
return renderJSON(w, result)
}
func settingsPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func settingsPutHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
if !c.User.Admin {
return http.StatusForbidden, nil
}

View File

@@ -8,10 +8,10 @@ import (
"strings"
"time"
fm "github.com/filebrowser/filebrowser"
fb "github.com/filebrowser/filebrowser"
)
func shareHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func shareHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
r.URL.Path = sanitizeURL(r.URL.Path)
switch r.Method {
@@ -26,10 +26,10 @@ func shareHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, e
return http.StatusNotImplemented, nil
}
func shareGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func shareGetHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
path := filepath.Join(c.User.Scope, r.URL.Path)
s, err := c.Store.Share.GetByPath(path)
if err == fm.ErrNotExist {
if err == fb.ErrNotExist {
return http.StatusNotFound, nil
}
@@ -51,10 +51,10 @@ func shareGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int
return renderJSON(w, s)
}
func sharePostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func sharePostHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
path := filepath.Join(c.User.Scope, r.URL.Path)
var s *fm.ShareLink
var s *fb.ShareLink
expire := r.URL.Query().Get("expires")
unit := r.URL.Query().Get("unit")
@@ -67,14 +67,14 @@ func sharePostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in
}
}
bytes, err := fm.GenerateRandomBytes(6)
bytes, err := fb.GenerateRandomBytes(6)
if err != nil {
return http.StatusInternalServerError, err
}
str := base64.URLEncoding.EncodeToString(bytes)
s = &fm.ShareLink{
s = &fb.ShareLink{
Path: path,
Hash: str,
Expires: expire != "",
@@ -108,9 +108,9 @@ func sharePostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in
return renderJSON(w, s)
}
func shareDeleteHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func shareDeleteHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
s, err := c.Store.Share.Get(strings.TrimPrefix(r.URL.Path, "/"))
if err == fm.ErrNotExist {
if err == fb.ErrNotExist {
return http.StatusNotFound, nil
}

View File

@@ -9,7 +9,7 @@ import (
"strconv"
"strings"
fm "github.com/filebrowser/filebrowser"
fb "github.com/filebrowser/filebrowser"
)
type modifyRequest struct {
@@ -19,12 +19,12 @@ type modifyRequest struct {
type modifyUserRequest struct {
modifyRequest
Data *fm.User `json:"data"`
Data *fb.User `json:"data"`
}
// usersHandler is the entry point of the users API. It's just a router
// to send the request to its
func usersHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func usersHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// If the user isn't admin and isn't making a PUT
// request, then return forbidden.
if !c.User.Admin && r.Method != http.MethodPut {
@@ -47,7 +47,7 @@ func usersHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, e
// getUserID returns the id from the user which is present
// in the request url. If the url is invalid and doesn't
// contain a valid ID, it returns an fm.Error.
// contain a valid ID, it returns an fb.Error.
func getUserID(r *http.Request) (int, error) {
// Obtains the ID in string from the URL and converts
// it into an integer.
@@ -63,11 +63,11 @@ func getUserID(r *http.Request) (int, error) {
// getUser returns the user which is present in the request
// body. If the body is empty or the JSON is invalid, it
// returns an fm.Error.
func getUser(c *fm.Context, r *http.Request) (*fm.User, string, error) {
// returns an fb.Error.
func getUser(c *fb.Context, r *http.Request) (*fb.User, string, error) {
// Checks if the request body is empty.
if r.Body == nil {
return nil, "", fm.ErrEmptyRequest
return nil, "", fb.ErrEmptyRequest
}
// Parses the request body and checks if it's well formed.
@@ -79,14 +79,14 @@ func getUser(c *fm.Context, r *http.Request) (*fm.User, string, error) {
// Checks if the request type is right.
if mod.What != "user" {
return nil, "", fm.ErrWrongDataType
return nil, "", fb.ErrWrongDataType
}
mod.Data.FileSystem = c.NewFS(mod.Data.Scope)
return mod.Data, mod.Which, nil
}
func usersGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func usersGetHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// Request for the default user data.
if r.URL.Path == "/base" {
return renderJSON(w, c.DefaultUser)
@@ -118,7 +118,7 @@ func usersGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int
}
u, err := c.Store.Users.Get(id, c.NewFS)
if err == fm.ErrExist {
if err == fb.ErrExist {
return http.StatusNotFound, err
}
@@ -130,7 +130,7 @@ func usersGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int
return renderJSON(w, u)
}
func usersPostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func usersPostHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
if r.URL.Path != "/" {
return http.StatusMethodNotAllowed, nil
}
@@ -142,22 +142,22 @@ func usersPostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in
// Checks if username isn't empty.
if u.Username == "" {
return http.StatusBadRequest, fm.ErrEmptyUsername
return http.StatusBadRequest, fb.ErrEmptyUsername
}
// Checks if scope isn't empty.
if u.Scope == "" {
return http.StatusBadRequest, fm.ErrEmptyScope
return http.StatusBadRequest, fb.ErrEmptyScope
}
// Checks if password isn't empty.
if u.Password == "" {
return http.StatusBadRequest, fm.ErrEmptyPassword
return http.StatusBadRequest, fb.ErrEmptyPassword
}
// Initialize rules if they're not initialized.
if u.Rules == nil {
u.Rules = []*fm.Rule{}
u.Rules = []*fb.Rule{}
}
// If the view mode is empty, initialize with the default one.
@@ -181,17 +181,17 @@ func usersPostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in
}
// Hashes the password.
pw, err := fm.HashPassword(u.Password)
pw, err := fb.HashPassword(u.Password)
if err != nil {
return http.StatusInternalServerError, err
}
u.Password = pw
u.ViewMode = fm.MosaicViewMode
u.ViewMode = fb.MosaicViewMode
// Saves the user to the database.
err = c.Store.Users.Save(u)
if err == fm.ErrExist {
if err == fb.ErrExist {
return http.StatusConflict, err
}
@@ -228,7 +228,7 @@ func checkFS(path string) (int, error) {
return 0, nil
}
func usersDeleteHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func usersDeleteHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
if r.URL.Path == "/" {
return http.StatusMethodNotAllowed, nil
}
@@ -240,8 +240,8 @@ func usersDeleteHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (
// Deletes the user from the database.
err = c.Store.Users.Delete(id)
if err == fm.ErrNotExist {
return http.StatusNotFound, fm.ErrNotExist
if err == fb.ErrNotExist {
return http.StatusNotFound, fb.ErrNotExist
}
if err != nil {
@@ -251,7 +251,7 @@ func usersDeleteHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (
return http.StatusOK, nil
}
func usersPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func usersPutHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// New users should be created on /api/users.
if r.URL.Path == "/" {
return http.StatusMethodNotAllowed, nil
@@ -298,14 +298,14 @@ func usersPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int
// Updates the Password.
if which == "password" {
if u.Password == "" {
return http.StatusBadRequest, fm.ErrEmptyPassword
return http.StatusBadRequest, fb.ErrEmptyPassword
}
if id == c.User.ID && c.User.LockPassword {
return http.StatusForbidden, nil
}
c.User.Password, err = fm.HashPassword(u.Password)
c.User.Password, err = fb.HashPassword(u.Password)
if err != nil {
return http.StatusInternalServerError, err
}
@@ -320,17 +320,17 @@ func usersPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int
// If can only be all.
if which != "all" {
return http.StatusBadRequest, fm.ErrInvalidUpdateField
return http.StatusBadRequest, fb.ErrInvalidUpdateField
}
// Checks if username isn't empty.
if u.Username == "" {
return http.StatusBadRequest, fm.ErrEmptyUsername
return http.StatusBadRequest, fb.ErrEmptyUsername
}
// Checks if filesystem isn't empty.
if u.Scope == "" {
return http.StatusBadRequest, fm.ErrEmptyScope
return http.StatusBadRequest, fb.ErrEmptyScope
}
// Checks if the scope exists.
@@ -340,7 +340,7 @@ func usersPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int
// Initialize rules if they're not initialized.
if u.Rules == nil {
u.Rules = []*fm.Rule{}
u.Rules = []*fb.Rule{}
}
// Initialize commands if not initialized.
@@ -350,7 +350,7 @@ func usersPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int
// Gets the current saved user from the in-memory map.
suser, err := c.Store.Users.Get(id, c.NewFS)
if err == fm.ErrNotExist {
if err == fb.ErrNotExist {
return http.StatusNotFound, nil
}
@@ -362,7 +362,7 @@ func usersPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int
// Changes the password if the request wants it.
if u.Password != "" {
pw, err := fm.HashPassword(u.Password)
pw, err := fb.HashPassword(u.Password)
if err != nil {
return http.StatusInternalServerError, err
}

View File

@@ -12,7 +12,7 @@ import (
"strings"
"time"
fm "github.com/filebrowser/filebrowser"
fb "github.com/filebrowser/filebrowser"
"github.com/gorilla/websocket"
)
@@ -27,8 +27,8 @@ var (
)
// command handles the requests for VCS related commands: git, svn and mercurial
func command(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// Upgrades the connection to a websocket and checks for fm.Errors.
func command(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// Upgrades the connection to a websocket and checks for fb.Errors.
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
return 0, err
@@ -57,13 +57,14 @@ func command(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error)
allowed := false
for _, cmd := range c.User.Commands {
if cmd == command[0] {
if regexp.MustCompile(cmd).MatchString(command[0]) {
allowed = true
break
}
}
if !allowed {
err = conn.WriteMessage(websocket.BinaryMessage, cmdNotAllowed)
err = conn.WriteMessage(websocket.TextMessage, cmdNotAllowed)
if err != nil {
return http.StatusInternalServerError, err
}
@@ -71,9 +72,9 @@ func command(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error)
return 0, nil
}
// Check if the program is talled is installed on the computer.
// Check if the program is installed on the computer.
if _, err = exec.LookPath(command[0]); err != nil {
err = conn.WriteMessage(websocket.BinaryMessage, cmdNotImplemented)
err = conn.WriteMessage(websocket.TextMessage, cmdNotImplemented)
if err != nil {
return http.StatusInternalServerError, err
}
@@ -92,7 +93,7 @@ func command(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error)
cmd.Stderr = buff
cmd.Stdout = buff
// Starts the command and checks for fm.Errors.
// Starts the command and checks for fb.Errors.
err = cmd.Start()
if err != nil {
return http.StatusInternalServerError, err
@@ -240,8 +241,8 @@ func parseSearch(value string) *searchOptions {
}
// search searches for a file or directory.
func search(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// Upgrades the connection to a websocket and checks for fm.Errors.
func search(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// Upgrades the connection to a websocket and checks for fb.Errors.
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
return 0, err

View File

@@ -3,6 +3,6 @@
"author": "File Browser contributors",
"private": true,
"dependencies": {
"filebrowser-frontend": "1.0.4"
"filebrowser-frontend": "1.4.0"
}
}

View File

@@ -1 +1 @@
ee6a18b32d66a98bab93e7c2dadc6b60b0d53495
874cb4f3e39c52014a4874f9a20e0f6a13cffbec

View File

@@ -10,7 +10,7 @@ import (
"path/filepath"
"strings"
fm "github.com/filebrowser/filebrowser"
fb "github.com/filebrowser/filebrowser"
"github.com/hacdias/varutils"
)
@@ -64,7 +64,7 @@ func (h Hugo) Name() string {
}
// Hook is the pre-api handler.
func (h Hugo) Hook(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func (h Hugo) Hook(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// If we are not using HTTP Post, we shall return Method Not Allowed
// since we are only working with this method.
if r.Method != http.MethodPost {
@@ -108,7 +108,7 @@ func (h Hugo) Hook(c *fm.Context, w http.ResponseWriter, r *http.Request) (int,
}
// Publish publishes a post.
func (h Hugo) Publish(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func (h Hugo) Publish(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
filename := filepath.Join(c.User.Scope, r.URL.Path)
// We only run undraft command if it is a file.
@@ -125,7 +125,7 @@ func (h Hugo) Publish(c *fm.Context, w http.ResponseWriter, r *http.Request) (in
}
// Preview handles the preview path.
func (h *Hugo) Preview(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func (h *Hugo) Preview(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// Get a new temporary path if there is none.
if h.previewPath == "" {
path, err := ioutil.TempDir("", "")

View File

@@ -9,7 +9,7 @@ import (
"path/filepath"
"strings"
fm "github.com/filebrowser/filebrowser"
fb "github.com/filebrowser/filebrowser"
)
// Jekyll is the Jekyll static website generator.
@@ -39,12 +39,12 @@ func (j Jekyll) SettingsPath() string {
}
// Hook is the pre-api handler.
func (j Jekyll) Hook(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func (j Jekyll) Hook(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
return 0, nil
}
// Publish publishes a post.
func (j Jekyll) Publish(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func (j Jekyll) Publish(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
filename := filepath.Join(c.User.Scope, r.URL.Path)
// We only run undraft command if it is a file.
@@ -59,7 +59,7 @@ func (j Jekyll) Publish(c *fm.Context, w http.ResponseWriter, r *http.Request) (
}
// Preview handles the preview path.
func (j *Jekyll) Preview(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
func (j *Jekyll) Preview(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// Get a new temporary path if there is none.
if j.previewPath == "" {
path, err := ioutil.TempDir("", "")