rlm_perl & %RAD_REPLY issue

Max Lock max at natcom.co.nz
Fri Oct 14 10:39:46 CEST 2005


On Fri, 2005-10-14 at 09:48 +0300, Boyan Jordanov wrote:
> On Thursday 13 October 2005 21:55, Max Lock wrote:
> > that's what I'm trying to do.
> >
> > sub authorize {
> 
> Maybe you need authenticate instead of authorize ?
> Read docs/aaa.txt
> 

 thanks Boyan,

 I realised that I'd accidently removed the var mappings for the return
states RLM_MODULE... now it's all working fine, and the debug shows the
vars I need going out..

 just for the record, if anyone wants to limit a users data traffic
here's some code, GPL applies as of current date...

 -Cheers Max.

use DBI;
use vars qw(%RAD_REQUEST %RAD_REPLY %RAD_CHECK);
use Data::Dumper;

#
# This the remaping of return values
#
        use constant    RLM_MODULE_REJECT=>    0;#  /* immediately
reject the request */
        use constant    RLM_MODULE_FAIL=>      1;#  /* module failed,
don't reply */
        use constant    RLM_MODULE_OK=>        2;#  /* the module is OK,
continue */
        use constant    RLM_MODULE_HANDLED=>   3;#  /* the module
handled the request, so stop. */
        use constant    RLM_MODULE_INVALID=>   4;#  /* the module
considers the request invalid. */
        use constant    RLM_MODULE_USERLOCK=>  5;#  /* reject the
request (user is locked out) */
        use constant    RLM_MODULE_NOTFOUND=>  6;#  /* user not found */
        use constant    RLM_MODULE_NOOP=>      7;#  /* module succeeded
without doing anything */
        use constant    RLM_MODULE_UPDATED=>   8;#  /* OK (pairs
modified) */
        use constant    RLM_MODULE_NUMCODES=>  9;#  /* How many return
codes there are */

sub authorize {
        my $used_user_octets =
&get_used_octets($RAD_REQUEST{'Stripped-User-Name'});
        if (!$used_user_octets) { $used_user_octets = 0};
        if (!$RAD_CHECK{'Max-All-Session-Data'}){
                $unused_user_octets =
($RAD_CHECK{'Max-Daily-Session-Data'} - $used_user_octets);
        }else{
                $unused_user_octets =
($RAD_CHECK{'Max-All-Session-Data'} - $used_user_octets);
        }
        &radiusd::radlog(1,"Voucher:$RAD_REQUEST{'Stripped-User-Name'}
Used:$used_user_octets Total:$RAD_CHECK{'Max-Daily-Session-Data'} Left:
$unused_user_octets");
        $RAD_REPLY{'ChilliSpot-Max-Total-Octets'} = $unused_user_octets;
        return RLM_MODULE_OK;
}

sub get_used_octets() {
        my $username = shift(@_);
        # get octets used from sql DB
        $dbuser = "freeradius";
        $dbpassword = "yourpasswordhere";
        $dbdatabase = "freeradius";
        $dbhost = "localhost";
        my $dsn = "DBI:mysql:database=$dbdatabase;host=$dbhost";
        my $dbh = DBI->connect($dsn, $dbuser, $dbpassword);
        my $octets_used_sql = "SELECT SUM(AcctInputOctets) +
SUM(AcctOutputOctets) FROM radacct WHERE UserName='".$username."'";
        my $sth = $dbh->prepare($octets_used_sql);
        $sth->execute;
        my @results = $sth->fetchrow_array;
        my $used_user_octets = $results[0];
        $sth->finish();
        $dbh->disconnect();
        return $used_user_octets;
}

 




More information about the Freeradius-Users mailing list