diff --git a/backend/cmd/root.go b/backend/cmd/root.go index 58493985..84080622 100644 --- a/backend/cmd/root.go +++ b/backend/cmd/root.go @@ -118,7 +118,7 @@ func cleanupHandler(listener net.Listener, c chan os.Signal) { //nolint:interfac } func quickSetup(d pythonData) { - settings.GlobalConfiguration.Key = generateKey() + settings.GlobalConfiguration.Auth.Key = generateKey() if settings.GlobalConfiguration.Auth.Method == "noauth" { err := d.store.Auth.Save(&auth.NoAuth{}) checkErr(err) @@ -131,8 +131,8 @@ func quickSetup(d pythonData) { checkErr(err) err = d.store.Settings.SaveServer(&settings.GlobalConfiguration.Server) checkErr(err) - username := settings.GlobalConfiguration.AdminUsername - password := settings.GlobalConfiguration.AdminPassword + username := settings.GlobalConfiguration.Auth.AdminUsername + password := settings.GlobalConfiguration.Auth.AdminPassword if username == "" || password == "" { log.Fatal("username and password cannot be empty during quick setup") } diff --git a/backend/filebrowser.yaml b/backend/filebrowser.yaml index 3fc41d26..4718e8a1 100644 --- a/backend/filebrowser.yaml +++ b/backend/filebrowser.yaml @@ -1,9 +1,10 @@ server: port: 8080 baseURL: "/" + root: "/Users/steffag/git/go" auth: method: password - signup: true + signup: false userDefaults: darkMode: true disableSettings: false diff --git a/backend/http/auth.go b/backend/http/auth.go index a2f67895..612efca6 100644 --- a/backend/http/auth.go +++ b/backend/http/auth.go @@ -55,7 +55,7 @@ func (e extractor) ExtractToken(r *http.Request) (string, error) { func withUser(fn handleFunc) handleFunc { return func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { keyFunc := func(token *jwt.Token) (interface{}, error) { - return d.settings.Key, nil + return d.settings.Auth.Key, nil } var tk authToken @@ -112,7 +112,7 @@ type signupBody struct { } var signupHandler = func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { - if !d.settings.Signup { + if !settings.GlobalConfiguration.Auth.Signup { return http.StatusMethodNotAllowed, nil } @@ -142,7 +142,7 @@ var signupHandler = func(w http.ResponseWriter, r *http.Request, d *data) (int, } user.Scope = userHome log.Printf("new user: %s, home dir: [%s].", user.Username, userHome) - + settings.GlobalConfiguration.UserDefaults.Apply(user) err = d.store.Users.Save(user) if err == errors.ErrExist { return http.StatusConflict, err @@ -168,7 +168,7 @@ func printToken(w http.ResponseWriter, _ *http.Request, d *data, user *users.Use } token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) - signed, err := token.SignedString(d.settings.Key) + signed, err := token.SignedString(d.settings.Auth.Key) if err != nil { return http.StatusInternalServerError, err } diff --git a/backend/http/public_test.go b/backend/http/public_test.go index 5c010e19..ad61a6d3 100644 --- a/backend/http/public_test.go +++ b/backend/http/public_test.go @@ -85,7 +85,11 @@ func TestPublicShareHandlerAuthentication(t *testing.T) { if err := storage.Users.Save(&users.User{Username: "username", Password: "pw"}); err != nil { t.Fatalf("failed to save user: %v", err) } - if err := storage.Settings.Save(&settings.Settings{Key: []byte("key")}); err != nil { + if err := storage.Settings.Save(&settings.Settings{ + Auth: settings.Auth{ + Key: []byte("key"), + }, + }); err != nil { t.Fatalf("failed to save settings: %v", err) } diff --git a/backend/http/settings.go b/backend/http/settings.go index 9591df5d..1acebf83 100644 --- a/backend/http/settings.go +++ b/backend/http/settings.go @@ -21,9 +21,9 @@ type settingsData struct { var settingsGetHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { data := &settingsData{ - Signup: d.settings.Signup, - CreateUserDir: d.settings.CreateUserDir, - UserHomeBasePath: d.settings.UserHomeBasePath, + Signup: settings.GlobalConfiguration.Auth.Signup, + CreateUserDir: settings.GlobalConfiguration.Server.CreateUserDir, + UserHomeBasePath: settings.GlobalConfiguration.Server.UserHomeBasePath, Defaults: d.settings.UserDefaults, Rules: d.settings.Rules, Frontend: d.settings.Frontend, @@ -41,9 +41,8 @@ var settingsPutHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, return http.StatusBadRequest, err } - d.settings.Signup = req.Signup - d.settings.CreateUserDir = req.CreateUserDir - d.settings.UserHomeBasePath = req.UserHomeBasePath + d.settings.Server.CreateUserDir = req.CreateUserDir + d.settings.Server.UserHomeBasePath = req.UserHomeBasePath d.settings.UserDefaults = req.Defaults d.settings.Rules = req.Rules d.settings.Frontend = req.Frontend diff --git a/backend/http/static.go b/backend/http/static.go index fa06de3a..f2f7b860 100644 --- a/backend/http/static.go +++ b/backend/http/static.go @@ -30,11 +30,12 @@ func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, fSys "Name": d.settings.Frontend.Name, "DisableExternal": d.settings.Frontend.DisableExternal, "DisableUsedPercentage": d.settings.Frontend.DisableUsedPercentage, + "darkMode": settings.GlobalConfiguration.UserDefaults.DarkMode, "Color": d.settings.Frontend.Color, "BaseURL": d.server.BaseURL, "Version": version.Version, "StaticURL": path.Join(d.server.BaseURL, "/static"), - "Signup": d.settings.Signup, + "Signup": settings.GlobalConfiguration.Auth.Signup, "NoAuth": d.settings.Auth.Method == "noauth", "AuthMethod": d.settings.Auth.Method, "LoginPage": auther.LoginPage(), diff --git a/backend/settings/config.go b/backend/settings/config.go index b7f7ef51..a4a839e5 100644 --- a/backend/settings/config.go +++ b/backend/settings/config.go @@ -45,9 +45,6 @@ func loadConfigFile(configFile string) []byte { func setDefaults() Settings { return Settings{ - Signup: true, - AdminUsername: "admin", - AdminPassword: "admin", Server: Server{ EnableThumbnails: true, EnableExec: false, @@ -60,8 +57,10 @@ func setDefaults() Settings { Root: "/srv", }, Auth: Auth{ - Method: "password", - Signup: true, + AdminUsername: "admin", + AdminPassword: "admin", + Method: "password", + Signup: true, Recaptcha: Recaptcha{ Host: "", }, diff --git a/backend/settings/dir.go b/backend/settings/dir.go index 25289ee4..369e74a1 100644 --- a/backend/settings/dir.go +++ b/backend/settings/dir.go @@ -21,13 +21,13 @@ var ( // MakeUserDir makes the user directory according to settings. func (s *Settings) MakeUserDir(username, userScope, serverRoot string) (string, error) { userScope = strings.TrimSpace(userScope) - if userScope == "" && s.CreateUserDir { + if userScope == "" && s.Server.CreateUserDir { username = cleanUsername(username) if username == "" || username == "-" || username == "." { log.Printf("create user: invalid user for home dir creation: [%s]", username) return "", errors.New("invalid user for home dir creation") } - userScope = path.Join(s.UserHomeBasePath, username) + userScope = path.Join(s.Server.UserHomeBasePath, username) } userScope = path.Join("/", userScope) diff --git a/backend/settings/dir_test.go b/backend/settings/dir_test.go index 1b3abc4e..fd28e5b1 100644 --- a/backend/settings/dir_test.go +++ b/backend/settings/dir_test.go @@ -8,7 +8,6 @@ import ( func TestSettings_MakeUserDir(t *testing.T) { type fields struct { - Key []byte Signup bool CreateUserDir bool UserHomeBasePath string @@ -40,20 +39,14 @@ func TestSettings_MakeUserDir(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { s := &Settings{ - Key: tt.fields.Key, - Signup: tt.fields.Signup, - CreateUserDir: tt.fields.CreateUserDir, - UserHomeBasePath: tt.fields.UserHomeBasePath, - Commands: tt.fields.Commands, - Shell: tt.fields.Shell, - AdminUsername: tt.fields.AdminUsername, - AdminPassword: tt.fields.AdminPassword, - Rules: tt.fields.Rules, - Server: tt.fields.Server, - Auth: tt.fields.Auth, - Frontend: tt.fields.Frontend, - Users: tt.fields.Users, - UserDefaults: tt.fields.UserDefaults, + Commands: tt.fields.Commands, + Shell: tt.fields.Shell, + Rules: tt.fields.Rules, + Server: tt.fields.Server, + Auth: tt.fields.Auth, + Frontend: tt.fields.Frontend, + Users: tt.fields.Users, + UserDefaults: tt.fields.UserDefaults, } got, err := s.MakeUserDir(tt.args.username, tt.args.userScope, tt.args.serverRoot) if (err != nil) != tt.wantErr { diff --git a/backend/settings/storage.go b/backend/settings/storage.go index f54acc62..522b6e0c 100644 --- a/backend/settings/storage.go +++ b/backend/settings/storage.go @@ -29,8 +29,8 @@ func (s *Storage) Get() (*Settings, error) { if err != nil { return nil, err } - if set.UserHomeBasePath == "" { - set.UserHomeBasePath = DefaultUsersHomeBasePath + if set.Server.UserHomeBasePath == "" { + set.Server.UserHomeBasePath = DefaultUsersHomeBasePath } return set, nil } @@ -45,7 +45,7 @@ var defaultEvents = []string{ // Save saves the settings for the current instance. func (s *Storage) Save(set *Settings) error { - if len(set.Key) == 0 { + if len(set.Auth.Key) == 0 { return errors.ErrEmptyKey } diff --git a/backend/settings/structs.go b/backend/settings/structs.go index 6afa9fda..03ea86ab 100644 --- a/backend/settings/structs.go +++ b/backend/settings/structs.go @@ -6,29 +6,26 @@ import ( ) type Settings struct { - Key []byte `json:"key"` - Signup bool `json:"signup"` - CreateUserDir bool `json:"createUserDir"` - UserHomeBasePath string `json:"userHomeBasePath"` - Commands map[string][]string `json:"commands"` - Shell []string `json:"shell"` - AdminUsername string `json:"adminUsername"` - AdminPassword string `json:"adminPassword"` - Rules []rules.Rule `json:"rules"` - Server Server `json:"server"` - Auth Auth `json:"auth"` - Frontend Frontend `json:"frontend"` - Users []UserDefaults `json:"users,omitempty"` - UserDefaults UserDefaults `json:"userDefaults"` + Commands map[string][]string `json:"commands"` + Shell []string `json:"shell"` + Rules []rules.Rule `json:"rules"` + Server Server `json:"server"` + Auth Auth `json:"auth"` + Frontend Frontend `json:"frontend"` + Users []UserDefaults `json:"users,omitempty"` + UserDefaults UserDefaults `json:"userDefaults"` } type Auth struct { - Recaptcha Recaptcha `json:"recaptcha"` - Header string `json:"header"` - Method string `json:"method"` - Command string `json:"command"` - Signup bool `json:"signup"` - Shell string `json:"shell"` + Recaptcha Recaptcha `json:"recaptcha"` + Header string `json:"header"` + Method string `json:"method"` + Command string `json:"command"` + Signup bool `json:"signup"` + Shell string `json:"shell"` + AdminUsername string `json:"adminUsername"` + AdminPassword string `json:"adminPassword"` + Key []byte `json:"key"` } type Recaptcha struct { @@ -54,6 +51,8 @@ type Server struct { Log string `json:"log"` Database string `json:"database"` Root string `json:"root"` + UserHomeBasePath string `json:"userHomeBasePath"` + CreateUserDir bool `json:"createUserDir"` } type Frontend struct { diff --git a/backend/storage/bolt/users.go b/backend/storage/bolt/users.go index c4837136..b7eeaac4 100644 --- a/backend/storage/bolt/users.go +++ b/backend/storage/bolt/users.go @@ -2,7 +2,6 @@ package bolt import ( "fmt" - "log" "reflect" "github.com/asdine/storm/v3" @@ -74,7 +73,6 @@ func (st usersBackend) Update(user *users.User, fields ...string) error { } func (st usersBackend) Save(user *users.User) error { - log.Println("userinfo", user.Password) pass, err := users.HashPwd(user.Password) if err != nil { return err diff --git a/backend/users/password.go b/backend/users/password.go index e5b5f72b..d7ef250a 100644 --- a/backend/users/password.go +++ b/backend/users/password.go @@ -1,14 +1,11 @@ package users import ( - "log" - "golang.org/x/crypto/bcrypt" ) // HashPwd hashes a password. func HashPwd(password string) (string, error) { - log.Println("hashing password", password) bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) return string(bytes), err } diff --git a/configuration.md b/configuration.md index 802ef80c..6284522e 100644 --- a/configuration.md +++ b/configuration.md @@ -7,10 +7,11 @@ This document covers the available configuration options, their defaults, and ho Here is an expanded config file which includes all possible configurations: ``` -signup: false adminUsername: admin adminPassword: admin server: + CreateUserDir: false + UserHomeBasePath: "" indexingInterval: 5 numImageProcessors: 4 socket: "" @@ -33,6 +34,7 @@ auth: header: "" method: json command: "" + signup: false shell: "" frontend: name: "" @@ -67,7 +69,6 @@ userDefaults: Here are the defaults if nothing is set: ``` -signup: true adminUsername: admin adminPassword: admin server: @@ -107,12 +108,6 @@ userDefaults: ## About each configuration -- `Signup`: This boolean value indicates whether user signup is enabled on the login page. NOTE: Be mindful of `userDefaults` settings if enabled. Default: `false` - -- `AdminUsername`: This is the username of the admin user. Default: `admin` - -- `AdminPassword`: This is the password of the admin user. Default: `admin` - ### Server configuration settings - `indexingInterval`: This is the time in minutes the system waits before checking for filesystem changes. Default: `5` @@ -143,6 +138,10 @@ userDefaults: - `root`: This is the root directory path. Default: `/srv` +- `CreateUserDir`: Boolean to create user directory on user creation. Default: `false` + +- `UserHomeBasePath`: String to define user home directory base path. Default: `""` + ### Auth configuration settings - `recaptcha`: @@ -166,6 +165,12 @@ userDefaults: - `shell`: This is the shell configuration. +- `Signup`: This boolean value indicates whether user signup is enabled on the login page. NOTE: Be mindful of `userDefaults` settings if enabled. Default: `false` + +- `AdminUsername`: This is the username of the admin user. Default: `admin` + +- `AdminPassword`: This is the password of the admin user. Default: `admin` + ### Frontend configuration settings - `name`: This is the name of the frontend. diff --git a/frontend/public/img/icons/safari-pinned-tab.svg b/frontend/public/img/icons/safari-pinned-tab.svg deleted file mode 100644 index 0119c21a..00000000 --- a/frontend/public/img/icons/safari-pinned-tab.svg +++ /dev/null @@ -1,42 +0,0 @@ - - - diff --git a/frontend/public/img/logo.png b/frontend/public/img/logo.png new file mode 100644 index 00000000..50b30a60 Binary files /dev/null and b/frontend/public/img/logo.png differ diff --git a/frontend/public/img/logo.svg b/frontend/public/img/logo.svg deleted file mode 100644 index 5e78eccf..00000000 --- a/frontend/public/img/logo.svg +++ /dev/null @@ -1,147 +0,0 @@ - - \ No newline at end of file diff --git a/frontend/public/index.html b/frontend/public/index.html index d8cbd347..b6da58f5 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -120,17 +120,22 @@
-