From d2ccea3520794130d4ce6c35c517ff9478353831 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 26 Sep 2023 20:10:50 +0800 Subject: [PATCH] Update firewall_api.py --- class/core/firewall_api.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/class/core/firewall_api.py b/class/core/firewall_api.py index 6eb436a90..5168dad84 100755 --- a/class/core/firewall_api.py +++ b/class/core/firewall_api.py @@ -430,8 +430,17 @@ class firewall_api: cmd = 'firewall-cmd --permanent --zone=public --add-port=' + port + '/udp' mw.execShell(cmd) elif self.__isIptables: - cmd = 'iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ' + port + ' -j ACCEPT' - mw.execShell(cmd) + if protocol == 'tcp': + cmd = 'iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ' + port + ' -j ACCEPT' + mw.execShell(cmd) + if protocol == 'udp': + cmd = 'iptables -I INPUT -p udp -m state --state NEW -m udp --dport ' + port + ' -j ACCEPT' + mw.execShell(cmd) + if protocol == 'tcp/udp': + cmd = 'iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ' + port + ' -j ACCEPT' + mw.execShell(cmd) + cmd = 'iptables -I INPUT -p udp -m state --state NEW -m udp --dport ' + port + ' -j ACCEPT' + mw.execShell(cmd) else: pass return True