new
This commit is contained in:
parent
d0cca8f285
commit
3fb940ba5b
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"port": 5555,
|
|
||||||
"baseURL": "",
|
|
||||||
"address": "",
|
|
||||||
"log": "stdout",
|
|
||||||
"database": "./database.db",
|
|
||||||
"root": "/srv"
|
|
||||||
}
|
|
|
@ -15,9 +15,6 @@ import (
|
||||||
"github.com/gtsteffaniak/filebrowser/users"
|
"github.com/gtsteffaniak/filebrowser/users"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MethodHookAuth is used to identify hook auth.
|
|
||||||
const MethodHookAuth = "hook"
|
|
||||||
|
|
||||||
type hookCred struct {
|
type hookCred struct {
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
|
|
|
@ -11,9 +11,6 @@ import (
|
||||||
"github.com/gtsteffaniak/filebrowser/users"
|
"github.com/gtsteffaniak/filebrowser/users"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MethodJSONAuth is used to identify json auth.
|
|
||||||
const MethodJSONAuth = "json"
|
|
||||||
|
|
||||||
type jsonCred struct {
|
type jsonCred struct {
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
|
|
|
@ -32,10 +32,6 @@ func addConfigFlags(flags *pflag.FlagSet) {
|
||||||
flags.BoolP("signup", "s", false, "allow users to signup")
|
flags.BoolP("signup", "s", false, "allow users to signup")
|
||||||
flags.String("shell", "", "shell command to which other commands should be appended")
|
flags.String("shell", "", "shell command to which other commands should be appended")
|
||||||
|
|
||||||
flags.String("auth.method", string(auth.MethodJSONAuth), "authentication type")
|
|
||||||
flags.String("auth.header", "", "HTTP header for auth.method=proxy")
|
|
||||||
flags.String("auth.command", "", "command for auth.method=hook")
|
|
||||||
|
|
||||||
flags.String("recaptcha.host", "https://www.google.com", "use another host for ReCAPTCHA. recaptcha.net might be useful in China")
|
flags.String("recaptcha.host", "https://www.google.com", "use another host for ReCAPTCHA. recaptcha.net might be useful in China")
|
||||||
flags.String("recaptcha.key", "", "ReCaptcha site key")
|
flags.String("recaptcha.key", "", "ReCaptcha site key")
|
||||||
flags.String("recaptcha.secret", "", "ReCaptcha secret")
|
flags.String("recaptcha.secret", "", "ReCaptcha secret")
|
||||||
|
@ -52,7 +48,7 @@ func getAuthentication() (string, auth.Auther) {
|
||||||
method := settings.GlobalConfiguration.Auth.Method
|
method := settings.GlobalConfiguration.Auth.Method
|
||||||
var defaultAuther map[string]interface{}
|
var defaultAuther map[string]interface{}
|
||||||
var auther auth.Auther
|
var auther auth.Auther
|
||||||
if method == auth.MethodProxyAuth {
|
if method == "proxy" {
|
||||||
header := settings.GlobalConfiguration.Auth.Header
|
header := settings.GlobalConfiguration.Auth.Header
|
||||||
if header == "" {
|
if header == "" {
|
||||||
header = defaultAuther["header"].(string)
|
header = defaultAuther["header"].(string)
|
||||||
|
@ -65,11 +61,11 @@ func getAuthentication() (string, auth.Auther) {
|
||||||
auther = &auth.ProxyAuth{Header: header}
|
auther = &auth.ProxyAuth{Header: header}
|
||||||
}
|
}
|
||||||
|
|
||||||
if method == auth.MethodNoAuth {
|
if method == "noauth" {
|
||||||
auther = &auth.NoAuth{}
|
auther = &auth.NoAuth{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if method == auth.MethodJSONAuth {
|
if method == "password" {
|
||||||
jsonAuth := &auth.JSONAuth{}
|
jsonAuth := &auth.JSONAuth{}
|
||||||
host := settings.GlobalConfiguration.Auth.Recaptcha.Host
|
host := settings.GlobalConfiguration.Auth.Recaptcha.Host
|
||||||
key := settings.GlobalConfiguration.Auth.Recaptcha.Key
|
key := settings.GlobalConfiguration.Auth.Recaptcha.Key
|
||||||
|
@ -97,7 +93,7 @@ func getAuthentication() (string, auth.Auther) {
|
||||||
auther = jsonAuth
|
auther = jsonAuth
|
||||||
}
|
}
|
||||||
|
|
||||||
if method == auth.MethodHookAuth {
|
if method == "hook" {
|
||||||
command := settings.GlobalConfiguration.Auth.Command
|
command := settings.GlobalConfiguration.Auth.Command
|
||||||
|
|
||||||
if command == "" {
|
if command == "" {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ The path must be for a json or yaml file.`,
|
||||||
file := settingsFile{}
|
file := settingsFile{}
|
||||||
err := unmarshal(args[0], &file)
|
err := unmarshal(args[0], &file)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
log.Println(file.Settings)
|
||||||
file.Settings.Key = key
|
file.Settings.Key = key
|
||||||
err = d.store.Settings.Save(file.Settings)
|
err = d.store.Settings.Save(file.Settings)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
@ -60,16 +61,16 @@ The path must be for a json or yaml file.`,
|
||||||
} else {
|
} else {
|
||||||
rawAuther = file.Auther
|
rawAuther = file.Auther
|
||||||
}
|
}
|
||||||
|
log.Println("config_import",file.Settings.Auth)
|
||||||
var auther auth.Auther
|
var auther auth.Auther
|
||||||
switch file.Settings.Auth.Method {
|
switch file.Settings.Auth.Method {
|
||||||
case auth.MethodJSONAuth:
|
case "password":
|
||||||
auther = getAuther(auth.JSONAuth{}, rawAuther).(*auth.JSONAuth)
|
auther = getAuther(auth.JSONAuth{}, rawAuther).(*auth.JSONAuth)
|
||||||
case auth.MethodNoAuth:
|
case "noauth":
|
||||||
auther = getAuther(auth.NoAuth{}, rawAuther).(*auth.NoAuth)
|
auther = getAuther(auth.NoAuth{}, rawAuther).(*auth.NoAuth)
|
||||||
case auth.MethodProxyAuth:
|
case "proxy":
|
||||||
auther = getAuther(auth.ProxyAuth{}, rawAuther).(*auth.ProxyAuth)
|
auther = getAuther(auth.ProxyAuth{}, rawAuther).(*auth.ProxyAuth)
|
||||||
case auth.MethodHookAuth:
|
case "hook":
|
||||||
auther = getAuther(&auth.HookAuth{}, rawAuther).(*auth.HookAuth)
|
auther = getAuther(&auth.HookAuth{}, rawAuther).(*auth.HookAuth)
|
||||||
default:
|
default:
|
||||||
checkErr(errors.New("invalid auth method"))
|
checkErr(errors.New("invalid auth method"))
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
v "github.com/spf13/viper"
|
v "github.com/spf13/viper"
|
||||||
lumberjack "gopkg.in/natefinch/lumberjack.v2"
|
lumberjack "gopkg.in/natefinch/lumberjack.v2"
|
||||||
|
|
||||||
"github.com/gtsteffaniak/filebrowser/auth"
|
|
||||||
"github.com/gtsteffaniak/filebrowser/diskcache"
|
"github.com/gtsteffaniak/filebrowser/diskcache"
|
||||||
fbhttp "github.com/gtsteffaniak/filebrowser/http"
|
fbhttp "github.com/gtsteffaniak/filebrowser/http"
|
||||||
"github.com/gtsteffaniak/filebrowser/img"
|
"github.com/gtsteffaniak/filebrowser/img"
|
||||||
|
@ -51,8 +50,6 @@ func init() {
|
||||||
persistent := rootCmd.PersistentFlags()
|
persistent := rootCmd.PersistentFlags()
|
||||||
|
|
||||||
persistent.StringVarP(&cfgFile, "config", "c", "", "config file path")
|
persistent.StringVarP(&cfgFile, "config", "c", "", "config file path")
|
||||||
persistent.StringP("database", "d", "./filebrowser.db", "database path")
|
|
||||||
flags.Bool("noauth", false, "use the noauth auther when using quick setup")
|
|
||||||
flags.String("username", "admin", "username for the first user when using quick config")
|
flags.String("username", "admin", "username for the first user when using quick config")
|
||||||
flags.String("password", "", "hashed password for the first user when using quick config (default \"admin\")")
|
flags.String("password", "", "hashed password for the first user when using quick config (default \"admin\")")
|
||||||
}
|
}
|
||||||
|
@ -245,13 +242,7 @@ func quickSetup(flags *pflag.FlagSet, d pythonData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if settings.GlobalConfiguration.Auth.Method == "noAuth" {
|
set.Auth.Method = settings.GlobalConfiguration.Auth.Method
|
||||||
set.Auth.Method = "noAuth"
|
|
||||||
err = d.store.Auth.Save(&auth.NoAuth{})
|
|
||||||
}else{
|
|
||||||
set.Auth.Method = auth.MethodJSONAuth
|
|
||||||
err = d.store.Auth.Save(&auth.JSONAuth{})
|
|
||||||
}
|
|
||||||
err = d.store.Settings.Save(set)
|
err = d.store.Settings.Save(set)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
server:
|
server:
|
||||||
port: 8050
|
port: 8050
|
||||||
baseURL: /files
|
baseURL: /
|
||||||
address: ''
|
address: ''
|
||||||
log: stdout
|
log: stdout
|
||||||
database: ./database.db
|
database: ./database.db
|
||||||
|
@ -12,7 +12,7 @@ general:
|
||||||
disable-type-detection-by-header: false
|
disable-type-detection-by-header: false
|
||||||
auth:
|
auth:
|
||||||
header: ''
|
header: ''
|
||||||
method: 'noauth'
|
method: noauth
|
||||||
command: ''
|
command: ''
|
||||||
signup: false
|
signup: false
|
||||||
shell: ''
|
shell: ''
|
||||||
|
|
|
@ -35,7 +35,7 @@ func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, fSys
|
||||||
"Version": version.Version,
|
"Version": version.Version,
|
||||||
"StaticURL": path.Join(d.server.BaseURL, "/static"),
|
"StaticURL": path.Join(d.server.BaseURL, "/static"),
|
||||||
"Signup": d.settings.Signup,
|
"Signup": d.settings.Signup,
|
||||||
"NoAuth": d.settings.Auth.Method == auth.MethodNoAuth,
|
"NoAuth": d.settings.Auth.Method == "noauth",
|
||||||
"AuthMethod": d.settings.Auth.Method,
|
"AuthMethod": d.settings.Auth.Method,
|
||||||
"LoginPage": auther.LoginPage(),
|
"LoginPage": auther.LoginPage(),
|
||||||
"CSS": false,
|
"CSS": false,
|
||||||
|
@ -59,7 +59,7 @@ func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, fSys
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.settings.Auth.Method == auth.MethodJSONAuth {
|
if d.settings.Auth.Method == "password" {
|
||||||
raw, err := d.store.Auth.Get(d.settings.Auth.Method) //nolint:govet
|
raw, err := d.store.Auth.Get(d.settings.Auth.Method) //nolint:govet
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
|
|
|
@ -22,12 +22,17 @@ func Initialize() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error reading YAML data: %v", err)
|
log.Fatalf("Error reading YAML data: %v", err)
|
||||||
}
|
}
|
||||||
|
log.Println(GlobalConfiguration)
|
||||||
setDefaults()
|
setDefaults()
|
||||||
|
log.Println(GlobalConfiguration)
|
||||||
|
|
||||||
// Unmarshal the YAML data into the Settings struct
|
// Unmarshal the YAML data into the Settings struct
|
||||||
err = yaml.Unmarshal(yamlData, &GlobalConfiguration)
|
err = yaml.Unmarshal(yamlData, &GlobalConfiguration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error unmarshaling YAML data: %v", err)
|
log.Fatalf("Error unmarshaling YAML data: %v", err)
|
||||||
}
|
}
|
||||||
|
log.Println(GlobalConfiguration)
|
||||||
|
|
||||||
// Now you have the Settings struct with values from the YAML file
|
// Now you have the Settings struct with values from the YAML file
|
||||||
// You can access the values like: defaultSettings.Key, defaultSettings.Server.Port, etc.
|
// You can access the values like: defaultSettings.Key, defaultSettings.Server.Port, etc.
|
||||||
}
|
}
|
||||||
|
@ -39,9 +44,10 @@ func setDefaults() {
|
||||||
IndexingInterval: 5,
|
IndexingInterval: 5,
|
||||||
Port: 8080,
|
Port: 8080,
|
||||||
NumImageProcessors: 1,
|
NumImageProcessors: 1,
|
||||||
BaseURL: "/files",
|
BaseURL: "/",
|
||||||
},
|
},
|
||||||
Auth: Auth{
|
Auth: Auth{
|
||||||
|
Method: "noauth",
|
||||||
Recaptcha: Recaptcha{
|
Recaptcha: Recaptcha{
|
||||||
Host: "",
|
Host: "",
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package bolt
|
package bolt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/asdine/storm/v3"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/asdine/storm/v3"
|
||||||
"github.com/gtsteffaniak/filebrowser/auth"
|
"github.com/gtsteffaniak/filebrowser/auth"
|
||||||
"github.com/gtsteffaniak/filebrowser/errors"
|
"github.com/gtsteffaniak/filebrowser/errors"
|
||||||
)
|
)
|
||||||
|
@ -13,15 +14,15 @@ type authBackend struct {
|
||||||
|
|
||||||
func (s authBackend) Get(t string) (auth.Auther, error) {
|
func (s authBackend) Get(t string) (auth.Auther, error) {
|
||||||
var auther auth.Auther
|
var auther auth.Auther
|
||||||
|
fmt.Println("auth.go", t)
|
||||||
switch t {
|
switch t {
|
||||||
case auth.MethodJSONAuth:
|
case "password":
|
||||||
auther = &auth.JSONAuth{}
|
auther = &auth.JSONAuth{}
|
||||||
case auth.MethodProxyAuth:
|
case "proxy":
|
||||||
auther = &auth.ProxyAuth{}
|
auther = &auth.ProxyAuth{}
|
||||||
case auth.MethodHookAuth:
|
case "hook":
|
||||||
auther = &auth.HookAuth{}
|
auther = &auth.HookAuth{}
|
||||||
case auth.MethodNoAuth:
|
case "noauth":
|
||||||
auther = &auth.NoAuth{}
|
auther = &auth.NoAuth{}
|
||||||
default:
|
default:
|
||||||
return nil, errors.ErrInvalidAuthMethod
|
return nil, errors.ErrInvalidAuthMethod
|
||||||
|
|
|
@ -144,18 +144,18 @@ func importConf(db *storm.DB, path string, sto *storage.Storage) error {
|
||||||
Address: cfg.Address,
|
Address: cfg.Address,
|
||||||
Log: cfg.Log,
|
Log: cfg.Log,
|
||||||
}
|
}
|
||||||
|
fmt.Println("config.go", server)
|
||||||
var auther auth.Auther
|
var auther auth.Auther
|
||||||
switch cfg.Auth.Method {
|
switch cfg.Auth.Method {
|
||||||
case "proxy":
|
case "proxy":
|
||||||
auther = &auth.ProxyAuth{Header: cfg.Auth.Header}
|
auther = &auth.ProxyAuth{Header: cfg.Auth.Header}
|
||||||
s.Auth.Method = string(auth.MethodProxyAuth)
|
s.Auth.Method = "proxy"
|
||||||
case "hook":
|
case "hook":
|
||||||
auther = &auth.HookAuth{Command: cfg.Auth.Command}
|
auther = &auth.HookAuth{Command: cfg.Auth.Command}
|
||||||
s.Auth.Method = string(auth.MethodHookAuth)
|
s.Auth.Method = "hoook"
|
||||||
case "none":
|
case "none":
|
||||||
auther = &auth.NoAuth{}
|
auther = &auth.NoAuth{}
|
||||||
s.Auth.Method = string(auth.MethodNoAuth)
|
s.Auth.Method = "noauth"
|
||||||
default:
|
default:
|
||||||
auther = &auth.JSONAuth{
|
auther = &auth.JSONAuth{
|
||||||
ReCaptcha: &auth.ReCaptcha{
|
ReCaptcha: &auth.ReCaptcha{
|
||||||
|
@ -164,7 +164,7 @@ func importConf(db *storm.DB, path string, sto *storage.Storage) error {
|
||||||
Secret: cfg.ReCaptcha.Secret,
|
Secret: cfg.ReCaptcha.Secret,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
s.Auth.Method = string(auth.MethodJSONAuth)
|
s.Auth.Method = "password"
|
||||||
}
|
}
|
||||||
|
|
||||||
err = sto.Auth.Save(auther)
|
err = sto.Auth.Save(auther)
|
||||||
|
|
Loading…
Reference in New Issue