Forum Discussion

Mike_Pimlott_61's avatar
Mike_Pimlott_61
Icon for Nimbostratus rankNimbostratus
Jun 24, 2008

safesearch - google et al

apologies if this sits somewhere else in the forums. a search didn't turn anything up.

 

 

I have a requirement to implement safesearch through the LTM, without forcing traffic through a proxy server. the proxy server is capable of implementing safesearch for google, altavista etc through a policy.

 

 

Is this also something that is possible (with ease) on the LTM, either in iRules, or utilising stream profiles?

 

 

in essence it is a "insert &safe=active" into a sepcific portion of the URI (although I am not sure how deep into the URIL this is by default).

 

 

any help is much appreciated.

3 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    If you know what part in the URI you want to modify, and what you want to modify it to, this could very easily be done via the stream profile.

     

     

    I.E. if you know you want to change search-x to search=x&safe=active, this would be simple.

     

     

    Colin
  • there is a "standard" part of the search string to which we can insert some text, but I am not 100% sure that this is x characters from the start each time a search is run.

     

     

    is it possible to find the string i.e. "en" and replace with "en&safe=active" without destroying the remainder of the URI?

     

     

    example with no safe search

     

    http://www.google.co.uk/search?hl=en&rlz=1G1GGLQ_ENGB268&q=halibut&meta=

     

     

    example with safe search

     

    http://www.google.co.uk/search?hl=en&safe=active&rlz=1G1GGLQ_ENGB268&q=halibut&meta=

     

     

    thestring "&safe=active" always comes after hl=en (in this case)

     

     

    any help?
  • You can use the "string map" command to do a search and replace quite easily. The following iRule will check to make sure the URI doesn't have the "safe=active" parameter. If it is not present in the URI, then it will replace all occurances of "hl=en" with "hl=en&safe=active". So, if you have more than one "hl=en" in the URI, it will replace both of them. If that's the case, you might want to look for a more unique term.

    when HTTP_REQUEST { 
       if { ! [HTTP::uri] contains "safe=active" } { 
         HTTP::uri [string map {"hl=en" "hl=en&safe=active"} [HTTP::uri]] 
       } 
     }

    If you just want to append it to the URI, then you can do so like this:

    when HTTP_REQUEST { 
       if { ! [HTTP::uri] contains "safe=active" } { 
         HTTP::uri "[HTTP::uri]&safe=active" 
       } 
     }

    Keep in mind that this may not work if you don't have any querystring arguments in the URI to begin with. The first querystring argument needs to start with a question mark and if you don't have any, this iRule will prefix the only querystring argument with a ampersand.

    Hope this is enough to get you started.

    -Joe