mirror of https://github.com/Xhofe/alist
✨ check parent folder password
parent
a73501463f
commit
959ef620fb
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func Auth(c *gin.Context) {
|
||||
|
@ -37,3 +38,18 @@ func CheckAccount(c *gin.Context) {
|
|||
}
|
||||
c.Next()
|
||||
}
|
||||
|
||||
func CheckParent(path string, password string) bool {
|
||||
meta, err := model.GetMetaByPath(path)
|
||||
if err == nil {
|
||||
if meta.Password != "" && meta.Password != password {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
if path == "/" {
|
||||
return true
|
||||
}
|
||||
return CheckParent(filepath.Dir(path), password)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@ package server
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -30,6 +32,12 @@ func Path(c *gin.Context) {
|
|||
}
|
||||
// TODO hide or ignore?
|
||||
}
|
||||
if conf.CheckParent {
|
||||
if !CheckParent(filepath.Dir(req.Path), req.Password) {
|
||||
ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
||||
return
|
||||
}
|
||||
}
|
||||
if model.AccountsCount() > 1 && req.Path == "/" {
|
||||
files, err := model.GetAccountFiles()
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue