#!/bin/sh

RUN_DIR=/var/run
AWK=/bin/awk
GREP=/bin/grep
ROUTE=/sbin/route
KILL=/bin/kill

. katrin-functions

function usage() {
	traff_usage
}

init_and_validate "$@"
if [ "$abonent" = "client" ]; then
	validate_ip "$ip"
	IP=$ip
	PPP_ID=`$ROUTE -n | $GREP $IP | $AWK {'print $8'}`
	if [ "x$PPP_ID" = "x" ]; then
		echo "Can't find ppp process with $IP ip address" >&2
		exit 1
	fi
	PID_FILE="$RUN_DIR/$PPP_ID.pid"

	PPP_PID=`sed 's/ //g' $PID_FILE`

	$KILL $PPP_PID
	sleep 5
	$KILL -TERM $PPP_PID

	rm -f $PID_FILE > /dev/null

	mailto_client "disabled"
else
	mailto_clientgroup "Traff" "disabled"
fi

