From 5f750e6f49e46e22876ba0958261d6c65eb232ef Mon Sep 17 00:00:00 2001 From: zhengkunwang223 <31820853+zhengkunwang223@users.noreply.github.com> Date: Fri, 30 Jun 2023 23:24:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E9=99=90=E5=88=B6=E5=AF=BC=E8=87=B4=20PHP=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#1499)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs https://github.com/1Panel-dev/1Panel/issues/1425 --- backend/app/api/v1/website.go | 2 +- backend/app/service/website.go | 59 ++++++++++++++-------------------- 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/backend/app/api/v1/website.go b/backend/app/api/v1/website.go index d6918996d..76c41d0c7 100644 --- a/backend/app/api/v1/website.go +++ b/backend/app/api/v1/website.go @@ -541,7 +541,7 @@ func (b *BaseApi) UpdateWebsitePHPConfig(c *gin.Context) { // @Tags Website PHP // @Summary Update php conf -// @Description 更新 php 配置 +// @Description 更新 php 配置文件 // @Accept json // @Param request body request.WebsitePHPFileUpdate true "request" // @Success 200 diff --git a/backend/app/service/website.go b/backend/app/service/website.go index 79bbcc725..411da5b0a 100644 --- a/backend/app/service/website.go +++ b/backend/app/service/website.go @@ -1059,50 +1059,41 @@ func (w WebsiteService) UpdatePHPConfig(req request.WebsitePHPConfigUpdate) (err return err } - if req.Scope == "params" { - content := string(contentBytes) - lines := strings.Split(content, "\n") - for i, line := range lines { - if strings.HasPrefix(line, ";") { - continue - } + content := string(contentBytes) + lines := strings.Split(content, "\n") + for i, line := range lines { + if strings.HasPrefix(line, ";") { + continue + } + switch req.Scope { + case "params": for key, value := range req.Params { pattern := "^" + regexp.QuoteMeta(key) + "\\s*=\\s*.*$" if matched, _ := regexp.MatchString(pattern, line); matched { lines[i] = key + " = " + value } } - } - updatedContent := strings.Join(lines, "\n") - if err := fileOp.WriteFile(phpConfigPath, strings.NewReader(updatedContent), 0755); err != nil { - return err + case "disable_functions": + pattern := "^" + regexp.QuoteMeta("disable_functions") + "\\s*=\\s*.*$" + if matched, _ := regexp.MatchString(pattern, line); matched { + lines[i] = "disable_functions" + " = " + strings.Join(req.DisableFunctions, ",") + break + } + case "upload_max_filesize": + pattern := "^" + regexp.QuoteMeta("post_max_size") + "\\s*=\\s*.*$" + if matched, _ := regexp.MatchString(pattern, line); matched { + lines[i] = "post_max_size" + " = " + req.UploadMaxSize + } + patternUpload := "^" + regexp.QuoteMeta("upload_max_filesize") + "\\s*=\\s*.*$" + if matched, _ := regexp.MatchString(patternUpload, line); matched { + lines[i] = "upload_max_filesize" + " = " + req.UploadMaxSize + } } } - - cfg, err := ini.Load(phpConfigPath) - if err != nil { - return err - } - phpConfig, err := cfg.GetSection("PHP") - if err != nil { + updatedContent := strings.Join(lines, "\n") + if err := fileOp.WriteFile(phpConfigPath, strings.NewReader(updatedContent), 0755); err != nil { return err } - if req.Scope == "disable_functions" { - disable := phpConfig.Key("disable_functions") - disable.SetValue(strings.Join(req.DisableFunctions, ",")) - if err = cfg.SaveTo(phpConfigPath); err != nil { - return err - } - } - if req.Scope == "upload_max_filesize" { - postMaxSize := phpConfig.Key("post_max_size") - postMaxSize.SetValue(req.UploadMaxSize) - uploadMaxFileSize := phpConfig.Key("upload_max_filesize") - uploadMaxFileSize.SetValue(req.UploadMaxSize) - if err = cfg.SaveTo(phpConfigPath); err != nil { - return err - } - } appInstallReq := request.AppInstalledOperate{ InstallId: appInstall.ID,