filebrowser/cmd/config.go
Henrique Dias 42227d9edd feat: many updates (see PR)
feat: add main command

feat: add todos

feat: add signup api

feat: do not repeat code

fix: user return

feat: work out static box

fix: setup static handlers

feat: add share types

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>

feat: start static

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>

feat: bring back more features

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>

add

feat: readd more files

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>

feat: add dockerignore

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>

feat: gitignore

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>

feat: readd submodule

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
2018-12-28 23:40:11 +00:00

109 lines
3.1 KiB
Go

package cmd
import (
"encoding/json"
"errors"
"fmt"
"os"
"text/tabwriter"
"github.com/filebrowser/filebrowser/auth"
"github.com/filebrowser/filebrowser/types"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(configCmd)
}
var configCmd = &cobra.Command{
Use: "config",
Short: "Configuration management utility",
Long: `Configuration management utility.`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
os.Exit(0)
},
}
func addConfigFlags(cmd *cobra.Command) {
addUserFlags(cmd)
cmd.Flags().StringP("baseURL", "b", "/", "base url of this installation")
cmd.Flags().BoolP("signup", "s", false, "allow users to signup")
cmd.Flags().String("auth.method", string(auth.MethodJSONAuth), "authentication type")
cmd.Flags().String("auth.header", "", "HTTP header for auth.method=proxy")
cmd.Flags().String("recaptcha.host", "https://www.google.com", "Use another host for ReCAPTCHA. recaptcha.net might be useful in China")
cmd.Flags().String("recaptcha.key", "", "ReCaptcha site key")
cmd.Flags().String("recaptcha.secret", "", "ReCaptcha secret")
}
func getAuthentication(cmd *cobra.Command) (types.AuthMethod, types.Auther) {
method := types.AuthMethod(mustGetString(cmd, "auth.method"))
var auther types.Auther
if method == auth.MethodProxyAuth {
header := mustGetString(cmd, "auth.header")
if header == "" {
panic(errors.New("you must set the flag 'auth.header' for method 'proxy'"))
}
auther = auth.ProxyAuth{Header: header}
}
if method == auth.MethodNoAuth {
auther = auth.NoAuth{}
}
if method == auth.MethodJSONAuth {
jsonAuth := auth.JSONAuth{}
host := mustGetString(cmd, "recaptcha.host")
key := mustGetString(cmd, "recaptcha.key")
secret := mustGetString(cmd, "recaptcha.secret")
if key != "" && secret != "" {
jsonAuth.ReCaptcha = &auth.ReCaptcha{
Host: host,
Key: key,
Secret: secret,
}
}
auther = jsonAuth
}
if auther == nil {
panic(types.ErrInvalidAuthMethod)
}
return method, auther
}
func printSettings(s *types.Settings, auther types.Auther) {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprintf(w, "\nBase URL:\t%s\n", s.BaseURL)
fmt.Fprintf(w, "Sign up:\t%t\n", s.Signup)
fmt.Fprintf(w, "Auth method:\t%s\n", s.AuthMethod)
fmt.Fprintln(w, "\nDefaults:")
fmt.Fprintf(w, "\tScope:\t%s\n", s.Defaults.Scope)
fmt.Fprintf(w, "\tLocale:\t%s\n", s.Defaults.Locale)
fmt.Fprintf(w, "\tView mode:\t%s\n", s.Defaults.ViewMode)
fmt.Fprintf(w, "\tPermissions:\n")
fmt.Fprintf(w, "\t\tAdmin:\t%t\n", s.Defaults.Perm.Admin)
fmt.Fprintf(w, "\t\tExecute:\t%t\n", s.Defaults.Perm.Execute)
fmt.Fprintf(w, "\t\tCreate:\t%t\n", s.Defaults.Perm.Create)
fmt.Fprintf(w, "\t\tRename:\t%t\n", s.Defaults.Perm.Rename)
fmt.Fprintf(w, "\t\tModify:\t%t\n", s.Defaults.Perm.Modify)
fmt.Fprintf(w, "\t\tDelete:\t%t\n", s.Defaults.Perm.Delete)
fmt.Fprintf(w, "\t\tShare:\t%t\n", s.Defaults.Perm.Share)
fmt.Fprintf(w, "\t\tDownload:\t%t\n", s.Defaults.Perm.Download)
w.Flush()
b, err := json.MarshalIndent(auther, "", " ")
checkErr(err)
fmt.Printf("\nAuther configuration (raw):\n\n%s\n\n", string(b))
}