v-delete-firewall-ban 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 defenition
  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. validate_format '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. sed -i "/IP='$ip' CHAIN='$chain'/d" $conf
  36. $iptables -D fail2ban-$chain -s $ip \
  37. -j REJECT --reject-with icmp-port-unreachable 2>/dev/null
  38. # Changing permissions
  39. chmod 660 $conf
  40. #----------------------------------------------------------#
  41. # Vesta #
  42. #----------------------------------------------------------#
  43. # Logging
  44. log_event "$OK" "$EVENT"
  45. exit