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

fix: 增加 ip 或 域名正则校验

This commit is contained in:
ssongliu 2023-03-17 10:54:16 +08:00 committed by f2c-ci-robot[bot]
parent be5a7c99e1
commit 1111b6b494
6 changed files with 26 additions and 3 deletions

View File

@ -15,6 +15,21 @@ const checkIp = (rule: any, value: any, callback: any) => {
}
};
const checkHost = (rule: any, value: any, callback: any) => {
if (value === '' || typeof value === 'undefined' || value == null) {
callback(new Error(i18n.global.t('commons.rule.requiredInput')));
} else {
const regIP =
/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
const regHost = /^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/;
if (!regIP.test(value) && !regHost.test(value)) {
callback(new Error(i18n.global.t('commons.rule.host')));
} else {
callback();
}
}
};
const complexityPassword = (rule: any, value: any, callback: any) => {
if (value === '' || typeof value === 'undefined' || value == null) {
callback(new Error(i18n.global.t('commons.rule.complexityPassword')));
@ -265,6 +280,7 @@ interface CommonRule {
number: FormItemRule;
integerNumber: FormItemRule;
ip: FormItemRule;
host: FormItemRule;
port: FormItemRule;
domain: FormItemRule;
databaseName: FormItemRule;
@ -363,6 +379,11 @@ export const Rules: CommonRule = {
required: true,
trigger: 'blur',
},
host: {
validator: checkHost,
required: true,
trigger: 'blur',
},
port: {
required: true,
trigger: 'blur',

View File

@ -140,6 +140,7 @@ export default {
number: 'Please enter the correct number',
integer: 'Please enter the correct positive integer',
ip: 'Please enter the correct IP address',
host: 'Enter the correct IP address or domain name',
port: 'Please enter the correct port',
selectHelper: 'Please select the correct {0} file',
domain: 'domain name format error',

View File

@ -144,6 +144,7 @@ export default {
number: '请输入正确的数字',
integer: '请输入正确的正整数',
ip: '请输入正确的 IP 地址',
host: '请输入正确的 IP 或者域名',
port: '请输入正确的端口,1-65535',
selectHelper: '请选择正确的 {0} 文件',
domain: '域名格式错误',

View File

@ -109,7 +109,7 @@ type FormInstance = InstanceType<typeof ElForm>;
const hostInfoRef = ref<FormInstance>();
const rules = reactive({
groupID: [Rules.requiredSelect],
addr: [Rules.requiredInput],
addr: [Rules.host],
port: [Rules.requiredInput, Rules.port],
user: [Rules.requiredInput],
authMode: [Rules.requiredSelect],

View File

@ -95,7 +95,7 @@ let hostInfo = reactive<Host.HostOperate>({
});
const rules = reactive({
addr: [Rules.ip],
addr: [Rules.host],
port: [Rules.requiredInput, Rules.port],
user: [Rules.requiredInput],
authMode: [Rules.requiredSelect],

View File

@ -93,7 +93,7 @@
<span v-if="errBuckets" class="input-error">{{ $t('commons.rule.requiredSelect') }}</span>
</el-form-item>
<div v-if="dialogData.rowData!.type === 'SFTP'">
<el-form-item :label="$t('setting.address')" prop="varsJson.address" :rules="Rules.ip">
<el-form-item :label="$t('setting.address')" prop="varsJson.address" :rules="Rules.host">
<el-input v-model.trim="dialogData.rowData!.varsJson['address']" />
</el-form-item>
<el-form-item :label="$t('setting.port')" prop="varsJson.port" :rules="[Rules.port]">