myvesta/bin/v-delete-firewall-ipv6-ban
2024-04-14 22:28:39 +02:00

65 lines
1.7 KiB
Bash

#!/bin/bash
# info: delete firewall blocking rule
# options: IP CHAIN
#
# The function deletes blocking rule from system firewall
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Importing system variables
source /etc/profile
# Argument definition
ipv6=$1
chain=$(echo $2|tr '[:lower:]' '[:upper:]')
# Defining absolute path for iptables and modprobe
iptables="/sbin/ip6tables"
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'IP CHAIN'
is_format_valid 'ipv6' 'chain'
is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Checking ip in banlist
conf="$VESTA/data/firewallv6/banlist.conf"
check_ip=$(grep "IP6='$ipv6' CHAIN='$chain'" $conf 2>/dev/null)
if [ -z "$check_ip" ]; then
exit
fi
# Deleting ip from banlist
sip=$(echo "$ipv6"| sed "s|/|\\\/|g")
sed -i "/IP6='$sip' CHAIN='$chain'/d" $conf
b=$($iptables -L fail2ban-$chain --line-number -n|grep $ipv6|awk '{print $1}')
$iptables -D fail2ban-$chain $b 2>/dev/null
# Changing permissions
chmod 660 $conf
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
exit