#!/bin/bash


IPTABLES_RULES=/etc/fire/rules
IP4TABLES_BINARY=/sbin/iptables
IP6TABLES_BINARY=/sbin/ip6tables
FIRE_HEADER=/usr/lib/fire/fire-header
FIRE_FUNCTIONS=/usr/lib/fire/fire-functions
FIRE_FAILSAFE=/usr/lib/fire/fire-failsafe
BACKUP_DIR=/var/lib/fire
LAST_OK_RULES="$BACKUP_DIR/last_ok_rules"


flag_verbose=no
flag_flush=no
flag_help=no
flag_failsafe=no


source $FIRE_FUNCTIONS


args=`getopt fhsv "$@"`
if test $? != 0 ;then
    print_help
exit 1
fi
set -- $args
                     
while [ $# -gt 0 ]
do
    case "$1" in
    (-v) flag_verbose=yes;;
    (-f) flag_flush=yes;;
    (-h) flag_help=yes;;
    (-s) flag_failsafe=yes;;
#     (-f) flist="$flist $2"; shift;;
    (--) shift; break;;
    (-*) echo "$0: error - unrecognized option $1" 1>&2; print_help;  exit 1;;
    (*)  break;;
    esac
    shift
done

#####################################################################################
# checking opts
#####################################################################################

if [ "$flag_flush" == "yes" ]; then
    echo -n "Flushing all rules: "
    iptables_flush
    echo " OK"
    exit 0
fi

if [ "$flag_help" == "yes" ]; then
    print_help
    exit 0
fi

if [ "$flag_failsafe" == "yes" ]; then
    source $FIRE_FAILSAFE
    exit 0
fi



source $FIRE_HEADER

source $IPTABLES_RULES

source  /usr/lib/fire/fire-footer

