Compare commits
21
Commits
v2.0.0-rc.1
...
v2.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5fa0772c6 | ||
|
|
ba5c67d9da | ||
|
|
f3d007025e | ||
|
|
e7a39808dd | ||
|
|
2b7aa7a0c9 | ||
|
|
4d8f0c532b | ||
|
|
367e251a0e | ||
|
|
cc6f2f8bec | ||
|
|
007fde8186 | ||
|
|
552f8168ea | ||
|
|
42426e3e69 | ||
|
|
e706391934 | ||
|
|
58ff28f84d | ||
|
|
74a1ecbb89 | ||
|
|
5fa1711a30 | ||
|
|
4bc6a23143 | ||
|
|
b578e2196a | ||
|
|
866375141f | ||
|
|
a3b9807717 | ||
|
|
d47774c828 | ||
|
|
bc4ac5eb9b |
No files matched your search
@@ -5,7 +5,6 @@ install: skip
|
|||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
- docker-ce
|
|
||||||
- pass
|
- pass
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ The path must be for a json or yaml file.`,
|
|||||||
checkErr(err)
|
checkErr(err)
|
||||||
key = settings.Key
|
key = settings.Key
|
||||||
} else {
|
} else {
|
||||||
key = generateRandomBytes(64)
|
key = generateKey()
|
||||||
}
|
}
|
||||||
|
|
||||||
file := settingsFile{}
|
file := settingsFile{}
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ override the options.`,
|
|||||||
authMethod, auther := getAuthentication(flags)
|
authMethod, auther := getAuthentication(flags)
|
||||||
|
|
||||||
s := &settings.Settings{
|
s := &settings.Settings{
|
||||||
Key: generateRandomBytes(64), // 256 bit
|
Key: generateKey(),
|
||||||
Signup: mustGetBool(flags, "signup"),
|
Signup: mustGetBool(flags, "signup"),
|
||||||
Shell: strings.Split(strings.TrimSpace(mustGetString(flags, "shell")), " "),
|
Shell: strings.Split(strings.TrimSpace(mustGetString(flags, "shell")), " "),
|
||||||
AuthMethod: authMethod,
|
AuthMethod: authMethod,
|
||||||
|
|||||||
+1
-1
@@ -215,7 +215,7 @@ func setupLog(logMethod string) {
|
|||||||
|
|
||||||
func quickSetup(flags *pflag.FlagSet, d pythonData) {
|
func quickSetup(flags *pflag.FlagSet, d pythonData) {
|
||||||
set := &settings.Settings{
|
set := &settings.Settings{
|
||||||
Key: generateRandomBytes(64), // 256 bit
|
Key: generateKey(),
|
||||||
Signup: false,
|
Signup: false,
|
||||||
Defaults: settings.UserDefaults{
|
Defaults: settings.UserDefaults{
|
||||||
Scope: ".",
|
Scope: ".",
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ list or set it to 0.`,
|
|||||||
checkErr(usernameConflictError(user.Username, conflictuous.ID, user.ID))
|
checkErr(usernameConflictError(user.Username, conflictuous.ID, user.ID))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// If it doesn't exist, set the ID to 0 to automatically get a new
|
||||||
|
// one that make sense in this DB.
|
||||||
|
user.ID = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
err = d.store.Users.Save(user)
|
err = d.store.Users.Save(user)
|
||||||
|
|||||||
+28
-16
@@ -1,7 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -10,6 +9,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/asdine/storm"
|
"github.com/asdine/storm"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
"github.com/filebrowser/filebrowser/v2/storage"
|
"github.com/filebrowser/filebrowser/v2/storage"
|
||||||
"github.com/filebrowser/filebrowser/v2/storage/bolt"
|
"github.com/filebrowser/filebrowser/v2/storage/bolt"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -41,12 +41,10 @@ func mustGetUint(flags *pflag.FlagSet, flag string) uint {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRandomBytes(n int) []byte {
|
func generateKey() []byte {
|
||||||
b := make([]byte, n)
|
k, err := settings.GenerateKey()
|
||||||
_, err := rand.Read(b)
|
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
// Note that err == nil only if we read len(b) bytes.
|
return k
|
||||||
return b
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type cobraFunc func(cmd *cobra.Command, args []string)
|
type cobraFunc func(cmd *cobra.Command, args []string)
|
||||||
@@ -62,29 +60,43 @@ type pythonData struct {
|
|||||||
store *storage.Storage
|
store *storage.Storage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dbExists(path string) (bool, error) {
|
||||||
|
stat, err := os.Stat(path)
|
||||||
|
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false, nil
|
||||||
|
} else if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if stat.Size() == 0 {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
func python(fn pythonFunc, cfg pythonConfig) cobraFunc {
|
func python(fn pythonFunc, cfg pythonConfig) cobraFunc {
|
||||||
return func(cmd *cobra.Command, args []string) {
|
return func(cmd *cobra.Command, args []string) {
|
||||||
data := pythonData{hadDB: true}
|
data := pythonData{hadDB: true}
|
||||||
|
|
||||||
path := getParam(cmd.Flags(), "database")
|
path := getParam(cmd.Flags(), "database")
|
||||||
_, err := os.Stat(path)
|
exists, err := dbExists(path)
|
||||||
|
|
||||||
if os.IsNotExist(err) {
|
if err != nil {
|
||||||
data.hadDB = false
|
|
||||||
|
|
||||||
if !cfg.noDB && !cfg.allowNoDB {
|
|
||||||
log.Fatal(path + " does not exist. Please run 'filebrowser config init' first.")
|
|
||||||
}
|
|
||||||
} else if err != nil {
|
|
||||||
panic(err)
|
panic(err)
|
||||||
} else if err == nil && cfg.noDB {
|
} else if exists && cfg.noDB {
|
||||||
log.Fatal(path + " already exists")
|
log.Fatal(path + " already exists")
|
||||||
|
} else if !exists && !cfg.noDB && !cfg.allowNoDB {
|
||||||
|
log.Fatal(path + " does not exist. Please run 'filebrowser config init' first.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.hadDB = exists
|
||||||
db, err := storm.Open(path)
|
db, err := storm.Open(path)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
data.store = bolt.NewStorage(db)
|
data.store, err = bolt.NewStorage(db)
|
||||||
|
checkErr(err)
|
||||||
fn(cmd, args, data)
|
fn(cmd, args, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
Submodule frontend updated: 2ed87febcb...e370fbe500.
+1
-1
@@ -30,7 +30,7 @@ type authToken struct {
|
|||||||
type extractor []string
|
type extractor []string
|
||||||
|
|
||||||
func (e extractor) ExtractToken(r *http.Request) (string, error) {
|
func (e extractor) ExtractToken(r *http.Request) (string, error) {
|
||||||
token, _ := request.AuthorizationHeaderExtractor.ExtractToken(r)
|
token, _ := request.HeaderExtractor{"X-Auth"}.ExtractToken(r)
|
||||||
|
|
||||||
// Checks if the token isn't empty and if it contains two dots.
|
// Checks if the token isn't empty and if it contains two dots.
|
||||||
// The former prevents incompatibility with URLs that previously
|
// The former prevents incompatibility with URLs that previously
|
||||||
|
|||||||
@@ -64,9 +64,5 @@ func handle(fn handleFunc, prefix string, storage *storage.Storage, server *sett
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if prefix == "" {
|
|
||||||
return handler
|
|
||||||
}
|
|
||||||
|
|
||||||
return http.StripPrefix(prefix, handler)
|
return http.StripPrefix(prefix, handler)
|
||||||
}
|
}
|
||||||
+3
-2
@@ -14,8 +14,9 @@ type modifyRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewHandler(storage *storage.Storage, server *settings.Server) (http.Handler, error) {
|
func NewHandler(storage *storage.Storage, server *settings.Server) (http.Handler, error) {
|
||||||
r := mux.NewRouter()
|
server.Clean()
|
||||||
|
|
||||||
|
r := mux.NewRouter()
|
||||||
index, static := getStaticHandlers(storage, server)
|
index, static := getStaticHandlers(storage, server)
|
||||||
|
|
||||||
monkey := func(fn handleFunc, prefix string) http.Handler {
|
monkey := func(fn handleFunc, prefix string) http.Handler {
|
||||||
@@ -59,5 +60,5 @@ func NewHandler(storage *storage.Storage, server *settings.Server) (http.Handler
|
|||||||
public.PathPrefix("/dl").Handler(monkey(publicDlHandler, "/api/public/dl/")).Methods("GET")
|
public.PathPrefix("/dl").Handler(monkey(publicDlHandler, "/api/public/dl/")).Methods("GET")
|
||||||
public.PathPrefix("/share").Handler(monkey(publicShareHandler, "/api/public/share/")).Methods("GET")
|
public.PathPrefix("/share").Handler(monkey(publicShareHandler, "/api/public/share/")).Methods("GET")
|
||||||
|
|
||||||
return r, nil
|
return http.StripPrefix(server.BaseURL, r), nil
|
||||||
}
|
}
|
||||||
+14
-7
@@ -18,16 +18,23 @@ type searchOptions struct {
|
|||||||
func Search(fs afero.Fs, scope, query string, checker rules.Checker, found func(path string, f os.FileInfo) error) error {
|
func Search(fs afero.Fs, scope, query string, checker rules.Checker, found func(path string, f os.FileInfo) error) error {
|
||||||
search := parseSearch(query)
|
search := parseSearch(query)
|
||||||
|
|
||||||
return afero.Walk(fs, scope, func(path string, f os.FileInfo, err error) error {
|
scope = strings.Replace(scope, "\\", "/", -1)
|
||||||
path = strings.TrimPrefix(path, "/")
|
scope = strings.TrimPrefix(scope, "/")
|
||||||
path = strings.Replace(path, "\\", "/", -1)
|
scope = strings.TrimSuffix(scope, "/")
|
||||||
|
scope = "/" + scope + "/"
|
||||||
|
|
||||||
if !checker.Check(path) {
|
return afero.Walk(fs, scope, func(originalPath string, f os.FileInfo, err error) error {
|
||||||
|
originalPath = strings.Replace(originalPath, "\\", "/", -1)
|
||||||
|
originalPath = strings.TrimPrefix(originalPath, "/")
|
||||||
|
originalPath = "/" + originalPath
|
||||||
|
path := originalPath
|
||||||
|
|
||||||
|
if path == scope {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !search.CaseSensitive {
|
if !checker.Check(path) {
|
||||||
path = strings.ToLower(path)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !search.CaseSensitive {
|
if !search.CaseSensitive {
|
||||||
@@ -52,7 +59,7 @@ func Search(fs afero.Fs, scope, query string, checker rules.Checker, found func(
|
|||||||
if len(search.Terms) > 0 {
|
if len(search.Terms) > 0 {
|
||||||
for _, term := range search.Terms {
|
for _, term := range search.Terms {
|
||||||
if strings.Contains(path, term) {
|
if strings.Contains(path, term) {
|
||||||
return found(strings.TrimPrefix(path, scope), f)
|
return found(strings.TrimPrefix(originalPath, scope), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-4
@@ -1,6 +1,11 @@
|
|||||||
package settings
|
package settings
|
||||||
|
|
||||||
import "github.com/filebrowser/filebrowser/v2/rules"
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/rules"
|
||||||
|
)
|
||||||
|
|
||||||
// AuthMethod describes an authentication method.
|
// AuthMethod describes an authentication method.
|
||||||
type AuthMethod string
|
type AuthMethod string
|
||||||
@@ -17,6 +22,11 @@ type Settings struct {
|
|||||||
Rules []rules.Rule `json:"rules"`
|
Rules []rules.Rule `json:"rules"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRules implements rules.Provider.
|
||||||
|
func (s *Settings) GetRules() []rules.Rule {
|
||||||
|
return s.Rules
|
||||||
|
}
|
||||||
|
|
||||||
// Server specific settings.
|
// Server specific settings.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Root string `json:"root"`
|
Root string `json:"root"`
|
||||||
@@ -28,7 +38,19 @@ type Server struct {
|
|||||||
Log string `json:"log"`
|
Log string `json:"log"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRules implements rules.Provider.
|
// Clean cleans any variables that might need cleaning.
|
||||||
func (s *Settings) GetRules() []rules.Rule {
|
func (s *Server) Clean() {
|
||||||
return s.Rules
|
s.BaseURL = strings.TrimSuffix(s.BaseURL, "/")
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenerateKey generates a key of 256 bits.
|
||||||
|
func GenerateKey() ([]byte, error) {
|
||||||
|
b := make([]byte, 64)
|
||||||
|
_, err := rand.Read(b)
|
||||||
|
// Note that err == nil only if we read len(b) bytes.
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return b, nil
|
||||||
}
|
}
|
||||||
+1
-3
@@ -1,8 +1,6 @@
|
|||||||
package settings
|
package settings
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/filebrowser/filebrowser/v2/errors"
|
"github.com/filebrowser/filebrowser/v2/errors"
|
||||||
"github.com/filebrowser/filebrowser/v2/rules"
|
"github.com/filebrowser/filebrowser/v2/rules"
|
||||||
"github.com/filebrowser/filebrowser/v2/users"
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
@@ -94,6 +92,6 @@ func (s *Storage) GetServer() (*Server, error) {
|
|||||||
|
|
||||||
// SaveServer wraps StorageBackend.SaveServer and adds some verification.
|
// SaveServer wraps StorageBackend.SaveServer and adds some verification.
|
||||||
func (s *Storage) SaveServer(ser *Server) error {
|
func (s *Storage) SaveServer(ser *Server) error {
|
||||||
ser.BaseURL = strings.TrimSuffix(ser.BaseURL, "/")
|
ser.Clean()
|
||||||
return s.back.SaveServer(ser)
|
return s.back.SaveServer(ser)
|
||||||
}
|
}
|
||||||
@@ -10,16 +10,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// NewStorage creates a storage.Storage based on Bolt DB.
|
// NewStorage creates a storage.Storage based on Bolt DB.
|
||||||
func NewStorage(db *storm.DB) *storage.Storage {
|
func NewStorage(db *storm.DB) (*storage.Storage, error) {
|
||||||
users := users.NewStorage(usersBackend{db: db})
|
users := users.NewStorage(usersBackend{db: db})
|
||||||
share := share.NewStorage(shareBackend{db: db})
|
share := share.NewStorage(shareBackend{db: db})
|
||||||
settings := settings.NewStorage(settingsBackend{db: db})
|
settings := settings.NewStorage(settingsBackend{db: db})
|
||||||
auth := auth.NewStorage(authBackend{db: db}, users)
|
auth := auth.NewStorage(authBackend{db: db}, users)
|
||||||
|
|
||||||
|
err := save(db, "version", 2)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &storage.Storage{
|
return &storage.Storage{
|
||||||
Auth: auth,
|
Auth: auth,
|
||||||
Users: users,
|
Users: users,
|
||||||
Share: share,
|
Share: share,
|
||||||
Settings: settings,
|
Settings: settings,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -99,7 +99,6 @@ func readConf(path string) (*oldConf, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func importConf(db *storm.DB, path string, sto *storage.Storage) error {
|
func importConf(db *storm.DB, path string, sto *storage.Storage) error {
|
||||||
|
|
||||||
cfg, err := readConf(path)
|
cfg, err := readConf(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -19,7 +19,10 @@ func Import(oldDB, oldConf, newDB string) error {
|
|||||||
}
|
}
|
||||||
defer new.Close()
|
defer new.Close()
|
||||||
|
|
||||||
sto := bolt.NewStorage(new)
|
sto, err := bolt.NewStorage(new)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = importUsers(old, sto)
|
err = importUsers(old, sto)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ func convertUsersToNew(old []*oldUser) ([]*users.User, error) {
|
|||||||
|
|
||||||
for _, oldUser := range old {
|
for _, oldUser := range old {
|
||||||
user := &users.User{
|
user := &users.User{
|
||||||
ID: uint(oldUser.ID),
|
|
||||||
Username: oldUser.Username,
|
Username: oldUser.Username,
|
||||||
Password: oldUser.Password,
|
Password: oldUser.Password,
|
||||||
Scope: oldUser.Scope,
|
Scope: oldUser.Scope,
|
||||||
|
|||||||
+3
-3
@@ -89,11 +89,11 @@ func (s *Storage) Save(user *User) error {
|
|||||||
// id must be a string for username lookup or a uint for id lookup. If id
|
// id must be a string for username lookup or a uint for id lookup. If id
|
||||||
// is neither, a ErrInvalidDataType will be returned.
|
// is neither, a ErrInvalidDataType will be returned.
|
||||||
func (s *Storage) Delete(id interface{}) (err error) {
|
func (s *Storage) Delete(id interface{}) (err error) {
|
||||||
switch id.(type) {
|
switch id := id.(type) {
|
||||||
case string:
|
case string:
|
||||||
err = s.back.DeleteByUsername(id.(string))
|
err = s.back.DeleteByUsername(id)
|
||||||
case uint:
|
case uint:
|
||||||
err = s.back.DeleteByID(id.(uint))
|
err = s.back.DeleteByID(id)
|
||||||
default:
|
default:
|
||||||
err = errors.ErrInvalidDataType
|
err = errors.ErrInvalidDataType
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -2,5 +2,5 @@ package version
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// Version is the current File Browser version.
|
// Version is the current File Browser version.
|
||||||
Version = "v2.0.0-rc.1"
|
Version = "v2.0.2"
|
||||||
)
|
)
|
||||||
@@ -132,7 +132,7 @@ pushRicebox () {
|
|||||||
git clone git@github.com:filebrowser/caddy caddy
|
git clone git@github.com:filebrowser/caddy caddy
|
||||||
cd caddy
|
cd caddy
|
||||||
cp ../http/rice-box.go ./
|
cp ../http/rice-box.go ./
|
||||||
sed -i 's/package lib/package caddy/g' ./rice-box.go
|
sed -i 's/package http/package caddy/g' ./rice-box.go
|
||||||
git checkout -b update-rice-box origin/master
|
git checkout -b update-rice-box origin/master
|
||||||
git config --local user.name "Filebrowser Bot"
|
git config --local user.name "Filebrowser Bot"
|
||||||
git config --local user.email "FilebrowserBot@users.noreply.github.com"
|
git config --local user.email "FilebrowserBot@users.noreply.github.com"
|
||||||
|
|||||||
Reference in new issue
Block a user