v-delete-firewall-ban 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. # info: delete firewall blocking rule
  3. # options: IP CHAIN
  4. #
  5. # The function deletes blocking rule from system firewall
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Importing system variables
  10. source /etc/profile
  11. # Argument definition
  12. ip=$1
  13. chain=$(echo $2|tr '[:lower:]' '[:upper:]')
  14. # Defining absolute path for iptables and modprobe
  15. iptables="/sbin/iptables"
  16. # Includes
  17. source $VESTA/func/main.sh
  18. source $VESTA/conf/vesta.conf
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. check_args '2' "$#" 'IP CHAIN'
  23. is_format_valid 'ip' 'chain'
  24. is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
  25. #----------------------------------------------------------#
  26. # Action #
  27. #----------------------------------------------------------#
  28. # Checking ip in banlist
  29. conf="$VESTA/data/firewall/banlist.conf"
  30. check_ip=$(grep "IP='$ip' CHAIN='$chain'" $conf 2>/dev/null)
  31. if [ -z "$check_ip" ]; then
  32. exit
  33. fi
  34. # Deleting ip from banlist
  35. sip=$(echo "$ip"| sed "s|/|\\\/|g")
  36. sed -i "/IP='$sip' CHAIN='$chain'/d" $conf
  37. b=$($iptables -L fail2ban-$chain --line-number -n|grep $ip|awk '{print $1}')
  38. $iptables -D fail2ban-$chain $b 2>/dev/null
  39. # Changing permissions
  40. chmod 660 $conf
  41. #----------------------------------------------------------#
  42. # Vesta #
  43. #----------------------------------------------------------#
  44. # Logging
  45. log_event "$OK" "$ARGUMENTS"
  46. exit