Forum Discussion
rleclerc_120926
Nimbostratus
Jan 08, 2013iRule to drop or allow base on cookie value and date
I need to put together an iRule that either allows or drops traffic based on a cookie value and the day of the month. So if cookie value ends in 0,2,4,6,8 and day of the month is 2-30 (all even numbe...
hoolio
Cirrostratus
Jan 08, 2013Actually, I missed that you want to allow odd numbered cookies on odd days. Can you try this?
when HTTP_REQUEST {
Get day of month:
set day [clock format [clock seconds] -format {%d}]
Check if it is even
if {[clock format [clock seconds] -format {%d}] % 2 == 0 and }{
Check if the cookie value is not null:
[HTTP::cookie my_cookie] ne ""
Get the last char of the cookie value:
[string range [HTTP::cookie my_cookie] end end]
Assign the last character of the cookie value to a variable, last_char
[set last_char [string range [HTTP::cookie my_cookie] end end]]
Check if $last_char is an integer
[string is integer ...
Check if the last character is even using modulus %
string is integer: http://www.tcl.tk/man/tcl8.4/TclCmd/string.htmM23
if {[HTTP::cookie my_cookie] ne "" and [string is integer [set last_char [string range [HTTP::cookie my_cookie] end end]]] and $last_char % 2 == 0 }{
Allow the request. Exit this event in this iRule so we do not block the request
return
}
} elseif {[HTTP::cookie my_cookie] ne "" and [string is integer [set last_char [string range [HTTP::cookie my_cookie] end end]]] and $last_char % 2 == 1}{
Allow the request. Exit this event in this iRule so we do not block the request
return
}
Default action is to block the request
HTTP::respond 403 content "you're blocked because you had cookie [HTTP::cookie my_cookie] and it is [clock format [clock seconds] -format {%d}] of the month"
}
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
