]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
MSSQL queries.conf: Simplify using expansions
authorTerry Burton <tez@terryburton.co.uk>
Fri, 16 Aug 2019 11:10:51 +0000 (12:10 +0100)
committerAlan DeKok <aland@freeradius.org>
Fri, 23 Aug 2019 17:29:05 +0000 (13:29 -0400)
raddb/mods-config/sql/main/mssql/queries.conf

index 6a5f3ff4e587eca630bded0eb8cb2367190f8631..6e0998fa183adbe5c534333855d9082f7d28c889 100644 (file)
 #
 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 = "DATEADD(SS, ${event_timestamp_epoch}, '19700101')"
+
 #######################################################################
 #  Authorization Queries
 #######################################################################
@@ -107,14 +126,14 @@ accounting {
                        query = "\
                                UPDATE ${....acct_table1} \
                                SET \
-                                       AcctStopTime=DATEADD(SS, %{%{integer:Event-Timestamp}:-%l}, '19700101'), \
-                                       AcctSessionTime=%{%{integer:Event-Timestamp}:-%l} - \
+                                       AcctStopTime=${....event_timestamp}, \
+                                       AcctSessionTime=${....event_timestamp_epoch} - \
                                                DATEDIFF(SS, '1970-01-01', AcctStartTime), \
                                        AcctTerminateCause='%{%{Acct-Terminate-Cause}:-NAS-Reboot}', \
                                        AcctStopDelay = %{%{Acct-Delay-Time}:-0} \
                                WHERE AcctStopTime = 0 \
                                AND NASIPAddress = '%{NAS-IP-Address}' \
-                               AND AcctStartTime <= DATEADD(SS, %{%{integer:Event-Timestamp}:-%l}, '19700101')"
+                               AND AcctStartTime <= ${....event_timestamp}"
                }
 
                accounting-off {
@@ -159,7 +178,7 @@ accounting {
                                        '%{NAS-IP-Address}', \
                                        '%{%{NAS-Port-ID}:-%{NAS-Port}}', \
                                        '%{NAS-Port-Type}', \
-                                       DATEADD(SS, %{%{integer:Event-Timestamp}:-%l}, '19700101'), \
+                                       ${....event_timestamp}, \
                                        '0', \
                                        '%{Acct-Authentic}', \
                                        '%{Connect-Info}', \
@@ -183,7 +202,7 @@ accounting {
                        query = "\
                                UPDATE ${....acct_table1} \
                                SET \
-                                       AcctStartTime = DATEADD(SS, %{%{integer:Event-Timestamp}:-%l}, '19700101'), \
+                                       AcctStartTime = ${....event_timestamp}, \
                                        AcctStartDelay = '%{%{Acct-Delay-Time}:-0}', \
                                        ConnectInfo_start = '%{Connect-Info}' \
                                WHERE AcctUniqueId = '%{Acct-Unique-Session-ID}' \
@@ -257,7 +276,7 @@ accounting {
                        query = "\
                                UPDATE ${....acct_table2} \
                                SET \
-                                       AcctStopTime = DATEADD(SS, %{%{integer:Event-Timestamp}:-%l}, '19700101'), \
+                                       AcctStopTime = ${....event_timestamp}, \
                                        AcctSessionTime = '%{Acct-Session-Time}', \
                                        AcctInputOctets = convert(bigint, '%{%{Acct-Input-Gigawords}:-0}' * POWER(2.0, 32)) | '%{%{Acct-Input-Octets}:-0}', \
                                        AcctOutputOctets = convert(bigint, '%{%{Acct-Output-Gigawords}:-0}' * POWER(2.0, 32)) | '%{%{Acct-Output-Octets}:-0}', \
@@ -303,7 +322,7 @@ accounting {
                                        '%{NAS-IP-Address}', \
                                        '%{%{NAS-Port-ID}:-%{NAS-Port}}', \
                                        '%{NAS-Port-Type}', \
-                                       DATEADD(SS, %{%{integer:Event-Timestamp}:-%l}, '19700101'), \
+                                       ${....event_timestamp}, \
                                        '%{Acct-Session-Time}', \
                                        '%{Acct-Authentic}', \
                                        '', \