Search code examples
sqlfreeradius

Freeradius SQLCounter


I'm using the SQL module of Freeradius to check if a user has reached it's weekly data limit, for that I'm using this query:

SELECT (IFNULL(SUM(AcctInputOctets), 0) + IFNULL(SUM(AcctOutputOctets), 0)) as used_data FROM (SELECT * FROM radacct b WHERE username = '%{%k}' AND DATE_FORMAT(acctstarttime, '%Y-%u') = DATE_FORMAT(CURDATE(), '%Y-%u') GROUP BY acctuniqueid) a

Now '%{%k}' is replaced by Freeradius with the users' username, but %u is also replaced, which should not happen as it should be processed by SQL to use the week number.

%Y is not touched by Freeradius.

Any ideas on how to make the query so that Freeradius won't escape this?


Solution

  • The correct escape sequence is %%u. The %% prevents it being interpreted as a single letter expansion.