✨ webdav visitor
This commit is contained in:
@ -158,7 +158,7 @@ func InitSettings() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "WebDAV username",
|
Key: "WebDAV username",
|
||||||
Value: "alist",
|
Value: "alist_admin",
|
||||||
Description: "WebDAV username",
|
Description: "WebDAV username",
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Access: model.PRIVATE,
|
Access: model.PRIVATE,
|
||||||
@ -166,12 +166,44 @@ func InitSettings() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "WebDAV password",
|
Key: "WebDAV password",
|
||||||
Value: "alist",
|
Value: "alist_admin",
|
||||||
Description: "WebDAV password",
|
Description: "WebDAV password",
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Access: model.PRIVATE,
|
Access: model.PRIVATE,
|
||||||
Group: model.BACK,
|
Group: model.BACK,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Key: "artplayer whitelist",
|
||||||
|
Value: "*",
|
||||||
|
Description: "refer to https://artplayer.org/document/options#whitelist",
|
||||||
|
Type: "string",
|
||||||
|
Access: model.PUBLIC,
|
||||||
|
Group: model.FRONT,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: "artplayer autoSize",
|
||||||
|
Value: "true",
|
||||||
|
Description: "refer to https://artplayer.org/document/options#autosize",
|
||||||
|
Type: "bool",
|
||||||
|
Access: model.PUBLIC,
|
||||||
|
Group: model.FRONT,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: "Visitor WebDAV username",
|
||||||
|
Value: "alist_visitor",
|
||||||
|
Description: "Visitor WebDAV username",
|
||||||
|
Type: "string",
|
||||||
|
Access: model.PRIVATE,
|
||||||
|
Group: model.BACK,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: "Visitor WebDAV password",
|
||||||
|
Value: "alist_visitor",
|
||||||
|
Description: "Visitor WebDAV password",
|
||||||
|
Type: "string",
|
||||||
|
Access: model.PRIVATE,
|
||||||
|
Group: model.BACK,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i, _ := range settings {
|
for i, _ := range settings {
|
||||||
v := settings[i]
|
v := settings[i]
|
||||||
|
@ -45,7 +45,9 @@ var (
|
|||||||
CheckParent bool
|
CheckParent bool
|
||||||
CheckDown bool
|
CheckDown bool
|
||||||
|
|
||||||
Token string
|
Token string
|
||||||
DavUsername string
|
DavUsername string
|
||||||
DavPassword string
|
DavPassword string
|
||||||
|
VisitorDavUsername string
|
||||||
|
VisitorDavPassword string
|
||||||
)
|
)
|
||||||
|
@ -132,4 +132,12 @@ func LoadSettings() {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
conf.DavPassword = davPassword.Value
|
conf.DavPassword = davPassword.Value
|
||||||
}
|
}
|
||||||
|
visitorDavUsername, err := GetSettingByKey("Visitor WebDAV username")
|
||||||
|
if err == nil {
|
||||||
|
conf.VisitorDavUsername = visitorDavUsername.Value
|
||||||
|
}
|
||||||
|
visitorDavPassword, err := GetSettingByKey("Visitor WebDAV password")
|
||||||
|
if err == nil {
|
||||||
|
conf.VisitorDavPassword = visitorDavPassword.Value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package server
|
|||||||
import (
|
import (
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/server/webdav"
|
"github.com/Xhofe/alist/server/webdav"
|
||||||
|
"github.com/Xhofe/alist/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
@ -33,7 +34,7 @@ func WebDav(r *gin.Engine) {
|
|||||||
|
|
||||||
func ServeWebDAV(c *gin.Context) {
|
func ServeWebDAV(c *gin.Context) {
|
||||||
fs := webdav.FileSystem{}
|
fs := webdav.FileSystem{}
|
||||||
handler.ServeHTTP(c.Writer,c.Request,&fs)
|
handler.ServeHTTP(c.Writer, c.Request, &fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WebDAVAuth(c *gin.Context) {
|
func WebDAVAuth(c *gin.Context) {
|
||||||
@ -48,13 +49,16 @@ func WebDAVAuth(c *gin.Context) {
|
|||||||
c.Abort()
|
c.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if conf.DavUsername != "" && conf.DavUsername != username {
|
if conf.DavUsername == username && conf.DavPassword == password {
|
||||||
c.Status(http.StatusUnauthorized)
|
c.Next()
|
||||||
c.Abort()
|
return
|
||||||
}
|
}
|
||||||
if conf.DavPassword != "" && conf.DavPassword != password {
|
if (conf.VisitorDavUsername == username && conf.VisitorDavPassword == password) || (conf.VisitorDavUsername == "" && conf.VisitorDavPassword == "") {
|
||||||
c.Status(http.StatusUnauthorized)
|
if !utils.IsContain([]string{"PUT", "DELETE", "PROPPATCH", "MKCOL", "COPY", "MOVE"}, c.Request.Method) {
|
||||||
c.Abort()
|
c.Next()
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.Next()
|
c.Status(http.StatusUnauthorized)
|
||||||
}
|
c.Abort()
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user