修改IP、子网掩码的校验逻辑

This commit is contained in:
fangxiang 2023-02-10 16:29:27 +08:00
parent 225fbd4faf
commit 2930add85f
11 changed files with 594 additions and 571 deletions

View File

@ -0,0 +1,59 @@
export default class ValidationUtil {
static isIpAddress(str: string): boolean {
return (
str == "localhost" ||
/^([1-9]|[1-9][0-9]|1\d\d|2[0-2][0-3])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])\.([1-9]|[1-9][0-9]|1\d\d|2[0-4]\d|25[0-4])$/.test(
str
)
);
}
static isHost(str: string): boolean {
return (
str == "localhost" ||
/^([1-9]|[1-9][0-9]|1\d\d|2[0-2][0-3])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])\.([1-9]|[1-9][0-9]|1\d\d|2[0-4]\d|25[0-4])$/.test(
str
) ||
/^([1-9]|[1-9][0-9]|1\d\d|2[0-2][0-3])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])\.([1-9]|[1-9][0-9]|1\d\d|2[0-4]\d|25[0-4])\:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/.test(
str
)
);
}
static isMacAddress(str: string): boolean {
return /([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}/.test(str);
}
static isMaskAddress(str: string): boolean {
return /^(254|252|248|240|224|192|128|0)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(254|252|248|240|224|192|128|0)$/.test(
str
);
}
static isHexStr(str: string): boolean {
if (str != null && str != undefined && typeof str == "string") {
str = str.trim();
if (str.length == 0) {
return true;
}
for (const item of str.split(" ")) {
if (item.length > 4) {
return false;
}
if (!/^0[xX][A-Fa-f0-9]{1,2}/.test(item)) {
return false;
}
}
return true;
}
return false;
}
static isResolution(str: string): boolean {
return /([0-9]{1,5})[x|X]([0-9]{1,5}@[0-9]{1,3}$)/.test(str);
}
static isEnglishOrNum(str: string): boolean {
return /^[0-9a-zA-Z_\-]+$/.test(str);
}
}

View File

@ -88,7 +88,8 @@
(val) =>
(val && val.length > 0) || $t('Please type something'),
(val) =>
isIpAddress(val) || $t('Please input vaild ip address'),
isMaskAddress(val) ||
$t('Please input vaild netmask address'),
]"
lazy-rules
/>
@ -162,12 +163,12 @@
</style>
<script lang="ts">
import { defineComponent, ref, Ref, reactive } from "vue";
import { defineComponent, ref } from "vue";
import { useStore } from "src/store";
import { useQuasar, copyToClipboard, uid } from "quasar";
import { useQuasar } from "quasar";
import { useI18n } from "vue-i18n";
import GlobalData from "src/common/GlobalData";
import { AdvancedIpAddressEntity } from "src/entities/AdvancedIpAddressEntity";
import ValidationUtil from "src/common/ValidationUtil";
export default defineComponent({
name: "ComponentSystenSettingAdvancedNetworkDialog",
@ -267,12 +268,10 @@ export default defineComponent({
} catch {}
},
isIpAddress(str: string) {
return (
str == "localhost" ||
/^(\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])$/.test(
str
)
);
return ValidationUtil.isIpAddress(str);
},
isMaskAddress(str: string) {
return ValidationUtil.isMaskAddress(str);
},
checkFilterListIp(str: string) {
if (Array.isArray(ip_filter_list)) {

View File

@ -139,6 +139,7 @@ import { useQuasar, copyToClipboard } from "quasar";
import { useI18n } from "vue-i18n";
import { ExternalControlTableEntity } from "src/entities/ExternalControlTableEntity";
import ValidationUtil from "src/common/ValidationUtil";
export default defineComponent({
name: "ComponentCenterControlButtonDialog",
@ -246,22 +247,7 @@ export default defineComponent({
show_dialog.value = false;
},
isHexStr(val: string) {
if (val != null && val != undefined && typeof val == "string") {
val = val.trim();
if (val.length == 0) {
return true;
}
for (const item of val.split(" ")) {
if (item.length > 4) {
return false;
}
if (!/^0[xX][A-Fa-f0-9]{1,2}/.test(item)) {
return false;
}
}
return true;
}
return false;
return ValidationUtil.isHexStr(val);
},
};
},

View File

@ -406,6 +406,7 @@ import {
SerialPortConfigEntity,
} from "src/entities/SerialPortConfigEntity";
import { Protocol } from "src/entities/WSProtocol";
import ValidationUtil from "src/common/ValidationUtil";
export default defineComponent({
name: "ComponentCenterControlDialog",
@ -733,12 +734,7 @@ export default defineComponent({
}
},
isIpAddress(str: string) {
return (
str == "localhost" ||
/^(\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])$/.test(
str
)
);
return ValidationUtil.isIpAddress(str);
},
};
},

View File

@ -152,6 +152,7 @@ import { api } from "boot/axios";
import { HttpProtocol } from "src/entities/HttpProtocol";
import JointActionEquipmentTableEntity from "src/entities/JointActionEquipmentTableEntity";
import EventBus, { EventNamesDefine } from "src/common/EventBus";
import ValidationUtil from "src/common/ValidationUtil";
export default defineComponent({
name: "ComponentEditJointActionEquipmentDialog",
@ -330,15 +331,7 @@ export default defineComponent({
}
},
isHost(str: string) {
return (
str == "localhost" ||
/^(\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])$/.test(
str
) ||
/^(\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])\:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/.test(
str
)
);
return ValidationUtil.isHost(str);
},
};
},

View File

@ -190,8 +190,8 @@
(val && val.length > 0) ||
$t('Please type something'),
(val) =>
isIpAddress(val) ||
$t('Please input vaild ip address'),
isMaskAddress(val) ||
$t('Please input vaild netmask address'),
]"
lazy-rules
/>
@ -1454,7 +1454,7 @@ import TimingTaskDialog from "src/components/TimingTaskDialog.vue";
import { useI18n } from "vue-i18n";
import GlobalData from "src/common/GlobalData";
import { HttpProtocol } from "src/entities/HttpProtocol";
import ValidationUtil from "src/common/ValidationUtil";
import { date } from "quasar";
import { Protocol } from "src/entities/WSProtocol";
import TimingTaskEntity, {
@ -2512,20 +2512,17 @@ export default defineComponent({
}
},
isIpAddress(str: string) {
return (
str == "localhost" ||
/^(\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])$/.test(
str
)
);
return ValidationUtil.isIpAddress(str);
},
isMacAddress(str: string) {
return /([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}/.test(str);
return ValidationUtil.isMacAddress(str);
},
isMaskAddress(str: string) {
return ValidationUtil.isMaskAddress(str);
},
checkResolution(str: string) {
const reg = /([0-9]{1,5})[x|X]([0-9]{1,5}@[0-9]{1,3}$)/;
return (
reg.test(str) ||
ValidationUtil.isResolution(str) ||
$t.t("the resolution format is incorrect,") +
$t.t("for example: ") +
"1920x1080@60"

View File

@ -294,6 +294,7 @@ import AdvancedIpAddressDialog from "src/components/AdvancedIpAddressDialog.vue"
import { AdvancedIpAddressEntity } from "src/entities/AdvancedIpAddressEntity";
import { api } from "src/boot/axios";
import { HttpProtocol } from "src/entities/HttpProtocol";
import ValidationUtil from "src/common/ValidationUtil";
export default defineComponent({
name: "ComponentSystenSettingAdvancedNetworkDialog",
@ -353,15 +354,6 @@ export default defineComponent({
const advance_ip_rows: Ref<AdvancedIpAddressEntity[]> = ref([]);
const isIpAddress = (str: string) => {
return (
str == "localhost" ||
/^(\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])$/.test(
str
)
);
};
let _resolove: any = null;
return {
@ -629,7 +621,7 @@ export default defineComponent({
});
},
isEnglishOrNum(str: string) {
return /^[0-9a-zA-Z_\-]+$/.test(str);
return ValidationUtil.isEnglishOrNum(str);
},
};
},

View File

@ -437,11 +437,11 @@ export default {
"set magic wall": "Set Magic wall",
"update magic wall": "Update Magic Wall",
"magic wall": "Magic Wall",
"angle":"Angle",
angle: "Angle",
"topology diagram": "Topology Diagram",
"physical central location": "Central Location",
"monitors list": "Monitors List",
"resize":"Resize",
resize: "Resize",
"export magic": "Export",
"raster graph":"Raster Graph"
"raster graph": "Raster Graph",
};

View File

@ -123,6 +123,7 @@ export default {
"local disk": "本地磁盘",
usb: "U盘",
"Please input vaild ip address": "请输入合法的IP地址",
"Please input vaild netmask address": "请输入合法的掩码地址",
"Please input vaild mac address": "请输入合法的MAC地址",
"server ip address": "服务器地址",
"please input server ip address": "请输入服务器地址",
@ -704,11 +705,11 @@ export default {
"set magic wall": "设置魔墙",
"update magic wall": "更新魔墙",
"magic wall": "魔墙",
"angle":"角度",
angle: "角度",
"topology diagram": "拓扑图",
"physical central location": "物理中心位置",
"monitors list": "显示器",
"resize":"缩放",
resize: "缩放",
"export magic": "导出",
"raster graph":"栅格图"
"raster graph": "栅格图",
};

View File

@ -68,11 +68,7 @@
(val && val.length > 0) ||
$t('Please type something'),
(val) =>
val == 'localhost' ||
/^(\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])$/.test(
val
) ||
$t('Please input vaild ip address'),
isHost(val) || $t('Please input vaild ip address'),
]"
@keydown="
(evt) => {
@ -363,6 +359,7 @@ import Initializer from "src/common/Initializer";
import { api } from "src/boot/axios";
import { HttpProtocol } from "src/entities/HttpProtocol";
import { Plugins as CapacitorPlugins } from "@capacitor/core";
import ValidationUtil from "src/common/ValidationUtil";
class _Data {
user_name: string | null = null;
@ -699,6 +696,9 @@ export default defineComponent({
}
}
},
isHost(str: string) {
return ValidationUtil.isHost(str);
},
};
},
});

View File

@ -37,11 +37,7 @@
(val && val.length > 0) ||
$t('Please type something'),
(val) =>
val == 'localhost' ||
/^(\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])$/.test(
val
) ||
$t('Please input vaild ip address'),
isHost(val) || $t('Please input vaild ip address'),
]"
@keydown="
(evt) => {
@ -211,6 +207,7 @@ import { Md5 } from "ts-md5";
import Initializer from "src/common/Initializer";
import { api } from "src/boot/axios";
import { HttpProtocol } from "src/entities/HttpProtocol";
import ValidationUtil from "src/common/ValidationUtil";
class _Data {
user_name: string | null = null;
@ -476,6 +473,9 @@ export default defineComponent({
data.password = null;
remember_password.value = false;
},
isHost(str: string) {
return ValidationUtil.isHost(str);
},
};
},
});