webdav fixe bug
This commit is contained in:
parent
43e31c36d8
commit
548cf7882e
@ -123,7 +123,51 @@ func RoutesPublic(r *mux.Router, bd *gorm.DB) {
|
|||||||
http.Error(w, "Erreur lors de la génération de la playlist", http.StatusInternalServerError)
|
http.Error(w, "Erreur lors de la génération de la playlist", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
setupWebdavRoute(r, bd)
|
r.PathPrefix("/webdav/").Handler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
// Authentification HTTP Basic avec vérification en base
|
||||||
|
userEmail, password, ok := req.BasicAuth()
|
||||||
|
if !ok {
|
||||||
|
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
||||||
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var user models.User
|
||||||
|
result := bd.Where("email = ?", userEmail).First(&user)
|
||||||
|
if result.Error != nil {
|
||||||
|
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
||||||
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password))
|
||||||
|
if err != nil {
|
||||||
|
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
||||||
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Protection lecture seule
|
||||||
|
if req.Method != "GET" && req.Method != "HEAD" && req.Method != "OPTIONS" && req.Method != "PROPFIND" {
|
||||||
|
http.Error(w, "Read-Only", http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("✅ WebDAV access for user: %s", userEmail)
|
||||||
|
|
||||||
|
// Headers WebDAV attendus
|
||||||
|
w.Header().Set("DAV", "1,2")
|
||||||
|
w.Header().Set("MS-Author-Via", "DAV")
|
||||||
|
|
||||||
|
// Serve le WebDAV
|
||||||
|
webdavHandler := &webdav.Handler{
|
||||||
|
Prefix: "/webdav/",
|
||||||
|
FileSystem: webdav.Dir("/app/upload"),
|
||||||
|
LockSystem: webdav.NewMemLS(),
|
||||||
|
}
|
||||||
|
|
||||||
|
webdavHandler.ServeHTTP(w, req)
|
||||||
|
}))
|
||||||
|
|
||||||
// WebDAV sécurisé
|
// WebDAV sécurisé
|
||||||
// username := "tonuser" // ton login
|
// username := "tonuser" // ton login
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user