Time for action – SQL statements as variables
One very powerful function of unlang is that it allows you to execute SQL queries through the sql
module. The query is actually a variable and the return value of this query is the value of the variable. We will now modify the previous exercise to fetch the time from the database and add this to the Reply-Message
value.
Note
To execute SQL queries you need to include and configure FreeRADIUS to use the sql
module. The sql
module also needs to be used in at least one section, for instance, the authorize
or the accounting
section.
- Edit the
sites-available/default
virtual server under the FreeRADIUS configuration directory and add the following inside thepost-auth
section, at the top of the section:if(control:Auth-Type == 'PAP'){ update reply { Reply-Message := "We are using %{control:Auth-Type} authentication and the time in the database is now %{sql:SELECT curtime();}" } }
- Restart FreeRADIUS in debug...