From 436a3b05a1e2bc2111e4bacb3c108f75fad3b2f3 Mon Sep 17 00:00:00 2001 From: Ethan Davis Date: Tue, 18 Jan 2022 22:17:20 +0800 Subject: [PATCH] fix: 'modify:false' is respected --- README.md | 1 + cmd/config.go | 1 + cmd/root.go | 3 +++ lib/webdav.go | 18 ++++++++---------- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9faf310..02f8c3c 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ tls: false cert: cert.pem key: key.pem prefix: / +debug: false # Default user settings (will be merged) scope: . diff --git a/cmd/config.go b/cmd/config.go index e8ca28b..4632b94 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -190,6 +190,7 @@ func readConfig(flags *pflag.FlagSet) *lib.Config { LockSystem: webdav.NewMemLS(), }, }, + Debug: getOptB(flags, "debug"), Auth: getOptB(flags, "auth"), NoSniff: getOptB(flags, "nosniff"), Cors: lib.CorsCfg{ diff --git a/cmd/root.go b/cmd/root.go index c4cba1d..60f1697 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -71,6 +71,9 @@ set WD_CERT.`, } loggerConfig := zap.NewProductionConfig() loggerConfig.DisableCaller = true + if cfg.Debug { + loggerConfig.Level = zap.NewAtomicLevelAt(zap.DebugLevel) + } loggerConfig.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder loggerConfig.Encoding = cfg.LogFormat logger, err := loggerConfig.Build() diff --git a/lib/webdav.go b/lib/webdav.go index 270a72f..ce2743d 100644 --- a/lib/webdav.go +++ b/lib/webdav.go @@ -22,6 +22,7 @@ type CorsCfg struct { type Config struct { *User Auth bool + Debug bool NoSniff bool Cors CorsCfg Users map[string]*User @@ -107,17 +108,14 @@ func (c *Config) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // Checks for user permissions relatively to this PATH. - noModification := r.Method == "GET" || - r.Method == "HEAD" || - r.Method == "OPTIONS" || - r.Method == "PROPFIND" || - r.Method == "PUT" || - r.Method == "LOCK" || - r.Method == "UNLOCK" || - r.Method == "MOVE" || - r.Method == "DELETE" + noModification := r.Method == "GET" || r.Method == "HEAD" || + r.Method == "OPTIONS" || r.Method == "PROPFIND" - if !u.Allowed(r.URL.Path, noModification) { + allowed := u.Allowed(r.URL.Path, noModification) + + zap.L().Debug("allowed & method & path", zap.Bool("allowed", allowed), zap.String("method", r.Method), zap.String("path", r.URL.Path)) + + if !allowed { w.WriteHeader(http.StatusForbidden) return }