#!/bin/sh

. /etc/PG.conf
FLOWEYE=/usr/ramdisk/bin/floweye
MONITOR="/usr/ramdisk/app/ipdb/ipdb_monitor"


ipdb_status()
{
	curver=`${FLOWEYE} ipdb stat | grep "^version=" | cut -d'=' -f2`
	if [ "${curver}" = "NULL" ]; then
		echo "disable"
	else
		echo "enable"
	fi
}


ipdb_start()
{
	mkdir -p /usr/ramdisk/admin/cgi-bin/App/ipdb
	cp -f ${PGPATH}/app/ipdb/webmain /usr/ramdisk/admin/cgi-bin/App/ipdb/
	cp -f ${PGPATH}/app/ipdb/update /usr/ramdisk/admin/cgi-bin/App/ipdb/

	if [ -e ${PGETC}/ip.dat ]; then
		errmsg=`${FLOWEYE} ipdb load file=${PGETC}/ip.dat`
	fi

	ipdb_stop
	chmod +x ${MONITOR}
	${MONITOR} >/dev/null 2>&1 &
}


ipdb_stop()
{
	pid=`ps -ax | grep "ipdb_monitor" | grep -v grep | awk '{print $1}'`
	kill -9 ${pid} >/dev/null 2>&1 &
}


case "$1" in 
"start")
	ipdb_start	
	;;

"status")
	ipdb_status
	;;

"stop")
	ipdb_stop
	;;

"enable")
	;;

"disable")
	;;

"unload")
	;;

*)
	echo "unknown action!"
	;;
esac

