[RADIATOR] Using SQL statements inside a PostAuthHook

Thomas Kurian thomas at kccg.com
Thu Mar 28 07:59:09 CDT 2013


Hi Heikki,
I appended the additional config lines you sent me in your reply. But i 
still did not get the desired result. I have included the error logged 
in the log file. Please advice me on how to resolve this error based on 
the updated script.

I also commented out some config lines  in the script file, can you 
please check if these are just unwanted statements which is not required 
for my purpose with the hook.

I just want to check if the user crossed his allocated quota , if yes 
then i need to call the web link containing username.

Also i could not find any prepared statements or quote() to get 
User-Name from a SQL query in the sqlDb.pm file . Can you please point 
out these prepared statements from the file.

Also tell me the syntax for adding additional log() calls._

error log_
Thu Mar 28 09:36:40 2013: DEBUG: AuthBy SQL result: ACCEPT,
Thu Mar 28 09:36:40 2013: DEBUG: Running PostAuthHook: Using Identifier

Thu Mar 28 09:36:40 2013: DEBUG: Query to 'dbi:ODBC:IRONMAN': 'select 
username from quotasubscribers where switched = 0 and type = 'Q' and 
monthlycounter >= maxquota '$
Thu Mar 28 09:36:40 2013: ERR: Error in PostAuthHook(): Can't call 
method "getOneRow" on an undefined value at (eval 53) line 50.
_
__Updated Script_
#! /usr/bin/perl -w
use strict;
use warnings;
use diagnostics;
use URI::Escape ('uri_escape');
require LWP::UserAgent;
sub {

# OBJECT REF

         my $p = ${$_[0]};
         my $r = ${$_[1]};

# RETURN VOID

         return unless ($p->code() eq 'Accounting-Request')
                                 && (${$_[2]} == $main::ACCEPT);

         my $handler             = $p->{Handler};

         my $identifier          = $handler->{thomas};

         &main::log($main::LOG_DEBUG, "Running PostAuthHook: Using 
Identifier
$identifier");

         my $username            =
$p->getAttrByNum($Radius::Radius::USER_NAME);


         my $sess_handle         = Radius::SessGeneric::find($identifier);

         my $query               = undef;
         my $self                = undef;

         #my $rt                  = $p->{RecvTime};

        # my $lower               = 1000;

       #  my $upper               = 2000000;

        # my $random              = int(rand( $upper-$lower+1 ) ) + $lower;

         #my $reallyrandom        = $random.$rt;


                 $query  = "select username from quotasubscribers where 
switched = 0 and type = 'Q' and monthlycounter >= maxquota ";
                 my $sth = $sess_handle->prepareAndExecute($query);
                 my @row = $self->getOneRow($sth);
                 $sth->finish;
                 my $db_user_name = $row[0];

my $ua = LWP::UserAgent->new;
if ( $db_user_name eq  $username )
{my $response = $ua->get('http://94.187.187.8:880/changespeed.aspx?uname=' .
   uri_escape($username) .
   '&pwd=peter'
);
         if ($response->is_success)
         {
          print $response->content; # or whatever
         }
         else
         {
          die $response->status_line;
         }
}

}


-- 
Requesting your kind help & cooperation ,

Thomas Kurian
IT Security Engineer (B.Tech. -- Electrical)
Kuwaiti Canadian Consulting Group (www.kccg.com)
T: +965 22435566
F: +965 22415149
E: thomas at kccg.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.open.com.au/pipermail/radiator/attachments/20130328/5277ce42/attachment-0001.html 


More information about the radiator mailing list