F5 is upgrading its customer support chat feature on My.F5.com. Chat support will be unavailable from 6am-10am PST on 1/20/26. Refer to K000159584 for details.

Forum Discussion

Fluidetom_12222's avatar
Jan 07, 2014

iRule to display one time warning message

Hey Guys,

 

We're going to decommission a website soon and we would like to use an iRule to display a warning message once per day to any user going on that website. Is this something possible with an iRule ?

 

9 Replies

  • Hi,

     

    Yes, you can do that and also you can do a redirect to another website.

     

    Please feel free to explore code samples in Devcentral. Some code examples here:

     

    https://devcentral.f5.com/questions/how-to-create-irule-to-deliver-an-alternate-page-response-other-than-page-unavailable

     

    https://devcentral.f5.com/articles/irule-maintenance-windows

     

    https://devcentral.f5.com/questions/irule-for-redirect-when-all-pool-members-down-need-one-for-each-pool-and-what-is-the-standard-practice-for-sorry-server

     

    https://devcentral.f5.com/wiki/irules.ltmmaintenancepage.ashx

     

  • Hey Pedro,

     

    Thanks for your answer.

     

    I've already created irule in the past to display a maintenance page. The request now is that a warning message would be displayed (somethin like "this service will be shut down soon") and then the user can access the site normally.

     

    How can I achieve this?

     

    Thanks

     

  • Hi,

     

    I think that there is no a smooth way to achieve that. But here you can find a few alternatives: https://devcentral.f5.com/questions/301-redirect-to-new-url-with-splash-page-and-retain-uri

     

  • If I may add, the trick is going to be how you track when and if a user has seen the message. HTTP is stateless in nature, so you need a mechanism to detect that the user has seen it at some point in that day. Some options include a long-lived session table entry on the LTM that stores the client's IP or user logon information, or more basically, a persistent cookie in the browser that expires daily. Here's an example:

    when HTTP_REQUEST {
        if { not ( [HTTP::cookie exists BANNERMESSAGE] ) } {
            set expires [clock format [clock seconds] -format "%A, %d-%b-%Y 20:00:00"]
            HTTP::respond 200 content "html banner content" "Set-Cookie" "BANNERMESSAGE=1; path=/; expires=$expires"
        }
    }
    

    If the BANNERMESSAGE cookie doesn't exist in the request, the iRule generates the HTML banner page and inserts a persistent (file-based) cookie that expires at 8pm that day. You'd probably want a link or button in the HTML content that lets the user acknowledge the message and redirects back to the application.

  • Hey Kevin,

     

    Thanks a lot this is exactly what I needed ! I created my iRule on our test F5 and all is working fine. Live deloyment is scheduled for tomorrow.

     

    I do get the warning HTML content on the first visit. If I try again, then the message is no longer displayed and I can see a cookie in my temp internet files. Indeed my HTML page contains a link to the site so the user can go back ot the application.

     

    Just as a comment if someone else is going to reuse this, do not forget that double-quote " is not allowed between the tags. So replace all " with a single quote ' in your HTML code.

     

    Thanks again Kevin and have a nice day

     

  • Just as a comment if someone else is going to reuse this, do not forget that double-quote " is not allowed between the tags. So replace all " with a single quote ' in your HTML code

     

    Or escape the double quotes:

     

    HTTP::respond 200 content "This is a \"test\" of internal double quotes"
  • R_Eastman_13667's avatar
    R_Eastman_13667
    Historic F5 Account

    I just wanted to comment that this doesn't work, once the cookie expires, the cookie isn't reset:

    when HTTP_REQUEST {
        if { not ( [HTTP::cookie exists BANNERMESSAGE] ) } {
            set expires [clock format [clock seconds] -format "%A, %d-%b-%Y 20:00:00"]
            HTTP::respond 200 content "html banner content" "Set-Cookie" "BANNERMESSAGE=1; path=/; expires=$expires"
        }
    }
    

    This does though:

    when HTTP_REQUEST {
        if { not ( [HTTP::cookie exists BANNERMESSAGE] ) } {
            set expires "28800"
            HTTP::respond 200 content "html banner content" "Set-Cookie" "BANNERMESSAGE=1; path=/; Max-Age=$expires"
        }
    }
    
  • Hi,

     

    Could anyone help me update R Eastman's code to include an "OK" button to refresh the screen and continue on the next page? I was looking for a way to display a consent banner before a user access a site. Unfortunately I have very little web coding experience and have been trying to modify the code for sometime now to display a okay button and proceed to the website. Thanks for your help, David

     

    when HTTP_REQUEST { if { not ( [HTTP::cookie exists BANNERMESSAGE] ) } { set expires "28800" HTTP::respond 200 content "html banner content" "Set-Cookie" "BANNERMESSAGE=1; path=/; Max-Age=$expires" } }