#!/bin/sh

if [ -z "$4" ]
then
    echo "Usage: $0 [options] user password server[:port] secret"
    echo "Options: -v       give more verbose output"
    echo "         -chap    perform CHAP authentication instead of PAP"
    exit 1
fi

passattr=User-Password
args=-q

while expr "$1" : "-" >/dev/null
do
    echo arg=$1
    case "$1" in
	-chap) passattr=CHAP-Password ;;
	-v)    args= ;;
    esac
    shift
done

echo rest=$*

cat <<EOF | radclient $args "$3" "$4"
User-Name="$1"
$passattr="$2"
EOF
