|
@@ -78,44 +78,88 @@ do_not_log_action () {
|
|
|
###############################################################
|
|
###############################################################
|
|
|
# Firewall actions function definition
|
|
# Firewall actions function definition
|
|
|
###############################################################
|
|
###############################################################
|
|
|
|
|
+get_table_information(){
|
|
|
|
|
+ if [ "$1" = "-t" ]
|
|
|
|
|
+ then
|
|
|
|
|
+ echo "$1 $2"
|
|
|
|
|
+ else
|
|
|
|
|
+ echo ""
|
|
|
|
|
+ fi
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+get_action_information(){
|
|
|
|
|
+ if [ "$1" = "-t" ]
|
|
|
|
|
+ then
|
|
|
|
|
+ echo "$3"
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "$1"
|
|
|
|
|
+ fi
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+get_command_information(){
|
|
|
|
|
+ if [ "$1" = "-t" ]
|
|
|
|
|
+ then
|
|
|
|
|
+ shift 3
|
|
|
|
|
+ else
|
|
|
|
|
+ shift
|
|
|
|
|
+ fi
|
|
|
|
|
+ echo "$*"
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+get_chain_information(){
|
|
|
|
|
+ if [ "$1" = "-t" ]
|
|
|
|
|
+ then
|
|
|
|
|
+ shift 3
|
|
|
|
|
+ else
|
|
|
|
|
+ shift
|
|
|
|
|
+ fi
|
|
|
|
|
+ echo "$1"
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
do_exec () {
|
|
do_exec () {
|
|
|
- case $1 in
|
|
|
|
|
|
|
+ local it_action=`get_action_information $*`
|
|
|
|
|
+ local it_table=`get_table_information $*`
|
|
|
|
|
+ local it_command=`get_command_information $*`
|
|
|
|
|
+ local it_option
|
|
|
|
|
+ case ${it_action} in
|
|
|
__iptable_add_action)
|
|
__iptable_add_action)
|
|
|
shift
|
|
shift
|
|
|
- iptables_option=-A
|
|
|
|
|
|
|
+ it_option=-A
|
|
|
;;
|
|
;;
|
|
|
__iptable_insert_action)
|
|
__iptable_insert_action)
|
|
|
shift
|
|
shift
|
|
|
- iptables_option=-I
|
|
|
|
|
|
|
+ it_option=-I
|
|
|
;;
|
|
;;
|
|
|
__iptable_set_policy_action)
|
|
__iptable_set_policy_action)
|
|
|
shift
|
|
shift
|
|
|
- iptables_option=-P
|
|
|
|
|
|
|
+ it_option=-P
|
|
|
;;
|
|
;;
|
|
|
*)
|
|
*)
|
|
|
echo "Nothing to be done for $1"
|
|
echo "Nothing to be done for $1"
|
|
|
;;
|
|
;;
|
|
|
esac
|
|
esac
|
|
|
if [ ${verbose} -ge 1 ] ; then
|
|
if [ ${verbose} -ge 1 ] ; then
|
|
|
- echo $IP_TABLES $iptables_option $*
|
|
|
|
|
|
|
+ echo $IP_TABLES $it_table $it_option $it_command
|
|
|
fi
|
|
fi
|
|
|
- if ! $IP_TABLES -C $* > /dev/null 2>&1
|
|
|
|
|
|
|
+ if ! $IP_TABLES $it_table -C $it_command > /dev/null 2>&1
|
|
|
then
|
|
then
|
|
|
- $IP_TABLES $iptables_option $*
|
|
|
|
|
|
|
+ $IP_TABLES $it_table $it_option $it_command
|
|
|
fi
|
|
fi
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
do_check () {
|
|
do_check () {
|
|
|
- local the_action
|
|
|
|
|
- the_action=$1
|
|
|
|
|
- shift
|
|
|
|
|
- case $the_action in
|
|
|
|
|
|
|
+ local it_action=`get_action_information $*`
|
|
|
|
|
+ local it_table=`get_table_information $*`
|
|
|
|
|
+ local it_command=`get_command_information $*`
|
|
|
|
|
+ local it_option
|
|
|
|
|
+ case $it_action in
|
|
|
__iptable_add_action)
|
|
__iptable_add_action)
|
|
|
- iptables_option=-A
|
|
|
|
|
|
|
+ it_option=-A
|
|
|
;;
|
|
;;
|
|
|
__iptable_insert_action)
|
|
__iptable_insert_action)
|
|
|
- iptables_option=-I
|
|
|
|
|
|
|
+ it_option=-I
|
|
|
;;
|
|
;;
|
|
|
__iptable_set_policy_action)
|
|
__iptable_set_policy_action)
|
|
|
return 0
|
|
return 0
|
|
@@ -126,33 +170,35 @@ do_check () {
|
|
|
esac
|
|
esac
|
|
|
default_option=-C
|
|
default_option=-C
|
|
|
if [ ${verbose} -ge 1 ] ; then
|
|
if [ ${verbose} -ge 1 ] ; then
|
|
|
- echo $do_log "$the_action:" $IP_TABLES -C $*
|
|
|
|
|
- echo $IP_TABLES -C $*
|
|
|
|
|
|
|
+ echo $do_log "$it_action:" $IP_TABLES $it_table -C $it_command
|
|
|
|
|
+ echo $IP_TABLES $it_table -C $it_command
|
|
|
fi
|
|
fi
|
|
|
- $do_log "$the_action:" $IP_TABLES -C $*
|
|
|
|
|
- $IP_TABLES -C $*
|
|
|
|
|
|
|
+ $do_log "$it_action:" $IP_TABLES -C $it_command
|
|
|
|
|
+ $IP_TABLES $it_table -C $it_command
|
|
|
global_status=$((global_status+$?))
|
|
global_status=$((global_status+$?))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
do_delete () {
|
|
do_delete () {
|
|
|
- local the_action
|
|
|
|
|
- the_action=$1
|
|
|
|
|
- shift
|
|
|
|
|
|
|
+ local it_action=`get_action_information $*`
|
|
|
|
|
+ local it_table=`get_table_information $*`
|
|
|
|
|
+ local it_command=`get_command_information $*`
|
|
|
|
|
+ local it_option
|
|
|
if [ ${verbose} -gt 1 ] ; then
|
|
if [ ${verbose} -gt 1 ] ; then
|
|
|
- $do_log "Trying to delete:" $(translate_iptables_rule $IP_TABLES $the_action $*)
|
|
|
|
|
|
|
+ $do_log "Trying to delete:" \
|
|
|
|
|
+ $(translate_iptables_rule $IP_TABLES $it_table $it_action $it_command)
|
|
|
fi
|
|
fi
|
|
|
- case $the_action in
|
|
|
|
|
|
|
+ case $it_action in
|
|
|
__iptable_add_action)
|
|
__iptable_add_action)
|
|
|
- iptables_option=-D
|
|
|
|
|
|
|
+ it_option=-D
|
|
|
;;
|
|
;;
|
|
|
__iptable_insert_action)
|
|
__iptable_insert_action)
|
|
|
- iptables_option=-D
|
|
|
|
|
|
|
+ it_option=-D
|
|
|
;;
|
|
;;
|
|
|
__iptable_set_policy_action)
|
|
__iptable_set_policy_action)
|
|
|
- CHAIN_NAME="$1"
|
|
|
|
|
- $do_log "DELETING: $IP_TABLES -P $CHAIN_NAME DROP"
|
|
|
|
|
- $IP_TABLES -P $CHAIN_NAME ACCEPT
|
|
|
|
|
|
|
+ CHAIN_NAME=`get_chain_information $*`
|
|
|
|
|
+ $do_log "DELETING: $IP_TABLES $it_table -P $CHAIN_NAME DROP"
|
|
|
|
|
+ $IP_TABLES $it_table -P $CHAIN_NAME ACCEPT
|
|
|
return 0
|
|
return 0
|
|
|
;;
|
|
;;
|
|
|
*)
|
|
*)
|
|
@@ -162,12 +208,12 @@ do_delete () {
|
|
|
|
|
|
|
|
|
|
|
|
|
# Checks the rule then delete it, if it exists
|
|
# Checks the rule then delete it, if it exists
|
|
|
- if $IP_TABLES -C $* > /dev/null 2>&1
|
|
|
|
|
|
|
+ if $IP_TABLES $it_table -C $it_command > /dev/null 2>&1
|
|
|
then
|
|
then
|
|
|
- $IP_TABLES $iptables_option $* || echo "DID NOT EXIST: "$IP_TABLES $iptables_option $*
|
|
|
|
|
- $do_log "DELETING:" $IP_TABLES $iptables_option $*
|
|
|
|
|
|
|
+ $IP_TABLES $it_table $it_option $it_command || echo "DID NOT EXIST: "$IP_TABLES $it_option $it_command
|
|
|
|
|
+ $do_log "DELETING:" $IP_TABLES $it_table $it_option $it_command
|
|
|
else
|
|
else
|
|
|
- $do_log "NOT EXISTING:" $IP_TABLES $iptables_option $*
|
|
|
|
|
|
|
+ $do_log "NOT EXISTING:" $IP_TABLES $it_table $it_option $it_command
|
|
|
fi
|
|
fi
|
|
|
global_status=$((global_status+$?))
|
|
global_status=$((global_status+$?))
|
|
|
}
|
|
}
|