How to get current datetime in freeradius?
Houman
houmie at gmail.com
Wed Oct 2 11:29:49 CEST 2019
Hello Christian,
You are right that I need to compare every time the current time against
the membership expiration date. Hence I should get it multiple times.
The issue is now that I need to convert the MySQL date Expires-At to
integer so that the two are comparable.
Because right now Expires-At is set as Date:
echo 'ATTRIBUTE Expires-At 3001 date' >>
/etc/freeradius/3.0/dictionary
And it throws this error:
/etc/freeradius/3.0/sites-enabled/default[568]: (&control:Tmp-Integer-0 >
&request:Expires-At) {
/etc/freeradius/3.0/sites-enabled/default[568]: ^ Attribute comparisons
must be of the same data type
So I changed it to integer:
echo 'ATTRIBUTE Expires-At 3001 integer' >>
/etc/freeradius/3.0/dictionary
And got it running, but naturally it doesn't convert the date to integer.
(23) # Executing section preacct from file
/etc/freeradius/3.0/sites-enabled/default
(23) preacct {
(23) [preprocess] = ok
(23) update control {
(23) EXPAND %l
(23) --> 1569999851
(23) &Tmp-Integer-0 := 1569999851
(23) } # update control = noop
(23) update request {
(23) EXPAND %{User-Name}
(23) --> houman
(23) SQL-User-Name set to 'houman'
rlm_sql (sql): Reserved connection (20)
(23) Executing select query: SELECT expires_at FROM main_db.`user`
WHERE main_db.`user`.username ='houman'
rlm_sql (sql): Released connection (20)
Need 6 more connections to reach 10 spares
rlm_sql (sql): Opening additional connection (24), 1 of 28 pending slots
used
rlm_sql_mysql: Starting connect to MySQL server
rlm_sql_mysql: Connected to database 'radius_db' on 3.10.46.171 via TCP/IP,
server version 8.0.17, protocol version 10
(23) EXPAND %{sql:SELECT expires_at FROM main_db.`user` WHERE
main_db.`user`.username ='%{User-Name}'}
(23) --> 2019-12-27 13:22:05
(23) } # update request = fail
(23) } # preacct = fail
(23) Not sending reply to client.
Is %l a unix time stamp? Is there a good way to covert the date to integer
within Radius? So that I don't have to change the database schema and add a
timestamp in there?
Alternatively there could be a way to calculate it in place.
Many Thanks,
Houman
On Wed, 2 Oct 2019 at 07:38, Christian Strauf <strauf at rz.tu-clausthal.de>
wrote:
> Hi Houman
>
> > I'm still unable to get the local timestamp. Do I have to enable anything
> > else?
> If you need the local time multiple times (or did I misunderstand you?),
> try something like this:
>
> update control {
> &Tmp-Integer-0 := "%l"
> }
>
> Use this in your configuration (note that I made some modifications to
> "Expires-At":
>
> preacct {
> update control {
> &Tmp-Integer-0 := "%l"
> }
> update request {
> &Expires-At := "%{sql:SELECT expires_at FROM
> main_db.`user` WHERE main_db.`user`.username ='%{User-Name}'}"
> }
> if (&control:Tmp-Integer-0 > &request:Expires-At) {
> update disconnect {
> &User-Name = "%{User-Name}"
> }
> }
> ...
> }
>
> If you don't need the time multiple times, you should be able to use "%l"
> instead of &control:Tmp-Integer-0. Also note that you need to use some
> other Tmp-Integer-0 if you already use that pre-defined control variable.
>
> Kind regards,
> Christian Strauf-
> List info/subscribe/unsubscribe? See
> http://www.freeradius.org/list/users.html
More information about the Freeradius-Users
mailing list