@@ -2,7 +2,7 @@ package cmd
22
33import (
44 "encoding/json"
5- nerrors "errors"
5+ "errors"
66 "fmt"
77 "os"
88 "strings"
@@ -12,7 +12,7 @@ import (
1212 "github.com/spf13/pflag"
1313
1414 "github.com/thevickypedia/filebrowser/v2/auth"
15- "github.com/thevickypedia/filebrowser/v2/errors"
15+ fberrors "github.com/thevickypedia/filebrowser/v2/errors"
1616 "github.com/thevickypedia/filebrowser/v2/settings"
1717)
1818
@@ -30,17 +30,22 @@ var configCmd = &cobra.Command{
3030func addConfigFlags (flags * pflag.FlagSet ) {
3131 addServerFlags (flags )
3232 addUserFlags (flags )
33+
3334 flags .BoolP ("signup" , "s" , false , "allow users to signup" )
3435 flags .Bool ("hideLoginButton" , false , "hide login button from public pages" )
3536 flags .Bool ("createUserDir" , false , "generate user's home directory automatically" )
3637 flags .Uint ("minimumPasswordLength" , settings .DefaultMinimumPasswordLength , "minimum password length for new users" )
3738 flags .String ("shell" , "" , "shell command to which other commands should be appended" )
3839
40+ // NB: these are string so they can be presented as octal in the help text
41+ // as that's the conventional representation for modes in Unix.
42+ flags .String ("fileMode" , fmt .Sprintf ("%O" , settings .DefaultFileMode ), "mode bits that new files are created with" )
43+ flags .String ("dirMode" , fmt .Sprintf ("%O" , settings .DefaultDirMode ), "mode bits that new directories are created with" )
44+
3945 flags .String ("auth.method" , string (auth .MethodJSONAuth ), "authentication type" )
4046 flags .String ("auth.header" , "" , "HTTP header for auth.method=proxy" )
4147 flags .String ("auth.command" , "" , "command for auth.method=hook" )
42-
43- flags .String ("authenticatorToken" , "" , "OTP shared secret (leave blank to disable)" )
48+ flags .String ("auth.logoutPage" , "" , "url of custom logout page" )
4449
4550 flags .String ("recaptcha.host" , "https://www.google.com" , "use another host for ReCAPTCHA. recaptcha.net might be useful in China" )
4651 flags .String ("recaptcha.key" , "" , "ReCaptcha site key" )
@@ -52,10 +57,6 @@ func addConfigFlags(flags *pflag.FlagSet) {
5257 flags .String ("branding.files" , "" , "path to directory with images and custom styles" )
5358 flags .Bool ("branding.disableExternal" , false , "disable external links such as GitHub links" )
5459 flags .Bool ("branding.disableUsedPercentage" , false , "disable used disk percentage graph" )
55- // NB: these are string so they can be presented as octal in the help text
56- // as that's the conventional representation for modes in Unix.
57- flags .String ("fileMode" , fmt .Sprintf ("%O" , settings .DefaultFileMode ), "mode bits that new files are created with" )
58- flags .String ("dirMode" , fmt .Sprintf ("%O" , settings .DefaultDirMode ), "mode bits that new directories are created with" )
5960
6061 flags .Uint64 ("tus.chunkSize" , settings .DefaultTusChunkSize , "the tus chunk size" )
6162 flags .Uint16 ("tus.retryCount" , settings .DefaultTusRetryCount , "the tus retry count" )
@@ -98,12 +99,12 @@ func getProxyAuth(flags *pflag.FlagSet, defaultAuther map[string]interface{}) (a
9899 return nil , err
99100 }
100101
101- if header == "" {
102+ if header == "" && defaultAuther != nil {
102103 header = defaultAuther ["header" ].(string )
103104 }
104105
105106 if header == "" {
106- return nil , nerrors .New ("you must set the flag 'auth.header' for method 'proxy'" )
107+ return nil , errors .New ("you must set the flag 'auth.header' for method 'proxy'" )
107108 }
108109
109110 return & auth.ProxyAuth {Header : header }, nil
@@ -115,27 +116,16 @@ func getNoAuth() auth.Auther {
115116
116117func getJSONAuth (flags * pflag.FlagSet , defaultAuther map [string ]interface {}) (auth.Auther , error ) {
117118 jsonAuth := & auth.JSONAuth {}
118- authenticationToken , err := flags .GetString ("authenticatorToken" )
119- if err != nil {
120- return nil , err
121- }
122-
123- if authenticationToken == "" {
124- if atok , ok := defaultAuther ["authenticatorToken" ].(string ); ok {
125- authenticationToken = atok
126- }
127- }
128-
129- jsonAuth .AuthenticatorToken = authenticationToken
130-
131119 host , err := flags .GetString ("recaptcha.host" )
132120 if err != nil {
133121 return nil , err
134122 }
123+
135124 key , err := flags .GetString ("recaptcha.key" )
136125 if err != nil {
137126 return nil , err
138127 }
128+
139129 secret , err := flags .GetString ("recaptcha.secret" )
140130 if err != nil {
141131 return nil , err
@@ -173,7 +163,7 @@ func getHookAuth(flags *pflag.FlagSet, defaultAuther map[string]interface{}) (au
173163 }
174164
175165 if command == "" {
176- return nil , nerrors .New ("you must set the flag 'auth.command' for method 'hook'" )
166+ return nil , errors .New ("you must set the flag 'auth.command' for method 'hook'" )
177167 }
178168
179169 return & auth.HookAuth {Command : command }, nil
@@ -196,7 +186,7 @@ func getAuthentication(flags *pflag.FlagSet, defaults ...interface{}) (settings.
196186 case auth .MethodHookAuth :
197187 auther , err = getHookAuth (flags , defaultAuther )
198188 default :
199- return "" , nil , errors .ErrInvalidAuthMethod
189+ return "" , nil , fberrors .ErrInvalidAuthMethod
200190 }
201191
202192 if err != nil {
@@ -212,6 +202,7 @@ func printSettings(ser *settings.Server, set *settings.Settings, auther auth.Aut
212202 fmt .Fprintf (w , "Sign up:\t %t\n " , set .Signup )
213203 fmt .Fprintf (w , "Hide Login Button:\t %t\n " , set .HideLoginButton )
214204 fmt .Fprintf (w , "Create User Dir:\t %t\n " , set .CreateUserDir )
205+ fmt .Fprintf (w , "Logout Page:\t %s\n " , set .LogoutPage )
215206 fmt .Fprintf (w , "Minimum Password Length:\t %d\n " , set .MinimumPasswordLength )
216207 fmt .Fprintf (w , "Auth Method:\t %s\n " , set .AuthMethod )
217208 fmt .Fprintf (w , "Shell:\t %s\t \n " , strings .Join (set .Shell , " " ))
@@ -253,9 +244,11 @@ func printSettings(ser *settings.Server, set *settings.Settings, auther auth.Aut
253244 fmt .Fprintf (w , "\t Directory Creation Mode:\t %O\n " , set .DirMode )
254245 fmt .Fprintf (w , "\t Commands:\t %s\n " , strings .Join (set .Defaults .Commands , " " ))
255246 fmt .Fprintf (w , "\t Ace editor syntax highlighting theme:\t %s\n " , set .Defaults .AceEditorTheme )
247+
256248 fmt .Fprintf (w , "\t Sorting:\n " )
257249 fmt .Fprintf (w , "\t \t By:\t %s\n " , set .Defaults .Sorting .By )
258250 fmt .Fprintf (w , "\t \t Asc:\t %t\n " , set .Defaults .Sorting .Asc )
251+
259252 fmt .Fprintf (w , "\t Permissions:\n " )
260253 fmt .Fprintf (w , "\t \t Admin:\t %t\n " , set .Defaults .Perm .Admin )
261254 fmt .Fprintf (w , "\t \t Execute:\t %t\n " , set .Defaults .Perm .Execute )
@@ -265,6 +258,7 @@ func printSettings(ser *settings.Server, set *settings.Settings, auther auth.Aut
265258 fmt .Fprintf (w , "\t \t Delete:\t %t\n " , set .Defaults .Perm .Delete )
266259 fmt .Fprintf (w , "\t \t Share:\t %t\n " , set .Defaults .Perm .Share )
267260 fmt .Fprintf (w , "\t \t Download:\t %t\n " , set .Defaults .Perm .Download )
261+
268262 w .Flush ()
269263
270264 b , err := json .MarshalIndent (auther , "" , " " )
@@ -314,6 +308,9 @@ func getSettings(flags *pflag.FlagSet, set *settings.Settings, ser *settings.Ser
314308 case "disableTypeDetectionByHeader" :
315309 ser .TypeDetectionByHeader , err = flags .GetBool (flag .Name )
316310 ser .TypeDetectionByHeader = ! ser .TypeDetectionByHeader
311+ case "disableImageResolutionCalc" :
312+ ser .ImageResolutionCal , err = flags .GetBool (flag .Name )
313+ ser .ImageResolutionCal = ! ser .ImageResolutionCal
317314
318315 // Settings flags from [addConfigFlags]
319316 case "signup" :
@@ -336,6 +333,8 @@ func getSettings(flags *pflag.FlagSet, set *settings.Settings, ser *settings.Ser
336333 set .DirMode , err = getAndParseFileMode (flags , flag .Name )
337334 case "auth.method" :
338335 hasAuth = true
336+ case "auth.logoutPage" :
337+ set .LogoutPage , err = flags .GetString (flag .Name )
339338 case "branding.name" :
340339 set .Branding .Name , err = flags .GetString (flag .Name )
341340 case "branding.theme" :
@@ -365,7 +364,7 @@ func getSettings(flags *pflag.FlagSet, set *settings.Settings, ser *settings.Ser
365364 flags .Visit (visit )
366365 }
367366
368- err := nerrors .Join (errs ... )
367+ err := errors .Join (errs ... )
369368 if err != nil {
370369 return nil , err
371370 }
0 commit comments