From: Jorge Pereira Date: Tue, 31 Aug 2021 22:42:16 +0000 (-0300) Subject: Add 'weeklycounter' for sqlcounter (#4216) X-Git-Tag: release_3_0_24~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=315a7eef34ea0f4b3e509a0337a9df180b142dc9;p=thirdparty%2Ffreeradius-server.git Add 'weeklycounter' for sqlcounter (#4216) --- diff --git a/doc/ChangeLog b/doc/ChangeLog index 425afe23ecd..fd2d8d63a51 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -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 diff --git a/raddb/mods-available/sqlcounter b/raddb/mods-available/sqlcounter index 9cd45589816..f616a80b030 100644 --- a/raddb/mods-available/sqlcounter +++ b/raddb/mods-available/sqlcounter @@ -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 index 00000000000..bf8a4c4b454 --- /dev/null +++ b/raddb/mods-config/sql/counter/mysql/weeklycounter.conf @@ -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 index 00000000000..0d809c1fe90 --- /dev/null +++ b/raddb/mods-config/sql/counter/postgresql/weeklycounter.conf @@ -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 index 00000000000..06ce3b6089f --- /dev/null +++ b/raddb/mods-config/sql/counter/sqlite/weeklycounter.conf @@ -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" +