cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.
Justin1
Nimbostratus
Nimbostratus

Problem this snippet solves:

I have been asked to have a maintenance page that can be used across multiple VIPS for different websites that all want different text displayed and also a logo. What I have come up with is some generic styling and then reference different datagroups for the logo and text.


The maintenance page will also kick in if the pool members are below 1 that are online.


If anyone has ideas on how to enable a maintenance page using a parameter with changing a datagroup or something please let me know. I don't want to use tables as they are flushed or not across a HA pair if there is a failover from what I understand.


If anyone wants to improve on it please post


How to use this snippet:

You will need several data groups and iFiles

Datagroups:


Name: MP_headerImage_DG

Type: String

Contents:

String: The website to match <what HTTP::host} would get> i.e. www.example.com

Value: <The name of the iFile imported> i.e. www.example.com_logo


Name: MP_messagetext_DG

Type: String

Contents:

String: String: The website to match <what HTTP::host} would get> i.e. www.example.com

Value: <message with some HTML> i.e.


<h1><span class="tbl">Website is currently under maintenance.</span></h1> <p><span class="tbl">The website is currently - OFFLINE.</span></p><p> This may be due to system maintenance. Please check back later. This website will refresh every minute until back online.</p><br> <br />


iFiles:


The name you give them in the datagroup. You can have several imported iFiles for the different logos. (Make sure they are appropiately sized as the response HTML has only the width set to 250px


I have also got in the code if you want to add a favicon. Import the file and name the iFile favicon

Code :

when HTTP_REQUEST {
set message [class match -value [HTTP::host] equals MP_messagetext_DG]
set VSPool [LB::server pool]
	if { [active_members $VSPool] < 1 } {
		if { [HTTP::uri] ends_with "favicon.ico" } {
			HTTP::respond 200 content [ifile get favicon] "Content-Type" "image/ico"
		} else {
			if { [HTTP::uri] ends_with "background.png" } {
        		set image [class match -value [HTTP::host] equals MP_headerImage_DG]
				HTTP::respond 200 content [ifile get $image] "Content-Type" "image/png"
			} else {
			    set registerbusinessMP "\r\n"
				append registerbusinessMP "\r\n"
                append registerbusinessMP "\r\n"
                append registerbusinessMP "[HTTP::host] Site Maintenence\r\n"
                append registerbusinessMP "\r\n"
                append registerbusinessMP "\r\n"
                append registerbusinessMP "\r\n"
                append registerbusinessMP "\r\n"
                append registerbusinessMP "\r\n"
                append registerbusinessMP "\r\n"
                append registerbusinessMP "\r\n"
                append registerbusinessMP "\r\n"
                append registerbusinessMP "
\r\n" append registerbusinessMP "\r\n" append registerbusinessMP "$message\r\n" append registerbusinessMP "
\r\n" append registerbusinessMP "\r\n" append registerbusinessMP "\r\n" HTTP::respond 200 -version 1.1 content $registerbusinessMP Content-Type "text/html; charset=utf-8" Strict-Transport-Security "16070400" Connection "close" } } } }

Tested this on version:

16.0
Version history
Last update:
‎05-Aug-2021 17:54
Updated by:
Contributors