mirror of
https://github.com/hacdias/webdav.git
synced 2024-04-21 12:32:06 +00:00
feat: allow no auth mode
License: MIT Signed-off-by: Henrique Dias <hacdias@gmail.com>
This commit is contained in:
+11
-4
@@ -163,6 +163,7 @@ type cfg struct {
|
||||
address string
|
||||
port string
|
||||
tls bool
|
||||
noAuth bool
|
||||
cert string
|
||||
key string
|
||||
auth map[string]string
|
||||
@@ -176,6 +177,7 @@ func parseConfig() *cfg {
|
||||
Port string `json:"port" yaml:"port"`
|
||||
TLS bool `json:"tls" yaml:"tls"`
|
||||
Cert string `json:"cert" yaml:"cert"`
|
||||
NoAuth bool `json:"noauth" yaml:"noauth"`
|
||||
Key string `json:"key" yaml:"key"`
|
||||
Scope string `json:"scope" yaml:"scope"`
|
||||
Modify bool `json:"modify" yaml:"modify"`
|
||||
@@ -188,6 +190,7 @@ func parseConfig() *cfg {
|
||||
Cert: "cert.pem",
|
||||
Key: "key.pem",
|
||||
Scope: "./",
|
||||
NoAuth: false,
|
||||
Modify: true,
|
||||
}
|
||||
|
||||
@@ -208,6 +211,7 @@ func parseConfig() *cfg {
|
||||
tls: data.TLS,
|
||||
cert: data.Cert,
|
||||
key: data.Key,
|
||||
noAuth: data.NoAuth,
|
||||
auth: map[string]string{},
|
||||
webdav: &webdav.Config{
|
||||
User: &webdav.User{
|
||||
@@ -223,10 +227,6 @@ func parseConfig() *cfg {
|
||||
},
|
||||
}
|
||||
|
||||
if len(data.Users) == 0 {
|
||||
log.Fatal("no user defined")
|
||||
}
|
||||
|
||||
if len(data.Rules) != 0 {
|
||||
config.webdav.User.Rules = parseRules(data.Rules)
|
||||
}
|
||||
@@ -236,6 +236,12 @@ func parseConfig() *cfg {
|
||||
}
|
||||
|
||||
func basicAuth(c *cfg) http.Handler {
|
||||
if c.noAuth {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
c.webdav.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
||||
|
||||
@@ -273,6 +279,7 @@ func checkPassword(saved, input string) bool {
|
||||
func main() {
|
||||
flag.Parse()
|
||||
cfg := parseConfig()
|
||||
|
||||
handler := basicAuth(cfg)
|
||||
|
||||
// Builds the address and a listener.
|
||||
|
||||
Reference in New Issue
Block a user