Update install func + add/edit func open/close ports + status firewall

This commit is contained in:
LoST 2024-12-19 21:59:56 +03:00 committed by GitHub
parent c42d12c329
commit 942eaa4394
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

53
x-ui.sh
View file

@ -682,11 +682,12 @@ show_xray_status() {
} }
firewall_menu() { firewall_menu() {
echo -e "${green}\t1.${plain} Install Firewall & open ports" echo -e "${green}\t1.${plain} Install Firewall"
echo -e "${green}\t2.${plain} Allowed List" echo -e "${green}\t2.${plain} Port List"
echo -e "${green}\t3.${plain} Delete Ports from List" echo -e "${green}\t3.${plain} Open Ports"
echo -e "${green}\t4.${plain} Delete Ports from List"
echo -e "${green}\t4.${plain} Disable Firewall" echo -e "${green}\t5.${plain} Disable Firewall"
echo -e "${green}\t5.${plain} Firewall Status"
echo -e "${green}\t0.${plain} Back to Main Menu" echo -e "${green}\t0.${plain} Back to Main Menu"
read -p "Choose an option: " choice read -p "Choose an option: " choice
case "$choice" in case "$choice" in
@ -694,7 +695,7 @@ firewall_menu() {
show_menu show_menu
;; ;;
1) 1)
open_ports install_firewall
firewall_menu firewall_menu
;; ;;
2) 2)
@ -702,13 +703,21 @@ firewall_menu() {
firewall_menu firewall_menu
;; ;;
3) 3)
sudo delete_ports sudo open_ports
firewall_menu firewall_menu
;; ;;
4) 4)
sudo delete_ports
firewall_menu
;;
5)
sudo ufw disable sudo ufw disable
firewall_menu firewall_menu
;; ;;
6)
sudo ufw status verbose
firewall_menu
;;
*) *)
echo -e "${red}Invalid option. Please select a valid number.${plain}\n" echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
firewall_menu firewall_menu
@ -716,7 +725,7 @@ firewall_menu() {
esac esac
} }
open_ports() { install_firewall() {
if ! command -v ufw &>/dev/null; then if ! command -v ufw &>/dev/null; then
echo "ufw firewall is not installed. Installing now..." echo "ufw firewall is not installed. Installing now..."
apt-get update apt-get update
@ -738,9 +747,12 @@ open_ports() {
# Enable the firewall # Enable the firewall
ufw --force enable ufw --force enable
fi fi
done
}
# Prompt the user to enter a list of ports open_ports() {
# Prompt the user to enter the ports they want to open
read -p "Enter the ports you want to open (e.g. 80,443,2053 or range 400-500): " ports read -p "Enter the ports you want to open (e.g. 80,443,2053 or range 400-500): " ports
# Check if the input is valid # Check if the input is valid
@ -756,19 +768,28 @@ open_ports() {
# Split the range into start and end ports # Split the range into start and end 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)
# Open the port range
ufw allow $start_port:$end_port/tcp ufw allow $start_port:$end_port/tcp
ufw allow $start_port:$end_port/udp ufw allow $start_port:$end_port/udp
else else
# Open the single port
ufw allow "$port" ufw allow "$port"
fi fi
done done
# Confirm that the ports are open # Confirm that the ports are opened
echo "The following ports are now open:" echo "Opened the specified ports:"
ufw status | grep "ALLOW" | grep -Eo "[0-9]+(/[a-z]+)?" for port in "${PORT_LIST[@]}"; do
if [[ $port == *-* ]]; then
echo "Firewall status:" start_port=$(echo $port | cut -d'-' -f1)
ufw status verbose end_port=$(echo $port | cut -d'-' -f2)
# Check if the port range has been successfully opened
(ufw status | grep -q "$start_port:$end_port") && echo "$start_port-$end_port"
else
# Check if the individual port has been successfully opened
(ufw status | grep -q "$port") && echo "$port"
fi
done
} }
delete_ports() { delete_ports() {