Online Status with FR & SQL + Simultaneous-Use

Gunther freeradius at caribsms.com
Mon Oct 10 03:52:31 CEST 2005


For those interested, here the solution I am using now:

I am using FR 1.0.5 with MySQL 4.1.10a, PHP and no flat files, except for
the DEFAULT values
and the standard configuration files radiusd.conf, sql.conf (my NAS list is
also
in a SQL table). I also changed most of the SQL column names, by adding a
prefix.
For the examples I changed it back to the original names.

How to get user online status:
==============================
1. Add the TIMESTAMP column to the radacct table
  `radacct_mdate` timestamp NULL default CURRENT_TIMESTAMP on update
CURRENT_TIMESTAMP

2. To get the online status set up a query something like this (using PHP):

define('RAD_ONLINE_TIMEOUT', 15); // 15 min since last timestamp from NAS,
assuming connection dead

$query = "SELECT COUNT(*) FROM radacct WHERE UserName = ' . $username . '
AND AcctStopTime=0 AND DATE_SUB(NOW(),INTERVAL ' . RAD_ONLINE_TIMEOUT .'
MINUTE) <= radacct_mdate ORDER BY AcctStartTime DESC LIMIT 1)";

My actual query is a bit more complicated as I verify against a user table
if they are 
actually allowed to be online ( Starttime < ActualTime < Stoptime)


How to get Simultaneous-Use with FR & MySQL working: 
====================================================
1. I setup my defaults in the raddb/users file (at the very end and nothing
else beside localhost)
   DEFAULT Simultaneous-Use := 1, Auth-Type := SQL (this seems to be the
only way)
        Idle-Timeout = 3600,
        Acct-Interim-Interval = 180
Note: You can override the default Simultaneous-Use attribute for a user or
a group by setting it
in radcheck or radgroupcheck table (groupname Simultaneous-Use := 3).

2. In raddb/radiusd.conf
	Instead of using radutmp, I am using SQL:
	accounting {
		.
		.
		sql
	}
	session {
        	#  See "Simultaneous Use Checking Querie" in sql.conf
        	sql
	}

3. In raddb/sql.conf

simul_count_query = "SELECT COUNT(*) FROM ${acct_table1} WHERE
UserName='%{SQL-User-Name}' AND AcctStopTime=0 AND CallingStationId <>
'%{Calling-Station-Id}' AND DATE_SUB(NOW(),INTERVAL 15 MINUTE) <=
radacct_mdate"

simul_verify_query = "SELECT RadAcctId, AcctSessionId, UserName,
NASIPAddress, NASPortId, FramedIPAddress, CallingStationId, FramedProtocol
FROM ${acct_table1} WHERE UserName='%{SQL-User-Name}' AND AcctStopTime = 0
AND CallingStationId <> '%{Calling-Station-Id}' AND DATE_SUB(NOW(),INTERVAL
15 MINUTE) <= radacct_mdate"


Not sure that this is all 100% like the developers intended it to be, but it
works.

Gunther





More information about the Freeradius-Users mailing list