From 3dd3e01f4c74bef6b3a4b878cacba295bed8e397 Mon Sep 17 00:00:00 2001 From: Graham Steffaniak Date: Sat, 5 Aug 2023 07:32:43 -0500 Subject: [PATCH] initial commit --- backend/.filebrowser.json | 15 +-- backend/auth/hook.go | 2 +- backend/auth/json.go | 2 +- backend/auth/none.go | 2 +- backend/auth/proxy.go | 2 +- backend/auth/storage.go | 5 +- backend/cmd/config.go | 4 +- backend/settings/branding.go | 11 --- backend/settings/defaults.go | 33 ------- backend/settings/settings.go | 31 +------ backend/settings/structs.go | 127 ++++++++++++++++++++++++++ backend/storage/bolt/auth.go | 3 +- backend/storage/bolt/importer/conf.go | 8 +- backend/version/version.go | 2 +- frontend/src/css/base.css | 1 + frontend/src/css/listing.css | 2 +- 16 files changed, 153 insertions(+), 97 deletions(-) delete mode 100644 backend/settings/branding.go delete mode 100644 backend/settings/defaults.go create mode 100644 backend/settings/structs.go diff --git a/backend/.filebrowser.json b/backend/.filebrowser.json index 885ddf54..29e14c41 100644 --- a/backend/.filebrowser.json +++ b/backend/.filebrowser.json @@ -1,8 +1,11 @@ { - "port": 8080, - "baseURL": "", - "address": "", - "log": "stdout", - "database": "./database.db", - "root": "/srv" + "server":{ + "port": 8080, + "baseURL": "", + "address": "", + "log": "stdout", + "database": "./database.db", + "root": "/srv" + } + } \ No newline at end of file diff --git a/backend/auth/hook.go b/backend/auth/hook.go index 0517699e..7e165f07 100644 --- a/backend/auth/hook.go +++ b/backend/auth/hook.go @@ -16,7 +16,7 @@ import ( ) // MethodHookAuth is used to identify hook auth. -const MethodHookAuth settings.AuthMethod = "hook" +const MethodHookAuth = "hook" type hookCred struct { Password string `json:"password"` diff --git a/backend/auth/json.go b/backend/auth/json.go index 36e1d14a..bcd8af52 100644 --- a/backend/auth/json.go +++ b/backend/auth/json.go @@ -12,7 +12,7 @@ import ( ) // MethodJSONAuth is used to identify json auth. -const MethodJSONAuth settings.AuthMethod = "json" +const MethodJSONAuth = "json" type jsonCred struct { Password string `json:"password"` diff --git a/backend/auth/none.go b/backend/auth/none.go index 2621e870..6549780f 100644 --- a/backend/auth/none.go +++ b/backend/auth/none.go @@ -8,7 +8,7 @@ import ( ) // MethodNoAuth is used to identify no auth. -const MethodNoAuth settings.AuthMethod = "noauth" +const MethodNoAuth = "noauth" // NoAuth is no auth implementation of auther. type NoAuth struct{} diff --git a/backend/auth/proxy.go b/backend/auth/proxy.go index ec313ce1..a14e92a6 100644 --- a/backend/auth/proxy.go +++ b/backend/auth/proxy.go @@ -10,7 +10,7 @@ import ( ) // MethodProxyAuth is used to identify no auth. -const MethodProxyAuth settings.AuthMethod = "proxy" +const MethodProxyAuth = "proxy" // ProxyAuth is a proxy implementation of an auther. type ProxyAuth struct { diff --git a/backend/auth/storage.go b/backend/auth/storage.go index 0b011391..0af743df 100644 --- a/backend/auth/storage.go +++ b/backend/auth/storage.go @@ -1,13 +1,12 @@ package auth import ( - "github.com/gtsteffaniak/filebrowser/settings" "github.com/gtsteffaniak/filebrowser/users" ) // StorageBackend is a storage backend for auth storage. type StorageBackend interface { - Get(settings.AuthMethod) (Auther, error) + Get(string) (Auther, error) Save(Auther) error } @@ -23,7 +22,7 @@ func NewStorage(back StorageBackend, userStore *users.Storage) *Storage { } // Get wraps a StorageBackend.Get. -func (s *Storage) Get(t settings.AuthMethod) (Auther, error) { +func (s *Storage) Get(t string) (Auther, error) { return s.back.Get(t) } diff --git a/backend/cmd/config.go b/backend/cmd/config.go index 47d9cd42..b93563b9 100644 --- a/backend/cmd/config.go +++ b/backend/cmd/config.go @@ -49,8 +49,8 @@ func addConfigFlags(flags *pflag.FlagSet) { } //nolint:gocyclo -func getAuthentication(flags *pflag.FlagSet, defaults ...interface{}) (settings.AuthMethod, auth.Auther) { - method := settings.AuthMethod(mustGetString(flags, "auth.method")) +func getAuthentication(flags *pflag.FlagSet, defaults ...interface{}) (string, auth.Auther) { + method := mustGetString(flags, "auth.method") var defaultAuther map[string]interface{} if len(defaults) > 0 { diff --git a/backend/settings/branding.go b/backend/settings/branding.go deleted file mode 100644 index cd196236..00000000 --- a/backend/settings/branding.go +++ /dev/null @@ -1,11 +0,0 @@ -package settings - -// Branding contains the branding settings of the app. -type Branding struct { - Name string `json:"name"` - DisableExternal bool `json:"disableExternal"` - DisableUsedPercentage bool `json:"disableUsedPercentage"` - Files string `json:"files"` - Theme string `json:"theme"` - Color string `json:"color"` -} diff --git a/backend/settings/defaults.go b/backend/settings/defaults.go deleted file mode 100644 index 160d2dd2..00000000 --- a/backend/settings/defaults.go +++ /dev/null @@ -1,33 +0,0 @@ -package settings - -import ( - "github.com/gtsteffaniak/filebrowser/files" - "github.com/gtsteffaniak/filebrowser/users" -) - -// UserDefaults is a type that holds the default values -// for some fields on User. -type UserDefaults struct { - Scope string `json:"scope"` - Locale string `json:"locale"` - ViewMode users.ViewMode `json:"viewMode"` - SingleClick bool `json:"singleClick"` - Sorting files.Sorting `json:"sorting"` - Perm users.Permissions `json:"perm"` - Commands []string `json:"commands"` - HideDotfiles bool `json:"hideDotfiles"` - DateFormat bool `json:"dateFormat"` -} - -// Apply applies the default options to a user. -func (d *UserDefaults) Apply(u *users.User) { - u.Scope = d.Scope - u.Locale = d.Locale - u.ViewMode = d.ViewMode - u.SingleClick = d.SingleClick - u.Perm = d.Perm - u.Sorting = d.Sorting - u.Commands = d.Commands - u.HideDotfiles = d.HideDotfiles - u.DateFormat = d.DateFormat -} diff --git a/backend/settings/settings.go b/backend/settings/settings.go index a8ed4e11..dde86d73 100644 --- a/backend/settings/settings.go +++ b/backend/settings/settings.go @@ -13,41 +13,12 @@ const DefaultUsersHomeBasePath = "/users" type AuthMethod string // Settings contain the main settings of the application. -type Settings struct { - Key []byte `json:"key"` - Signup bool `json:"signup"` - CreateUserDir bool `json:"createUserDir"` - UserHomeBasePath string `json:"userHomeBasePath"` - Defaults UserDefaults `json:"defaults"` - AuthMethod AuthMethod `json:"authMethod"` - Branding Branding `json:"branding"` - Commands map[string][]string `json:"commands"` - Shell []string `json:"shell"` - Rules []rules.Rule `json:"rules"` -} - // GetRules implements rules.Provider. func (s *Settings) GetRules() []rules.Rule { return s.Rules } -// Server specific settings. -type Server struct { - Root string `json:"root"` - BaseURL string `json:"baseURL"` - Socket string `json:"socket"` - TLSKey string `json:"tlsKey"` - TLSCert string `json:"tlsCert"` - Port string `json:"port"` - Address string `json:"address"` - Log string `json:"log"` - EnableThumbnails bool `json:"enableThumbnails"` - ResizePreview bool `json:"resizePreview"` - EnableExec bool `json:"enableExec"` - TypeDetectionByHeader bool `json:"typeDetectionByHeader"` - AuthHook string `json:"authHook"` -} - +// Server specific settings // Clean cleans any variables that might need cleaning. func (s *Server) Clean() { s.BaseURL = strings.TrimSuffix(s.BaseURL, "/") diff --git a/backend/settings/structs.go b/backend/settings/structs.go new file mode 100644 index 00000000..5669684a --- /dev/null +++ b/backend/settings/structs.go @@ -0,0 +1,127 @@ +package settings + +import ( + "github.com/gtsteffaniak/filebrowser/files" + "github.com/gtsteffaniak/filebrowser/rules" + "github.com/gtsteffaniak/filebrowser/users" +) + +// Apply applies the default options to a user. +func (d *UserDefaults) Apply(u *users.User) { + u.Scope = d.Scope + u.Locale = d.Locale + u.ViewMode = d.ViewMode + u.SingleClick = d.SingleClick + u.Perm = d.Perm + u.Sorting = d.Sorting + u.Commands = d.Commands + u.HideDotfiles = d.HideDotfiles + u.DateFormat = d.DateFormat +} + +type Settings struct { + Key []byte `json:"key"` + Signup bool `json:"signup"` + CreateUserDir bool `json:"createUserDir"` + UserHomeBasePath string `json:"userHomeBasePath"` + Defaults UserDefaults `json:"defaults"` + Commands map[string][]string `json:"commands"` + Shell []string `json:"shell"` + Rules []rules.Rule `json:"rules"` + Server Server `json:"server"` + AuthMethod string `json:"authMethod"` + Auth struct { + Header string `json:"header"` + Method string `json:"method"` + Command string `json:"command"` + Signup bool `json:"signup"` + Shell string `json:"shell"` + } `json:"auth"` + + Branding Branding `json:"branding"` + + UserDefaults UserDefaults `json:"userDefaults"` +} + +type Server struct { + Socket string `json:"socket"` + TLSKey string `json:"tlsKey"` + TLSCert string `json:"tlsCert"` + EnableThumbnails bool `json:"enableThumbnails"` + ResizePreview bool `json:"resizePreview"` + EnableExec bool `json:"enableExec"` + TypeDetectionByHeader bool `json:"typeDetectionByHeader"` + AuthHook string `json:"authHook"` + Port string `json:"port"` + BaseURL string `json:"baseURL"` + Address string `json:"address"` + Log string `json:"log"` + Database string `json:"database"` + Root string `json:"root"` + EnablePreviewResize bool `json:"disable-preview-resize"` +} + +type Branding struct { + Name string `json:"name"` + DisableExternal bool `json:"disableExternal"` + DisableUsedPercentage bool `json:"disableUsedPercentage"` + Files string `json:"files"` + Theme string `json:"theme"` + Color string `json:"color"` +} + +// UserDefaults is a type that holds the default values +// for some fields on User. +type UserDefaults struct { + Scope string `json:"scope"` + Locale string `json:"locale"` + ViewMode users.ViewMode `json:"viewMode"` + SingleClick bool `json:"singleClick"` + Sorting files.Sorting `json:"sorting"` + Perm users.Permissions `json:"perm"` + Commands []string `json:"commands"` + HideDotfiles bool `json:"hideDotfiles"` + DateFormat bool `json:"dateFormat"` +} + +//{ +// "server":{ +// "port":8080, +// "baseURL":"", +// "address":"", +// "log":"stdout", +// "database":"./database.db", +// "root":"/srv", +// "disable-thumbnails":false, +// "disable-preview-resize":false, +// "disable-exec":false, +// "disable-type-detection-by-header":false +// }, +// "auth":{ +// "header":"", +// "method":"", +// "command":"", +// "signup":false, +// "shell":"" +// }, +// "branding":{ +// "name":"", +// "color":"", +// "files":"", +// "disableExternal":"", +// "disableUsedPercentage":"" +// }, +// "permissions":{ +// "Admin":false, +// "Execute":true, +// "Create":true, +// "Rename":true, +// "Modify":true, +// "Delete":true, +// "Share":true, +// "Download":true +// }, +// "commands":{}, +// "shell":{}, +// "rules":{} +// } diff --git a/backend/storage/bolt/auth.go b/backend/storage/bolt/auth.go index a0e8d1c8..abba4e1d 100644 --- a/backend/storage/bolt/auth.go +++ b/backend/storage/bolt/auth.go @@ -5,14 +5,13 @@ import ( "github.com/gtsteffaniak/filebrowser/auth" "github.com/gtsteffaniak/filebrowser/errors" - "github.com/gtsteffaniak/filebrowser/settings" ) type authBackend struct { db *storm.DB } -func (s authBackend) Get(t settings.AuthMethod) (auth.Auther, error) { +func (s authBackend) Get(t string) (auth.Auther, error) { var auther auth.Auther switch t { diff --git a/backend/storage/bolt/importer/conf.go b/backend/storage/bolt/importer/conf.go index e31ba3fc..939559c2 100644 --- a/backend/storage/bolt/importer/conf.go +++ b/backend/storage/bolt/importer/conf.go @@ -149,13 +149,13 @@ func importConf(db *storm.DB, path string, sto *storage.Storage) error { switch cfg.Auth.Method { case "proxy": auther = &auth.ProxyAuth{Header: cfg.Auth.Header} - s.AuthMethod = auth.MethodProxyAuth + s.AuthMethod = string(auth.MethodProxyAuth) case "hook": auther = &auth.HookAuth{Command: cfg.Auth.Command} - s.AuthMethod = auth.MethodHookAuth + s.AuthMethod = string(auth.MethodHookAuth) case "none": auther = &auth.NoAuth{} - s.AuthMethod = auth.MethodNoAuth + s.AuthMethod = string(auth.MethodNoAuth) default: auther = &auth.JSONAuth{ ReCaptcha: &auth.ReCaptcha{ @@ -164,7 +164,7 @@ func importConf(db *storm.DB, path string, sto *storage.Storage) error { Secret: cfg.ReCaptcha.Secret, }, } - s.AuthMethod = auth.MethodJSONAuth + s.AuthMethod = string(auth.MethodJSONAuth) } err = sto.Auth.Save(auther) diff --git a/backend/version/version.go b/backend/version/version.go index 8229781c..03dbd250 100644 --- a/backend/version/version.go +++ b/backend/version/version.go @@ -2,7 +2,7 @@ package version var ( // Version is the current File Browser version. - Version = "(0.1.3)" + Version = "(0.1.4)" // CommitSHA is the commmit sha. CommitSHA = "(unknown)" ) diff --git a/frontend/src/css/base.css b/frontend/src/css/base.css index 048fedd0..91842561 100644 --- a/frontend/src/css/base.css +++ b/frontend/src/css/base.css @@ -125,6 +125,7 @@ main { .breadcrumbs a { color: inherit; transition: 0.1s ease-in; + display: flex; border-radius: 0.125em; } diff --git a/frontend/src/css/listing.css b/frontend/src/css/listing.css index 528311fe..389aa82a 100644 --- a/frontend/src/css/listing.css +++ b/frontend/src/css/listing.css @@ -160,7 +160,7 @@ body.rtl #listing { width: 100%; margin: 0; border: 1px solid rgba(0, 0, 0, 0.1); - padding: 1em; + padding: 0; border-top: 0; }