#!/bin/bash
# info: delete firewall rule
# options: RULE
#
# The function deletes firewall rule.


#----------------------------------------------------------#
#                    Variable&Function                     #
#----------------------------------------------------------#

# Importing system variables
source /etc/profile

# Argument definition
rule=$1

# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf


#----------------------------------------------------------#
#                    Verifications                         #
#----------------------------------------------------------#

check_args '1' "$#" 'RULE'
is_format_valid 'rule'
is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
is_object_valid '../../data/firewall/rules' 'RULE' "$rule"


#----------------------------------------------------------#
#                       Action                             #
#----------------------------------------------------------#

# Deleting rule
sed -i "/RULE='$rule' /d" $VESTA/data/firewall/rules.conf

# Updating system firewall
$BIN/v-update-firewall


#----------------------------------------------------------#
#                       Vesta                              #
#----------------------------------------------------------#

# Logging
log_event "$OK" "$ARGUMENTS"

exit