mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
Add option to use FM w/o login
This commit is contained in:
parent
58a3edde40
commit
f572fc7837
@ -24,7 +24,7 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div v-if="!$store.state.user.noAuth">
|
||||
<router-link class="action" to="/settings" :aria-label="$t('sidebar.settings')" :title="$t('sidebar.settings')">
|
||||
<i class="material-icons">settings_applications</i>
|
||||
<span>{{ $t('sidebar.settings') }}</span>
|
||||
|
@ -97,6 +97,12 @@ const router = new Router({
|
||||
requiresAdmin: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/files',
|
||||
redirect: {
|
||||
path: '/files/'
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/*',
|
||||
redirect: {
|
||||
|
16
auth.go
16
auth.go
@ -15,6 +15,11 @@ import (
|
||||
|
||||
// authHandler proccesses the authentication for the user.
|
||||
func authHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
// NoAuth instances shouldn't call this method.
|
||||
if c.NoAuth {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// Receive the credentials from the request and unmarshal them.
|
||||
var cred User
|
||||
if r.Body == nil {
|
||||
@ -56,6 +61,7 @@ func renewAuthHandler(c *RequestContext, w http.ResponseWriter, r *http.Request)
|
||||
// claims is the JWT claims.
|
||||
type claims struct {
|
||||
User
|
||||
NoAuth bool `json:"noAuth"`
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
@ -70,6 +76,7 @@ func printToken(c *RequestContext, w http.ResponseWriter) (int, error) {
|
||||
// Builds the claims.
|
||||
claims := claims{
|
||||
u,
|
||||
c.NoAuth,
|
||||
jwt.StandardClaims{
|
||||
ExpiresAt: time.Now().Add(time.Hour * 24).Unix(),
|
||||
Issuer: "File Manager",
|
||||
@ -78,7 +85,7 @@ func printToken(c *RequestContext, w http.ResponseWriter) (int, error) {
|
||||
|
||||
// Creates the token and signs it.
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
string, err := token.SignedString(c.key)
|
||||
signed, err := token.SignedString(c.key)
|
||||
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
@ -86,7 +93,7 @@ func printToken(c *RequestContext, w http.ResponseWriter) (int, error) {
|
||||
|
||||
// Writes the token.
|
||||
w.Header().Set("Content-Type", "cty")
|
||||
w.Write([]byte(string))
|
||||
w.Write([]byte(signed))
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
@ -113,6 +120,11 @@ func (e extractor) ExtractToken(r *http.Request) (string, error) {
|
||||
// validateAuth is used to validate the authentication and returns the
|
||||
// User if it is valid.
|
||||
func validateAuth(c *RequestContext, r *http.Request) (bool, *User) {
|
||||
if c.NoAuth {
|
||||
c.User = c.DefaultUser
|
||||
return true, c.User
|
||||
}
|
||||
|
||||
keyFunc := func(token *jwt.Token) (interface{}, error) {
|
||||
return c.key, nil
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ var (
|
||||
plugin string
|
||||
locale string
|
||||
port int
|
||||
noAuth bool
|
||||
allowCommands bool
|
||||
allowEdit bool
|
||||
allowNew bool
|
||||
@ -48,6 +49,7 @@ func init() {
|
||||
flag.BoolVar(&allowCommands, "allow-commands", true, "Default allow commands option for new users")
|
||||
flag.BoolVar(&allowEdit, "allow-edit", true, "Default allow edit option for new users")
|
||||
flag.BoolVar(&allowNew, "allow-new", true, "Default allow new option for new users")
|
||||
flag.BoolVar(&noAuth, "no-auth", false, "Disables authentication")
|
||||
flag.StringVar(&locale, "locale", "en", "Default locale for new users")
|
||||
flag.StringVar(&plugin, "plugin", "", "Plugin you want to enable")
|
||||
flag.BoolVarP(&showVer, "version", "v", false, "Show version")
|
||||
@ -65,6 +67,7 @@ func setupViper() {
|
||||
viper.SetDefault("AllowNew", true)
|
||||
viper.SetDefault("Plugin", "")
|
||||
viper.SetDefault("Locale", "en")
|
||||
viper.SetDefault("NoAuth", false)
|
||||
|
||||
viper.BindPFlag("Port", flag.Lookup("port"))
|
||||
viper.BindPFlag("Address", flag.Lookup("address"))
|
||||
@ -77,6 +80,7 @@ func setupViper() {
|
||||
viper.BindPFlag("AlowNew", flag.Lookup("allow-new"))
|
||||
viper.BindPFlag("Locale", flag.Lookup("locale"))
|
||||
viper.BindPFlag("Plugin", flag.Lookup("plugin"))
|
||||
viper.BindPFlag("NoAuth", flag.Lookup("no-auth"))
|
||||
|
||||
viper.SetConfigName("filemanager")
|
||||
viper.AddConfigPath(".")
|
||||
@ -142,6 +146,10 @@ func main() {
|
||||
FileSystem: fileutils.Dir(viper.GetString("Scope")),
|
||||
})
|
||||
|
||||
if viper.GetBool("NoAuth") {
|
||||
fm.NoAuth = true
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -103,6 +103,10 @@ type FileManager struct {
|
||||
// edited directly. Use SetBaseURL.
|
||||
BaseURL string
|
||||
|
||||
// NoAuth disables the authentication. When the authentication is disabled,
|
||||
// there will only exist one user, called "admin".
|
||||
NoAuth bool
|
||||
|
||||
// The Default User needed to build the New User page.
|
||||
DefaultUser *User
|
||||
|
||||
|
2318
rice-box.go
2318
rice-box.go
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user