session timeout eval random only during night hours
Hello, basically what i have is: Session-Timeout = 24*60*60 (secons so = one day) what i whould like to eval this timeout every time user gets ack/ok reply to be (randomly) in hours let's say 0200 - 0600 hours. any quick hint? Don't want to reinvent the wheel or use some cannons to shut at butter fly. maybe someone has some advice? thanks.
On Mar 14, 2019, at 3:35 PM, Krzysztof Drewicz <krzysztofdrewicz@gmail.com> wrote:
basically what i have is:
Session-Timeout = 24*60*60 (secons so = one day)
what i whould like to eval this timeout every time user gets ack/ok reply to be (randomly) in hours let's say 0200 - 0600 hours.
That's a little unusual, and therefore a bit more difficult. There are a few things going on here. What do you want to do *during* that time? i.e. what happens if the user logs in between 0200-0600? If there's outside of that time, it's a bit simpler. Just calculate how far away 0200 is, and then add 0-(4*3600) random seconds. Exactly how to do this isn't trivial. TBH, the simplest solution might be a short Perl or Python script. The "unlang" language isn't really intended to be a general purpose programming language. Alan DeKok.
czw., 14 mar 2019 o 21:02 Alan DeKok <aland@deployingradius.com> napisał(a):
Session-Timeout = 24*60*60 (secons so = one day) to be (randomly) in hours let's say 0200 - 0600 hours.
That's a little unusual, and therefore a bit more difficult.
There are a few things going on here. What do you want to do *during* that time? i.e. what happens if the user logs in between 0200-0600?
Nothing in particular, in other words, if user gets 10 disconnects during 2-6 night hours, well - he/she is unlucky, but it's ok for me.
If there's outside of that time, it's a bit simpler. Just calculate how far away 0200 is, and then add 0-(4*3600) random seconds.
Exactly how to do this isn't trivial. TBH, the simplest solution might be a short Perl or Python script. The "unlang" language isn't really intended to be a general purpose programming language.
Thanks, this is just what i've thought. If i've got something working, i whould share. to fire up perl/python every session well, looks like cpu consuming thing.
On Mar 14, 2019, at 4:47 PM, Krzysztof Drewicz <krzysztofdrewicz@gmail.com> wrote:
If i've got something working, i whould share. to fire up perl/python every session well, looks like cpu consuming thing.
The server has a Python and Perl plugin. You don't need to start a new interpreter every time. See raddb/mods-available/python and perl Alan DeKok.
On Thu, 2019-03-14 at 16:02 -0400, Alan DeKok wrote:
On Mar 14, 2019, at 3:35 PM, Krzysztof Drewicz < krzysztofdrewicz@gmail.com> wrote:
basically what i have is:
Session-Timeout = 24*60*60 (secons so = one day)
what i whould like to eval this timeout every time user gets ack/ok reply to be (randomly) in hours let's say 0200 - 0600 hours.
That's a little unusual, and therefore a bit more difficult.
There are a few things going on here. What do you want to do *during* that time? i.e. what happens if the user logs in between 0200-0600?
If there's outside of that time, it's a bit simpler. Just calculate how far away 0200 is, and then add 0-(4*3600) random seconds.
This may work, if I understood the question correctly: update reply { &Session-Timeout := "%{expr:((%l / 86400) * 86400) + 93600 + %{rand:14400} - %l}" } Request time (%l) / 86400 * 86400 in integer arithmetic gets midnight of last night. "+ 93600" adds on 26 hours (2am tomorrow) "+ %{rand:14400}" adds on between 0-4 hours (i.e. 2am-6am) "- %l" takes current time off, to get seconds remaining. -- Matthew
On Mar 15, 2019, at 6:26 AM, Matthew Newton <mcn@freeradius.org> wrote:
On Thu, 2019-03-14 at 16:02 -0400, Alan DeKok wrote:
On Mar 14, 2019, at 3:35 PM, Krzysztof Drewicz < krzysztofdrewicz@gmail.com> wrote:
basically what i have is:
Session-Timeout = 24*60*60 (secons so = one day)
what i whould like to eval this timeout every time user gets ack/ok reply to be (randomly) in hours let's say 0200 - 0600 hours.
That's a little unusual, and therefore a bit more difficult.
There are a few things going on here. What do you want to do *during* that time? i.e. what happens if the user logs in between 0200-0600?
If there's outside of that time, it's a bit simpler. Just calculate how far away 0200 is, and then add 0-(4*3600) random seconds.
This may work, if I understood the question correctly:
update reply { &Session-Timeout := "%{expr:((%l / 86400) * 86400) + 93600 + %{rand:14400} - %l}" }
Request time (%l) / 86400 * 86400 in integer arithmetic gets midnight of last night.
"+ 93600" adds on 26 hours (2am tomorrow)
"+ %{rand:14400}" adds on between 0-4 hours (i.e. 2am-6am)
"- %l" takes current time off, to get seconds remaining.
or update reply { &Session-Time := "%{expr:%{nexttime:1d} + 7200 + %{rand:14400}}" } - %{nexttime:1d} - Number of seconds until tomorrow. - + 7200 - Plus two hours - + %{rand:14400} random value between 0-4 hours. -Arran
On Mar 15, 2019, at 9:47 PM, Arran Cudbard-Bell <a.cudbardb@freeradius.org> wrote:
update reply { &Session-Time := "%{expr:%{nexttime:1d} + 7200 + %{rand:14400}}" }
- %{nexttime:1d} - Number of seconds until tomorrow. - + 7200 - Plus two hours - + %{rand:14400} random value between 0-4 hours.
Uh... yes. It's trivial. FR is officially at the point where I don't know it any more. :( Alan DeKok.
participants (4)
-
Alan DeKok -
Arran Cudbard-Bell -
Krzysztof Drewicz -
Matthew Newton