/ Scripts / Menu / menu-firewall.sh
menu-firewall.sh
  1  #!/bin/bash
  2  
  3  # shellcheck source=./Scripts/defaults.sh
  4  . "$HOME"/RoninDojo/Scripts/defaults.sh
  5  
  6  # shellcheck source=./Scripts/functions.sh
  7  . "$HOME"/RoninDojo/Scripts/functions.sh
  8  
  9  OPTIONS=(1 "Enable"
 10           2 "Disable"
 11           3 "Status"
 12           4 "Delete Rule"
 13           5 "Reload"
 14           6 "Add IP Range for SSH"
 15           7 "Add Specific IP for SSH"
 16           8 "Go Back")
 17  
 18  CHOICE=$(dialog --clear \
 19                  --title "$TITLE" \
 20                  --menu "$MENU" \
 21                  "$HEIGHT" "$WIDTH" "$CHOICE_HEIGHT" \
 22                  "${OPTIONS[@]}" \
 23                  2>&1 >/dev/tty)
 24  
 25  clear
 26  case $CHOICE in
 27          1)
 28              _print_message "Enabling Firewall..."
 29              _sleep
 30              sudo ufw enable
 31              _pause return
 32              bash -c "${ronin_firewall_menu}"
 33              ;;
 34          2)
 35              _print_message "Disabling Firewall..."
 36              _sleep
 37              sudo ufw disable
 38              _pause return
 39              bash -c "${ronin_firewall_menu}"
 40              ;;
 41          3)
 42              _print_message "Showing Status..."
 43              _sleep
 44              sudo ufw status
 45              _pause return
 46              bash -c "${ronin_firewall_menu}"
 47              ;;
 48          4)
 49              _print_message "Find the rule you want to delete, and type its row number to delete it..."
 50              _sleep
 51              sudo ufw status
 52  
 53              _print_message "Be careful when deleting old firewall rules! Don't lock yourself out from SSH access..."
 54              _sleep
 55  
 56              _print_message "Example: If you want to delete the 3rd rule listed, press the number 3, and press Enter..."
 57              _sleep
 58  
 59              read -rp "Please type the rule number to delete now: " ufw_rule_number
 60              sudo ufw delete "$ufw_rule_number"
 61  
 62              _print_message "Reloading..."
 63              sudo ufw reload
 64  
 65              _print_message "Showing status..."
 66              _sleep
 67              sudo ufw status
 68  
 69              _pause return
 70              bash -c "${ronin_firewall_menu}"
 71              ;;
 72          5)
 73              _print_message "Reloading..."
 74              sudo ufw reload
 75              _pause return
 76              bash -c "${ronin_firewall_menu}"
 77              ;;
 78          6)
 79              _print_message "Obtain the IP address of any machine on the same local network as your RoninDojo..."
 80              _sleep
 81              _print_message "The IP address entered will be adapted to end with .0/24 range..."
 82              _sleep
 83              _print_message "This will allow any machine on the same network to have SSH access..."
 84              _sleep
 85              _print_message "Your IP address on the network may look like 192.168.4.21 or 12.34.56.78 depending on setup..."
 86              _sleep
 87              _print_message "Enter the local IP address you wish to give SSH access now..."
 88              _sleep
 89  
 90              read -rp 'Local IP Address: ' ip_address
 91              sudo ufw allow from "${ip_address}"/24 to any port 22 comment 'SSH access restricted to local network'
 92  
 93              _print_message "Reloading..."
 94              sudo ufw reload
 95              
 96              _print_message "Showing status..."
 97              _sleep
 98              sudo ufw status
 99  
100              _print_message "Make sure that you see your new rule!"
101              _sleep
102  
103              _pause return
104              bash -c "${ronin_firewall_menu}"
105              exit
106              ;;
107          7)
108              _print_message "Obtain the specific IP address you wish to give access to SSH..."
109              _sleep
110              _print_message "SSH access will be restricted to this IP address only..."
111              _sleep
112              _print_message "Your IP address on the network may look like 192.168.4.21 or 12.34.56.78 depending on setup..."
113              _sleep
114              _print_message "Enter the local IP address you wish to give SSH access now..."
115  
116              read -rp 'Local IP Address: ' ip_address
117              sudo ufw allow from "${ip_address}" to any port 22 comment 'SSH access restricted to specific IP'
118  
119              _print_message "Reloading..."
120              sudo ufw reload
121  
122              _print_message "Showing status..."
123              _sleep
124              sudo ufw status
125  
126              _print_message "Make sure that you see your new rule!"
127              _sleep
128  
129              _pause return
130              bash -c "${ronin_firewall_menu}"
131              ;;
132          8)
133              bash -c "${ronin_system_menu2}"
134              ;;
135  esac