mirror of
https://github.com/hacdias/webdav.git
synced 2026-09-26 05:01:54 +08:00
fix: 'modify:false' is respected
This commit is contained in:
@@ -22,6 +22,7 @@ tls: false
|
|||||||
cert: cert.pem
|
cert: cert.pem
|
||||||
key: key.pem
|
key: key.pem
|
||||||
prefix: /
|
prefix: /
|
||||||
|
debug: false
|
||||||
|
|
||||||
# Default user settings (will be merged)
|
# Default user settings (will be merged)
|
||||||
scope: .
|
scope: .
|
||||||
|
|||||||
@@ -190,6 +190,7 @@ func readConfig(flags *pflag.FlagSet) *lib.Config {
|
|||||||
LockSystem: webdav.NewMemLS(),
|
LockSystem: webdav.NewMemLS(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Debug: getOptB(flags, "debug"),
|
||||||
Auth: getOptB(flags, "auth"),
|
Auth: getOptB(flags, "auth"),
|
||||||
NoSniff: getOptB(flags, "nosniff"),
|
NoSniff: getOptB(flags, "nosniff"),
|
||||||
Cors: lib.CorsCfg{
|
Cors: lib.CorsCfg{
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ set WD_CERT.`,
|
|||||||
}
|
}
|
||||||
loggerConfig := zap.NewProductionConfig()
|
loggerConfig := zap.NewProductionConfig()
|
||||||
loggerConfig.DisableCaller = true
|
loggerConfig.DisableCaller = true
|
||||||
|
if cfg.Debug {
|
||||||
|
loggerConfig.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
|
||||||
|
}
|
||||||
loggerConfig.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
loggerConfig.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||||
loggerConfig.Encoding = cfg.LogFormat
|
loggerConfig.Encoding = cfg.LogFormat
|
||||||
logger, err := loggerConfig.Build()
|
logger, err := loggerConfig.Build()
|
||||||
|
|||||||
+8
-10
@@ -22,6 +22,7 @@ type CorsCfg struct {
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
*User
|
*User
|
||||||
Auth bool
|
Auth bool
|
||||||
|
Debug bool
|
||||||
NoSniff bool
|
NoSniff bool
|
||||||
Cors CorsCfg
|
Cors CorsCfg
|
||||||
Users map[string]*User
|
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.
|
// Checks for user permissions relatively to this PATH.
|
||||||
noModification := r.Method == "GET" ||
|
noModification := r.Method == "GET" || r.Method == "HEAD" ||
|
||||||
r.Method == "HEAD" ||
|
r.Method == "OPTIONS" || r.Method == "PROPFIND"
|
||||||
r.Method == "OPTIONS" ||
|
|
||||||
r.Method == "PROPFIND" ||
|
|
||||||
r.Method == "PUT" ||
|
|
||||||
r.Method == "LOCK" ||
|
|
||||||
r.Method == "UNLOCK" ||
|
|
||||||
r.Method == "MOVE" ||
|
|
||||||
r.Method == "DELETE"
|
|
||||||
|
|
||||||
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)
|
w.WriteHeader(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user