mirror of
https://github.com/cloudreve/cloudreve.git
synced 2025-12-15 10:04:01 +08:00
feat(webdav): option to disable system file uploads (#2871)
This commit is contained in:
2
assets
2
assets
Submodule assets updated: e53eb86a32...dcf21d5eb9
@@ -257,6 +257,7 @@ func FileTypeFromString(s string) FileType {
|
||||
const (
|
||||
DavAccountReadOnly DavAccountOption = iota
|
||||
DavAccountProxy
|
||||
DavAccountDisableSysFiles
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -9,6 +9,12 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cloudreve/Cloudreve/v4/application/dependency"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent"
|
||||
"github.com/cloudreve/Cloudreve/v4/inventory"
|
||||
@@ -26,11 +32,6 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/samber/lo"
|
||||
"golang.org/x/tools/container/intsets"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -228,6 +229,12 @@ func handlePut(c *gin.Context, user *ent.User, fm manager.FileManager) (status i
|
||||
return purposeStatusCodeFromError(err), err
|
||||
}
|
||||
|
||||
if user.Edges.DavAccounts[0].Options.Enabled(int(types.DavAccountDisableSysFiles)) {
|
||||
if strings.HasPrefix(reqPath.Name(), ".") {
|
||||
return http.StatusMethodNotAllowed, nil
|
||||
}
|
||||
}
|
||||
|
||||
release, ls, status, err := confirmLock(c, fm, user, ancestor, nil, uri, nil)
|
||||
if err != nil {
|
||||
return status, err
|
||||
|
||||
@@ -86,10 +86,11 @@ func (service *ListDavAccountsService) List(c *gin.Context) (*ListDavAccountResp
|
||||
|
||||
type (
|
||||
CreateDavAccountService struct {
|
||||
Uri string `json:"uri" binding:"required"`
|
||||
Name string `json:"name" binding:"required,min=1,max=255"`
|
||||
Readonly bool `json:"readonly"`
|
||||
Proxy bool `json:"proxy"`
|
||||
Uri string `json:"uri" binding:"required"`
|
||||
Name string `json:"name" binding:"required,min=1,max=255"`
|
||||
Readonly bool `json:"readonly"`
|
||||
Proxy bool `json:"proxy"`
|
||||
DisableSysFiles bool `json:"disable_sys_files"`
|
||||
}
|
||||
CreateDavAccountParamCtx struct{}
|
||||
)
|
||||
@@ -173,6 +174,10 @@ func (service *CreateDavAccountService) validateAndGetBs(user *ent.User) (*bools
|
||||
boolset.Set(types.DavAccountReadOnly, true, &bs)
|
||||
}
|
||||
|
||||
if service.DisableSysFiles {
|
||||
boolset.Set(types.DavAccountDisableSysFiles, true, &bs)
|
||||
}
|
||||
|
||||
if service.Proxy && user.Edges.Group.Permissions.Enabled(int(types.GroupPermissionWebDAVProxy)) {
|
||||
boolset.Set(types.DavAccountProxy, true, &bs)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user