]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Use Event-Timestamp for MySQL and remove acctdelay columns.
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 18 Jul 2012 21:43:28 +0000 (22:43 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 18 Jul 2012 21:46:13 +0000 (22:46 +0100)
Store acctupdate and use it to calculate acctinterval (this helps with dead session detection).

Remove xascendsession column, its dumb having vendor specific stuff in the default schema.

Add unique index constraint on acctuniqueid so that the alternate query fires correctly.

raddb/sql/mysql/dialup.conf
raddb/sql/mysql/schema.sql

index 09733ca69976d92716cffcdf5a66d6de285f781f..28900fd190f66abb3b367bc0a0ef52456248f3e1 100644 (file)
        #safe-characters = "@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /"
 
        #######################################################################
-        #  Connection config
-        #######################################################################
-        # The character set is not configurable. The default character set of
-        # the mysql client library is used. To control the character set,
-        # create/edit my.cnf (typically in /etc/mysql/my.cnf or /etc/my.cnf)
-        # and enter
-        # [client]
-        # default-character-set           = utf8
-        #
+       #  Connection config
+       #######################################################################
+       # The character set is not configurable. The default character set of
+       # the mysql client library is used. To control the character set,
+       # create/edit my.cnf (typically in /etc/mysql/my.cnf or /etc/my.cnf)
+       # and enter
+       # [client]
+       # default-character-set = utf8
+       #
 
-       #######################################################################
+       #######################################################################
        #  Query config:  Username
        #######################################################################
        # This is the username that will get substituted, escaped, and added
        accounting_onoff_query = " \
        UPDATE ${acct_table1} \
        SET \
-               acctstoptime    = '%S', \
-               acctsessiontime = unix_timestamp('%S') - \
-                       unix_timestamp(acctstarttime), \
+               acctstoptime    = FROM_UNIXTIME(%{Event-Timestamp}), \
+               acctsessiontime = '%{Event-Timestamp}' \
+                       - UNIX_TIMESTAMP(acctstarttime), \
                acctterminatecause = '%{Acct-Terminate-Cause}', \
-               acctstopdelay   = %{%{Acct-Delay-Time}:-0} \
        WHERE acctstoptime IS NULL \
        AND nasipaddress        = '%{NAS-IP-Address}' \
        AND acctstarttime       <= '%S'"
        accounting_update_query = " \
        UPDATE ${acct_table1} \
        SET \
+               acctupdatetime  = (@acctupdatetime_old:=acctupdatetime), \
+               acctupdatetime  = FROM_UNIXTIME(%{Event-Timestamp}), \
+               acctinterval    = \
+                       %{Event-Timestamp} - UNIX_TIMESTAMP(@acctupdatetime_old), \
                framedipaddress = '%{Framed-IP-Address}', \
                acctsessiontime = '%{Acct-Session-Time}', \
                acctinputoctets = '%{%{Acct-Input-Gigawords}:-0}' << 32 | \
        accounting_update_query_alt = " \
        INSERT INTO ${acct_table1} \
                (acctsessionid,         acctuniqueid,           username, \
-               realm,                  nasipaddress,           nasportid, \
-               nasporttype,            acctstarttime,          acctsessiontime, \
-               acctauthentic,          connectinfo_start,      acctinputoctets, \
-               acctoutputoctets,       calledstationid,        callingstationid, \
-               servicetype,            framedprotocol,         framedipaddress, \
-               acctstartdelay,         xascendsessionsvrkey) \
+               realm,                          nasipaddress,           nasportid, \
+               nasporttype,            acctstarttime,          acctupdatetime, \
+               acctsessiontime,        acctauthentic,          connectinfo_start, \
+               acctinputoctets,        acctoutputoctets,       calledstationid, \
+               callingstationid,       servicetype,            framedprotocol, \
+               framedipaddress) \
        VALUES \
                ('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', \
                '%{SQL-User-Name}', \
                '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', \
                '%{NAS-Port-Type}', \
-               DATE_SUB('%S', \
-                       INTERVAL (%{%{Acct-Session-Time}:-0} + \
-                               %{%{Acct-Delay-Time}:-0}) SECOND), \
-                       '%{Acct-Session-Time}', \
+               FROM_UNIXTIME(%{Event-Timestamp} - \
+                       %{%{Acct-Session-Time}:-0}), \
+               FROM_UNIXTIME(%{Event-Timestamp}), \
+               '%{Acct-Session-Time}', \
                '%{Acct-Authentic}', '', \
                '%{%{Acct-Input-Gigawords}:-0}' << 32 | \
                '%{%{Acct-Input-Octets}:-0}', \
                '%{%{Acct-Output-Octets}:-0}', \
                '%{Called-Station-Id}', '%{Calling-Station-Id}', \
                '%{Service-Type}', '%{Framed-Protocol}', \
-               '%{Framed-IP-Address}', \
-               '0', '%{X-Ascend-Session-Svr-Key}')"
+               '%{Framed-IP-Address}')"
 
        accounting_start_query = " \
        INSERT INTO ${acct_table1} \
                (acctsessionid,         acctuniqueid,           username, \
-               realm,                  nasipaddress,           nasportid, \
-               nasporttype,            acctstarttime,          acctstoptime, \
-               acctsessiontime,        acctauthentic,          connectinfo_start, \
-               connectinfo_stop,       acctinputoctets,        acctoutputoctets, \
-               calledstationid,        callingstationid,       acctterminatecause, \
-               servicetype,            framedprotocol,         framedipaddress, \
-               acctstartdelay,         acctstopdelay,          xascendsessionsvrkey) \
+               realm,                          nasipaddress,           nasportid, \
+               nasporttype,            acctstarttime,          acctupdatetime, \
+               acctstoptime,           acctsessiontime,        acctauthentic, \
+               connectinfo_start,      connectinfo_stop,       acctinputoctets, \
+               acctoutputoctets,       calledstationid,        callingstationid, \
+               acctterminatecause,     servicetype,            framedprotocol, \
+               framedipaddress) \
        VALUES \
                ('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', \
                '%{SQL-User-Name}', \
                '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', \
-               '%{NAS-Port-Type}', '%S', NULL, \
-               '0', '%{Acct-Authentic}', '%{Connect-Info}', \
-               '', '0', '0', \
-               '%{Called-Station-Id}', '%{Calling-Station-Id}', '', \
-               '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}', \
-               '%{%{Acct-Delay-Time}:-0}', '0', '%{X-Ascend-Session-Svr-Key}')"
+               '%{NAS-Port-Type}', \
+               FROM_UNIXTIME(%{Event-Timestamp}), \
+               FROM_UNIXTIME(%{Event-Timestamp}), \
+               NULL, '0', '%{Acct-Authentic}', \
+               '%{Connect-Info}', '', '0', \
+               '0', '%{Called-Station-Id}', '%{Calling-Station-Id}', \
+               '', '%{Service-Type}', '%{Framed-Protocol}', \
+               '%{Framed-IP-Address}')"
 
        accounting_start_query_alt = " \
        UPDATE ${acct_table1} SET \
-               acctstarttime   = '%S', \
-               acctstartdelay  = '%{%{Acct-Delay-Time}:-0}', \
+               acctstarttime   = FROM_UNIXTIME(%{Event-Timestamp}), \
+               acctupdatetime  = FROM_UNIXTIME(%{Event-Timestamp}), \
                connectinfo_start = '%{Connect-Info}' \
        WHERE acctsessionid     = '%{Acct-Session-Id}' \
        AND username            = '%{SQL-User-Name}' \
 
        accounting_stop_query = " \
        UPDATE ${acct_table2} SET \
-               acctstoptime    = '%S', \
+               acctstoptime    = FROM_UNIXTIME(%{Event-Timestamp}), \
                acctsessiontime = '%{Acct-Session-Time}', \
                acctinputoctets = '%{%{Acct-Input-Gigawords}:-0}' << 32 | \
                        '%{%{Acct-Input-Octets}:-0}', \
                acctoutputoctets = '%{%{Acct-Output-Gigawords}:-0}' << 32 | \
                        '%{%{Acct-Output-Octets}:-0}', \
                acctterminatecause = '%{Acct-Terminate-Cause}', \
-               acctstopdelay   = '%{%{Acct-Delay-Time}:-0}', \
                connectinfo_stop = '%{Connect-Info}' \
        WHERE acctsessionid     = '%{Acct-Session-Id}' \
        AND username            = '%{SQL-User-Name}' \
        accounting_stop_query_alt = " \
        INSERT INTO ${acct_table2} \
                (acctsessionid,         acctuniqueid,           username, \
-               realm,                  nasipaddress,           nasportid, \
-               nasporttype,            acctstarttime,          acctstoptime, \
-               acctsessiontime,        acctauthentic,          connectinfo_start, \
-               connectinfo_stop,       acctinputoctets,        acctoutputoctets, \
-               calledstationid,        callingstationid,       acctterminatecause, \
-               servicetype,            framedprotocol,         framedipaddress, \
-               acctstartdelay,         acctstopdelay) \
+               realm,                          nasipaddress,           nasportid, \
+               nasporttype,            acctstarttime,          acctupdatetime, \
+               acctstoptime,           acctsessiontime,        acctauthentic,  \
+               connectinfo_start,      connectinfo_stop,       acctinputoctets, \
+               acctoutputoctets,       calledstationid,        callingstationid, \
+               acctterminatecause,     servicetype,            framedprotocol, \
+               framedipaddress) \
        VALUES \
                ('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', \
                '%{SQL-User-Name}', \
                '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', \
                '%{NAS-Port-Type}', \
-               DATE_SUB('%S', \
-               INTERVAL (%{%{Acct-Session-Time}:-0} + \
-               %{%{Acct-Delay-Time}:-0}) SECOND), \
-               '%S', '%{Acct-Session-Time}', '%{Acct-Authentic}', '', \
+               FROM_UNIXTIME(%{Event-Timestamp} - \
+                       %{%{Acct-Session-Time}:-0}), \
+               FROM_UNIXTIME(%{Event-Timestamp}), \
+               FROM_UNIXTIME(%{Event-Timestamp}), \
+               '%{Acct-Session-Time}', '%{Acct-Authentic}', '', \
                '%{Connect-Info}', \
                '%{%{Acct-Input-Gigawords}:-0}' << 32 | \
                '%{%{Acct-Input-Octets}:-0}', \
                '%{%{Acct-Output-Octets}:-0}', \
                '%{Called-Station-Id}', '%{Calling-Station-Id}', \
                '%{Acct-Terminate-Cause}', \
-               '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}', \
-               '0', '%{%{Acct-Delay-Time}:-0}')"
+               '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}')"
 
        #######################################################################
        # Simultaneous Use Checking Queries
index 1e75f7bb7faeedaa57cbc79706a5970ecfc7849a..39954174dad79ca4ec9439136101fa593bed9383 100644 (file)
@@ -25,7 +25,9 @@ CREATE TABLE radacct (
   nasportid varchar(15) default NULL,
   nasporttype varchar(32) default NULL,
   acctstarttime datetime NULL default NULL,
+  acctupdatetime datetime NULL default NULL,
   acctstoptime datetime NULL default NULL,
+  acctinterval int(12) default NULL,
   acctsessiontime int(12) default NULL,
   acctauthentic varchar(32) default NULL,
   connectinfo_start varchar(50) default NULL,
@@ -38,16 +40,14 @@ CREATE TABLE radacct (
   servicetype varchar(32) default NULL,
   framedprotocol varchar(32) default NULL,
   framedipaddress varchar(15) NOT NULL default '',
-  acctstartdelay int(12) default NULL,
-  acctstopdelay int(12) default NULL,
-  xascendsessionsvrkey varchar(10) default NULL,
-  PRIMARY KEY  (radacctid),
+  PRIMARY KEY (radacctid),
+  UNIQUE KEY acctuniqueid (acctuniqueid),
   KEY username (username),
   KEY framedipaddress (framedipaddress),
   KEY acctsessionid (acctsessionid),
   KEY acctsessiontime (acctsessiontime),
-  KEY acctuniqueid (acctuniqueid),
   KEY acctstarttime (acctstarttime),
+  KEY acctinterval (acctinterval),
   KEY acctstoptime (acctstoptime),
   KEY nasipaddress (nasipaddress)
 ) ENGINE = INNODB;
@@ -64,7 +64,7 @@ CREATE TABLE radcheck (
   value varchar(253) NOT NULL default '',
   PRIMARY KEY  (id),
   KEY username (username(32))
-) ;
+);
 
 #
 # Table structure for table 'radgroupcheck'
@@ -78,7 +78,7 @@ CREATE TABLE radgroupcheck (
   value varchar(253)  NOT NULL default '',
   PRIMARY KEY  (id),
   KEY groupname (groupname(32))
-) ;
+);
 
 #
 # Table structure for table 'radgroupreply'
@@ -92,7 +92,7 @@ CREATE TABLE radgroupreply (
   value varchar(253)  NOT NULL default '',
   PRIMARY KEY  (id),
   KEY groupname (groupname(32))
-) ;
+);
 
 #
 # Table structure for table 'radreply'
@@ -106,7 +106,7 @@ CREATE TABLE radreply (
   value varchar(253) NOT NULL default '',
   PRIMARY KEY  (id),
   KEY username (username(32))
-) ;
+);
 
 
 #
@@ -118,7 +118,7 @@ CREATE TABLE radusergroup (
   groupname varchar(64) NOT NULL default '',
   priority int(11) NOT NULL default '1',
   KEY username (username(32))
-) ;
+);
 
 #
 # Table structure for table 'radpostauth'