diff --git a/cmd/filebrowser/main.go b/cmd/filebrowser/main.go index 5ef469db..2bdd4031 100644 --- a/cmd/filebrowser/main.go +++ b/cmd/filebrowser/main.go @@ -2,15 +2,7 @@ package main import ( "fmt" - "io/ioutil" - "log" - "net" - "net/http" - "os" - "path/filepath" - "strings" "github.com/asdine/storm" - "gopkg.in/natefinch/lumberjack.v2" "github.com/filebrowser/filebrowser" "github.com/filebrowser/filebrowser/bolt" h "github.com/filebrowser/filebrowser/http" @@ -18,6 +10,14 @@ import ( "github.com/hacdias/fileutils" flag "github.com/spf13/pflag" "github.com/spf13/viper" + "gopkg.in/natefinch/lumberjack.v2" + "io/ioutil" + "log" + "net" + "net/http" + "os" + "path/filepath" + "strings" ) var ( @@ -35,17 +35,17 @@ var ( recaptchakey string recaptchasecret string port int - auth struct { - method string - loginHeader string + auth struct { + method string + loginHeader string } - noAuth bool - allowCommands bool - allowEdit bool - allowNew bool - allowPublish bool - showVer bool - alterRecaptcha bool + noAuth bool + allowCommands bool + allowEdit bool + allowNew bool + allowPublish bool + showVer bool + alterRecaptcha bool ) func init() { @@ -65,7 +65,7 @@ func init() { flag.BoolVar(&allowEdit, "allow-edit", true, "Default allow edit option for new users") flag.BoolVar(&allowPublish, "allow-publish", true, "Default allow publish option for new users") flag.StringVar(&auth.method, "auth.method", "default", "Switch between 'default' and 'proxy' authentication.") - flag.StringVar(&auth.loginHeader, "auth.login-header", "X-Forwarded-User", "The header name used for proxy authentication.") + flag.StringVar(&auth.loginHeader, "auth.login-header", "X-Forwarded-User", "The header name used for proxy authentication.") flag.BoolVar(&allowNew, "allow-new", true, "Default allow new option for new users") flag.BoolVar(&noAuth, "no-auth", false, "Disables authentication") flag.BoolVar(&alterRecaptcha, "alternative-recaptcha", false, "Use recaptcha.net for serving and handling, useful in China") @@ -87,8 +87,8 @@ func setupViper() { viper.SetDefault("AllowPublish", true) viper.SetDefault("StaticGen", "") viper.SetDefault("Locale", "") - viper.SetDefault("AuthMethod", "default") - viper.SetDefault("LoginHeader", "X-Fowarded-User"); + viper.SetDefault("AuthMethod", "default") + viper.SetDefault("LoginHeader", "X-Fowarded-User") viper.SetDefault("NoAuth", false) viper.SetDefault("BaseURL", "") viper.SetDefault("PrefixURL", "") @@ -110,7 +110,7 @@ func setupViper() { viper.BindPFlag("Locale", flag.Lookup("locale")) viper.BindPFlag("StaticGen", flag.Lookup("staticgen")) viper.BindPFlag("AuthMethod", flag.Lookup("auth.method")) - viper.BindPFlag("LoginHeader", flag.Lookup("auth.login-header")) + viper.BindPFlag("LoginHeader", flag.Lookup("auth.login-header")) viper.BindPFlag("NoAuth", flag.Lookup("no-auth")) viper.BindPFlag("BaseURL", flag.Lookup("baseurl")) viper.BindPFlag("PrefixURL", flag.Lookup("prefixurl")) @@ -176,12 +176,12 @@ func main() { } // Validate the provided config before moving forward - if(viper.GetString("AuthMethod") != "default" && viper.GetString("AuthMethod") != "proxy") { + if viper.GetString("AuthMethod") != "default" && viper.GetString("AuthMethod") != "proxy" { log.Fatal("The property 'auth.method' needs to be set to 'default' or 'proxy'.") - } + } - if (viper.GetString("AuthMethod") == "proxy") { - if(viper.GetString("LoginHeader") == "") { + if viper.GetString("AuthMethod") == "proxy" { + if viper.GetString("LoginHeader") == "" { log.Fatal("The 'login-header' needs to be specified when 'proxy' authentication is used.") } log.Println("[WARN] Filebrowser authentication is configured to 'proxy' authentication. This can cause a huge security issue if the infrastructure is not configured correctly.") diff --git a/filebrowser.go b/filebrowser.go index baa102b8..4d607131 100644 --- a/filebrowser.go +++ b/filebrowser.go @@ -71,7 +71,7 @@ type FileBrowser struct { // there will only exist one user, called "admin". NoAuth bool - // Define if either, the common authentication mechansim or 'proxy' authentication should be used. + // Define if either, the common authentication mechansim or 'proxy' authentication should be used. // 'proxy' authentication enables a mechanism that authenticates a user based on forwarded // headers. AuthMethod string diff --git a/http/auth.go b/http/auth.go index 155fcab0..cfcc2430 100644 --- a/http/auth.go +++ b/http/auth.go @@ -177,11 +177,11 @@ func validateAuth(c *fb.Context, r *http.Request) (bool, *fb.User) { // If proxy auth is used do not verify the JWT token if the header is provided. if c.AuthMethod == "proxy" { - u, err := c.Store.Users.GetByUsername(r.Header.Get(c.LoginHeader), c.NewFS) - if err != nil { - return false, nil + u, err := c.Store.Users.GetByUsername(r.Header.Get(c.LoginHeader), c.NewFS) + if err != nil { + return false, nil } - c.User = u; + c.User = u return true, c.User } @@ -208,4 +208,3 @@ func validateAuth(c *fb.Context, r *http.Request) (bool, *fb.User) { c.User = u return true, u } -