(RADIATOR) PreAuthHook problem

Ganbold ganbold at micom.mng.net
Thu Dec 12 03:29:12 CST 2002


Hi,

I'm having trouble to make PreAuthHook work. It seems like not working and 
I don't see any problem with PreAuthHook file.

Ganbold

Following is the hook file and config file.
---------------------------------------------------------------------------------------------------------------------------------------------------
sub
{
     use Time::Local;
     use DBI;

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

     my $user_name = $p->get_attr('User-Name');

     my ($dsn)="DBI:mysql:radius:202.179.0.140";
     my ($namex)="admin";
     my ($dbh,$sth);

     $dbh=DBI->connect($dsn,$namex,"wcup\#02\$",{RaiseError=>1});


     if($p->code eq 'Accounting-Request'){

         if ($p->get_attr('Acct-Status-Type') eq 'Stop')
         {
             my $session_time = $p->get_attr('Acct-Session-Time') + 0;
             my $time_stamp = $p->{RecvTime} - int 
$p->get_attr('Acct-Delay-Time');
             my $duration = $session_time;


                 my ($rduration, $i);
                 my ($start_stamp);

                 my ($start_hour,$end_hour);
                 my ($start_day, $end_day);

                 my 
($s_tstamp_at_0,$s_tstamp_at_7,$e_tstamp_at_0,$e_tstamp_at_7);

                 my ($diff, $day_diff, @numDays, $thismonth);
                 my ($sec,$min,$hour,$mday,$mon,$wday,$yday,$isdst,$year);

                 $rduration = 0;

                 $start_stamp = $time_stamp - $duration;

                 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = 
localtime($start_stamp);
                 $s_tstamp_at_0 = timelocal(0,0,0,$mday,$mon,$year);
                 $s_tstamp_at_7 = timelocal(0,0,7,$mday,$mon,$year);

                 for($i=0; $i<12; $i += 2){
                         $numDays[$i] = 31;
                 }
                 for($i=1; $i<12; $i += 2){
                         $numDays[$i] = 30;
                 }

                 if(($year % 4) != 0){
                         $numDays[1] = 28;
                 }elsif(($year % 400) == 0){
                         $numDays[1] = 29;
                 }elsif(($year % 100) == 0){
                         $numDays[1] = 28;
                 }else{
                         $numDays[1] = 29;
                 }
                 $thismonth = $mon;

                 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = 
localtime($time_stamp);
                 $e_tstamp_at_0 = timelocal(0,0,0,$mday,$mon,$year);
                 $e_tstamp_at_7 = timelocal(0,0,7,$mday,$mon,$year);

                 ($sec,$min,$start_hour,$start_day,$mon,$year,$wday,$yday,$isdst) 
= localtime($start_stamp);
                 ($sec,$min,$end_hour,$end_day,$mon,$year,$wday,$yday,$isdst) 
= localtime($time_stamp);


                 $diff = int $duration/86400;    # how many day's 
connection continued

                 if($end_day < $start_day){
                         $day_diff = $numDays[$thismonth] - $start_day + 
$end_day;
                 }else{
                         $day_diff = $end_day - $start_day;
                 }
                 if($start_hour >= 0 && $start_hour < 7){

                         if($end_hour >= 0 && $end_hour < 7){

                                 if($day_diff > 0){
                 $rduration = $duration - ($s_tstamp_at_7 - $start_stamp) - 
($diff * 25200) - ($time_stamp - $e_tstamp_at_0);
                                 }else{
                                         $rduration = 0;
                                 }
                         }elsif($end_hour >= 7 && $end_hour <= 23){

                                 $rduration = $duration - ($s_tstamp_at_7 - 
$start_stamp) - ($diff * 25200);
                         }
                 }elsif($start_hour >= 7 && $start_hour <= 23){

                         if($end_hour >= 7 && $end_hour <= 23){
                                 $rduration = $duration - ($day_diff * 25200);

                         }elsif($end_hour >= 0 && $end_hour < 7){
                                 $rduration = $duration - ($time_stamp - 
$e_tstamp_at_0) - ($diff * 25200);
                         }
                 }



             print "User: $user_name, Duration: $duration, Real duration: 
$rduration\n";
             &main::log($main::LOG_DEBUG, "Time calculated! Duration: 
$duration, Real duration: $rduration");

             ${$_[0]}->add_attr('Real-Time-Used',$rduration);

#           my ($sth)=$dbh->prepare (qq{update SUBSCRIBERS set TIMELEFT = 
(TIMELEFT - $rduration) where USERNAME = '$user_name and PREPAID='YES'});
#           $sth->execute();

         }
     }
}

Config file:
----------------------------------------------------------------------------------------------------------------------------------------------------

  . . . .
<AuthBy SQL>
         DBSource        dbi:mysql:radius:202.179.0.140
         DBUsername      admin
         DBAuth          wcup#02$

         Identifier SQLAcctOnly

         AuthSelect

         AccountingTable ACCOUNTING
         HandleAcctStatusTypes   Stop

         AcctColumnDef   USERNAME,User-Name
         AcctColumnDef   TIME_STAMP,Timestamp,integer
         AcctColumnDef   ACCTSTATUSTYPE,Acct-Status-Type
         AcctColumnDef   ACCTDELAYTIME,Acct-Delay-Time,integer
         AcctColumnDef   ACCTINPUTOCTETS,Acct-Input-Octets,integer
         AcctColumnDef   ACCTOUTPUTOCTETS,Acct-Output-Octets,integer
         AcctColumnDef   ACCTSESSIONID,Acct-Session-Id
         AcctColumnDef   ACCTSESSIONTIME,Acct-Session-Time,integer
         AcctColumnDef   ACCTTERMINATECAUSE,Acct-Terminate-Cause
         AcctColumnDef   NASIDENTIFIER,NAS-Identifier
         AcctColumnDef   NASPORT,NAS-Port
         AcctColumnDef   FRAMEDIPADDRESS,Framed-IP-Address
         AcctColumnDef   CALLINGSTATIONID,Calling-Station-Id
         AcctColumnDef 
class_id,Class,literal,substring('%{Class}',1,locate(':','%{Class}')-1)
         AcctColumnDef 
CONTRACTID,Class,literal,substring('%{Class}',locate(':','%{Class}')+1)
         AcctColumnDef   TIME_USED,Real-Time-Used,integer

</AuthBy>

. . .

<Handler Time = "Al0700-2359", Request-Type = Accounting-Request>
         AuthByPolicy ContinueAlways
         AuthBy SQLAdjustTimeleft
</Handler>


<Handler Time = "Al0700-2359", NAS-IP-Address = 202.179.0.135>
         RewriteUsername s/^([^@]+).*/$1/
         RejectHasReason
         AccountingHandled
         SessionDatabase SQL1
         PreAuthHook file:"/usr/local/Radiator-3.3.1/CalculateTimeUsed"
         AuthByPolicy ContinueUntilAccept
         AuthBy CiscoAdjustAuthOnly
         PostAuthHook file:"/usr/local/Radiator-3.3.1/CheckBlockTimeLeft"
</Handler>


===
Archive at http://www.open.com.au/archives/radiator/
Announcements on radiator-announce at open.com.au
To unsubscribe, email 'majordomo at open.com.au' with
'unsubscribe radiator' in the body of the message.


More information about the radiator mailing list