Forum Discussion

Fluidetom_12222's avatar
Jan 13, 2014

iRule to detect browser and display warning message

Hey Guys,

I'm trying to write an iRule to display a warning message when a user is trying to access our internal SharePoint intranet with a non-supported browser (such as Firefox - which is popular amongst our devs). I want this message to be displayed once per day and if the user clicks on "Continue" I'd like the F5 to redirect him to whatever address he was trying to access.

My problem is that I do not know the syntax for the irule.

I suppose it will be something +/- like this

when HTTP_REQUEST {
    if { not ( [HTTP::cookie exists BANNERMESSAGE] ) AND [HTTP::header "User-Agent"] contains "mozilla"]} {
        set expires [clock format [clock seconds] -format "%A, %d-%b-%Y 20:00:00"]
        HTTP::respond 200 content "
            
            
             
            Unsuppored browser
            
            

            
            
            Dear Users,
            You are using a non supported browser to access SharePoint.
            If you use this browser not all SharePoint funtionalities will be available to you.
            Please also note that the Helpdesk will only accept cases if using Internet Explorer.
            
              Click  to continue anyway
            
            
            
            
        " "Set-Cookie" "WRONGBROWSER=1; path=/; expires=$expires"

What I do not know is :

  • How to do a IF statement on two conditions (IF the WRONGBROWSER cookie does not exist AND if User-agent contains Mozilla THEN ...)
  • How to capture the address the user was trying to reach and provide in my HTML page a link "Click here to continue" which would redirect the user to that specific address.

Would you know how I coul achieve this ?

Thanks in advance

8 Replies

  • OK for some reason the iRule is not properly displayed, so here's a stripped down version without the HTML code

     

    when HTTP_REQUEST {
        if { not ( [HTTP::cookie exists WRONGBROWSER] ) AND [class match [HTTP::header "User-Agent"] contains "Mozilla"]} {            set expires [clock format [clock seconds] -format "%A, %d-%b-%Y 20:00:00"]
            HTTP::respond 200 content "
                HTML
                click here to continue (with a link to https://whatever_he-was_trying_access
                /HTML
            " "Set-Cookie" "WRONGBROWSER=1; path=/; expires=$expires"
        }
    }
  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    I'd recommend converting the User-Agent to lower case before doing the comparison:

     

    [string tolower [HTTP::header "User-Agent"]]

     

    However, the bigger problem I see is that virtually all browsers (including IE) feature the string "Mozilla" in the User-Agent header... (see http://www.useragentstring.com/pages/Internet%20Explorer/)

     

  • Hey

     

    Thanks for the information.

     

    I used "mozilla" because I did not know what else to use. Basically what I want to do is display that page to users using Firefox. Which user agent should I use then?

     

  • OK so assuming my syntax is correct I'd have something like the iRule below. How can I capture the address entered to the user so I can redirect him to that address once he click "Continue" on the warning page?

    when HTTP_REQUEST {
        if { not ( [HTTP::cookie exists WRONGBROWSER] ) AND [class match [string tolower[HTTP::header "User-Agent"]] contains "firefox"]} {
            set expires [clock format [clock seconds] -format "%A, %d-%b-%Y 20:00:00"]
            HTTP::respond 200 content "
                HTML
                click here to continue (with a link to https://whatever_he-was_trying_access
                /HTML
            " "Set-Cookie" "WRONGBROWSER=1; path=/; expires=$expires"
        }
    }
    
  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    My apologies for the formatting; for some reason the editor keeps messing it up. :-(

     

  • Hi,

     

    Could you post the updated iRule for this Redirect. I am working for displaying the compatibility for TLS 1.2 instead of TLS 1.0/TLS 1.1

     

    Here is my iRule but. I don't want to direct to some other page, i want to display same warning to update the user about TLS and redirect to the same URI.

     

    when RULE_INIT { set static::refresh_time 15 set static::unsupported_browser_page { System Notification http://www.xxx.com">

     

    System Notification

    You are using an unsupported browser. You must use internet explorer 10.0 or higher

     

    Please upgrade or install a supported browser.

     

    You will be redirected to http://www.xxx.com

     

    Wait $static::refresh_time seconds to continue, or click http://www.xxx.com\">here to continue.

     

    } set static::unsupported_cipher_page { System Notification http://www.xxx.com"> System Notification

    You are using an browser that does not support TLS version 1.1 or 1.2

     

    please check the security settings of your browser and enable TLS version 1.1 or 1.2

     

    You will be redirected to http://www.xxx.com

     

    Wait $static::refresh_time seconds to continue, or click http://www.xxx.com\">here to continue.

     

    } } when HTTP_REQUEST { switch -glob [ string tolower [HTTP::header User-Agent]] { "msie 10.0" - "msie 9.0" - "msie 8.0" - "msie 7.0" - "msie 6." { HTTP::respond 200 content [subst $static::unsupported_browser_page] Mime-Type "text/html" log local0. "Client IP:[IP::client_addr] has been redirected with user agent :[HTTP::header User-Agent]" } default { if { [SSL::cipher version] equals "TLSv1"}{ HTTP::respond 200 content [subst $static::unsupported_cipher_page] Mime-Type "text/html" log local0. "TLSv1.0 connection detected from [IP::client_addr] for [virtual name]" } } } }