2 ######################################################################
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 # Copyright (C) 2009 Network RADIUS SARL <info@networkradius.com>
20 ######################################################################
22 # This script assumes that "radmin" is in PATH, and that the user
23 # running this script has permission to connect to the radmin socket,
24 # and to read/write files in the "logdir" directory. If none of this is
25 # true, then it won't work.
27 # Usage: raddebug [-c condition] [-i client-ip-address] [-I client-ipv6-address] [-f socket_file] [-t timeout] [-u username]
32 printf "Usage: %s: [-c condition] [-d directory] [-n name] [-D dictdir] [-i client-ip-address] [-I client-ipv6-address] [-f socket_file] [-t timeout] [-u user]\n" $(basename $0) >&2
39 while getopts 'd:n:D:c:i:I:f:t:u:' OPTION
42 c) condition="$OPTARG"
44 d) extra="$extra -d $OPTARG"
46 n) extra="$extra -n $OPTARG"
48 D) extra="$extra -D $OPTARG"
50 i) x="(Packet-Src-IP-Address == $OPTARG)"
51 if [ "$condition" = "" ]; then
54 condition="$condition && $x"
57 I) x="(Packet-Src-IPv6-Address == $OPTARG)"
58 if [ "$condition" = "" ]; then
61 condition="$condition && $x"
64 f) extra="$extra -f $OPTARG"
67 [ "$timeout" = "0" ] && timeout=1000000
69 u) x="(User-Name == '$OPTARG')"
70 if [ "$condition" = "" ]; then
73 condition="$condition && $x"
80 shift $(($OPTIND - 1))
82 radmin="radmin $extra"
85 # Start off by turning off debugging.
86 # If there's a problem, die.
88 $radmin -e "debug condition"
89 if [ "$?" != "0" ]; then
94 # Debug to a file, and then tell us where the file is.
96 outfile=`$radmin -e "debug file radmin.debug.$$" -e "show debug file"`
97 group=`$radmin -e "debug file radmin.debug.$$" -e "show config security.group"`
100 # If there was an error setting the debug output, re-set the
101 # debug condition, echo the error, and exit.
103 echo $outfile | grep 'ERROR' >/dev/null 2>&1
104 if [ "$?" = "0" ]; then
105 $radmin -e "debug condition"
111 # Truncate the file, and ensure it's writable by radiusd
113 cp /dev/null $outfile
114 [ "$group" != "" ] && chgrp $group $outfile
120 # Set the trap to clean up on exit and any interrupts.
122 trap '$radmin -e "debug condition" -e "debug file"; rm -f $outfile;kill -TERM $TAILPID;exit 0' 1 2 15
125 # Set the debug condition
127 $radmin -e "debug condition \"$condition\"" | grep -I 'error'
128 if [ $? -eq 0 ]; then
133 # Print the output, and wait for "timeout". Then, stop printing.
139 $radmin -e "debug condition" -e "debug file"