Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Clear all filters
Answers

irule to pop-up a notification banner over a webpage.

Need an irule to pop-up a notification over a webpage with a "click here for more information" content. This can be statically hosted too or just a pop-up once every time one logs in. Any ideas?

0
Rate this Question
Comments on this Question
Comment made 07-Feb-2018 by Andy McGrath 2563

Technically you can do this, I would look at some javascript which can be inserted into the HTML during a response, but why would you not just apply to the actual web application on the backend?

It would be a lot less work and quicker.

0
Comment made 07-Feb-2018 by surgeon

AMG is right. That would be much easier. As alternative you can forward the traffic via icap servers. This requires some administrative work but it is very flexible solution and you can modify your webpage as much as you want without touching actual web servers https://support.f5.com/csp/article/K15819

0
Comment made 07-Feb-2018 by Robell Pontes 180

It isn't pretty, but this iRule works by inserting some JavaScript using the STREAM profile.

Image Text

Mind you the following points:

1) it looks for the end of the HTTP header and insert the JS before it. This can/should be changed in your case as it may not be the best place to insert the JS.

2) you need to set the condition to trigger the banner on the HTTP REQUEST and ensure it's something only occurs once, otherwise, you'll see the pop up on every response. I'll leave the logic of that to you ;).

3) if you click cancel, it redirects you to Google.

when HTTP_REQUEST {
    set THIS_IS_THE_CONDITION 1
    HTTP::header remove Accept-Encoding
    STREAM::disable
} 
when HTTP_RESPONSE {
    if { [HTTP::header Content-Type] contains "text" }{
        if {$THIS_IS_THE_CONDITION == 1 }{
            set POP_UP {<script>window.onload = new function(){if (confirm("This is a message.\n\nIf you disagree please click the 'Cancel' button.") == true) {} else{window.location = "http://www.google.com";}};</script></head>}
            STREAM::expression "@</head>@$POP_UP@"
            STREAM::enable;
            set THIS_IS_THE_CONDITION 0
        }
    }
}
0

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

The following pops up a warning banner on our SharePoint site. It includes a User Agent conditional that will bypass the banner in the event the user is connecting with an MS Product containing one of the agent strings listed.

Hope this helps.

-Kevin

when RULE_INIT {    
set static::notification_page {
    <html lang=\"en_US\">
                            <head><title>System Notification</title>
                            <meta http-equiv=\"Content-Type\" content=\"text/html; charset=us-ascii\">
                            <meta http-equiv=\"CACHE-CONTROL\" content=\"NO-CACHE\">
                            <meta http-equiv=\"PRAGMA\" content=\"NO-CACHE\">
                            <meta http-equiv=\"EXPIRES\" content=\"Mon, 22 Jul 2002 11:12:01 GMT\">

<script>
var warning = 'This warning banner provides privacy and security notices consistent with applicable guidance for accessing this system, which includes (1) this computer network, (2) all computers connected to this network, and (3) all devices and storage media attached to this network or to a computer on this network.' +
        '\\n\\nThis system is provided for authorized use only.' +
        '\\n\\nUnauthorized or improper use of this system is prohibited and may result in disciplinary action and/or civil and criminal penalties.';

if(confirm(warning)==true)
{
    document.cookie = 'NotificationDone=true;path=/'; 
    window.location.href='[HTTP::uri]';
}
</script>
                            </head>
                            <body>
                            <h1>System Notification</h1>
                            <hr>
                            <p>Acknowledgement of the privacy and security notice is required.</p>
            <p>Once the notice is acknowledged, you will be redirected to your requested page. 
                            <p>Click <a href=\"[HTTP::uri]\">here to continue.</a></p>              
            </body>
                           </html>    

}
}

when HTTP_REQUEST  {

set ckname NotificationDone
set ckvalue 1
set ckdomain ".[HTTP::host]"
set noticeMimeType "text/html"

# MS Office Application requests cannot process javascript prompts.
# Do not process for specific request for files from Office Applications.

    switch -glob -- [HTTP::header value "User-Agent"] 
{ 
    "*Microsoft Office*" - "*MS FrontPage*" - "*MSOffice*" - "*FrontPage*" - "*Microsoft Office Protocol Discovery*" - "*SOAP Toolkit*" - "*Microsoft Office InfoPath*" - "*Microsoft Office Existence Discovery*" - "*Microsoft-WebDAV-MiniRedir*"
        {
                # Microsoft Office Application Request for specific file  
            return                  
        }

        default 
        {               
                if { (not [HTTP::cookie exists $ckname]) } 
            {
                    HTTP::respond 200 content [subst $static::notification_page] Mime-Type $noticeMimeType 
            }               
        }
}}
0
Comments on this Answer
Comment made 3 months ago by action_- 136

This is very cool, thank you for sharing.

0