fix: 修改端口转发校验规则 (#5711)

This commit is contained in:
ssongliu 2024-07-08 15:49:25 +08:00 committed by GitHub
parent 577dfadb9a
commit 8d1322af37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 5 deletions

View File

@ -306,6 +306,21 @@ func (u *FirewallService) OperateForwardRule(req dto.ForwardRuleOperate) error {
return err
}
rules, _ := client.ListForward()
for _, rule := range rules {
for _, reqRule := range req.Rules {
if reqRule.Operation == "remove" {
continue
}
if reqRule.TargetIP == "" {
reqRule.TargetIP = "127.0.0.1"
}
if reqRule.Port == rule.Port && reqRule.TargetPort == rule.TargetPort && reqRule.TargetIP == rule.TargetIP {
return constant.ErrRecordExist
}
}
}
sort.SliceStable(req.Rules, func(i, j int) bool {
n1, _ := strconv.Atoi(req.Rules[i].Num)
n2, _ := strconv.Atoi(req.Rules[j].Num)

View File

@ -58,7 +58,7 @@ import DrawerHeader from '@/components/drawer-header/index.vue';
import { MsgSuccess } from '@/utils/message';
import { Host } from '@/api/interface/host';
import { operateForwardRule } from '@/api/modules/host';
import { checkCidr, checkIpV4V6, checkPort, deepCopy } from '@/utils/util';
import { checkCidr, checkIp, checkPort, deepCopy } from '@/utils/util';
const loading = ref();
const oldRule = ref<Host.RuleForward>();
@ -89,14 +89,14 @@ const handleClose = () => {
const rules = reactive({
protocol: [Rules.requiredSelect],
port: [{ validator: checkPortRule, trigger: 'blur' }],
targetPort: [{ validator: checkPortRule, trigger: 'blur' }],
port: [{ validator: checkPortRule, trigger: 'blur', required: true }],
targetPort: [{ validator: checkPortRule, trigger: 'blur', required: true }],
targetIP: [{ validator: checkAddress, trigger: 'blur' }],
});
function checkPortRule(rule: any, value: string, callback: any) {
if (!value) {
return callback();
return callback(new Error(i18n.global.t('firewall.portFormatError')));
}
if (checkPort(value)) {
return callback(new Error(i18n.global.t('firewall.portFormatError')));
@ -114,7 +114,7 @@ function checkAddress(rule: any, value: string, callback: any) {
return callback(new Error(i18n.global.t('firewall.addressFormatError')));
}
} else {
if (checkIpV4V6(item)) {
if (checkIp(item)) {
return callback(new Error(i18n.global.t('firewall.addressFormatError')));
}
}