diff --git a/config.go b/config.go index 2e937f1..d1aa135 100644 --- a/config.go +++ b/config.go @@ -1,4 +1,4 @@ -// Copyright (c) 2018, Andreas Schneider +// Copyright (c) 2019, Andreas Schneider // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -26,35 +26,34 @@ package main import ( - "github.com/BurntSushi/toml" - "golang.org/x/crypto/bcrypt" - "log" - "strings" + "github.com/go-yaml/yaml" + "os" ) type Config struct { - ListenAddress string - BaseDirectory string - Shares map[string]Share - Logins map[string]Login + ListenAddress string `yaml:"listenAddress"` + BaseDirectory string `yaml:"baseDirectory"` + Shares map[string]Share `yaml:"shares"` } type Share struct { - Directory string + Directory string `yaml:"directory"` + Users map[string]ShareUser `yaml:"users"` } -type Login struct { - Credentials map[string]Credential -} - -type Credential struct { - Password string - Share string +type ShareUser struct { + Role string `yaml:"role"` + Logins map[string]string `yaml:"logins"` } func LoadConfig(filename string) Config { c := Config{} - if _, err := toml.DecodeFile(filename, &c); err != nil { + f, err := os.Open(filename) + if err != nil { + panic(err) + } + defer f.Close() + if err := yaml.NewDecoder(f).Decode(&c); err != nil { panic(err) } @@ -62,7 +61,7 @@ func LoadConfig(filename string) Config { } func (c *Config) ValidateDAVUser(username, password string) (valid bool, directory string) { - parts := strings.SplitN(username, "@", 2) + /*parts := strings.SplitN(username, "@", 2) if len(parts) != 2 { return false, "" } @@ -91,5 +90,6 @@ func (c *Config) ValidateDAVUser(username, password string) (valid bool, directo return false, "" } else { return true, share.Directory - } + }*/ + return false, "" } diff --git a/example.toml b/example.toml deleted file mode 100644 index 71b75b6..0000000 --- a/example.toml +++ /dev/null @@ -1,17 +0,0 @@ -ListenAddress = ":3000" -BaseDirectory = "data" - -[Shares] - - [Shares.Test1] - Directory = "share1" - - [Shares.Test2] - Directory = "share2" - -[Logins] - - [Logins.User1] - [Logins.User1.Credentials.Test1] - Password = "$2a$10$5AuehKad7TxDqW2HXdYaZ.ipFajhl7ULyTR3DLCquTA3B/dxHujIq" #test - Share = "Test1" \ No newline at end of file diff --git a/example.yaml b/example.yaml new file mode 100644 index 0000000..00f3057 --- /dev/null +++ b/example.yaml @@ -0,0 +1,18 @@ +listenAddress: :3000 +baseDirectory: data +shares: + test1: + directory: share1 + users: + User1: + role: admin + logins: + dev1: $2a$10$5AuehKad7TxDqW2HXdYaZ.ipFajhl7ULyTR3DLCquTA3B/dxHujIq #test + test2: + directory: share2 + users: + User1: + role: reader +users: + User1: + diff --git a/main.go b/main.go index d3029ad..37718b2 100644 --- a/main.go +++ b/main.go @@ -37,7 +37,7 @@ import ( "time" ) -var configFile = flag.String("config", "sharedav.toml", "Config file to be used.") +var configFile = flag.String("config", "sharedav.yaml", "Config file to be used.") var genPassword = flag.Bool("genpass", false, "If set, a password will be generated and hashed.") var hashPassword = flag.String("hashpass", "", "If set, the given password will be hashed.")