Skip to content

Commit

Permalink
Update x-ui.sh with ufw port settings (#2230)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Athameral committed Apr 20, 2024
1 parent a3a2d7a commit 3d5c06b
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions x-ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,9 @@ open_ports() {

# Check if the firewall is inactive
if ufw status | grep -q "Status: active"; then
echo "firewall is already active"
echo "Firewall is already active"
else
echo "Activating firewall..."
# Open the necessary ports
ufw allow ssh
ufw allow http
Expand All @@ -619,17 +620,18 @@ open_ports() {
# Split the range into start and end ports
start_port=$(echo $port | cut -d'-' -f1)
end_port=$(echo $port | cut -d'-' -f2)
# Loop through the range and open each port
for ((i = start_port; i <= end_port; i++)); do
ufw allow $i
done
ufw allow $start_port:$end_port
else
ufw allow "$port"
fi
done

# Confirm that the ports are open
ufw status | grep $ports
echo "The following ports are now open:"
ufw status | grep "ALLOW" | grep -Eo "[0-9]+(/[a-z]+)?"

echo "Firewall status:"
ufw status verbose
}

delete_ports() {
Expand All @@ -649,18 +651,16 @@ delete_ports() {
# Split the range into start and end ports
start_port=$(echo $port | cut -d'-' -f1)
end_port=$(echo $port | cut -d'-' -f2)
# Loop through the range and delete each port
for ((i = start_port; i <= end_port; i++)); do
ufw delete allow $i
done
# Delete the port range
ufw delete allow $start_port:$end_port
else
ufw delete allow "$port"
fi
done

# Confirm that the ports are deleted
echo "Deleted the specified ports:"
ufw status | grep $ports
ufw status | grep "ALLOW" | grep -Eo "[0-9]+(/[a-z]+)?"
}

update_geo() {
Expand Down

0 comments on commit 3d5c06b

Please sign in to comment.