CodeShare Refresh: HTTP Session Limit
The iRules CodeShare on DevCentral is an amazingly powerful, diverse collection of iRules that perform a myriad of tasks ranging from credit card scrubbing to form based authentication to, as in toda...
Published Dec 27, 2011
Version 1.0Colin_Walker_12
Historic F5 Account
Joined May 12, 2005
Colin_Walker_12
Historic F5 Account
Joined May 12, 2005
KevinA_246454
Oct 18, 2018Cirrostratus
I tried, the irule above with some modications to it, but I can get the counter to display i see on the logs files the below
Thu Oct 18 14:50:40 CAT 2018 err bigip1 tmm[12118] 01220001 TCL error: /Common/qasessionlimitv1 - can't read "countsessions": no such variable while executing "HTTP::respond 200 content "$countsessions"
HERE IS MY IRULE I USED, any help guys ?
when RULE_INIT { set static::max_active_clients 1 log local0. "rule session limit reached"
}when HTTP_REQUEST {
test cookie presence
if {[HTTP::cookie exists "ClientID"]} {
set need_cookie 0
set client_id [HTTP::cookie "ClientID"]
if cookie not present & connection limit not reached, set up client_id
if { [HTTP::uri] eq "/counter"} { HTTP::respond 200 content "$countsessions"}
} else {
if {not ([table keys -subtable httplimit] > $static::max_active_clients)} {
set need_cookie 1
set client_id [format "%08d" [expr { int(100000000 * rand()) }]]
Only count this request if it's the first on the TCP connection
if {[HTTP::request_num] == 1}{
table set -subtable httplimit [IP::client_addr]:[TCP::client_port] "blocked"
set countsessions [table keys -subtable $httplimit -count]
set timer [after 60000 -periodic { table lookup -subtable httplimit [IP::client_addr]:[TCP::client_port] }]
}
} else {
HTTP::respond 200 content {
derick jp wp
Thank you for visisting this useless webpage
We are realy not sorry to drop you in the maintenance page
Please Go!
If you stay we will try to redirect you to the realwebsite
}
}
}
}
when HTTP_RESPONSE { insert cookie if needed if {$need_cookie == 1} { HTTP::cookie insert name "ClientID" value $client_id path "/" } }