mirror of
				https://github.com/filebrowser/filebrowser.git
				synced 2025-10-31 17:23:09 +00:00 
			
		
		
		
	 1259fc1bbc
			
		
	
	
		1259fc1bbc
		
	
	
	
	
		
			
			License: MIT Signed-off-by: Henrique Dias <hacdias@gmail.com> Former-commit-id: 04a60c58f20d63ca7b25731c41e144bcf0f538cc [formerly e6e179799b64779515051df53352df5e63edc259] [formerly 0689eba81ff5f7ee3ea75db37b91cef4d6d8f35c [formerly 85899acae6edc445506384a5fa2c972131cb06e6]] Former-commit-id: 96ca0cadb94131ddd3b57f0f11ad629edf687e40 [formerly 50130c75d39e67b15a645e7f4879acf34a5d6620] Former-commit-id: 53b8120673a82217c3625de161d4ec57a96e1470
		
			
				
	
	
		
			129 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			129 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package cmd
 | |
| 
 | |
| import (
 | |
| 	"encoding/json"
 | |
| 	nerrors "errors"
 | |
| 	"fmt"
 | |
| 	"os"
 | |
| 	"strings"
 | |
| 	"text/tabwriter"
 | |
| 
 | |
| 	"github.com/filebrowser/filebrowser/v2/auth"
 | |
| 	"github.com/filebrowser/filebrowser/v2/errors"
 | |
| 	"github.com/filebrowser/filebrowser/v2/settings"
 | |
| 	"github.com/spf13/cobra"
 | |
| 	"github.com/spf13/pflag"
 | |
| )
 | |
| 
 | |
| func init() {
 | |
| 	rootCmd.AddCommand(configCmd)
 | |
| }
 | |
| 
 | |
| var configCmd = &cobra.Command{
 | |
| 	Use:   "config",
 | |
| 	Short: "Configuration management utility",
 | |
| 	Long:  `Configuration management utility.`,
 | |
| 	Args:  cobra.NoArgs,
 | |
| }
 | |
| 
 | |
| func addConfigFlags(flags *pflag.FlagSet) {
 | |
| 	addServerFlags(flags)
 | |
| 	addUserFlags(flags)
 | |
| 	flags.BoolP("signup", "s", false, "allow users to signup")
 | |
| 	flags.String("shell", "", "shell command to which other commands should be appended")
 | |
| 
 | |
| 	flags.String("auth.method", string(auth.MethodJSONAuth), "authentication type")
 | |
| 	flags.String("auth.header", "", "HTTP header for auth.method=proxy")
 | |
| 
 | |
| 	flags.String("recaptcha.host", "https://www.google.com", "use another host for ReCAPTCHA. recaptcha.net might be useful in China")
 | |
| 	flags.String("recaptcha.key", "", "ReCaptcha site key")
 | |
| 	flags.String("recaptcha.secret", "", "ReCaptcha secret")
 | |
| 
 | |
| 	flags.String("branding.name", "", "replace 'File Browser' by this name")
 | |
| 	flags.String("branding.files", "", "path to directory with images and custom styles")
 | |
| 	flags.Bool("branding.disableExternal", false, "disable external links such as GitHub links")
 | |
| }
 | |
| 
 | |
| func getAuthentication(flags *pflag.FlagSet) (settings.AuthMethod, auth.Auther) {
 | |
| 	method := settings.AuthMethod(mustGetString(flags, "auth.method"))
 | |
| 
 | |
| 	var auther auth.Auther
 | |
| 	if method == auth.MethodProxyAuth {
 | |
| 		header := mustGetString(flags, "auth.header")
 | |
| 		if header == "" {
 | |
| 			panic(nerrors.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(flags, "recaptcha.host")
 | |
| 		key := mustGetString(flags, "recaptcha.key")
 | |
| 		secret := mustGetString(flags, "recaptcha.secret")
 | |
| 
 | |
| 		if key != "" && secret != "" {
 | |
| 			jsonAuth.ReCaptcha = &auth.ReCaptcha{
 | |
| 				Host:   host,
 | |
| 				Key:    key,
 | |
| 				Secret: secret,
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		auther = jsonAuth
 | |
| 	}
 | |
| 
 | |
| 	if auther == nil {
 | |
| 		panic(errors.ErrInvalidAuthMethod)
 | |
| 	}
 | |
| 
 | |
| 	return method, auther
 | |
| }
 | |
| 
 | |
| func printSettings(ser *settings.Server, set *settings.Settings, auther auth.Auther) {
 | |
| 	w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
 | |
| 
 | |
| 	fmt.Fprintf(w, "Sign up:\t%t\n", set.Signup)
 | |
| 	fmt.Fprintf(w, "Auth method:\t%s\n", set.AuthMethod)
 | |
| 	fmt.Fprintf(w, "Shell:\t%s\t\n", strings.Join(set.Shell, " "))
 | |
| 	fmt.Fprintln(w, "\nBranding:")
 | |
| 	fmt.Fprintf(w, "\tName:\t%s\n", set.Branding.Name)
 | |
| 	fmt.Fprintf(w, "\tFiles override:\t%s\n", set.Branding.Files)
 | |
| 	fmt.Fprintf(w, "\tDisable external links:\t%t\n", set.Branding.DisableExternal)
 | |
| 	fmt.Fprintln(w, "\nServer:")
 | |
| 	fmt.Fprintf(w, "\tLog:\t%s\n", ser.Log)
 | |
| 	fmt.Fprintf(w, "\tPort:\t%s\n", ser.Port)
 | |
| 	fmt.Fprintf(w, "\tBase URL:\t%s\n", ser.BaseURL)
 | |
| 	fmt.Fprintf(w, "\tRoot:\t%s\n", ser.Root)
 | |
| 	fmt.Fprintf(w, "\tAddress:\t%s\n", ser.Address)
 | |
| 	fmt.Fprintf(w, "\tTLS Cert:\t%s\n", ser.TLSCert)
 | |
| 	fmt.Fprintf(w, "\tTLS Key:\t%s\n", ser.TLSKey)
 | |
| 	fmt.Fprintln(w, "\nDefaults:")
 | |
| 	fmt.Fprintf(w, "\tScope:\t%s\n", set.Defaults.Scope)
 | |
| 	fmt.Fprintf(w, "\tLocale:\t%s\n", set.Defaults.Locale)
 | |
| 	fmt.Fprintf(w, "\tView mode:\t%s\n", set.Defaults.ViewMode)
 | |
| 	fmt.Fprintf(w, "\tCommands:\t%s\n", strings.Join(set.Defaults.Commands, " "))
 | |
| 	fmt.Fprintf(w, "\tSorting:\n")
 | |
| 	fmt.Fprintf(w, "\t\tBy:\t%s\n", set.Defaults.Sorting.By)
 | |
| 	fmt.Fprintf(w, "\t\tAsc:\t%t\n", set.Defaults.Sorting.Asc)
 | |
| 	fmt.Fprintf(w, "\tPermissions:\n")
 | |
| 	fmt.Fprintf(w, "\t\tAdmin:\t%t\n", set.Defaults.Perm.Admin)
 | |
| 	fmt.Fprintf(w, "\t\tExecute:\t%t\n", set.Defaults.Perm.Execute)
 | |
| 	fmt.Fprintf(w, "\t\tCreate:\t%t\n", set.Defaults.Perm.Create)
 | |
| 	fmt.Fprintf(w, "\t\tRename:\t%t\n", set.Defaults.Perm.Rename)
 | |
| 	fmt.Fprintf(w, "\t\tModify:\t%t\n", set.Defaults.Perm.Modify)
 | |
| 	fmt.Fprintf(w, "\t\tDelete:\t%t\n", set.Defaults.Perm.Delete)
 | |
| 	fmt.Fprintf(w, "\t\tShare:\t%t\n", set.Defaults.Perm.Share)
 | |
| 	fmt.Fprintf(w, "\t\tDownload:\t%t\n", set.Defaults.Perm.Download)
 | |
| 	w.Flush()
 | |
| 
 | |
| 	b, err := json.MarshalIndent(auther, "", "  ")
 | |
| 	checkErr(err)
 | |
| 	fmt.Printf("\nAuther configuration (raw):\n\n%s\n\n", string(b))
 | |
| }
 |