Forum Discussion

Jason_40769's avatar
Jason_40769
Icon for Nimbostratus rankNimbostratus
May 18, 2011

Code injection

I am trying to figure out how to inject code into a web site like a POP Under AD from an ad company without it disrupting the site itself. Im a beginner Iruler any thoughts?
  • Hi Jason,

     

     

    Not that I like the idea, but you could take the concept from this Codeshare example from Joe and modify it to inject Javascript in response content to trigger a pop under page.

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/GomezInjection.html

     

     

    Aaron
  • Hoolio,

     

     

    Thanks for your response...

     

     

    The gomez code doesnt really do what i want it to do. Here is what I have so far perhaps you can point me further into the right direction..

     

     

    See code below

     

  • 
    when RULE_INIT { 
     set txt_texttoinsert "
    
    
     " 
     } 
     
     when HTTP_REQUEST { 
      Don't allow data to be chunked 
     if { [HTTP::version] eq "1.1" } { 
     if { [HTTP::header is_keepalive] } { 
     HTTP::header replace "Connection" "Keep-Alive" 
     } 
     HTTP::version "1.0" 
     } 
     } 
    when HTTP_RESPONSE { 
    
                if { [HTTP::header Content-Type] starts_with "text/html" } { 
    
                            if { [HTTP::header exists "Content-Length"] } { 
    
                                        set content_length [HTTP::header "Content-Length"] 
    
                            } else { 
    
                                        set content_length 1000000 
    
                             }                       
    
                           if { $content_length > 0 } { 
    
                                        HTTP::collect $content_length 
    
                            } 
    
                } 
    }
    
    when HTTP_RESPONSE_DATA {
       set resp [HTTP::payload]  
       (( search resp for body or /body and get the offset ))
       (( set first_part substr $resp 1  ))
       (( set rest $insert_text[substr $resp  
  • Hi Jason,

     

    Your code is similar to another article that was published by our very own Joe Pruitt regarding inserting Google Analytics. You should take a look at the articles in HTTP_RESPONSE_DATA which I think might be the key to what you want to do.

     

     

    Here is the article

     

    http://devcentral.f5.com/Default.aspx?tabid=63&articleType=ArticleView&articleId=174

     

     

     

    I hope this helps

     

    Bhattman
  • Here's an example using a stream profile:

     

     

    http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/1179209/showtab/groupforums/Default.aspx

     

     

    Aaron
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Keep in mind the stream profile is going to perform better than doing it manually, in most cases. So if you can, sticking with the profile and associated iRule commands is the way to go.

     

     

    Colin