Merge pull request #430 from wa8n/1.1.1

【修复】更换端口时判断是否需要修改防火墙设置
This commit is contained in:
allinssl
2026-01-13 16:59:07 +08:00
committed by YANGJINZE
parent 904f6e7bf5
commit 4e49ca075a

View File

@@ -155,6 +155,37 @@ function get_pack_manager(){
fi 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(){ function set_firewall(){
sshPort=$(cat /etc/ssh/sshd_config | grep 'Port '|awk '{print $2}') sshPort=$(cat /etc/ssh/sshd_config | grep 'Port '|awk '{print $2}')
if [ "${PM}" = "apt-get" ]; then if [ "${PM}" = "apt-get" ]; then
@@ -233,8 +264,10 @@ elif [ "$1" == "7" ]; then
# 放行新端口 # 放行新端口
get_pack_manager get_pack_manager
echo "正在放行端口 ${panelPort}..." if should_set_firewall; then
set_firewall echo "正在放行端口 ${panelPort}..."
set_firewall
fi
echo "✅ 端口修改并放行完成!" echo "✅ 端口修改并放行完成!"
exit 0 exit 0