#!/bin/sh
# check_ipv4
# Written by cailiuqing <liuqing.cai@cs2c.com.cn>

PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION="@NP_VERSION@"

. $PROGPATH/utils.sh
print_usage() {
        echo "Usage:"
        echo "  $PROGNAME"
        echo "  $PROGNAME --version"
}

case "$1" in
1)
        cmd='--version'
        ;;
*)
        cmd="$1"
        ;;
esac

# Information options
case "$cmd" in
--version)
        print_revision $PROGNAME $REVISION
        exit $STATE_OK
        ;;
esac

state=0
STAT_VAL=0

# change the way to monitor iptables for bug 20070
# Date:2012-2-21
sudo service iptables status &>/dev/null
ST=$?
if [ $ST -eq 0 ];then
#	echo "I'm here"
        STAT_VAL=1
	#key-key
        #echo "Firewall is running. | status=$STAT_VAL;;;"
        echo "service_firewall_running"
        state=0
elif [ $ST -eq 1 ] || [ $ST -eq 3 ];then
#	echo "iptables does not existed"
        STAT_VAL=0
	#key-key
        #echo "Firewall is stopped or not configured. | status=$STAT_VAL;;;"
        echo "service_firewall_stoppedornotconfigured"
        state=2
else
	#key-key
	#echo "Unknow error."
	echo "service_firewall_unknown_error"
	state=3
fi

#no status
#exit $state

