1

I'm using freeradius with mysql and choovachilli to implement captive portal. I'm currently trying to implement daily accounts using rlm_sqlcounter, but with no success. Here is my configuration file that I include into global config:

sqlcounter dailycounter {
    counter-name = 'Daily-Session-Time'
    check-name = 'Max-Daily-Session'
    sql_module_instance = 'sql'
    key = 'User-Name'
    reset = daily
    query = "SELECT SUM(acctsessiontime - GREATEST((%b - UNIX_TIMESTAMP(acctstarttime)), 0)) FROM radacct WHERE username='%{${key}}' AND UNIX_TIMESTAMP(acctstarttime) + acctsessiontime > '%b'"
}

authorize {
    sql
    dailycounter
}

accounting {
    sql
}

In the freeradius log there is only this output related to the counter:

Tue Oct  6 13:02:22 2015 : Debug:  Module: Linked to module rlm_expr
Tue Oct  6 13:02:22 2015 : Debug:  Module: Instantiating module "expr" from file /etc/freeradius/modules/expr
Tue Oct  6 13:02:22 2015 : Debug:     (Loaded rlm_counter, checking if it's valid)
Tue Oct  6 13:02:22 2015 : Debug:  Module: Linked to module rlm_counter
Tue Oct  6 13:02:22 2015 : Debug:  Module: Instantiating module "daily" from file /etc/freeradius/modules/counter
Tue Oct  6 13:02:22 2015 : Debug:   counter daily {
Tue Oct  6 13:02:22 2015 : Debug:   filename = "/etc/freeradius/db.daily"
Tue Oct  6 13:02:22 2015 : Debug:   key = "User-Name"
Tue Oct  6 13:02:22 2015 : Debug:   reset = "daily"
Tue Oct  6 13:02:22 2015 : Debug:   count-attribute = "Acct-Session-Time"
Tue Oct  6 13:02:22 2015 : Debug:   counter-name = "Daily-Session-Time"
Tue Oct  6 13:02:22 2015 : Debug:   check-name = "Max-Daily-Session"
Tue Oct  6 13:02:22 2015 : Debug:   reply-name = "Session-Timeout"
Tue Oct  6 13:02:22 2015 : Debug:   allowed-servicetype = "Framed-User"
Tue Oct  6 13:02:22 2015 : Debug:   cache-size = 5000
Tue Oct  6 13:02:22 2015 : Debug:   }
Tue Oct  6 13:02:22 2015 : Debug: rlm_counter: Counter attribute Daily-Session-Time is number 3000
Tue Oct  6 13:02:22 2015 : Debug: rlm_counter: Current Time: 1444129342 [2015-10-06 13:02:22], Next reset 1444168800 [2015-10-07 00:00:00]

I would really appreciate if someone could explain to me how this counter actually works. I managed to understand the point of check-name and reset, but query option confuses me. I understand query syntax and what will return value be, but I don't understand when is that query called and who will use its return value and how?

1 Answers1

2

The explain of Daily-Session-Time.

  1. user can login and online 3000s per day
  2. with Max-Daily-Session. you add value to 3000. it means 3000s.
  3. Radius will reply attribute Session-Timeout to nas 3000s. it means nas must disconnect user in 3000s
  4. if user login and online for 1000s, He logout. Then He login again, radius will reply Session-Timeout to nas 2000s.
  5. after user uses all 3000s, he can not login. He need to wait until tomorrow.