diff --git a/app/http/controllers/file_controller.go b/app/http/controllers/file_controller.go index ed43fa44..14df0eae 100644 --- a/app/http/controllers/file_controller.go +++ b/app/http/controllers/file_controller.go @@ -5,6 +5,7 @@ import ( stdio "io" stdos "os" "path/filepath" + "strconv" "strings" "syscall" @@ -354,10 +355,16 @@ func (r *FileController) Permission(ctx http.Context) http.Response { return sanitize } - if err := io.Chmod(request.Path, stdos.FileMode(request.Mode)); err != nil { + // 解析成8进制 + mode, err := strconv.ParseUint(request.Mode, 8, 64) + if err != nil { return Error(ctx, http.StatusInternalServerError, err.Error()) } - if err := io.Chown(request.Path, request.Owner, request.Group); err != nil { + + if err = io.Chmod(request.Path, stdos.FileMode(mode)); err != nil { + return Error(ctx, http.StatusInternalServerError, err.Error()) + } + if err = io.Chown(request.Path, request.Owner, request.Group); err != nil { return Error(ctx, http.StatusInternalServerError, err.Error()) } @@ -505,7 +512,7 @@ func (r *FileController) List(ctx http.Context) http.Response { } // setPermission -func (r *FileController) setPermission(path string, mode uint, owner, group string) { - _ = io.Chmod(path, stdos.FileMode(mode)) +func (r *FileController) setPermission(path string, mode stdos.FileMode, owner, group string) { + _ = io.Chmod(path, mode) _ = io.Chown(path, owner, group) } diff --git a/app/http/controllers/plugins/mysql_controller.go b/app/http/controllers/plugins/mysql_controller.go index 53c63e26..0d74848e 100644 --- a/app/http/controllers/plugins/mysql_controller.go +++ b/app/http/controllers/plugins/mysql_controller.go @@ -487,7 +487,7 @@ func (r *MySQLController) getSock() string { } if io.Exists("/www/server/mysql/config/my.cnf") { config, _ := io.Read("/www/server/mysql/config/my.cnf") - re := regexp.MustCompile(`socket\s*=\s*(['"]?)([^'"]+)\1`) + re := regexp.MustCompile(`socket\s*=\s*(['"]?)([^'"]+)`) matches := re.FindStringSubmatch(config) if len(matches) > 2 { return matches[2] @@ -495,7 +495,7 @@ func (r *MySQLController) getSock() string { } if io.Exists("/etc/my.cnf") { config, _ := io.Read("/etc/my.cnf") - re := regexp.MustCompile(`socket\s*=\s*(['"]?)([^'"]+)\1`) + re := regexp.MustCompile(`socket\s*=\s*(['"]?)([^'"]+)`) matches := re.FindStringSubmatch(config) if len(matches) > 2 { return matches[2] diff --git a/app/http/requests/file/permission.go b/app/http/requests/file/permission.go index 687feee1..fce8653f 100644 --- a/app/http/requests/file/permission.go +++ b/app/http/requests/file/permission.go @@ -7,7 +7,7 @@ import ( type Permission struct { Path string `form:"path" json:"path"` - Mode uint `form:"mode" json:"mode" filter:"uint"` + Mode string `form:"mode" json:"mode"` Owner string `form:"owner" json:"owner"` Group string `form:"group" json:"group"` } @@ -19,7 +19,7 @@ func (r *Permission) Authorize(ctx http.Context) error { func (r *Permission) Rules(ctx http.Context) map[string]string { return map[string]string{ "path": `regex:^/.*$|path_exists`, - "mode": "regex:^[0-7]{3}$|uint", + "mode": "regex:^0[0-7]{3}$", "owner": "regex:^[a-zA-Z0-9_-]+$", "group": "regex:^[a-zA-Z0-9_-]+$", }