Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/app/service/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ 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"
Expand Down Expand Up @@ -189,6 +191,9 @@ func (u *DeviceService) UpdateHosts(req []dto.HostHelper) 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())
if err != nil {
if strings.Contains(err.Error(), "does not exist") {
return buserr.New(constant.ErrNotExistUser)
}
return errors.New(std)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion backend/app/service/fail2ban.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (u *Fail2BanService) LoadBaseInfo() (dto.Fail2BanBaseInfo, error) {
return baseInfo, err
}
baseInfo.IsEnable, baseInfo.IsActive, baseInfo.IsExist = client.Status()
if !baseInfo.IsExist {
if !baseInfo.IsActive {
baseInfo.Version = "-"
return baseInfo, nil
}
Expand Down
4 changes: 4 additions & 0 deletions backend/constant/errs.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,7 @@ var (
var (
ErrBashExecute = "ErrBashExecute"
)

var (
ErrNotExistUser = "ErrNotExistUser"
)
5 changes: 4 additions & 1 deletion backend/i18n/lang/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,7 @@ ErrUserFindErr: "Failed to find user {{ .name }} {{ .err }}"
ErrFirewall: "No firewalld or ufw service is detected. Please check and try again!"

#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!"
5 changes: 4 additions & 1 deletion backend/i18n/lang/zh-Hant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,7 @@ ErrUserFindErr: "用戶 {{ .name }} 查找失敗 {{ .err }}"
ErrFirewall: "當前未檢測到系統 firewalld 或 ufw 服務,請檢查後重試!"

#cronjob
ErrBashExecute: "腳本執行錯誤,請在任務輸出文本域中查看具體信息。"
ErrBashExecute: "腳本執行錯誤,請在任務輸出文本域中查看具體信息。"

#toolbox
ErrNotExistUser: "當前使用者不存在,請修改後重試!"
3 changes: 3 additions & 0 deletions backend/i18n/lang/zh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,6 @@ ErrFirewall: "当前未检测到系统 firewalld 或 ufw 服务,请检查后

#cronjob
ErrBashExecute: "脚本执行错误,请在任务输出文本域中查看具体信息。"

#toolbox
ErrNotExistUser: "当前用户不存在,请修改后重试!"
8 changes: 4 additions & 4 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1153,10 +1153,10 @@ const message = {
setting: {
all: 'All',
panel: 'Panel',
userChange: 'Change username',
userChangeHelper: 'Change the user name to log out. Do you want to continue?',
user: 'User Name',
passwd: 'Password',
user: 'Panel User',
userChange: 'Change Panel User',
userChangeHelper: 'Changing the panel user will log you out. Continue?',
passwd: 'Panel Password',
emailHelper: 'For password retrieval',
title: 'Panel Alias',
panelPort: 'Panel Port',
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,10 +1097,10 @@ const message = {
setting: {
all: '全部',
panel: '面板',
user: '用戶名稱',
userChange: '修改用戶名',
userChangeHelper: '修改用戶名將退出登陸,是否繼續?',
passwd: '用戶密碼',
user: '面板用户',
userChange: '修改面板用户',
userChangeHelper: '修改面板用户将退出登录,是否继续?',
passwd: '面板密码',
emailHelper: '用於密碼找回',
title: '面板別名',
panelPort: '面板端口',
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1098,10 +1098,10 @@ const message = {
setting: {
all: '全部',
panel: '面板',
user: '用户名称',
userChange: '修改用户名',
userChangeHelper: '修改用户名将退出登陆,是否继续?',
passwd: '用户密码',
user: '面板用户',
userChange: '修改面板用户',
userChangeHelper: '修改面板用户将退出登陆,是否继续?',
passwd: '面板密码',
emailHelper: '用于密码找回',
title: '面板别名',
panelPort: '面板端口',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/setting/panel/name/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<el-form ref="formRef" label-position="top" :model="form" @submit.prevent v-loading="loading">
<el-row type="flex" justify="center">
<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-form-item>
</el-col>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/setting/panel/username/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div>
<el-drawer v-model="drawerVisible" :destroy-on-close="true" :close-on-click-modal="false" size="30%">
<template #header>
<DrawerHeader :header="$t('commons.login.username')" :back="handleClose" />
<DrawerHeader :header="$t('setting.user')" :back="handleClose" />
</template>
<el-form
ref="formRef"
Expand All @@ -14,7 +14,7 @@
>
<el-row type="flex" justify="center">
<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-form-item>
</el-col>
Expand Down
23 changes: 15 additions & 8 deletions frontend/src/views/toolbox/fail2ban/max-retry/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
<template #header>
<DrawerHeader :header="$t('toolbox.fail2ban.maxRetry')" :back="handleClose" />
</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-col :span="22">
<el-form-item
:label="$t('toolbox.fail2ban.maxRetry')"
prop="maxRetry"
:rules="Rules.requiredInput"
>
<el-input clearable v-model.number="form.maxRetry">
<el-form-item :label="$t('toolbox.fail2ban.maxRetry')" prop="maxRetry">
<el-input type="number" clearable v-model.number="form.maxRetry">
<template #append>{{ $t('commons.units.time') }}</template>
</el-input>
</el-form-item>
Expand All @@ -35,7 +38,7 @@ import { reactive, ref } from 'vue';
import i18n from '@/lang';
import { MsgSuccess } from '@/utils/message';
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 { updateFail2ban } from '@/api/modules/toolbox';

Expand All @@ -51,6 +54,10 @@ const form = reactive({
maxRetry: 5,
});

const rules = reactive({
maxRetry: [Rules.number, checkNumberRange(1, 99)],
});

const formRef = ref<FormInstance>();

const acceptParams = (params: DialogProps): void => {
Expand Down
Loading