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

fix: 增加部分表单校验 (#3181)

Refs #3174
This commit is contained in:
ssongliu 2023-12-05 10:46:10 +08:00 committed by GitHub
parent 30c577dbaf
commit 14142be38f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 51 additions and 26 deletions

View File

@ -12,6 +12,8 @@ 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/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/common"
@ -189,6 +191,9 @@ func (u *DeviceService) UpdateHosts(req []dto.HostHelper) error {
func (u *DeviceService) UpdatePasswd(req dto.ChangePasswd) error { func (u *DeviceService) UpdatePasswd(req dto.ChangePasswd) error {
std, err := cmd.Execf("%s echo '%s:%s' | %s chpasswd", cmd.SudoHandleCmd(), req.User, req.Passwd, cmd.SudoHandleCmd()) std, err := cmd.Execf("%s echo '%s:%s' | %s chpasswd", cmd.SudoHandleCmd(), req.User, req.Passwd, cmd.SudoHandleCmd())
if err != nil { if err != nil {
if strings.Contains(err.Error(), "does not exist") {
return buserr.New(constant.ErrNotExistUser)
}
return errors.New(std) return errors.New(std)
} }
return nil return nil

View File

@ -35,7 +35,7 @@ func (u *Fail2BanService) LoadBaseInfo() (dto.Fail2BanBaseInfo, error) {
return baseInfo, err return baseInfo, err
} }
baseInfo.IsEnable, baseInfo.IsActive, baseInfo.IsExist = client.Status() baseInfo.IsEnable, baseInfo.IsActive, baseInfo.IsExist = client.Status()
if !baseInfo.IsExist { if !baseInfo.IsActive {
baseInfo.Version = "-" baseInfo.Version = "-"
return baseInfo, nil return baseInfo, nil
} }

View File

@ -144,3 +144,7 @@ var (
var ( var (
ErrBashExecute = "ErrBashExecute" ErrBashExecute = "ErrBashExecute"
) )
var (
ErrNotExistUser = "ErrNotExistUser"
)

View File

@ -155,4 +155,7 @@ ErrUserFindErr: "Failed to find user {{ .name }} {{ .err }}"
ErrFirewall: "No firewalld or ufw service is detected. Please check and try again!" ErrFirewall: "No firewalld or ufw service is detected. Please check and try again!"
#cronjob #cronjob
ErrBashExecute: "Script execution error, please check the specific information in the task output text area." ErrBashExecute: "Script execution error, please check the specific information in the task output text area."
#toolbox
ErrNotExistUser: "The current user does not exist. Please modify and retry!"

View File

@ -156,4 +156,7 @@ ErrUserFindErr: "用戶 {{ .name }} 查找失敗 {{ .err }}"
ErrFirewall: "當前未檢測到系統 firewalld 或 ufw 服務,請檢查後重試!" ErrFirewall: "當前未檢測到系統 firewalld 或 ufw 服務,請檢查後重試!"
#cronjob #cronjob
ErrBashExecute: "腳本執行錯誤,請在任務輸出文本域中查看具體信息。" ErrBashExecute: "腳本執行錯誤,請在任務輸出文本域中查看具體信息。"
#toolbox
ErrNotExistUser: "當前使用者不存在,請修改後重試!"

View File

@ -156,3 +156,6 @@ ErrFirewall: "当前未检测到系统 firewalld 或 ufw 服务,请检查后
#cronjob #cronjob
ErrBashExecute: "脚本执行错误,请在任务输出文本域中查看具体信息。" ErrBashExecute: "脚本执行错误,请在任务输出文本域中查看具体信息。"
#toolbox
ErrNotExistUser: "当前用户不存在,请修改后重试!"

View File

@ -1153,10 +1153,10 @@ const message = {
setting: { setting: {
all: 'All', all: 'All',
panel: 'Panel', panel: 'Panel',
userChange: 'Change username', user: 'Panel User',
userChangeHelper: 'Change the user name to log out. Do you want to continue?', userChange: 'Change Panel User',
user: 'User Name', userChangeHelper: 'Changing the panel user will log you out. Continue?',
passwd: 'Password', passwd: 'Panel Password',
emailHelper: 'For password retrieval', emailHelper: 'For password retrieval',
title: 'Panel Alias', title: 'Panel Alias',
panelPort: 'Panel Port', panelPort: 'Panel Port',

View File

@ -1097,10 +1097,10 @@ const message = {
setting: { setting: {
all: '全部', all: '全部',
panel: '面板', panel: '面板',
user: '用戶名稱', user: '面板用户',
userChange: '修改用戶名', userChange: '修改面板用户',
userChangeHelper: '修改用戶名將退出登陸是否繼續', userChangeHelper: '修改面板用户将退出登录是否继续',
passwd: '用戶密碼', passwd: '面板密码',
emailHelper: '用於密碼找回', emailHelper: '用於密碼找回',
title: '面板別名', title: '面板別名',
panelPort: '面板端口', panelPort: '面板端口',

View File

@ -1098,10 +1098,10 @@ const message = {
setting: { setting: {
all: '全部', all: '全部',
panel: '面板', panel: '面板',
user: '用户名称', user: '面板用户',
userChange: '修改用户', userChange: '修改面板用户',
userChangeHelper: '修改用户将退出登陆是否继续', userChangeHelper: '修改面板用户将退出登陆是否继续',
passwd: '用户密码', passwd: '面板密码',
emailHelper: '用于密码找回', emailHelper: '用于密码找回',
title: '面板别名', title: '面板别名',
panelPort: '面板端口', panelPort: '面板端口',

View File

@ -7,7 +7,7 @@
<el-form ref="formRef" label-position="top" :model="form" @submit.prevent v-loading="loading"> <el-form ref="formRef" label-position="top" :model="form" @submit.prevent v-loading="loading">
<el-row type="flex" justify="center"> <el-row type="flex" justify="center">
<el-col :span="22"> <el-col :span="22">
<el-form-item :label="$t('setting.title')" prop="panelName" :rules="Rules.requiredInput"> <el-form-item :label="$t('setting.title')" prop="panelName" :rules="Rules.simpleName">
<el-input clearable v-model="form.panelName" /> <el-input clearable v-model="form.panelName" />
</el-form-item> </el-form-item>
</el-col> </el-col>

View File

@ -2,7 +2,7 @@
<div> <div>
<el-drawer v-model="drawerVisible" :destroy-on-close="true" :close-on-click-modal="false" size="30%"> <el-drawer v-model="drawerVisible" :destroy-on-close="true" :close-on-click-modal="false" size="30%">
<template #header> <template #header>
<DrawerHeader :header="$t('commons.login.username')" :back="handleClose" /> <DrawerHeader :header="$t('setting.user')" :back="handleClose" />
</template> </template>
<el-form <el-form
ref="formRef" ref="formRef"
@ -14,7 +14,7 @@
> >
<el-row type="flex" justify="center"> <el-row type="flex" justify="center">
<el-col :span="22"> <el-col :span="22">
<el-form-item :label="$t('commons.login.username')" prop="userName"> <el-form-item :label="$t('setting.user')" prop="userName">
<el-input clearable v-model.trim="form.userName" /> <el-input clearable v-model.trim="form.userName" />
</el-form-item> </el-form-item>
</el-col> </el-col>

View File

@ -4,15 +4,18 @@
<template #header> <template #header>
<DrawerHeader :header="$t('toolbox.fail2ban.maxRetry')" :back="handleClose" /> <DrawerHeader :header="$t('toolbox.fail2ban.maxRetry')" :back="handleClose" />
</template> </template>
<el-form ref="formRef" label-position="top" :model="form" @submit.prevent v-loading="loading"> <el-form
ref="formRef"
label-position="top"
:rules="rules"
:model="form"
@submit.prevent
v-loading="loading"
>
<el-row type="flex" justify="center"> <el-row type="flex" justify="center">
<el-col :span="22"> <el-col :span="22">
<el-form-item <el-form-item :label="$t('toolbox.fail2ban.maxRetry')" prop="maxRetry">
:label="$t('toolbox.fail2ban.maxRetry')" <el-input type="number" clearable v-model.number="form.maxRetry">
prop="maxRetry"
:rules="Rules.requiredInput"
>
<el-input clearable v-model.number="form.maxRetry">
<template #append>{{ $t('commons.units.time') }}</template> <template #append>{{ $t('commons.units.time') }}</template>
</el-input> </el-input>
</el-form-item> </el-form-item>
@ -35,7 +38,7 @@ import { reactive, ref } from 'vue';
import i18n from '@/lang'; import i18n from '@/lang';
import { MsgSuccess } from '@/utils/message'; import { MsgSuccess } from '@/utils/message';
import { FormInstance } from 'element-plus'; import { FormInstance } from 'element-plus';
import { Rules } from '@/global/form-rules'; import { Rules, checkNumberRange } from '@/global/form-rules';
import DrawerHeader from '@/components/drawer-header/index.vue'; import DrawerHeader from '@/components/drawer-header/index.vue';
import { updateFail2ban } from '@/api/modules/toolbox'; import { updateFail2ban } from '@/api/modules/toolbox';
@ -51,6 +54,10 @@ const form = reactive({
maxRetry: 5, maxRetry: 5,
}); });
const rules = reactive({
maxRetry: [Rules.number, checkNumberRange(1, 99)],
});
const formRef = ref<FormInstance>(); const formRef = ref<FormInstance>();
const acceptParams = (params: DialogProps): void => { const acceptParams = (params: DialogProps): void => {