Forum Discussion
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
- Pedro_HaoaRet. Employee
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
- Pedro_HaoaRet. Employee
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
- Kevin_Stewart
Employee
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
- Kevin_Stewart
Employee
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_13667Historic 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" } }- Domai_23823
Nimbostratus
Thank you ....worked like a charm.
- Blackbird_23118
Nimbostratus
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" } }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com