on
09-Dec-2011
11:46
- edited on
31-Jan-2023
16:48
by
LiefZimmerman
New in BIG-IP version 11.1 are iFiles, a feature that allows users to load files through tmsh or the GUI onto the BIG-IP which can be referenced from iRules. This has an immediate use case of supplanting several of our codeshare entries for sorry and/or maintenance pages delivered directly from the BIG-IP instead of redirecting to a server to handle those requests. In this tech tip, I’ll cover the command options, the GUI configuration, and finally offer up a maintenance page iRule referencing iFiles.
When serving up html pages from an iRule in a variable or a data-group, several things, such as encoding images and escaping special characters to prevent Tcl errors or unfortunate interpretations, must be considered. With iFiles, however, much (and potentially all) of that trouble is eliminated. For this maintenance page, I want to return an HTML5 canvas bouncing F5 ball (original script source can be found here at vectorlight.net) to distract users during maintenance. So I’ll need two files, one image file for the F5 bouncing ball, and one text file for the html elements. The html text I’m using is below:
<html><script>
var surface;
var happy;
var x = 50;
var y = 0;
var dirX = 1;
var dirY = 1;function drawCanvas() {
// Get our Canvas element
surface = document.getElementById("myCanvas");
if (surface.getContext) {
// If Canvas is supported, load the image
happy = new Image();
happy.onload = loadingComplete;
happy.src="f5b_mini.png";
}
}function loadingComplete(e) {
// When the image has loaded begin the loop
setInterval(loop, 15);
}function loop() {
// Each loop we move the image by altering its x/y position
// Grab the context
var surfaceContext = surface.getContext('2d');
// Draw the image
surfaceContext.drawImage(happy, x, y);x += dirX;
y += dirY;if (x <= 0 || x > 500 - 18) {
dirX = -dirX;
}
if (y <= 0 || y > 250 - 28) {
dirY = -dirY;
}
}
</script><body onload="drawCanvas();">
<center>
<h1>Hey there...</h1><br>
<h2>Relax and be mesmerized by the F5 ball as we make some changes</h2><br>
<div>
<canvas id="myCanvas" width="500" height="250">
<p>Your browser doesn't support canvas.</p>
</canvas>
</div><br>
<h2>We'll be back online shortly...the DevCentral team</h2>
</center>
</body></html>
Now that my page is ready, I can upload the files. This is done in System->File Management->iFile List->Import:
A couple quick notes on importing files. First, iFiles maximum size is 4M. Second, it’s probably a good idea to adopt a naming standard early in use of iFiles. I’m using <app_function|name_type>, but whatever works, right? Now that the files are on the system (default location: /config/filestore/files_d/Common_d/ifile_d), I need to create a reference for each of them under Local Traffic->iRules->iFile List. I’m just repeating the name I used for the iFile itself:
The complete syntax for the iFile command is below. For details on each command, please visit the iFile wiki page.
ifile get <iFile Name>
ifile listall
ifile attributes <iFile Name>
ifile size <iFile Name>
ifile last_updated_by <iFile Name>
ifile last_update_time <iFile Name>
ifile revision <iFile Name>
ifile checksum <iFile Name>
array set <variable> [ifile attributes <iFile Name>]
Obviously the logic to serve up the maintenance page would need to be adjusted for a production environment, but for this example I’m just doing an HTTP::respond if the URL is “/”, and then I need a condition for the image as well. So what used to be a lot more work with encoding images and massaging javascript, with iFiles, I can just return the contents with no concerns utilizing the [ifile get <iFile Name>] command. It really is that simple.
when HTTP_REQUEST {
if { [HTTP::uri] eq "/" } {
HTTP::respond 200 content [ifile get testapp_index_txt]
} elseif { [HTTP::uri] eq "/f5b_mini.png" } {
HTTP::respond 200 content [ifile get testapp_f5ball_img]
} else { discard }
}
Browsing to the virtual results in this page:
I highlighted the maintenance page use case, but data served from external files will be useful for a large number of scenarios. Happy coding with the new iFiles feature delivered in BIG-IP v11.1.
Just a quick one hopefully... What are the benefits of using iFiles over the 'External files' functionality?
Cheers
Gavin
iFiles are best suited for loading static content into LTM memory. Data groups offer better querying support using the class command. You have the same functionality for retrieving the source file for an external data group as you do with an iFile.
Aaron
Richard
Yes, iFiles are limited to 4Mb currently. We're tracking a request to make this user-configurable in BZ385237. You can open a case with F5 Support to add your request to this request for enhancement.
Thanks, Aaron
HTTP::respond 200 content "[ifile get ifile1][ifile get ifile2]"
Aaron
I am trying to use the iFiles to do a maintenance page, but I don't want to do a redirect to /maintenance/index.html, I just want to do an HTTP response 200, but using the suggestion from Aaron, of
HTTP::respond 200 content "[ifile get ifile1][ifile get ifile2]"
This simply displays the first file, then the second, basically as concatenated text files(does the same with gif's). I have an index.thml, a css and several gifs. Any ideas on how to display that via iFiles?
Create a single extra virtual server "maintpage" with no pool members, and an always available state (no health check?), and put the simple irule to server up the ifile always.
Then use the fallback host setting in the http profile(s), to send the to maintpage server. Thoughts ?
I know this post is old !!! Don't know if this still the best way to redirect queries to a maintenance page if no pool member is available. Actually, I want to do this on GTM itself, if none of the pool VS is available in a pool (means if both VS is down in both DC's) i want to redirect queries to a maintenance page hosted locally on a f5 GTM. What will be the change is iRule? or any other change required in above article. Currently i am running version 11.5.3 on GTM and LTM