#
sql_user_name = "%{User-Name}"
+#######################################################################
+# Query config: Event-Timestamp
+#######################################################################
+# event_timestamp_epoch is the basis for the time inserted into
+# accounting records. Typically this will be the Event-Timestamp of the
+# accounting request, which is usually provided by a NAS.
+#
+# Uncomment the next line, if you want the timestamp to be based on the
+# request reception time recorded by this server, for example if you
+# distrust the provided Event-Timestamp.
+#event_timestamp_epoch = "%l"
+
+event_timestamp_epoch = "%{%{integer:Event-Timestamp}:-%l}"
+
+# event_timestamp is the SQL snippet for converting an epoch timestamp
+# to an SQL date.
+
+event_timestamp = "${event_timestamp_epoch}"
+
+# NOTE: Recent SQLite versions allow proper arithmetic with dates
+# stored as strings including comparison using an index, so we keep
+# these variables differentiated in preparation for switching away from
+# integer storage.
+
#######################################################################
# Default profile
#######################################################################
query = "\
UPDATE ${....acct_table1} \
SET \
- acctstoptime = %{%{integer:Event-Timestamp}:-date('now')}, \
+ acctstoptime = ${....event_timestamp}, \
acctsessiontime = \
- (%{%{integer:Event-Timestamp}:-strftime('%%s', 'now')} \
- - strftime('%%s', acctstarttime)), \
+ (${....event_timestamp_epoch} \
+ - acctstarttime), \
acctterminatecause = '%{Acct-Terminate-Cause}' \
WHERE acctstoptime IS NULL \
AND nasipaddress = '%{NAS-IP-Address}' \
- AND acctstarttime <= %{integer:Event-Timestamp}"
+ AND acctstarttime <= ${....event_timestamp}"
}
accounting-off {
'%{%{NAS-IPv6-Address}:-%{NAS-IP-Address}}', \
NULLIF('%{%{NAS-Port-ID}:-%{NAS-Port}}', ''), \
'%{NAS-Port-Type}', \
- %{%{integer:Event-Timestamp}:-date('now')}, \
+ ${....event_timestamp}, \
NULL, \
NULL, \
0, \
query = "\
UPDATE ${....acct_table1} SET \
- AcctStartTime = %{%{integer:Event-Timestamp}:-date('now')}, \
- AcctUpdateTime = %{%{integer:Event-Timestamp}:-date('now')}, \
+ AcctStartTime = ${....event_timestamp}, \
+ AcctUpdateTime = ${....event_timestamp}, \
ConnectInfo_start = '%{Connect-Info}', \
AcctSessionId = '%{Acct-Session-Id}' \
WHERE UserName = '%{SQL-User-Name}' \
'%{NAS-IP-Address}', \
'%{%{NAS-Port-ID}:-%{NAS-Port}}', \
'%{NAS-Port-Type}', \
- %{%{integer:Event-Timestamp}:-date('now')}, \
- %{%{integer:Event-Timestamp}:-date('now')}, \
+ ${....event_timestamp}, \
+ ${....event_timestamp}, \
NULL, \
'0', \
'%{Acct-Authentic}', \
framedipv6prefix = '%{Framed-IPv6-Prefix}', \
framedinterfaceid = '%{Framed-Interface-Id}', \
delegatedipv6prefix = '%{Delegated-IPv6-Prefix}', \
- AcctStartTime = %{%{integer:Event-Timestamp}:-date('now')}, \
- AcctUpdateTime = %{%{integer:Event-Timestamp}:-date('now')} \
+ AcctStartTime = ${....event_timestamp}, \
+ AcctUpdateTime = ${....event_timestamp} \
WHERE UserName = '%{SQL-User-Name}' \
AND NASIPAddress = '%{%{NAS-IPv6-Address}:-%{NAS-IP-Address}}' \
AND NASPortId = '%{%{NAS-Port-ID}:-%{NAS-Port}}' \
#
query = "\
UPDATE ${....acct_table1} SET \
- acctstarttime = %{%{integer:Event-Timestamp}:-date('now')}, \
- acctupdatetime = %{%{integer:Event-Timestamp}:-date('now')}, \
+ acctstarttime = ${....event_timestamp}, \
+ acctupdatetime = ${....event_timestamp}, \
connectinfo_start = '%{Connect-Info}' \
WHERE AcctUniqueId = '%{Acct-Unique-Session-Id}'"
}
query = "\
UPDATE ${....acct_table1} \
SET \
- acctupdatetime = %{%{integer:Event-Timestamp}:-date('now')}, \
+ acctupdatetime = ${....event_timestamp}, \
acctinterval = 0, \
framedipaddress = '%{Framed-IP-Address}', \
framedipv6address = '%{Framed-IPv6-Address}', \
'%{NAS-IP-Address}', \
'%{%{NAS-Port-ID}:-%{NAS-Port}}', \
'%{NAS-Port-Type}', \
- (%{%{integer:Event-Timestamp}:-strftime('%%s', 'now')} - %{%{Acct-Session-Time}:-0}), \
- %{%{integer:Event-Timestamp}:-date('now')}, \
+ (${....event_timestamp_epoch} - %{%{Acct-Session-Time}:-0}), \
+ ${....event_timestamp}, \
NULL, \
%{%{Acct-Session-Time}:-NULL}, \
'%{Acct-Authentic}', \
framedipv6prefix = '%{Framed-IPv6-Prefix}', \
framedinterfaceid = '%{Framed-Interface-Id}', \
delegatedipv6prefix = '%{Delegated-IPv6-Prefix}', \
- AcctUpdateTime = %{%{integer:Event-Timestamp}:-date('now')}, \
+ AcctUpdateTime = ${....event_timestamp}, \
AcctSessionTime = %{%{Acct-Session-Time}:-NULL}, \
AcctInputOctets = '%{%{Acct-Input-Gigawords}:-0}' \
<< 32 | '%{%{Acct-Input-Octets}:-0}', \
#
query = "\
UPDATE ${....acct_table2} SET \
- acctstoptime = %{%{integer:Event-Timestamp}:-date('now')}, \
+ acctstoptime = ${....event_timestamp}, \
acctsessiontime = %{%{Acct-Session-Time}:-NULL}, \
acctinputoctets = %{%{Acct-Input-Gigawords}:-0} \
<< 32 | %{%{Acct-Input-Octets}:-0}, \
'%{NAS-IP-Address}', \
'%{%{NAS-Port-ID}:-%{NAS-Port}}', \
'%{NAS-Port-Type}', \
- (%{%{integer:Event-Timestamp}:-strftime('%%s', 'now')} - %{%{Acct-Session-Time}:-0}), \
- %{%{integer:Event-Timestamp}:-date('now')}, \
- %{%{integer:Event-Timestamp}:-date('now')}, \
+ (${....event_timestamp_epoch} - %{%{Acct-Session-Time}:-0}), \
+ ${....event_timestamp}, \
+ ${....event_timestamp}, \
%{%{Acct-Session-Time}:-NULL}, \
'%{Acct-Authentic}', \
'', \
framedipv6prefix = '%{Framed-IPv6-Prefix}', \
framedinterfaceid = '%{Framed-Interface-Id}', \
delegatedipv6prefix = '%{Delegated-IPv6-Prefix}', \
- AcctStopTime = %{%{integer:Event-Timestamp}:-date('now')}, \
- AcctUpdateTime = %{%{integer:Event-Timestamp}:-date('now')}, \
+ AcctStopTime = ${....event_timestamp}, \
+ AcctUpdateTime = ${....event_timestamp}, \
AcctSessionTime = %{%{Acct-Session-Time}:-NULL}, \
AcctInputOctets = '%{%{Acct-Input-Gigawords}:-0}' \
<< 32 | '%{%{Acct-Input-Octets}:-0}', \