Compare commits

...
6 Commits
Author SHA1 Message Date
Henrique Dias b645ac51eb Merge pull request #3 from fzoske/master
Add Support For BCrypt Storage of Passwords
2018-03-31 15:32:19 +01:00
Fabian Zoske 62aea27486 Add Support For BCrypt Storage of Passwords 2018-03-31 12:01:00 +02:00
Henrique Dias 541defc796 Update .travis.yml 2017-12-21 17:07:12 +00:00
Henrique Dias d2f2b1ccde Update Travis 2017-12-21 17:02:37 +00:00
Henrique Dias 6c10c35efe Merge pull request #2 from c35sys/master
Add *address* config option
2017-12-21 17:01:18 +00:00
Christophe Le Guern 8271975046 Add *address* config option 2017-12-21 17:50:03 +01:00
3 changed files with 37 additions and 20 deletions
+1 -4
View File
@@ -9,10 +9,7 @@ install:
- go get ./...
# Install gometalinter and certain linters
- go get github.com/alecthomas/gometalinter
- go get github.com/client9/misspell/cmd/misspell
- go get github.com/gordonklaus/ineffassign
- go get golang.org/x/tools/cmd/goimports
- go get github.com/tsenart/deadcode
- gometalinter --install
script:
- gometalinter --disable-all -E vet -E gofmt -E misspell -E ineffassign -E goimports -E deadcode --tests ./...
+32 -15
View File
@@ -11,8 +11,10 @@ import (
"os"
"path/filepath"
"regexp"
"strings"
"github.com/hacdias/webdav"
"golang.org/x/crypto/bcrypt"
wd "golang.org/x/net/webdav"
yaml "gopkg.in/yaml.v2"
)
@@ -133,24 +135,27 @@ func getConfig() []byte {
}
type cfg struct {
webdav *webdav.Config
port string
auth map[string]string
webdav *webdav.Config
address string
port string
auth map[string]string
}
func parseConfig() *cfg {
file := getConfig()
data := struct {
Port string `json:"port" yaml:"port"`
Scope string `json:"scope" yaml:"scope"`
Modify bool `json:"modify" yaml:"modify"`
Rules []map[string]interface{} `json:"rules" yaml:"rules"`
Users []map[string]interface{} `json:"users" yaml:"users"`
Address string `json:"address" yaml:"address"`
Port string `json:"port" yaml:"port"`
Scope string `json:"scope" yaml:"scope"`
Modify bool `json:"modify" yaml:"modify"`
Rules []map[string]interface{} `json:"rules" yaml:"rules"`
Users []map[string]interface{} `json:"users" yaml:"users"`
}{
Port: "0",
Scope: "./",
Modify: true,
Address: "0.0.0.0",
Port: "0",
Scope: "./",
Modify: true,
}
var err error
@@ -165,8 +170,9 @@ func parseConfig() *cfg {
}
config := &cfg{
port: data.Port,
auth: map[string]string{},
address: data.Address,
port: data.Port,
auth: map[string]string{},
webdav: &webdav.Config{
User: &webdav.User{
Scope: data.Scope,
@@ -209,7 +215,8 @@ func basicAuth(c *cfg) http.Handler {
return
}
if password != p {
if !checkPassword(p, password) {
log.Println("Wrong Password for user", username)
http.Error(w, "Not authorized", 401)
return
}
@@ -218,13 +225,23 @@ func basicAuth(c *cfg) http.Handler {
})
}
func checkPassword(saved, input string) bool {
if strings.HasPrefix(saved, "{bcrypt}") {
savedPassword := strings.TrimPrefix(saved, "{bcrypt}")
return bcrypt.CompareHashAndPassword([]byte(savedPassword), []byte(input)) == nil
}
return saved == input
}
func main() {
flag.Parse()
cfg := parseConfig()
handler := basicAuth(cfg)
// Builds the address and a listener.
laddr := ":" + cfg.port
laddr := cfg.address + ":" + cfg.port
listener, err := net.Listen("tcp", laddr)
if err != nil {
log.Fatal(err)
+4 -1
View File
@@ -7,10 +7,13 @@
```yaml
scope: /path/to/files
address: 0.0.0.0
port: 8080
users:
- username: admin
password: admin
- username: encrypted
password: "{bcrypt}$2y$10$zEP6oofmXFeHaeMfBNLnP.DO8m.H.Mwhd24/TOX2MWLxAExXi4qgi"
- username: basic
password: basic
modify: false
@@ -22,4 +25,4 @@ users:
You can specify the path to the configuration file using the `--config` flag. By default, it will search for a `config.{yaml,json}` file on your current working directory.
Download it [here](https://github.com/hacdias/webdav/releases).
Download it [here](https://github.com/hacdias/webdav/releases).