#!/bin/sh

if [ -z "$3" ]
then
    echo "Usage:   $0 [options] user server[:port] secret"
    echo "         [nas-port [dnis [cli [ppphint [nasip [nasid]]]]]]"
    echo
    echo "Options: -v               more verbose output"
    echo "         -start           send Accounting-Start instead of -Stop"
    echo "         -time seconds    include Acct-Session-Time"
    exit 1
fi

args=-nq
type=Stop
while expr "$1" : "-" >/dev/null
do
    case "$1" in
	-v)     args= ;;
	-time)  time="$2" ; shift ;;
	-start) type=Start ;;
    esac
    shift
done

dir=`dirname $0`
(
    echo User-Name=\""$1"\"
    echo Acct-Session-Id=$$
    echo Acct-Status-Type="$type"
    [ "$time" ] && echo Acct-Session-Time="$time"
    [ "$4" ] && echo NAS-Port=$4
    [ "$5" ] && echo Called-Station-Id=\""$5"\"
    [ "$6" ] && echo Calling-Station-Id=\""$6"\"
    [ "$7" ] && echo Service-Type=Framed && echo Framed-Protocol=PPP
    [ "$8" ] && echo NAS-IP-Address=$8
    [ "$9" ] && echo NAS-Identifier=\""$9"\"
) | $dir/radclient -a $args "$2" "$3"

