check parent folder password

pull/548/head
微凉 2021-11-13 16:12:12 +08:00
parent a73501463f
commit 959ef620fb
2 changed files with 24 additions and 0 deletions

View File

@ -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)
}
}

View File

@ -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 {