Skip to content

Commit ce3fa94

Browse files
authored
feat(iptables): range forward (#11188)
1 parent 7f9f4ae commit ce3fa94

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

agent/utils/firewall/client/iptables/forward.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
)
77

88
func AddForward(protocol, srcPort, dest, destPort, iface string, save bool) error {
9+
// iptabels destPort 范围端口规则为:%d-%d
10+
destPort = strings.ReplaceAll(destPort, ":", "-")
911
if dest != "" && dest != "127.0.0.1" && dest != "localhost" {
1012
iptablesArg := fmt.Sprintf("-A %s", Chain1PanelPreRouting)
1113
if iface != "" {

frontend/src/lang/modules/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,6 +2915,7 @@ const message = {
29152915
targetPort: 'Destination port',
29162916
forwardHelper1: 'If you want to forward to the local port, the destination IP should be set to "127.0.0.1".',
29172917
forwardHelper2: 'Leave the destination IP blank to forward to the local port.',
2918+
forwardPortHelper: 'Support port range, e.g. 80:90',
29182919
forwardInboundInterface: 'Forward Inbound Network Interface',
29192920
exportHelper: 'About to export {0} firewall rules. Continue?',
29202921
importSuccess: 'Successfully imported {0} rules',

frontend/src/lang/modules/zh.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,6 +2703,7 @@ const message = {
27032703
targetPort: '目标端口',
27042704
forwardHelper1: '如果是本机端口转发,目标IP为:127.0.0.1',
27052705
forwardHelper2: '如果目标IP不填写,则默认为本机端口转发',
2706+
forwardPortHelper: '支持端口范围,如:80:90',
27062707
forwardInboundInterface: '转发入站网卡',
27072708
exportHelper: '即将导出 {0} 条防火墙规则,是否继续?',
27082709
importSuccess: '成功导入 {0} 条规则',

frontend/src/views/host/firewall/forward/operate/index.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<el-form-item :label="$t('firewall.sourcePort')" prop="port">
1616
<el-input clearable v-model.trim="dialogData.rowData!.port" />
17+
<span class="input-help">{{ $t('firewall.forwardPortHelper') }}</span>
1718
</el-form-item>
1819

1920
<el-form-item :label="$t('firewall.targetIP')" prop="targetIP">
@@ -24,6 +25,7 @@
2425

2526
<el-form-item :label="$t('firewall.targetPort')" prop="targetPort">
2627
<el-input clearable v-model.trim="dialogData.rowData!.targetPort" />
28+
<span class="input-help">{{ $t('firewall.forwardPortHelper') }}</span>
2729
</el-form-item>
2830

2931
<el-form-item :label="$t('firewall.forwardInboundInterface')" prop="interface">
@@ -103,8 +105,21 @@ function checkPortRule(rule: any, value: string, callback: any) {
103105
if (!value) {
104106
return callback(new Error(i18n.global.t('firewall.portFormatError')));
105107
}
106-
if (checkPort(value)) {
107-
return callback(new Error(i18n.global.t('firewall.portFormatError')));
108+
if (value.indexOf(':') !== -1) {
109+
const ports = value.split(':');
110+
if (ports.length !== 2) {
111+
return callback(new Error(i18n.global.t('firewall.portFormatError')));
112+
}
113+
if (checkPort(ports[0]) || checkPort(ports[1])) {
114+
return callback(new Error(i18n.global.t('firewall.portFormatError')));
115+
}
116+
if (Number(ports[0]) > Number(ports[1])) {
117+
return callback(new Error(i18n.global.t('firewall.portFormatError')));
118+
}
119+
} else {
120+
if (checkPort(value)) {
121+
return callback(new Error(i18n.global.t('firewall.portFormatError')));
122+
}
108123
}
109124
callback();
110125
}

0 commit comments

Comments
 (0)