up
This commit is contained in:
parent
4f2b9dba1c
commit
c3ae090f59
@ -21,35 +21,7 @@ import (
|
||||
"golang.org/x/net/webdav"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
func setupWebdavRoute(r *mux.Router, db *gorm.DB) {
|
||||
webdavHandler := &webdav.Handler{
|
||||
Prefix: "/webdav/",
|
||||
FileSystem: webdav.Dir("/app/upload"),
|
||||
LockSystem: webdav.NewMemLS(),
|
||||
}
|
||||
|
||||
// Middleware HTTP Basic qui interroge la DB
|
||||
authHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
user, pass, ok := req.BasicAuth()
|
||||
if !ok || !checkUserCredentials(db, user, pass) {
|
||||
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
// Lecture seule
|
||||
if req.Method != "GET" && req.Method != "HEAD" && req.Method != "OPTIONS" && req.Method != "PROPFIND" {
|
||||
http.Error(w, "Read-Only", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("DAV", "1,2")
|
||||
w.Header().Set("MS-Author-Via", "DAV")
|
||||
webdavHandler.ServeHTTP(w, req)
|
||||
})
|
||||
|
||||
r.PathPrefix("/webdav/").Handler(authHandler)
|
||||
}
|
||||
func checkUserCredentials(db *gorm.DB, email string, password string) bool {
|
||||
var user models.User
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user