diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index 63baf8065..ccd6c0f1c 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -12,6 +12,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/app/dto/request" "github.com/1Panel-dev/1Panel/backend/app/dto/response" + "github.com/1Panel-dev/1Panel/backend/buserr" "github.com/1Panel-dev/1Panel/backend/app/repo" @@ -269,6 +270,9 @@ func (a AppInstallService) GetUpdateVersions(installId uint) ([]dto.AppVersion, } func (a AppInstallService) ChangeAppPort(req request.PortUpdate) error { + if common.ScanPort(int(req.Port)) { + return buserr.WithDetail(constant.ErrPortInUsed, req.Port, nil) + } return updateInstallInfoInDB(req.Key, "", "port", true, strconv.FormatInt(req.Port, 10)) } diff --git a/backend/app/service/database_mysql.go b/backend/app/service/database_mysql.go index 99154a2ff..4bbbc8024 100644 --- a/backend/app/service/database_mysql.go +++ b/backend/app/service/database_mysql.go @@ -528,7 +528,7 @@ func updateMyCnf(oldFiles []string, group string, param string, value interface{ newFiles = append(newFiles, line) continue } - if strings.HasPrefix(line, param) || strings.HasPrefix(line, "# "+param) { + if strings.HasPrefix(line, param+"=") || strings.HasPrefix(line, "# "+param+"=") { newFiles = append(newFiles, fmt.Sprintf("%s=%v", param, value)) hasKey = true continue diff --git a/backend/app/service/setting.go b/backend/app/service/setting.go index bbb97c641..332960c7b 100644 --- a/backend/app/service/setting.go +++ b/backend/app/service/setting.go @@ -6,9 +6,11 @@ import ( "time" "github.com/1Panel-dev/1Panel/backend/app/dto" + "github.com/1Panel-dev/1Panel/backend/buserr" "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/cmd" + "github.com/1Panel-dev/1Panel/backend/utils/common" "github.com/1Panel-dev/1Panel/backend/utils/encrypt" "github.com/gin-gonic/gin" ) @@ -62,6 +64,10 @@ func (u *SettingService) Update(key, value string) error { } func (u *SettingService) UpdatePort(port uint) error { + if common.ScanPort(int(port)) { + return buserr.WithDetail(constant.ErrPortInUsed, port, nil) + } + if err := settingRepo.Update("ServerPort", strconv.Itoa(int(port))); err != nil { return err } diff --git a/frontend/src/views/database/mysql/setting/index.vue b/frontend/src/views/database/mysql/setting/index.vue index e170f2434..50c76c563 100644 --- a/frontend/src/views/database/mysql/setting/index.vue +++ b/frontend/src/views/database/mysql/setting/index.vue @@ -2,7 +2,7 @@