Skip to content

Commit

Permalink
Correction of Previous Mistaken PR and the delete_ports function (#2231)
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.


This commit is to correct the previous one, which cannot handle port range settings correctly.

Corrected the confirmation of the deleted ports.
  • Loading branch information
Athameral authored Apr 22, 2024
1 parent e794d3d commit 835cf28
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions x-ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ open_ports() {
# Split the range into start and end ports
start_port=$(echo $port | cut -d'-' -f1)
end_port=$(echo $port | cut -d'-' -f2)
ufw allow $start_port:$end_port
ufw allow $start_port:$end_port/tcp
ufw allow $start_port:$end_port/udp
else
ufw allow "$port"
fi
Expand Down Expand Up @@ -652,15 +653,27 @@ delete_ports() {
start_port=$(echo $port | cut -d'-' -f1)
end_port=$(echo $port | cut -d'-' -f2)
# Delete the port range
ufw delete allow $start_port:$end_port
ufw delete allow $start_port:$end_port/tcp
ufw delete allow $start_port:$end_port/udp
else
ufw delete allow "$port"
fi
done

# Confirm that the ports are deleted

echo "Deleted the specified ports:"
ufw status | grep "ALLOW" | grep -Eo "[0-9]+(/[a-z]+)?"
for port in "${PORT_LIST[@]}"; do
if [[ $port == *-* ]]; then
start_port=$(echo $port | cut -d'-' -f1)
end_port=$(echo $port | cut -d'-' -f2)
# Check if the port range has been successfully deleted
(ufw status | grep -q "$start_port:$end_port") || echo "$start_port-$end_port"
else
# Check if the individual port has been successfully deleted
(ufw status | grep -q "$port") || echo "$port"
fi
done
}

update_geo() {
Expand Down

0 comments on commit 835cf28

Please sign in to comment.