Add option to use FM w/o login

pull/189/head
Henrique Dias 2017-08-02 14:10:05 +01:00
parent 58a3edde40
commit f572fc7837
No known key found for this signature in database
GPG Key ID: 936F5EB68D786730
6 changed files with 33 additions and 2321 deletions

View File

@ -24,7 +24,7 @@
</button> </button>
</div> </div>
<div> <div v-if="!$store.state.user.noAuth">
<router-link class="action" to="/settings" :aria-label="$t('sidebar.settings')" :title="$t('sidebar.settings')"> <router-link class="action" to="/settings" :aria-label="$t('sidebar.settings')" :title="$t('sidebar.settings')">
<i class="material-icons">settings_applications</i> <i class="material-icons">settings_applications</i>
<span>{{ $t('sidebar.settings') }}</span> <span>{{ $t('sidebar.settings') }}</span>

View File

@ -97,6 +97,12 @@ const router = new Router({
requiresAdmin: true requiresAdmin: true
} }
}, },
{
path: '/files',
redirect: {
path: '/files/'
}
},
{ {
path: '/*', path: '/*',
redirect: { redirect: {

16
auth.go
View File

@ -15,6 +15,11 @@ import (
// authHandler proccesses the authentication for the user. // authHandler proccesses the authentication for the user.
func authHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) { 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. // Receive the credentials from the request and unmarshal them.
var cred User var cred User
if r.Body == nil { if r.Body == nil {
@ -56,6 +61,7 @@ func renewAuthHandler(c *RequestContext, w http.ResponseWriter, r *http.Request)
// claims is the JWT claims. // claims is the JWT claims.
type claims struct { type claims struct {
User User
NoAuth bool `json:"noAuth"`
jwt.StandardClaims jwt.StandardClaims
} }
@ -70,6 +76,7 @@ func printToken(c *RequestContext, w http.ResponseWriter) (int, error) {
// Builds the claims. // Builds the claims.
claims := claims{ claims := claims{
u, u,
c.NoAuth,
jwt.StandardClaims{ jwt.StandardClaims{
ExpiresAt: time.Now().Add(time.Hour * 24).Unix(), ExpiresAt: time.Now().Add(time.Hour * 24).Unix(),
Issuer: "File Manager", Issuer: "File Manager",
@ -78,7 +85,7 @@ func printToken(c *RequestContext, w http.ResponseWriter) (int, error) {
// Creates the token and signs it. // Creates the token and signs it.
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
string, err := token.SignedString(c.key) signed, err := token.SignedString(c.key)
if err != nil { if err != nil {
return http.StatusInternalServerError, err return http.StatusInternalServerError, err
@ -86,7 +93,7 @@ func printToken(c *RequestContext, w http.ResponseWriter) (int, error) {
// Writes the token. // Writes the token.
w.Header().Set("Content-Type", "cty") w.Header().Set("Content-Type", "cty")
w.Write([]byte(string)) w.Write([]byte(signed))
return 0, nil 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 // validateAuth is used to validate the authentication and returns the
// User if it is valid. // User if it is valid.
func validateAuth(c *RequestContext, r *http.Request) (bool, *User) { 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) { keyFunc := func(token *jwt.Token) (interface{}, error) {
return c.key, nil return c.key, nil
} }

View File

@ -30,6 +30,7 @@ var (
plugin string plugin string
locale string locale string
port int port int
noAuth bool
allowCommands bool allowCommands bool
allowEdit bool allowEdit bool
allowNew bool allowNew bool
@ -48,6 +49,7 @@ func init() {
flag.BoolVar(&allowCommands, "allow-commands", true, "Default allow commands option for new users") 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(&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(&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(&locale, "locale", "en", "Default locale for new users")
flag.StringVar(&plugin, "plugin", "", "Plugin you want to enable") flag.StringVar(&plugin, "plugin", "", "Plugin you want to enable")
flag.BoolVarP(&showVer, "version", "v", false, "Show version") flag.BoolVarP(&showVer, "version", "v", false, "Show version")
@ -65,6 +67,7 @@ func setupViper() {
viper.SetDefault("AllowNew", true) viper.SetDefault("AllowNew", true)
viper.SetDefault("Plugin", "") viper.SetDefault("Plugin", "")
viper.SetDefault("Locale", "en") viper.SetDefault("Locale", "en")
viper.SetDefault("NoAuth", false)
viper.BindPFlag("Port", flag.Lookup("port")) viper.BindPFlag("Port", flag.Lookup("port"))
viper.BindPFlag("Address", flag.Lookup("address")) viper.BindPFlag("Address", flag.Lookup("address"))
@ -77,6 +80,7 @@ func setupViper() {
viper.BindPFlag("AlowNew", flag.Lookup("allow-new")) viper.BindPFlag("AlowNew", flag.Lookup("allow-new"))
viper.BindPFlag("Locale", flag.Lookup("locale")) viper.BindPFlag("Locale", flag.Lookup("locale"))
viper.BindPFlag("Plugin", flag.Lookup("plugin")) viper.BindPFlag("Plugin", flag.Lookup("plugin"))
viper.BindPFlag("NoAuth", flag.Lookup("no-auth"))
viper.SetConfigName("filemanager") viper.SetConfigName("filemanager")
viper.AddConfigPath(".") viper.AddConfigPath(".")
@ -142,6 +146,10 @@ func main() {
FileSystem: fileutils.Dir(viper.GetString("Scope")), FileSystem: fileutils.Dir(viper.GetString("Scope")),
}) })
if viper.GetBool("NoAuth") {
fm.NoAuth = true
}
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -103,6 +103,10 @@ type FileManager struct {
// edited directly. Use SetBaseURL. // edited directly. Use SetBaseURL.
BaseURL string 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. // The Default User needed to build the New User page.
DefaultUser *User DefaultUser *User

File diff suppressed because one or more lines are too long