@@ -683,12 +683,13 @@ show_xray_status() {
683
683
}
684
684
685
685
firewall_menu () {
686
- echo -e " ${green} \t1.${plain} Install Firewall"
687
- echo -e " ${green} \t2.${plain} Port List"
688
- echo -e " ${green} \t3.${plain} Open Ports"
689
- echo -e " ${green} \t4.${plain} Delete Ports from List"
690
- echo -e " ${green} \t5.${plain} Disable Firewall"
691
- echo -e " ${green} \t6.${plain} Firewall Status"
686
+ echo -e " ${green} \t1.${plain} ${green} Install${plain} Firewall"
687
+ echo -e " ${green} \t2.${plain} Port List [numbered]"
688
+ echo -e " ${green} \t3.${plain} ${green} Open${plain} Ports"
689
+ echo -e " ${green} \t4.${plain} ${red} Delete${plain} Ports from List"
690
+ echo -e " ${green} \t5.${plain} ${green} Enable${plain} Firewall"
691
+ echo -e " ${green} \t6.${plain} ${red} Disable${plain} Firewall"
692
+ echo -e " ${green} \t7.${plain} Firewall Status"
692
693
echo -e " ${green} \t0.${plain} Back to Main Menu"
693
694
read -p " Choose an option: " choice
694
695
case " $choice " in
@@ -712,10 +713,14 @@ firewall_menu() {
712
713
firewall_menu
713
714
;;
714
715
5)
715
- ufw disable
716
+ ufw enable
716
717
firewall_menu
717
718
;;
718
719
6)
720
+ ufw disable
721
+ firewall_menu
722
+ ;;
723
+ 7)
719
724
ufw status verbose
720
725
firewall_menu
721
726
;;
@@ -794,46 +799,81 @@ open_ports() {
794
799
}
795
800
796
801
delete_ports () {
797
- # Prompt the user to enter the ports they want to delete
798
- read -p " Enter the ports you want to delete (e.g. 80,443,2053 or range 400-500): " ports
802
+ # Display current rules with numbers
803
+ echo " Current UFW rules:"
804
+ ufw status numbered
805
+
806
+ # Ask the user how they want to delete rules
807
+ echo " Do you want to delete rules by:"
808
+ echo " 1) Rule numbers"
809
+ echo " 2) Ports"
810
+ read -p " Enter your choice (1 or 2): " choice
811
+
812
+ if [[ $choice -eq 1 ]]; then
813
+ # Deleting by rule numbers
814
+ read -p " Enter the rule numbers you want to delete (1, 2, etc.): " rule_numbers
815
+
816
+ # Validate the input
817
+ if ! [[ $rule_numbers =~ ^([0-9]+)(,[0-9]+)* $ ]]; then
818
+ echo " Error: Invalid input. Please enter a comma-separated list of rule numbers." >&2
819
+ exit 1
820
+ fi
799
821
800
- # Check if the input is valid
801
- if ! [[ $ports =~ ^([0-9]+| [0-9]+-[0-9]+)(,([0-9]+| [0-9]+-[0-9]+))* $ ]]; then
802
- echo " Error: Invalid input. Please enter a comma-separated list of ports or a range of ports (e.g. 80,443,2053 or 400-500)." >&2
803
- exit 1
804
- fi
822
+ # Split numbers into an array
823
+ IFS=' ,' read -ra RULE_NUMBERS <<< " $rule_numbers"
824
+ for rule_number in " ${RULE_NUMBERS[@]} " ; do
825
+ # Delete the rule by number
826
+ ufw delete " $rule_number " || echo " Failed to delete rule number $rule_number "
827
+ done
805
828
806
- # Delete the specified ports using ufw
807
- IFS=' ,' read -ra PORT_LIST <<< " $ports"
808
- for port in " ${PORT_LIST[@]} " ; do
809
- if [[ $port == * -* ]]; then
810
- # Split the range into start and end ports
811
- start_port=$( echo $port | cut -d' -' -f1)
812
- end_port=$( echo $port | cut -d' -' -f2)
813
- # Delete the port range
814
- ufw delete allow $start_port :$end_port /tcp
815
- ufw delete allow $start_port :$end_port /udp
816
- else
817
- ufw delete allow " $port "
818
- fi
819
- done
829
+ echo " Selected rules have been deleted."
820
830
821
- # Confirm that the ports are deleted
831
+ elif [[ $choice -eq 2 ]]; then
832
+ # Deleting by ports
833
+ read -p " Enter the ports you want to delete (e.g. 80,443,2053 or range 400-500): " ports
822
834
823
- echo " Deleted the specified ports:"
824
- for port in " ${PORT_LIST[@]} " ; do
825
- if [[ $port == * -* ]]; then
826
- start_port=$( echo $port | cut -d' -' -f1)
827
- end_port=$( echo $port | cut -d' -' -f2)
828
- # Check if the port range has been successfully deleted
829
- (ufw status | grep -q " $start_port :$end_port " ) || echo " $start_port -$end_port "
830
- else
831
- # Check if the individual port has been successfully deleted
832
- (ufw status | grep -q " $port " ) || echo " $port "
835
+ # Validate the input
836
+ if ! [[ $ports =~ ^([0-9]+| [0-9]+-[0-9]+)(,([0-9]+| [0-9]+-[0-9]+))* $ ]]; then
837
+ echo " Error: Invalid input. Please enter a comma-separated list of ports or a range of ports (e.g. 80,443,2053 or 400-500)." >&2
838
+ exit 1
833
839
fi
834
- done
840
+
841
+ # Split ports into an array
842
+ IFS=' ,' read -ra PORT_LIST <<< " $ports"
843
+ for port in " ${PORT_LIST[@]} " ; do
844
+ if [[ $port == * -* ]]; then
845
+ # Split the port range
846
+ start_port=$( echo $port | cut -d' -' -f1)
847
+ end_port=$( echo $port | cut -d' -' -f2)
848
+ # Delete the port range
849
+ ufw delete allow $start_port :$end_port /tcp
850
+ ufw delete allow $start_port :$end_port /udp
851
+ else
852
+ # Delete a single port
853
+ ufw delete allow " $port "
854
+ fi
855
+ done
856
+
857
+ # Confirmation of deletion
858
+ echo " Deleted the specified ports:"
859
+ for port in " ${PORT_LIST[@]} " ; do
860
+ if [[ $port == * -* ]]; then
861
+ start_port=$( echo $port | cut -d' -' -f1)
862
+ end_port=$( echo $port | cut -d' -' -f2)
863
+ # Check if the port range has been deleted
864
+ (ufw status | grep -q " $start_port :$end_port " ) || echo " $start_port -$end_port "
865
+ else
866
+ # Check if the individual port has been deleted
867
+ (ufw status | grep -q " $port " ) || echo " $port "
868
+ fi
869
+ done
870
+ else
871
+ echo " ${red} Error:${plain} Invalid choice. Please enter 1 or 2." >&2
872
+ exit 1
873
+ fi
835
874
}
836
875
876
+
837
877
update_geo () {
838
878
echo -e " ${green} \t1.${plain} Loyalsoldier (geoip.dat, geosite.dat)"
839
879
echo -e " ${green} \t2.${plain} chocolate4u (geoip_IR.dat, geosite_IR.dat)"
0 commit comments