#!/bin/sh
#
# very simple reload-example for the new chargemax feature of isdnlog
# this is called by isdnlog every time we get a AOCD and chargesum of
# active device is greater then CHARGEMAX.
# there are three parameter available:
#
#  first ($1) is chargesum-CHARGEMAX
# second ($2) is ALIAS as defined in ISDNLOG.CONF
#  third ($3) is total chargesum for active device
#

nbeep() {
	local n=$1
	while [ $n -gt 0 ]; do
		echo "" >> /dev/console
		sleep 1
		n=$(($n - 1))
	done
}

case "$1" in
0\.* | 1\.* )
        echo "WARNING, charge-limit set by CHARGEMAX is reached!" >> /dev/console
        echo "$2 is talking to much!" >> /dev/console
        nbeep 2
        ;;

2\.* )
        echo "WARNING, $2 got charge-overflow == $1, total chargesum == $3" >> /dev/console
        echo "next chargeint will cause i4l to stop" >> /dev/console
	nbeep 3
        ;;

3\.* | 4\.* )
        echo "reload got charge-overflow == $1, now i4l will be stopped!" >> /dev/console
	nbeep 5
        /etc/init.d/network stop -o type=ippp
	/etc/init.d/network stop -o type=isdn
        ;;

5\.* | 6\.* )
        echo "aeh, still alive?! so we'll do a reboot!!" >> /dev/console
	nbeep 10
        /sbin/reboot
        ;;
esac

echo "got charge_ov=$1 dev=$2 scharge=$3 " >> /dev/console
