@@ -682,40 +682,50 @@ show_xray_status() {
682
682
}
683
683
684
684
firewall_menu () {
685
- echo -e " ${green} \t1.${plain} Install Firewall & open ports"
686
- echo -e " ${green} \t2.${plain} Allowed List"
687
- echo -e " ${green} \t3.${plain} Delete Ports from List"
688
- echo -e " ${green} \t4.${plain} Disable Firewall"
685
+ echo -e " ${green} \t1.${plain} Install Firewall"
686
+ echo -e " ${green} \t2.${plain} Port List"
687
+ echo -e " ${green} \t3.${plain} Open Ports"
688
+ echo -e " ${green} \t4.${plain} Delete Ports from List"
689
+ echo -e " ${green} \t5.${plain} Disable Firewall"
690
+ echo -e " ${green} \t6.${plain} Firewall Status"
689
691
echo -e " ${green} \t0.${plain} Back to Main Menu"
690
692
read -p " Choose an option: " choice
691
693
case " $choice " in
692
694
0)
693
695
show_menu
694
696
;;
695
697
1)
696
- open_ports
698
+ install_firewall
697
699
firewall_menu
698
700
;;
699
701
2)
700
- sudo ufw status
702
+ sudo ufw status numbered
701
703
firewall_menu
702
704
;;
703
705
3)
704
- delete_ports
706
+ sudo open_ports
705
707
firewall_menu
706
708
;;
707
709
4)
710
+ sudo delete_ports
711
+ firewall_menu
712
+ ;;
713
+ 5)
708
714
sudo ufw disable
709
715
firewall_menu
710
716
;;
717
+ 6)
718
+ sudo ufw status verbose
719
+ firewall_menu
720
+ ;;
711
721
* )
712
722
echo -e " ${red} Invalid option. Please select a valid number.${plain} \n"
713
723
firewall_menu
714
724
;;
715
725
esac
716
726
}
717
727
718
- open_ports () {
728
+ install_firewall () {
719
729
if ! command -v ufw & > /dev/null; then
720
730
echo " ufw firewall is not installed. Installing now..."
721
731
apt-get update
@@ -733,13 +743,17 @@ open_ports() {
733
743
ufw allow ssh
734
744
ufw allow http
735
745
ufw allow https
736
- ufw allow 2053/tcp
746
+ ufw allow 2053/tcp # webPort
747
+ ufw allow 2096/tcp # subport
737
748
738
749
# Enable the firewall
739
750
ufw --force enable
740
- fi
751
+ fi
752
+ done
753
+ }
741
754
742
- # Prompt the user to enter a list of ports
755
+ open_ports () {
756
+ # Prompt the user to enter the ports they want to open
743
757
read -p " Enter the ports you want to open (e.g. 80,443,2053 or range 400-500): " ports
744
758
745
759
# Check if the input is valid
@@ -755,19 +769,28 @@ open_ports() {
755
769
# Split the range into start and end ports
756
770
start_port=$( echo $port | cut -d' -' -f1)
757
771
end_port=$( echo $port | cut -d' -' -f2)
772
+ # Open the port range
758
773
ufw allow $start_port :$end_port /tcp
759
774
ufw allow $start_port :$end_port /udp
760
775
else
776
+ # Open the single port
761
777
ufw allow " $port "
762
778
fi
763
779
done
764
780
765
- # Confirm that the ports are open
766
- echo " The following ports are now open:"
767
- ufw status | grep " ALLOW" | grep -Eo " [0-9]+(/[a-z]+)?"
768
-
769
- echo " Firewall status:"
770
- ufw status verbose
781
+ # Confirm that the ports are opened
782
+ echo " Opened the specified ports:"
783
+ for port in " ${PORT_LIST[@]} " ; do
784
+ if [[ $port == * -* ]]; then
785
+ start_port=$( echo $port | cut -d' -' -f1)
786
+ end_port=$( echo $port | cut -d' -' -f2)
787
+ # Check if the port range has been successfully opened
788
+ (ufw status | grep -q " $start_port :$end_port " ) && echo " $start_port -$end_port "
789
+ else
790
+ # Check if the individual port has been successfully opened
791
+ (ufw status | grep -q " $port " ) && echo " $port "
792
+ fi
793
+ done
771
794
}
772
795
773
796
delete_ports () {
0 commit comments