1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 16:29:17 +08:00

fix: 端口修改增加存在校验

This commit is contained in:
ssongliu 2023-03-07 18:20:52 +08:00 committed by ssongliu
parent fc206deddf
commit d7ab5ff1b7
4 changed files with 35 additions and 5 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/1Panel-dev/1Panel/backend/app/dto/request" "github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/response" "github.com/1Panel-dev/1Panel/backend/app/dto/response"
"github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/1Panel-dev/1Panel/backend/app/repo" "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 { 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)) return updateInstallInfoInDB(req.Key, "", "port", true, strconv.FormatInt(req.Port, 10))
} }

View File

@ -528,7 +528,7 @@ func updateMyCnf(oldFiles []string, group string, param string, value interface{
newFiles = append(newFiles, line) newFiles = append(newFiles, line)
continue 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)) newFiles = append(newFiles, fmt.Sprintf("%s=%v", param, value))
hasKey = true hasKey = true
continue continue

View File

@ -6,9 +6,11 @@ import (
"time" "time"
"github.com/1Panel-dev/1Panel/backend/app/dto" "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/constant"
"github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/cmd" "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/1Panel-dev/1Panel/backend/utils/encrypt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -62,6 +64,10 @@ func (u *SettingService) Update(key, value string) error {
} }
func (u *SettingService) UpdatePort(port uint) 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 { if err := settingRepo.Update("ServerPort", strconv.Itoa(int(port))); err != nil {
return err return err
} }

View File

@ -2,7 +2,7 @@
<div v-show="onSetting" v-loading="loading"> <div v-show="onSetting" v-loading="loading">
<LayoutContent :title="'MySQL ' + $t('database.setting')" :reload="true"> <LayoutContent :title="'MySQL ' + $t('database.setting')" :reload="true">
<template #buttons> <template #buttons>
<el-button type="primary" :plain="activeName !== 'conf'" @click="activeName = 'conf'"> <el-button type="primary" :plain="activeName !== 'conf'" @click="jumpToConf">
{{ $t('database.confChange') }} {{ $t('database.confChange') }}
</el-button> </el-button>
<el-button <el-button
@ -35,7 +35,7 @@
<el-button <el-button
type="primary" type="primary"
:disabled="mysqlStatus !== 'Running'" :disabled="mysqlStatus !== 'Running'"
@click="activeName = 'slowLog'" @click="jumpToSlowlog"
:plain="activeName !== 'slowLog'" :plain="activeName !== 'slowLog'"
> >
{{ $t('database.slowLog') }} {{ $t('database.slowLog') }}
@ -94,7 +94,12 @@
</el-form> </el-form>
</div> </div>
<ContainerLog v-show="activeName === 'log'" ref="dialogContainerLogRef" /> <ContainerLog v-show="activeName === 'log'" ref="dialogContainerLogRef" />
<SlowLog @loading="changeLoading" v-show="activeName === 'slowLog'" ref="slowLogRef" /> <SlowLog
@loading="changeLoading"
@refresh="loadBaseInfo"
v-show="activeName === 'slowLog'"
ref="slowLogRef"
/>
</template> </template>
</LayoutContent> </LayoutContent>
@ -125,6 +130,7 @@ import { MsgSuccess } from '@/utils/message';
const loading = ref(false); const loading = ref(false);
const baseDir = ref();
const extensions = [javascript(), oneDark]; const extensions = [javascript(), oneDark];
const activeName = ref('conf'); const activeName = ref('conf');
@ -172,6 +178,17 @@ const onClose = (): void => {
onSetting.value = false; onSetting.value = false;
}; };
const jumpToConf = async () => {
activeName.value = 'conf';
const pathRes = await loadBaseDir();
loadMysqlConf(`${pathRes.data}/apps/mysql/${mysqlName.value}/conf/my.cnf`);
};
const jumpToSlowlog = async () => {
activeName.value = 'slowLog';
loadSlowLogs();
};
const onSubmitChangePort = async () => { const onSubmitChangePort = async () => {
let params = { let params = {
key: 'mysql', key: 'mysql',
@ -255,6 +272,7 @@ const loadBaseInfo = async () => {
baseInfo.port = res.data?.port; baseInfo.port = res.data?.port;
baseInfo.containerID = res.data?.containerName; baseInfo.containerID = res.data?.containerName;
const pathRes = await loadBaseDir(); const pathRes = await loadBaseDir();
baseDir.value = pathRes.data;
loadMysqlConf(`${pathRes.data}/apps/mysql/${mysqlName.value}/conf/my.cnf`); loadMysqlConf(`${pathRes.data}/apps/mysql/${mysqlName.value}/conf/my.cnf`);
loadContainerLog(baseInfo.containerID); loadContainerLog(baseInfo.containerID);
}; };
@ -274,7 +292,9 @@ const loadVariables = async () => {
}; };
const loadSlowLogs = async () => { const loadSlowLogs = async () => {
await Promise.all([loadBaseInfo(), loadVariables()]); const res = await loadMysqlVariables();
variables.value = res.data;
let param = { let param = {
mysqlName: mysqlName.value, mysqlName: mysqlName.value,
variables: variables.value, variables: variables.value,