From d0db90f28277862e716e4099fb47e56f1786164d Mon Sep 17 00:00:00 2001 From: wangsongyan <1104237534@qq.com> Date: Tue, 11 Nov 2025 22:58:43 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E6=9B=B4?= =?UTF-8?q?=E6=8D=A2=E7=AB=AF=E5=8F=A3=E6=97=B6=E5=88=A4=E6=96=AD=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E9=9C=80=E8=A6=81=E4=BF=AE=E6=94=B9=E9=98=B2=E7=81=AB?= =?UTF-8?q?=E5=A2=99=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/allinssl.sh | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/script/allinssl.sh b/script/allinssl.sh index d194d77..cd47b09 100644 --- a/script/allinssl.sh +++ b/script/allinssl.sh @@ -155,6 +155,37 @@ function get_pack_manager(){ fi } +function should_set_firewall() { + if [ "${PM}" = "apt-get" ]; then + # 检查 ufw 是否已启用 + if command -v ufw &>/dev/null; then + ufw_status=$(ufw status | grep -i "Status: active") + if [ -n "$ufw_status" ]; then + return 0 + fi + else + return 1 + fi + else + # 检查 firewalld 是否已启用 + if systemctl is-active --quiet firewalld; then + return 0 + else + return 1 + fi + # 检查 iptables 服务是否已启用 + if [ -f "/etc/init.d/iptables" ]; then + iptables_status=$(service iptables status | grep 'not running') + if [ -z "${iptables_status}" ]; then + return 0 + fi + else + return 1 + fi + fi + return 1 +} + function set_firewall(){ sshPort=$(cat /etc/ssh/sshd_config | grep 'Port '|awk '{print $2}') if [ "${PM}" = "apt-get" ]; then @@ -233,8 +264,10 @@ elif [ "$1" == "7" ]; then # 放行新端口 get_pack_manager - echo "正在放行端口 ${panelPort}..." - set_firewall + if should_set_firewall; then + echo "正在放行端口 ${panelPort}..." + set_firewall + fi echo "✅ 端口修改并放行完成!" exit 0