Update x-ui.sh with ufw port settings

It really costs time when adding rules for a large range, if for loop is used in bash. Changed it to built-in port range support in ufw.
This commit is contained in:
Gzngskxgr20 2024-04-21 00:09:05 +08:00 committed by GitHub
parent a3a2d7a6a3
commit fb877ab84a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

14
x-ui.sh
View file

@ -620,9 +620,10 @@ open_ports() {
start_port=$(echo $port | cut -d'-' -f1) start_port=$(echo $port | cut -d'-' -f1)
end_port=$(echo $port | cut -d'-' -f2) end_port=$(echo $port | cut -d'-' -f2)
# Loop through the range and open each port # Loop through the range and open each port
for ((i = start_port; i <= end_port; i++)); do # for ((i = start_port; i <= end_port; i++)); do
ufw allow $i # ufw allow $i
done # done
ufw allow $start_port:$end_port
else else
ufw allow "$port" ufw allow "$port"
fi fi
@ -650,9 +651,10 @@ delete_ports() {
start_port=$(echo $port | cut -d'-' -f1) start_port=$(echo $port | cut -d'-' -f1)
end_port=$(echo $port | cut -d'-' -f2) end_port=$(echo $port | cut -d'-' -f2)
# Loop through the range and delete each port # Loop through the range and delete each port
for ((i = start_port; i <= end_port; i++)); do # for ((i = start_port; i <= end_port; i++)); do
ufw delete allow $i # ufw delete allow $i
done # done
ufw delete allow $start_port:$end_port
else else
ufw delete allow "$port" ufw delete allow "$port"
fi fi