From 09703761ebfc7b15d3000f505bee3d9e5d77f80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Mon, 24 Jun 2024 22:20:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=96=87=E4=BB=B6):=20=E6=9D=83=E9=99=90?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/http/controllers/file_controller.go | 15 +++++++++++---- app/http/controllers/plugins/mysql_controller.go | 4 ++-- app/http/requests/file/permission.go | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) 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_-]+$", }