[RADIATOR] Missing Session Accounting

Heikki Vatiainen hvn at open.com.au
Thu Sep 11 08:28:02 CDT 2014


On 09/10/2014 05:16 PM, Christopher Bland wrote:

> I recently change a postauthhook to do cleanup of the RADONLINE session table and have lost users sessions.  I added the following 

Hello Chris,

I suggest a couple of small changes plus some debugging. Please see
below for more:

>     my $username = $p->getAttrByNum($Radius::Radius::USER_NAME);
>     my $now = &Radius::Util::format_special('%t', $p);

You can remove the line above.

>     if ($result == $main::ACCEPT) {
> 
>        my $dbhandler = DBI->connect ($dsn,$dbuser,$dbpasswd) || die "Error opening database: $DBI::errstr\n";
>        my $yesterday = $now - 86400;

my $yesterday = time() - 86400;

This should be the shortest way to get yesterday's timestamp.

>        # Build insert sql

$username = $dbhandler->quote($username);

Username is typically user input, so it should be handled with care.

>        $sql = "delete from RADONLINE where USERNAME='$username' and TIME_STAMP < $yesterday";

main::log($main::LOG_INFO, 'SQL query is: $sql");

This should show what the query will look like.

>        # Execute RADONLINE cleanup and disconnect from db
>        my $radonlinecleanup = $dbhandler->prepare($sql);
>        $radonlinecleanup->execute;
>        $radonlinecleanup->finish;
> 
>        $dbhandler->disconnect;
>    }

A further modification might be to do something like this:
  my $authby = Radius::AuthGeneric::find($identifier);

to get a handle on an AuthBy SQL or some other clause that is already
configured to use the database your hook uses. You could then do
$authby->prepareAndExecute(...) etc. See goodies/lookupauthgroup.pl and
how $sqlclause is used.

> Since putting this in user sessions are not being added even though only session older than 24 hours are getting deleted.

The extra debugging might help to tell what's happening.

Thanks,
Heikki

-- 
Heikki Vatiainen <hvn at open.com.au>

Radiator: the most portable, flexible and configurable RADIUS server
anywhere. SQL, proxy, DBM, files, LDAP, NIS+, password, NT, Emerald,
Platypus, Freeside, TACACS+, PAM, external, Active Directory, EAP, TLS,
TTLS, PEAP, TNC, WiMAX, RSA, Vasco, Yubikey, MOTP, HOTP, TOTP,
DIAMETER etc. Full source on Unix, Windows, MacOSX, Solaris, VMS,
NetWare etc.


More information about the radiator mailing list