Forum Discussion

Brian_Deitch_11's avatar
Brian_Deitch_11
Historic F5 Account
Apr 23, 2009

Replace HTML code with multiple links

So here is my dilemma. I need to create an iRule that will:

 

1. Match a link

 

2. Replace each link with one from a list.

 

 

So, on the response request, the F5 WA will match data.mysite.com and replace each data.mysite.com with data1.mysite.com thru data10.mysite.com. I'm sure this has already been done before but I'm clueless as to what to search for.

 

 

FYI...They reason why we just do not use multiconnect in the WA policy is the data hosted on data.mysite is hosted externally from the WA.

 

 

Thanks in advance,

 

 

Brian

6 Replies

  • James_Quinby_46's avatar
    James_Quinby_46
    Historic F5 Account
    I just want to make sure I understand...for all fully qualified URLs in a returned HTML page (IMG SRC and HREFs), you want to replace 'data.' with 'data{n}.', where n={1..10}?
  • Brian_Deitch_11's avatar
    Brian_Deitch_11
    Historic F5 Account
    Okay..I'm a little bit closer here....

    when HTTP_RESPONSE {    
     if { [HTTP::status] == 200} {   
      find and replace   
     STREAM::expression ",http://data.,http://data1.,"   
     STREAM::enable   
     }   
     }   
     

    Any ideas how I can now step thru this to rewrite each data{n} where n={1-10}
  • James_Quinby_46's avatar
    James_Quinby_46
    Historic F5 Account
    Yeah, I was going that way too but I think the stream profile substitution only does 1 replacement at a time. I started hacking away at something based on the SSN masking iRule here:

     

     

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

     

     

    ...but had to set it aside for a bit. In a nutshell:

     

     

    1. De-chunk and gather up the response

     

    2. Find the strings

     

    3. iterate over them and append an incremented value

     

     

     

  • Brian_Deitch_11's avatar
    Brian_Deitch_11
    Historic F5 Account
    Well it took an act of God and some great help from Greg with F5 support but we accomplished the task at hand!

     when RULE_INIT {  
      set this to 0 for production  
     set debug 1  
     }  
     when HTTP_RESPONSE {  
      Counter goes from 1 to 10  
     set data_counter 1  
      Disable the stream filter by default    
     STREAM::disable    
      Check if response type is html or javascript  
     if { ( [HTTP::header value Content-Type] contains "text/html" ) or ( [HTTP::header value Content-Type] contains "javascript" )}{    
      Match any http://data. and don't automatically replace it with anything   
     STREAM::expression "@http://data\.mydomain\.com@DUMMY@"  
      Enable the stream filter for this response only    
     STREAM::enable    
     }    
     }     
     when STREAM_MATCHED {    
     if { $::debug >= 1 } { log local0. "[IP::client_addr]:[TCP::local_port]: matched: [STREAM::match], replaced with: [string map [list "data" [format "data%u" $data_counter] ] [STREAM::match] ]" }  
     STREAM::replace [string map [list "data" [format "data%u" $data_counter] ] [STREAM::match] ]  
      Iterate the data_counter  
     set data_counter [ expr  { $data_counter % 10 + 1 } ]  
     }