🐛 fix windows check parent password
This commit is contained in:
parent
ffdd88ec66
commit
71b1517de7
@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Auth(c *gin.Context) {
|
func Auth(c *gin.Context) {
|
||||||
@ -52,7 +51,7 @@ func CheckParent(path string, password string) bool {
|
|||||||
if path == "/" || path == "\\" {
|
if path == "/" || path == "\\" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return CheckParent(filepath.Dir(path), password)
|
return CheckParent(utils.Dir(path), password)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +74,6 @@ func CheckDownLink(path string, passwordMd5 string) bool {
|
|||||||
if path == "/" || path == "\\" {
|
if path == "/" || path == "\\" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return CheckDownLink(filepath.Dir(path), passwordMd5)
|
return CheckDownLink(utils.Dir(path), passwordMd5)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ func Down(c *gin.Context) {
|
|||||||
rawPath = utils.ParsePath(rawPath)
|
rawPath = utils.ParsePath(rawPath)
|
||||||
log.Debugf("down: %s", rawPath)
|
log.Debugf("down: %s", rawPath)
|
||||||
pw := c.Query("pw")
|
pw := c.Query("pw")
|
||||||
if !CheckDownLink(filepath.Dir(rawPath), pw) {
|
if !CheckDownLink(utils.Dir(rawPath), pw) {
|
||||||
ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ func Proxy(c *gin.Context) {
|
|||||||
rawPath = utils.ParsePath(rawPath)
|
rawPath = utils.ParsePath(rawPath)
|
||||||
log.Debugf("proxy: %s", rawPath)
|
log.Debugf("proxy: %s", rawPath)
|
||||||
pw := c.Query("pw")
|
pw := c.Query("pw")
|
||||||
if !CheckDownLink(filepath.Dir(rawPath), pw) {
|
if !CheckDownLink(utils.Dir(rawPath), pw) {
|
||||||
ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ func Path(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
// TODO hide or ignore?
|
// TODO hide or ignore?
|
||||||
} else if conf.CheckParent {
|
} else if conf.CheckParent {
|
||||||
if !CheckParent(filepath.Dir(req.Path), req.Password) {
|
if !CheckParent(utils.Dir(req.Path), req.Password) {
|
||||||
ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ func GetPW(path string) string {
|
|||||||
if path == "/" || path == "\\" {
|
if path == "/" || path == "\\" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return GetPW(filepath.Dir(path))
|
return GetPW(utils.Dir(path))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ func (fs *FileSystem) Link(r *http.Request, rawPath string) (string, error) {
|
|||||||
if driver.Config().OnlyProxy || account.WebdavProxy {
|
if driver.Config().OnlyProxy || account.WebdavProxy {
|
||||||
link = fmt.Sprintf("%s://%s/p%s", protocol, r.Host, rawPath)
|
link = fmt.Sprintf("%s://%s/p%s", protocol, r.Host, rawPath)
|
||||||
if conf.CheckDown {
|
if conf.CheckDown {
|
||||||
pw := GetPW(filepath.Dir(rawPath))
|
pw := GetPW(utils.Dir(rawPath))
|
||||||
link += "?pw" + pw
|
link += "?pw" + pw
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -94,4 +94,10 @@ func RemoveLastSlash(path string) string {
|
|||||||
return strings.TrimSuffix(path, "/")
|
return strings.TrimSuffix(path, "/")
|
||||||
}
|
}
|
||||||
return path
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
func Dir(path string) string {
|
||||||
|
path = ParsePath(path)
|
||||||
|
idx := strings.LastIndex(path, "/")
|
||||||
|
return path[:idx]
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user