]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add 'weeklycounter' for sqlcounter (#4216)
authorJorge Pereira <jpereira@users.noreply.github.com>
Tue, 31 Aug 2021 22:42:16 +0000 (19:42 -0300)
committerGitHub <noreply@github.com>
Tue, 31 Aug 2021 22:42:16 +0000 (18:42 -0400)
doc/ChangeLog
raddb/mods-available/sqlcounter
raddb/mods-config/sql/counter/mysql/weeklycounter.conf [new file with mode: 0644]
raddb/mods-config/sql/counter/postgresql/weeklycounter.conf [new file with mode: 0644]
raddb/mods-config/sql/counter/sqlite/weeklycounter.conf [new file with mode: 0644]

index 425afe23ecd505a9041e63faba767a7c7c1550e1..fd2d8d63a518cd8730a5d47c34ca0550ca1bf353 100644 (file)
@@ -39,6 +39,7 @@ FreeRADIUS 3.0.24 Thu 10 Jun 2021 12:00:00 EDT urgency=low
        * Fix sqlcounter wrong memory free. PR #4192 from Jorge Pereira
        * Accept slow writes from proxies over TCP, which allows the
          server to make more progress when it receives partial packets.
+       * Add 'weeklycounter' for rlm_sqlcounter.
 
 FreeRADIUS 3.0.23 Thu 10 Jun 2021 12:00:00 EDT urgency=low
        Feature improvements
index 9cd4558981604cced181c9c80a1519a3e23c87bc..f616a80b030979b9d0dccb9429226afc05d32732 100644 (file)
@@ -58,6 +58,20 @@ sqlcounter dailycounter {
        $INCLUDE ${modconfdir}/sql/counter/${dialect}/${.:instance}.conf
 }
 
+sqlcounter weeklycounter {
+       sql_module_instance = sql
+       dialect = ${modules.sql.dialect}
+
+       counter_name = Weekly-Session-Time
+       check_name = Max-Weekly-Session
+       reply_name = Session-Timeout
+
+       key = User-Name
+       reset = weekly
+
+       $INCLUDE ${modconfdir}/sql/counter/${dialect}/${.:instance}.conf
+}
+
 sqlcounter monthlycounter {
        sql_module_instance = sql
        dialect = ${modules.sql.dialect}
diff --git a/raddb/mods-config/sql/counter/mysql/weeklycounter.conf b/raddb/mods-config/sql/counter/mysql/weeklycounter.conf
new file mode 100644 (file)
index 0000000..bf8a4c4
--- /dev/null
@@ -0,0 +1,11 @@
+#
+#  This query properly handles calls that span from the
+#  previous reset period into the current period but
+#  involves more work for the SQL server than those
+#  below
+#
+query = "\
+       SELECT SUM(acctsessiontime - GREATEST((%%b - UNIX_TIMESTAMP(acctstarttime)), 0)) \
+       FROM radacct \
+       WHERE username = '%{${key}}' \
+       AND UNIX_TIMESTAMP(acctstarttime) + acctsessiontime > '%%b'"
diff --git a/raddb/mods-config/sql/counter/postgresql/weeklycounter.conf b/raddb/mods-config/sql/counter/postgresql/weeklycounter.conf
new file mode 100644 (file)
index 0000000..0d809c1
--- /dev/null
@@ -0,0 +1,12 @@
+#
+#  This query properly handles calls that span from the
+#  previous reset period into the current period but
+#  involves more work for the SQL server than those
+#  below
+#
+query = "\
+       SELECT SUM(AcctSessionTime - GREATEST((%%b - EXTRACT(epoch FROM AcctStartTime)), 0)) \
+       FROM radacct \
+       WHERE UserName='%{${key}}' \
+       AND EXTRACT(epoch FROM AcctStartTime) + AcctSessionTime > '%%b'"
+
diff --git a/raddb/mods-config/sql/counter/sqlite/weeklycounter.conf b/raddb/mods-config/sql/counter/sqlite/weeklycounter.conf
new file mode 100644 (file)
index 0000000..06ce3b6
--- /dev/null
@@ -0,0 +1,12 @@
+#
+#  This query properly handles calls that span from the
+#  previous reset period into the current period but
+#  involves more work for the SQL server than those
+#  below
+#
+query = "\
+       SELECT SUM(acctsessiontime - GREATEST((%%b - strftime('%%s', acctstarttime)), 0)) \
+       FROM radacct \
+       WHERE username = '%{${key}}' \
+       AND (strftime('%%s', acctstarttime) + acctsessiontime) > %%b"
+