up
This commit is contained in:
parent
548cf7882e
commit
4f2b9dba1c
@ -123,9 +123,16 @@ 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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
r.PathPrefix("/webdav/").Handler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
r.PathPrefix("/webdav/").Handler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
// Authentification HTTP Basic avec vérification en base
|
authHeader := req.Header.Get("Authorization")
|
||||||
userEmail, password, ok := req.BasicAuth()
|
if authHeader == "" {
|
||||||
|
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
||||||
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Authentification HTTP Basic en base de données
|
||||||
|
email, password, ok := req.BasicAuth()
|
||||||
if !ok {
|
if !ok {
|
||||||
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
||||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||||
@ -133,7 +140,7 @@ func RoutesPublic(r *mux.Router, bd *gorm.DB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var user models.User
|
var user models.User
|
||||||
result := bd.Where("email = ?", userEmail).First(&user)
|
result := bd.Where("email = ?", email).First(&user)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
||||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||||
@ -147,19 +154,17 @@ func RoutesPublic(r *mux.Router, bd *gorm.DB) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Protection lecture seule
|
// Lecture seule
|
||||||
if req.Method != "GET" && req.Method != "HEAD" && req.Method != "OPTIONS" && req.Method != "PROPFIND" {
|
if req.Method != "GET" && req.Method != "HEAD" && req.Method != "OPTIONS" && req.Method != "PROPFIND" {
|
||||||
http.Error(w, "Read-Only", http.StatusForbidden)
|
http.Error(w, "Read-Only", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("✅ WebDAV access for user: %s", userEmail)
|
log.Printf("✅ WebDAV access for user: %s", email)
|
||||||
|
|
||||||
// Headers WebDAV attendus
|
|
||||||
w.Header().Set("DAV", "1,2")
|
w.Header().Set("DAV", "1,2")
|
||||||
w.Header().Set("MS-Author-Via", "DAV")
|
w.Header().Set("MS-Author-Via", "DAV")
|
||||||
|
|
||||||
// Serve le WebDAV
|
|
||||||
webdavHandler := &webdav.Handler{
|
webdavHandler := &webdav.Handler{
|
||||||
Prefix: "/webdav/",
|
Prefix: "/webdav/",
|
||||||
FileSystem: webdav.Dir("/app/upload"),
|
FileSystem: webdav.Dir("/app/upload"),
|
||||||
@ -167,7 +172,7 @@ func RoutesPublic(r *mux.Router, bd *gorm.DB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
webdavHandler.ServeHTTP(w, req)
|
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