Compare commits
28
Commits
v2.0.0-rc.1
...
v2.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20d80bb054 | ||
|
|
cbdf3cafb6 | ||
|
|
1259fc1bbc | ||
|
|
4cf1f2f6b4 | ||
|
|
a90bb28cae | ||
|
|
e86dfbe8ff | ||
|
|
437a238aca | ||
|
|
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
@@ -3,3 +3,4 @@
|
|||||||
*.bak
|
*.bak
|
||||||
_old
|
_old
|
||||||
rice-box.go
|
rice-box.go
|
||||||
|
.idea/
|
||||||
@@ -5,7 +5,6 @@ install: skip
|
|||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
- docker-ce
|
|
||||||
- pass
|
- pass
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
|
|||||||
@@ -10,4 +10,6 @@ import (
|
|||||||
type Auther interface {
|
type Auther interface {
|
||||||
// Auth is called to authenticate a request.
|
// Auth is called to authenticate a request.
|
||||||
Auth(r *http.Request, s *users.Storage, root string) (*users.User, error)
|
Auth(r *http.Request, s *users.Storage, root string) (*users.User, error)
|
||||||
|
// LoginPage indicates if this auther needs a login page.
|
||||||
|
LoginPage() bool
|
||||||
}
|
}
|
||||||
@@ -59,6 +59,11 @@ func (a JSONAuth) Auth(r *http.Request, sto *users.Storage, root string) (*users
|
|||||||
return u, nil
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoginPage tells that json auth doesn't require a login page.
|
||||||
|
func (a JSONAuth) LoginPage() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
const reCaptchaAPI = "/recaptcha/api/siteverify"
|
const reCaptchaAPI = "/recaptcha/api/siteverify"
|
||||||
|
|
||||||
// ReCaptcha identifies a recaptcha conenction.
|
// ReCaptcha identifies a recaptcha conenction.
|
||||||
|
|||||||
@@ -17,3 +17,8 @@ type NoAuth struct{}
|
|||||||
func (a NoAuth) Auth(r *http.Request, sto *users.Storage, root string) (*users.User, error) {
|
func (a NoAuth) Auth(r *http.Request, sto *users.Storage, root string) (*users.User, error) {
|
||||||
return sto.Get(root, uint(1))
|
return sto.Get(root, uint(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoginPage tells that no auth doesn't require a login page.
|
||||||
|
func (a NoAuth) LoginPage() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
@@ -27,3 +27,8 @@ func (a ProxyAuth) Auth(r *http.Request, sto *users.Storage, root string) (*user
|
|||||||
|
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoginPage tells that proxy auth doesn't require a login page.
|
||||||
|
func (a ProxyAuth) LoginPage() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
+4
-5
@@ -11,11 +11,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var cmdsCmd = &cobra.Command{
|
var cmdsCmd = &cobra.Command{
|
||||||
Use: "cmds",
|
Use: "cmds",
|
||||||
Version: rootCmd.Version,
|
Short: "Command runner management utility",
|
||||||
Short: "Command runner management utility",
|
Long: `Command runner management utility.`,
|
||||||
Long: `Command runner management utility.`,
|
Args: cobra.NoArgs,
|
||||||
Args: cobra.NoArgs,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func printEvents(m map[string][]string) {
|
func printEvents(m map[string][]string) {
|
||||||
|
|||||||
+4
-5
@@ -20,11 +20,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var configCmd = &cobra.Command{
|
var configCmd = &cobra.Command{
|
||||||
Use: "config",
|
Use: "config",
|
||||||
Version: rootCmd.Version,
|
Short: "Configuration management utility",
|
||||||
Short: "Configuration management utility",
|
Long: `Configuration management utility.`,
|
||||||
Long: `Configuration management utility.`,
|
Args: cobra.NoArgs,
|
||||||
Args: cobra.NoArgs,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func addConfigFlags(flags *pflag.FlagSet) {
|
func addConfigFlags(flags *pflag.FlagSet) {
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
+4
-5
@@ -12,11 +12,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var hashCmd = &cobra.Command{
|
var hashCmd = &cobra.Command{
|
||||||
Use: "hash <password>",
|
Use: "hash <password>",
|
||||||
Version: rootCmd.Version,
|
Short: "Hashes a password",
|
||||||
Short: "Hashes a password",
|
Long: `Hashes a password using bcrypt algorithm.`,
|
||||||
Long: `Hashes a password using bcrypt algorithm.`,
|
Args: cobra.ExactArgs(1),
|
||||||
Args: cobra.ExactArgs(1),
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
pwd, err := users.HashPwd(args[0])
|
pwd, err := users.HashPwd(args[0])
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|||||||
+3
-5
@@ -15,7 +15,6 @@ import (
|
|||||||
"github.com/filebrowser/filebrowser/v2/settings"
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
"github.com/filebrowser/filebrowser/v2/storage"
|
"github.com/filebrowser/filebrowser/v2/storage"
|
||||||
"github.com/filebrowser/filebrowser/v2/users"
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
"github.com/filebrowser/filebrowser/v2/version"
|
|
||||||
homedir "github.com/mitchellh/go-homedir"
|
homedir "github.com/mitchellh/go-homedir"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
@@ -55,9 +54,8 @@ func addServerFlags(flags *pflag.FlagSet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "filebrowser",
|
Use: "filebrowser",
|
||||||
Version: version.Version,
|
Short: "A stylish web-based file browser",
|
||||||
Short: "A stylish web-based file browser",
|
|
||||||
Long: `File Browser CLI lets you create the database to use with File Browser,
|
Long: `File Browser CLI lets you create the database to use with File Browser,
|
||||||
manage your users and all the configurations without acessing the
|
manage your users and all the configurations without acessing the
|
||||||
web interface.
|
web interface.
|
||||||
@@ -215,7 +213,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: ".",
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ func init() {
|
|||||||
|
|
||||||
var rulesCmd = &cobra.Command{
|
var rulesCmd = &cobra.Command{
|
||||||
Use: "rules",
|
Use: "rules",
|
||||||
Version: rootCmd.Version,
|
|
||||||
Short: "Rules management utility",
|
Short: "Rules management utility",
|
||||||
Long: `On each subcommand you'll have available at least two flags:
|
Long: `On each subcommand you'll have available at least two flags:
|
||||||
"username" and "id". You must either set only one of them
|
"username" and "id". You must either set only one of them
|
||||||
|
|||||||
+2
-3
@@ -14,9 +14,8 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var upgradeCmd = &cobra.Command{
|
var upgradeCmd = &cobra.Command{
|
||||||
Use: "upgrade",
|
Use: "upgrade",
|
||||||
Version: rootCmd.Version,
|
Short: "Upgrades an old configuration",
|
||||||
Short: "Upgrades an old configuration",
|
|
||||||
Long: `Upgrades an old configuration. This command DOES NOT
|
Long: `Upgrades an old configuration. This command DOES NOT
|
||||||
import share links because they are incompatible with
|
import share links because they are incompatible with
|
||||||
this version.`,
|
this version.`,
|
||||||
|
|||||||
+4
-5
@@ -18,11 +18,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var usersCmd = &cobra.Command{
|
var usersCmd = &cobra.Command{
|
||||||
Use: "users",
|
Use: "users",
|
||||||
Version: rootCmd.Version,
|
Short: "Users management utility",
|
||||||
Short: "Users management utility",
|
Long: `Users management utility.`,
|
||||||
Long: `Users management utility.`,
|
Args: cobra.NoArgs,
|
||||||
Args: cobra.NoArgs,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func printUsers(users []*users.User) {
|
func printUsers(users []*users.User) {
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
+30
-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,45 @@ type pythonData struct {
|
|||||||
store *storage.Storage
|
store *storage.Storage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dbExists(path string) (bool, error) {
|
||||||
|
stat, err := os.Stat(path)
|
||||||
|
if err == nil {
|
||||||
|
return stat.Size() != 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
d := filepath.Dir(path)
|
||||||
|
_, err = os.Stat(d)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
os.MkdirAll(d, 0700)
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-16
@@ -1,32 +1,20 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"text/template"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/version"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(versionCmd)
|
rootCmd.AddCommand(versionCmd)
|
||||||
cmdsCmd.AddCommand(versionCmd)
|
|
||||||
configCmd.AddCommand(versionCmd)
|
|
||||||
hashCmd.AddCommand(versionCmd)
|
|
||||||
upgradeCmd.AddCommand(versionCmd)
|
|
||||||
rulesCmd.AddCommand(versionCmd)
|
|
||||||
usersCmd.AddCommand(versionCmd)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var versionCmd = &cobra.Command{
|
var versionCmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Print the version number of File Browser",
|
Short: "Print the version number",
|
||||||
Long: `All software has versions. This is File Browser's`,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
// https://github.com/spf13/cobra/issues/724
|
fmt.Println("File Browser Version " + version.Version)
|
||||||
t := template.New("version")
|
|
||||||
template.Must(t.Parse(rootCmd.VersionTemplate()))
|
|
||||||
err := t.Execute(rootCmd.OutOrStdout(), rootCmd)
|
|
||||||
if err != nil {
|
|
||||||
rootCmd.Println(err)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
+2
-1
@@ -2,6 +2,7 @@ package files
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/maruel/natural"
|
"github.com/maruel/natural"
|
||||||
)
|
)
|
||||||
@@ -68,7 +69,7 @@ func (l byName) Less(i, j int) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return natural.Less(l.Items[i].Name, l.Items[j].Name)
|
return natural.Less(strings.ToLower(l.Items[j].Name), strings.ToLower(l.Items[i].Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// By Size
|
// By Size
|
||||||
|
|||||||
+1
-1
Submodule frontend updated: 2ed87febcb...9c3f563f83.
@@ -21,12 +21,12 @@ require (
|
|||||||
github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 // indirect
|
github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 // indirect
|
||||||
github.com/kr/pretty v0.1.0 // indirect
|
github.com/kr/pretty v0.1.0 // indirect
|
||||||
github.com/maruel/natural v0.0.0-20180416170133-dbcb3e2e8cf1
|
github.com/maruel/natural v0.0.0-20180416170133-dbcb3e2e8cf1
|
||||||
github.com/mholt/archiver v3.1.0+incompatible
|
github.com/mholt/archiver v3.1.1+incompatible
|
||||||
github.com/mholt/caddy v0.11.1
|
github.com/mholt/caddy v0.11.1
|
||||||
github.com/mitchellh/go-homedir v1.0.0
|
github.com/mitchellh/go-homedir v1.0.0
|
||||||
github.com/nwaples/rardecode v1.0.0 // indirect
|
github.com/nwaples/rardecode v1.0.0 // indirect
|
||||||
github.com/pelletier/go-toml v1.2.0
|
github.com/pelletier/go-toml v1.2.0
|
||||||
github.com/pierrec/lz4 v2.0.5+incompatible // indirect
|
github.com/pierrec/lz4 v0.0.0-20190131084431-473cd7ce01a1 // indirect
|
||||||
github.com/spf13/afero v1.1.2
|
github.com/spf13/afero v1.1.2
|
||||||
github.com/spf13/cobra v0.0.3
|
github.com/spf13/cobra v0.0.3
|
||||||
github.com/spf13/pflag v1.0.3
|
github.com/spf13/pflag v1.0.3
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ github.com/maruel/natural v0.0.0-20180416170133-dbcb3e2e8cf1 h1:PEhRT94KBTY4E0Kd
|
|||||||
github.com/maruel/natural v0.0.0-20180416170133-dbcb3e2e8cf1/go.mod h1:wI697HNhDFM/vBruYM3ckbszQ2+DOIeH9qdBKMdf288=
|
github.com/maruel/natural v0.0.0-20180416170133-dbcb3e2e8cf1/go.mod h1:wI697HNhDFM/vBruYM3ckbszQ2+DOIeH9qdBKMdf288=
|
||||||
github.com/mholt/archiver v3.1.0+incompatible h1:S1rFZ7umHtN6cG+6cusrfoXTMPqp6u/R89iKxBYJd4w=
|
github.com/mholt/archiver v3.1.0+incompatible h1:S1rFZ7umHtN6cG+6cusrfoXTMPqp6u/R89iKxBYJd4w=
|
||||||
github.com/mholt/archiver v3.1.0+incompatible/go.mod h1:Dh2dOXnSdiLxRiPoVfIr/fI1TwETms9B8CTWfeh7ROU=
|
github.com/mholt/archiver v3.1.0+incompatible/go.mod h1:Dh2dOXnSdiLxRiPoVfIr/fI1TwETms9B8CTWfeh7ROU=
|
||||||
|
github.com/mholt/archiver v3.1.1+incompatible h1:1dCVxuqs0dJseYEhi5pl7MYPH9zDa1wBi7mF09cbNkU=
|
||||||
|
github.com/mholt/archiver v3.1.1+incompatible/go.mod h1:Dh2dOXnSdiLxRiPoVfIr/fI1TwETms9B8CTWfeh7ROU=
|
||||||
github.com/mholt/caddy v0.11.1 h1:oNfejqftVesLoFxw53Gh17aBPNbTxQ9xJw1pn4IiAPk=
|
github.com/mholt/caddy v0.11.1 h1:oNfejqftVesLoFxw53Gh17aBPNbTxQ9xJw1pn4IiAPk=
|
||||||
github.com/mholt/caddy v0.11.1/go.mod h1:Wb1PlT4DAYSqOEd03MsqkdkXnTxA8v9pKjdpxbqM1kY=
|
github.com/mholt/caddy v0.11.1/go.mod h1:Wb1PlT4DAYSqOEd03MsqkdkXnTxA8v9pKjdpxbqM1kY=
|
||||||
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
|
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
|
||||||
@@ -67,8 +69,11 @@ github.com/nwaples/rardecode v1.0.0 h1:r7vGuS5akxOnR4JQSkko62RJ1ReCMXxQRPtxsiFMB
|
|||||||
github.com/nwaples/rardecode v1.0.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
|
github.com/nwaples/rardecode v1.0.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
|
||||||
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
|
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
|
||||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||||
|
github.com/pierrec/lz4 v0.0.0-20190131084431-473cd7ce01a1 h1:0utzB5Mn6QyMzIeOn+oD7pjKQLjJwfM9bz6TkPPdxcw=
|
||||||
|
github.com/pierrec/lz4 v0.0.0-20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
|
||||||
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
|
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
|
||||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||||
|
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
|
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
|
||||||
|
|||||||
+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
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,11 @@ func handleWithStaticData(w http.ResponseWriter, r *http.Request, d *data, box *
|
|||||||
|
|
||||||
staticURL := strings.TrimPrefix(d.server.BaseURL+"/static", "/")
|
staticURL := strings.TrimPrefix(d.server.BaseURL+"/static", "/")
|
||||||
|
|
||||||
|
auther, err := d.store.Auth.Get(d.settings.AuthMethod)
|
||||||
|
if err != nil {
|
||||||
|
return http.StatusInternalServerError, err
|
||||||
|
}
|
||||||
|
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"Name": d.settings.Branding.Name,
|
"Name": d.settings.Branding.Name,
|
||||||
"DisableExternal": d.settings.Branding.DisableExternal,
|
"DisableExternal": d.settings.Branding.DisableExternal,
|
||||||
@@ -29,6 +34,7 @@ func handleWithStaticData(w http.ResponseWriter, r *http.Request, d *data, box *
|
|||||||
"StaticURL": staticURL,
|
"StaticURL": staticURL,
|
||||||
"Signup": d.settings.Signup,
|
"Signup": d.settings.Signup,
|
||||||
"NoAuth": d.settings.AuthMethod == auth.MethodNoAuth,
|
"NoAuth": d.settings.AuthMethod == auth.MethodNoAuth,
|
||||||
|
"LoginPage": auther.LoginPage(),
|
||||||
"CSS": false,
|
"CSS": false,
|
||||||
"ReCaptcha": false,
|
"ReCaptcha": false,
|
||||||
}
|
}
|
||||||
|
|||||||
+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.3"
|
||||||
)
|
)
|
||||||
@@ -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