#!/bin/sh /etc/rc.common
START=99
EXTRA_COMMANDS="status"
EXTRA_HELP="        status Print the status of the service"

export PATH=/usr/bin:/usr/sbin:/bin:/sbin
export HOME=$(grep -e "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6)
export HOME=${HOME:-/root}
export PS1='\u@\h:\w\$ '
export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/tmp/ram_root/usr/sbin:/tmp/ram_root/usr/bin
export LD_LIBRARY_PATH=/lib:/usr/lib:/tmp/ram_root/lib:/tmp/ram_root/usr/lib


[ -x /bin/more ] || alias more=less
[ -x /usr/bin/vim ] && alias vi=vim || alias vim=vi

[ -z "$KSH_VERSION" -o \! -s /etc/mkshrc ] || . /etc/mkshrc

[ -x /usr/bin/arp ] || arp() { cat /proc/net/arp; }
[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }

start() {
	ifconfig mon0 > /dev/null 2> /dev/null
	if [ $? -ne 0 ] 	
	then
		airmon-ng start wlan0
	fi
	tcpdump -i mon0 -e type mgt subtype probe-req | /usr/local/allshoppings-cportal/aspcap &
	# tcpdump -B 128 -i mon0 -s0 -nn -vv -t | grep RA: | /usr/local/allshoppings-cportal/aspcap &
}

stop() {
	echo "stoping as-mac-capture"
	killall -9 aspcap 2> /dev/null
	killall -9 tcpdump 2> /dev/null
}

status() {
	ifconfig mon0 > /dev/null 2> /dev/null
	if [ $? -ne 0 ]; then 
                echo "as-mac-capture is Stopped"
                exit 1                  
	else
		pgrep tcpdump
		if [ $? -ne 0 ]; then
			echo "as-mac-capture is Stopped"
			exit 1
		else
			pgrep aspcap
			if [ $? -ne 0 ]; then
                        	echo "as-mac-capture is Stopped"
                        	exit 1                          
			else
				echo "as-mac-capture is Running"
			fi
		fi
	fi
}

restart() {
	echo "restarting as-mac-capture"
	stop
	sleep 2
	start
}

reload() {
        ifconfig mon0 > /dev/null 2> /dev/null
        if [ $? -ne 0 ]; then
		restart
	else
		pgrep tcpdump
	        if [ $? -ne 0 ]; then
			restart
		else
			pgrep aspcap
			if [ $? -ne 0 ]; then
				restart
			else
				echo "no need to reload"
			fi
		fi
	fi
}
