#! /bin/sh
#
# radtest	Emulate the user interface of the old
#		radtest that used to be part of FreeRADIUS.
#
# Version:	$Id$
#

prefix="@prefix@"
exec_prefix="@exec_prefix@"
bindir="@bindir@"

usage() {
	echo "Usage: radtest user passwd radius-server[:port] nas-port-number secret [ppphint] [nasname]" >&2
	exit 1
}

radclient=$bindir/radclient
if [ ! -x "$radclient" ] && [ -x ./radclient ]
then
	radclient=./radclient
fi

if [ "$1" = "-d" ]
then
    DICTIONARY="-d $2"
    shift;shift
else
    DICTIONARY=""
fi

if [ $# -lt 5 ] || [ $# -gt 7 ]
then
	usage
fi

if [ "$7" ]
then
	nas=$7
else
	nas=`hostname`
fi

(
	echo "User-Name = \"$1\""
	echo "User-Password = \"$2\""
	echo "NAS-IP-Address = $nas"
	echo "NAS-Port = $4"
	if [ "$6" ]
	then
		echo "Framed-Protocol = PPP"
	fi
) | $radclient $DICTIONARY -x $3 auth $5

