Added -t option
[freeradius.git] / src / main / radtest.in
1 #! /bin/sh
2 #
3 # radtest       Emulate the user interface of the old
4 #               radtest that used to be part of FreeRADIUS.
5 #
6 # Version:      $Id$
7 #
8
9 prefix="@prefix@"
10 exec_prefix="@exec_prefix@"
11 bindir="@bindir@"
12
13 usage() {
14         echo "Usage: radtest [OPTIONS] user passwd radius-server[:port] nas-port-number secret [ppphint] [nasname]" >&2
15         echo "        -d RADIUS_DIR       Set radius directory" >&2
16         echo "        -t pap/chap/mschap  Set authentication method" >&2
17         echo "        -x                  Enable debug output" >&2
18         exit 1
19 }
20
21 radclient=$bindir/radclient
22 if [ ! -x "$radclient" ] && [ -x ./radclient ]
23 then
24         radclient=./radclient
25 fi
26
27 OPTIONS=
28 PASSWORD="User-Password"
29
30 #  We need at LEAST these many options
31 if [ $# -lt 5 ] || [ $# -gt 7 ]
32 then
33         usage
34 fi
35
36 # Parse new command-line options
37 while [ `echo "$1" | cut -c 1` = "-" ]
38 do
39    case "$1" in
40         -d) 
41                 OPTIONS="$OPTIONS -d $2"
42                 shift;shift
43                 ;;
44         -x)
45                 OPTIONS="$OPTIONS -x"
46                 shift
47                 ;;
48
49         -t)
50                 shift;
51                 case "$1" in
52                         pap)
53                                 PASSWORD="User-Password"
54                                 ;;
55                         chap)
56                                 PASSWORD="CHAP-Password"
57                                 ;;
58                         mschap)
59                                 PASSWORD="MS-CHAP-Password"
60                                 ;;
61                         *)
62                                 usage
63                                 ;;
64                 esac
65                 shift
66                 ;;
67
68         *)
69                 usage
70                 ;;
71   esac
72 done
73
74 # Check that there are enough options left over.
75 if [ $# -lt 5 ] || [ $# -gt 7 ]
76 then
77         usage
78 fi
79
80 if [ "$7" ]
81 then
82         nas=$7
83 else
84         nas=`hostname`
85 fi
86
87 (
88         echo "User-Name = \"$1\""
89         echo "$PASSWORD = \"$2\""
90         echo "NAS-IP-Address = $nas"
91         echo "NAS-Port = $4"
92         if [ "$6" ]
93         then
94                 echo "Framed-Protocol = PPP"
95         fi
96 ) | $radclient $OPTIONS -x $3 auth $5
97
98 exit $?