#!/bin/bash installUFW() { if [[ "$CFG_REQUIREMENT_UFW" == "true" ]]; then ISUFW=$( (runSystem ufw status ) 2>&1 ) if [[ "$ISUFW" == *"command not found"* ]]; then isHeader "Install UFW Firewall" ((menu_number++)) echo "" echo "---- $menu_number. Installing using linux package installer" echo "" local result; result=$(yes | runSystem apt-get install ufw ) checkSuccess "Installing UFW package" # ((menu_number++)) # echo "" # echo "---- $menu_number. Updating Firewall Rules" # echo "" # # Detect SSH port if not provided # if [[ -z "$ssh_port" ]]; then # SSH_CONFIG="/etc/ssh/sshd_config" # ssh_port=$(grep "^Port" "$SSH_CONFIG" 2>/dev/null | awk '{print $2}' | head -n1) # ssh_port=${ssh_port:-22} # Default to 22 if not found # fi # local result; result=$(runSystem ufw allow $ssh_port) # checkSuccess "Enabling Port $ssh_port through the firewall" # local result; result=$(runSystem ufw allow ssh) # checkSuccess "Enabling SSH through the firewall" # while true; do # isQuestion "Do you want to keep port $ssh_port (SSH) open? (y/n): " # read -rp "" UFWSSH # if [[ "$UFWSSH" =~ ^[yYnN]$ ]]; then # break # fi # isNotice "Please provide a valid input (y/n)." # done # if [[ "$UFWSSH" == [nN] ]]; then # local result; result=$(runSystem ufw deny $ssh_port) # checkSuccess "Blocking Port $ssh_port through the firewall" # local result; result=$(runSystem ufw deny ssh) # checkSuccess "Blocking SSH through the firewall" # fi local result; result=$(runSystem ufw --force enable) checkSuccess "Enabling UFW Firewall" ((menu_number++)) echo "" echo "---- $menu_number. Changing logging options" echo "" local result; result=$(yes | runSystem ufw logging $CFG_UFW_LOGGING) checkSuccess "Disabling UFW Firewall Logging" isSuccessful "UFW Firewall has been installed, you can use ufw status to see the status" menu_number=0 cd fi fi }