cancel
Showing results for 
Search instead for 
Did you mean: 
The_Bhattman
Altostratus
Altostratus

Problem this snippet solves:

This is irule that was slightly altered together to insert Javascript code prior to the tag in a website. The idea is that you can quickly insert javascipt code to a website the ADC is hosting It requires a streaming profile and works on v10

Code :

when RULE_INIT {
set static::jscript {

}
}

when HTTP_REQUEST { 
# Disable the stream filter by default 
STREAM::disable 
set uri [string tolower [HTTP::uri]] 
}

when HTTP_RESPONSE { 
if { [HTTP::status] == 200 } {
if {[HTTP::header value Content-Type] contains "text"} { 
set stream_find ""
set stream_find_lower ""
set stream_repl ""
set insertJscript 1

# Do not allow the Javascript insertion if the pages end with the following
switch -glob $uri { 
"*.ashx*" - 
"*.asmx*" - 
"*.axd*" - 
"*.js*" { 
set insertJscript 0 
}
default {
if { [HTTP::payload] contains "META HTTP-EQUIV=\"Refresh\""} { 
set insertJscript 0 
}
}
}

if {$insertJscript == 1} { 
append stream_repl $static::jscript
append stream_expression "@$stream_find@$stream_repl$stream_find@" 
append stream_expression "@$stream_find_lower@$stream_repl$stream_find_lower@" 

STREAM::expression $stream_expression 
STREAM::enable 
}
}
}
}
Comments
Greg_33923
Nimbostratus
Nimbostratus
I like this irule and have used it! Is there a way to use the same irule for different VIP's, but add some logic to run a different script if the user's dns name was different? so if usera connects to sites.intranet.com and userb connects to sites.internet.com they execute a different script?
Version history
Last update:
‎18-Mar-2015 16:30
Updated by:
Contributors