This commit is contained in:
1138-4EB 2019-01-06 19:40:37 +01:00
parent 6bf7065dad
commit 0bce6c0a14
6 changed files with 34 additions and 26 deletions

View File

@ -2,7 +2,6 @@ package cmd
import ( import (
"crypto/tls" "crypto/tls"
"errors"
"io/ioutil" "io/ioutil"
"log" "log"
"net" "net"
@ -92,8 +91,8 @@ func mustGetStringViperFlag(flags *pflag.FlagSet, key string) string {
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "filebrowser", Use: "filebrowser",
Short: "A stylish web-based file browser",
Version: version.Version, Version: version.Version,
Short: "A stylish web-based file browser",
Long: `File Browser CLI lets you create the database to use with File Browser, Long: `File Browser CLI lets you create the database to use with File Browser,
manage your users and all the configurations without acessing the manage your users and all the configurations without acessing the
web interface. web interface.
@ -129,7 +128,11 @@ set FB_DATABASE.
Also, if the database path doesn't exist, File Browser will enter into Also, if the database path doesn't exist, File Browser will enter into
the quick setup mode and a new database will be bootstraped and a new the quick setup mode and a new database will be bootstraped and a new
user created with the credentials from options "username" and "password".`, user created with the credentials from options "username" and "password".`,
Run: python(func(cmd *cobra.Command, args []string, d pythonData) { Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
log.Println(cfgFile)
if !d.hadDB { if !d.hadDB {
quickSetup(cmd.Flags(), d) quickSetup(cmd.Flags(), d)
} }
@ -141,22 +144,23 @@ user created with the credentials from options "username" and "password".`,
checkErr(err) checkErr(err)
server.Root = root server.Root = root
handler, err := fbhttp.NewHandler(d.store, server) adr := server.Address + ":" + server.Port
checkErr(err)
var listener net.Listener var listener net.Listener
if server.TLSKey != "" && server.TLSCert != "" { if server.TLSKey != "" && server.TLSCert != "" {
cer, err := tls.LoadX509KeyPair(server.TLSCert, server.TLSKey) cer, err := tls.LoadX509KeyPair(server.TLSCert, server.TLSKey)
checkErr(err) checkErr(err)
config := &tls.Config{Certificates: []tls.Certificate{cer}} listener, err = tls.Listen("tcp", adr, &tls.Config{Certificates: []tls.Certificate{cer}})
listener, err = tls.Listen("tcp", server.Address+":"+server.Port, config)
checkErr(err) checkErr(err)
} else { } else {
listener, err = net.Listen("tcp", server.Address+":"+server.Port) listener, err = net.Listen("tcp", adr)
checkErr(err) checkErr(err)
} }
handler, err := fbhttp.NewHandler(d.store, server)
checkErr(err)
log.Println("Listening on", listener.Addr().String()) log.Println("Listening on", listener.Addr().String())
if err := http.Serve(listener, handler); err != nil { if err := http.Serve(listener, handler); err != nil {
log.Fatal(err) log.Fatal(err)
@ -267,7 +271,7 @@ func quickSetup(flags *pflag.FlagSet, d pythonData) {
} }
if username == "" || password == "" { if username == "" || password == "" {
checkErr(errors.New("username and password cannot be empty during quick setup")) log.Fatal("username and password cannot be empty during quick setup")
} }
user := &users.User{ user := &users.User{
@ -303,7 +307,9 @@ func initConfig() {
if _, ok := err.(v.ConfigParseError); ok { if _, ok := err.(v.ConfigParseError); ok {
panic(err) panic(err)
} }
// TODO: log.Println("No config file provided") cfgFile = "No config file used"
} else {
cfgFile = "Using config file: " + v.ConfigFileUsed()
} }
// else TODO: log.Println("Using config file:", v.ConfigFileUsed())
} }

View File

@ -43,14 +43,14 @@ func runRules(st *storage.Storage, cmd *cobra.Command, users func(*users.User),
return return
} }
settings, err := st.Settings.Get() s, err := st.Settings.Get()
checkErr(err) checkErr(err)
if global != nil { if global != nil {
global(settings) global(s)
} }
printRules(settings.Rules, id) printRules(s.Rules, id)
} }
func getUserIdentifier(flags *pflag.FlagSet) interface{} { func getUserIdentifier(flags *pflag.FlagSet) interface{} {

View File

@ -26,8 +26,10 @@ options you want to change.`,
password := mustGetString(flags, "password") password := mustGetString(flags, "password")
newUsername := mustGetString(flags, "username") newUsername := mustGetString(flags, "username")
var err error var (
var user *users.User err error
user *users.User
)
if id != 0 { if id != 0 {
user, err = d.store.Users.Get("", id) user, err = d.store.Users.Get("", id)

View File

@ -7,7 +7,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/dgrijalva/jwt-go" jwt "github.com/dgrijalva/jwt-go"
"github.com/dgrijalva/jwt-go/request" "github.com/dgrijalva/jwt-go/request"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/users" "github.com/filebrowser/filebrowser/v2/users"

View File

@ -9,7 +9,7 @@ import (
"strings" "strings"
"text/template" "text/template"
"github.com/GeertJohan/go.rice" rice "github.com/GeertJohan/go.rice"
"github.com/filebrowser/filebrowser/v2/auth" "github.com/filebrowser/filebrowser/v2/auth"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/filebrowser/filebrowser/v2/settings"
"github.com/filebrowser/filebrowser/v2/storage" "github.com/filebrowser/filebrowser/v2/storage"

View File

@ -13,8 +13,8 @@ import (
"github.com/asdine/storm" "github.com/asdine/storm"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/filebrowser/filebrowser/v2/settings"
"github.com/filebrowser/filebrowser/v2/storage" "github.com/filebrowser/filebrowser/v2/storage"
"github.com/pelletier/go-toml" toml "github.com/pelletier/go-toml"
"gopkg.in/yaml.v2" yaml "gopkg.in/yaml.v2"
) )
type oldDefs struct { type oldDefs struct {
@ -33,7 +33,7 @@ type oldAuth struct {
} }
type oldConf struct { type oldConf struct {
Port string `json:"port" yaml:"port" toml:"port"` Port string `json:"port" yaml:"port" toml:"port"`
BaseURL string `json:"baseURL" yaml:"baseURL" toml:"baseURL"` BaseURL string `json:"baseURL" yaml:"baseURL" toml:"baseURL"`
Log string `json:"log" yaml:"log" toml:"log"` Log string `json:"log" yaml:"log" toml:"log"`
Address string `json:"address" yaml:"address" toml:"address"` Address string `json:"address" yaml:"address" toml:"address"`
@ -118,8 +118,8 @@ func importConf(db *storm.DB, path string, sto *storage.Storage) error {
} }
s := &settings.Settings{ s := &settings.Settings{
Key: key, Key: key,
Signup: false, Signup: false,
Defaults: settings.UserDefaults{ Defaults: settings.UserDefaults{
Scope: cfg.Defaults.Scope, Scope: cfg.Defaults.Scope,
Commands: cfg.Defaults.Commands, Commands: cfg.Defaults.Commands,
@ -139,10 +139,10 @@ func importConf(db *storm.DB, path string, sto *storage.Storage) error {
} }
server := &settings.Server{ server := &settings.Server{
BaseURL : cfg.BaseURL, BaseURL: cfg.BaseURL,
Port : cfg.Port, Port: cfg.Port,
Address : cfg.Address, Address: cfg.Address,
Log : cfg.Log, Log: cfg.Log,
} }
var auther auth.Auther var auther auth.Auther