(RADIATOR) Re: hook to update the radpool table when using AddressAllocator SQL

Kwang Moon kwang.moon at O2.com
Fri Feb 6 10:43:45 CST 2004


Hi,

Having trawled through the archives again, I have found the answer:
http://www.open.com.au/archives/radiator/2000-06/msg00023.html

Makes the hook much tidier...

sub {
        my $request             = ${$_[0]};

        # If the packet is an Accounting Alive packet reset the expiry value
in the RADIUS DB for a further 24 hours.
        return unless ($request->code() eq 'Accounting-Request');
        my $statustype = $request->get_attr('Acct-Status-Type');
        return unless ($statustype eq 'Alive');

        my $addralloc_handle    =
Radius::AddressAllocatorGeneric::find('SQLAllocator');
        my $query               = undef;
        my $expiry              = time + 86400;
        my $framedipaddress     = $request->get_attr('Framed-IP-Address');
        my $sth                 = undef;

        $query = "update radpool set expiry=? where yiaddr=?";
        $sth = $addralloc_handle->prepareAndExecute($query, $expiry,
$framedipaddress);
}

Cheers,
Kwang


----- Original Message ----- 
From: "Kwang Moon" <kwang.moon at o2.com>
To: <radiator at open.com.au>
Sent: Friday, February 06, 2004 2:20 PM
Subject: hook to update the radpool table when using AddressAllocator SQL


> Hi,
>
> I'm trying to implement a hook to deal with accounting alive packets - ie
> when an alive packet is received, then update the expiry value in the
> RADPOOL table for a further 24 hours.
>
> This is the hook that I wrote.  It works, but I'm sure there's a better
way
> to do it by accessing the database handle that was opened by the
> AddressAllocator clause rather than opening up and closing down a new sql
> connection each time the hook is fired.
>
> sub {
>         my $request             = ${$_[0]};
>
>         # If the packet is an Accounting Alive packet reset the expiry
value
> in the RADIUS DB for a further 24 hours.
>         return unless ($request->code() eq 'Accounting-Request');
>         my $statustype = $request->get_attr('Acct-Status-Type');
>         return unless ($statustype eq 'Alive');
>
>         my $query               = undef;
>         my $expiry              = time + 86400;
>         my $framedipaddress     = $request->get_attr('Framed-IP-Address');
>         my $sth                 = undef;
>         my $rv                  = undef;
>         my $sess_handle         = DBI->connect("dbi:Oracle:radius", "xxx",
> "xxx", { RaiseError => 1, AutoCommit => 0 });
>
>         $query = "update radpool set expiry=? where yiaddr=?";
>         $sth = $sess_handle->prepare($query);
>         $rv = $sth->execute($expiry, $framedipaddress);
>
>         $sth->finish;
>         $sess_handle->disconnect;
> }
>
> Any suggestions for improvement would be most welcomed.  Thanks in
advance.
>
> Cheers,
> Kwang
>

===
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