Forum Discussion

Will_Adams_1995's avatar
Will_Adams_1995
Icon for Nimbostratus rankNimbostratus
Feb 15, 2016

IRule - 11.6 HF4 User-Header and redirect to original page.

I am trying to write a custom iRule to perform the following:

 

  • Display a warning to the end user depending on the browser version they are using
  • An example of this, user is on Internet Explorer 8 and a warning message appears to tell them to upgrade or set TLS options. A user on Internet Explorer 11 wouldn't get the same message.
  • The above would apply to other browser type/versions as well.
  • When the message is displayed it will then allow them to continue to the original page.

So user connects to "https://workwebsite.com" and when they use a browser I want to warn them about they get a "custom HTML" page and then the F5 continues to load "https://workwebsite.com" as per normal

 

After some reading on DevCentral etc. an iRule seems to be the best way to go from here. I don't really want to have to touch the APM policy I have in place (if it can be avoided). This is the iRule that I have constructed so far (with some bits and pieces from around DevCentral and others). I want this message to appear constantly (for now). This iRule as it stands doesn't do anything with the cookie as it still does the redirect. If I put in my website (it basically loops - i.e. it processes, shows the message, redirects to the website and shows the message, over and over and over).

 

** iRule **

 

when RULE_INIT { set static::refresh_time 60 set static::notification_page { Browser Notification http://workwebsite.com">

 

Browser Notification

You are using an unsupported browser.

 

It is a requirement when accessing our systems to use the latest and greatest

 

This message will close in 15 seconds

 

} }

 

when HTTP_REQUEST { switch -glob [ string tolower [HTTP::header User-Agent]] { "msie 11.0" - "msie 10.0" - "msie 9.0" - "msie 8.0" - "msie 7.0" - "msie 6." { HTTP::respond 200 content [subst $static::notification_page] Mime-Type "text/html" log local0. "Client IP:[IP::client_addr] has been redirected with user agent :[HTTP::header User-Agent]" } "Set-Cookie" "WRONGBROWSER=1; path=/; expires=$expires" default { go to a default location if nothing matches } } }

 

5 Replies

  • I noted that msie 11.0 is in the code and this will be removed later. This is more proof of concept.

     

  • I have played around some more with the iRule and hae it responding to an iFile instead, however I can't (like the above iRule) get it to continue onto the web page. I am stuck in a loop. Here is the update iRule with the iFile.

     

    when HTTP_REQUEST { switch -glob [ string tolower [HTTP::header User-Agent]] { "chrome/40" - "msie 11.0" - "msie 10.0" - "msie 9.0" - "msie 8.0" - "msie 7.0" - "msie 6." { HTTP::respond 200 content [ifile get "us_a_supported_browser_html"] set lookup ==1 log local0. "Client IP:[IP::client_addr] has been redirected with user agent :[HTTP::header User-Agent]" } if {$lookup ==1 } default { go to a default location if nothing matches } } }

     

  • I have played around some more with the iRule and hae it responding to an iFile instead, however I can't (like the above iRule) get it to continue onto the web page. I am stuck in a loop. Here is the update iRule with the iFile.

     

    when HTTP_REQUEST { switch -glob [ string tolower [HTTP::header User-Agent]] { "chrome/40" - "msie 11.0" - "msie 10.0" - "msie 9.0" - "msie 8.0" - "msie 7.0" - "msie 6." { HTTP::respond 200 content [ifile get "us_a_supported_browser_html"] set lookup ==1 log local0. "Client IP:[IP::client_addr] has been redirected with user agent :[HTTP::header User-Agent]" } if {$lookup ==1 } default { go to a default location if nothing matches } } }

     

  • Hi Will,

    you may try the snippet below. It uses a

    UnsupportedBrowser=true
    cookie to track/check if the user was already informed to update the browser. The warning message will reapper just every 86400 seconds (=1day)...

    when HTTP_REQUEST
        if { [HTTP::cookie value "UnsupportedBrowser"] eq "" } then {
            switch -glob -- [string tolower [HTTP::header value "User-Agent"]] { 
                "chrome/40" - "msie 11.0" - "msie 10.0" - "msie 9.0" - "msie 8.0" - "msie 7.0" - "msie 6." { 
                    HTTP::respond 200 content [ifile get "us_a_supported_browser_html"] "Set-Cookie" "Unsupported_Browser=true; HttpOnly; Max-Age=86400; Path=/"
                    log local0. "Client IP:[IP::client_addr] has been redirected with user agent :[HTTP::header value "User-Agent"]" 
                }
            }
        } else {
            log local0. "Client IP:[IP::client_addr] has already been redirected with user agent :[HTTP::header value "User-Agent"]" 
        }
    }
    

    Note: You have to rework the

    -glob User-Agent
    conditions. They are not valid and/or missing some wildcards (
    *
    ) to match just a certain substring.

    Cheers, Kai

  • Thanks Kai,

     

    I have had problems implementing the above script and in the end gave up on the iRule. Despite checking what I needed to, the rule simply would not work. I had a moment of inspiration and instead simplified it by using an expression within the APM to do an mcget of session.user.agent and then performing a match for specific key words in the header.