Forum Discussion

pgsmith_120398's avatar
pgsmith_120398
Icon for Nimbostratus rankNimbostratus
Apr 24, 2013

Sorry Server iRule with iFiles

Hello,

 

 

I have been searching the forums, wiki, and web for more information about setting up an iRule that will utilize iFiles to deliver a sorry page using the HTTP::content command. I have found several examples of using iFiles within iRules that have all worked to some extent, however im only able to ever get the HTML file and a single image file to display. Is it possible to display a fully formatted html page with css and multiple images?

 

Lets say i have an HTML file that links to an external css file /css/style.css. Also in the HTML file there are several links to images such as /images/image1.gif, /images/background.jpg, etc. Is there a way through iRules (and if possible with the use of iFiles) to have the HTML, CSS, and images all display correctly as if it were hosted from a web server? I am able to embed the CSS code in the HTML file and it the css will apply properly, however I would like to use an external css file if possible.

 

9 Replies

  • Can you provide an example of what you've tried please so I don't just give you more of the same.
  • Assuming you have the iFiles in place (uploaded) and configured (assigned in the GUI), then you'd use a series of URI or path conditionals and the HTTP::respond command. Here's an example:

    
    when HTTP_REQUEST {
         switch [string tolower [HTTP::uri]] {
              "/images/background.jpg" {
                   HTTP::respond 200 content [ifile get ] "Content-Type" "image/jpeg"
              }
              "/css/styles.css" {
                   HTTP::respond 200 content [ifile get ] "Content-Type" "text/css"
              }
              "/index.html" {
                   HTTP::respond 200 content [ifile get ] "Content-Type" "text/html"
              }
         }
    }
    

    The HTTP::respond command allows an arbitrary set of headers after the content, which allows you in this case to send the Content-Type header to the browser for proper rendering.
  • Two other points I forgot to mention:

     

     

    1. You can also pass cache-control headers with the HTTP::respond command, so that may enhance performance.

     

     

    2. Your html file will normally reference your external objects.
  • I think the underlying issue is i probably dont fully understand whats going on. I think i do but i probably dont...

     

     

    I started with somthing like this:

     

    https://devcentral.f5.com/tech-tips...via-ifiles

     

    And it worked fine to display the page with a single image file.

     

     

    I worked my way up to somthing like you suggested before:

     

    https://devcentral.f5.com/tech-tips...via-ifiles

     

    I then took the general idea from that page and simply tried to extend it to more uri's

     

    switch [HTTP::uri] {

     

    "/" { HTTP::respond 200 content [ifile get "index"] }

     

    "/some-image.jpg" { HTTP::respond 200 content [ifile get "some-image"] }

     

    "/some-other-image.jpg" { HTTP::respond 200 content [ifile get "some-other-image"] }

     

     

    Ive also tried this same idea with the use of multiple elseif lines but eventually tried to use switch instead.

     

     

  • I had also referenced this page and interpreted it as /reset.css = /reset.css in the html file its rendering. With that line of thought I continued to assume that for each /file.ext (which I assume are really URIs) I could just stick in multiple files and as it hit them it would pop them into place in the HTML file it was serving.

     

     

    https://devcentral.f5.com/community/group/aft/2165545/asg/50
  • OK, can you post the html file, I think we'll then see where it's going wrong. It doesn't need to be /xxx in the html file.
  • It really doesnt want me to upload a file so ill jut paste the HTML here:

    
    
    
    ERPRD is Undergoing Maintenance
    
    
    
    
    
    
    
    
    
    
      
        
          
          
            
    
    
            
          
          
        
      
      
         
         
         
      
      
         
         
         
      
      
         
         
         
      
      
         
    
    
    This page was automatically generated by the software that monitors Enterprise Reporting for scheduled maintenance, upgrades and service interruptions.  myUFL system administrators are aware of unplanned service interruptions to Enterprise Reporting when this page is active.  After confirmation that Enterprise reporting is actually unavailable due to a non-planned service interruption, an Alert will be posted.  Please check the Alerts page for updates.  You also may report this incident to the UF Help Desk at 392-HELP or .  Thank you.
         
         
      
      
         
         
         
      
      
         
         
         
      
      
         
        
          
          Copyright © 2006, University of Florida, Gainesville,
            FL 32611; (352) 392-HELP.
            
          
         
      
    
    
    
     
  • If you're using something like the iRule example I listed above, the only other recommendation I'd make is that you use "full path" URLs in your HTML page. Add a logging statement to the beginning of your HTTP_REQUEST event to see what I mean:

     

     

    log local0. [HTTP::uri]

     

     

    You'll notice that ALL URIs start at the root "/" path. The BIG-IP wouldn't see or understand "relative" references. So for example, a link to "CSS/UFSTYLE.css" in the HTML file would be "/CSS/UFSTYLE.css" to the HTTP::uri command (notice the starting slash). You're better off then being more explicit in your HTML file so that there's no confusion.
  • I'm really not entirely sure why it wasn't working, however I finally got it working with the following code:

     

     

    
    when HTTP_REQUEST {
    if { [active_members [LB::server pool]] < 1} {
         switch [string tolower [HTTP::uri]] {
              "/" {
                   HTTP::respond 200 content [ifile get index.html] "Content-Type" "text/html"
              }
              "/ufstyle.css" {
                   HTTP::respond 200 content [ifile get ufstyle.css] "Content-Type" "text/css"
              }
              "/myuflheaderborder.jpg" {
                   HTTP::respond 200 content [ifile get myuflheaderborder.jpg] "Content-Type" "image/jpeg"
              }
              "/myuflheader_bg.jpg" {
                   HTTP::respond 200 content [ifile get myuflheader_bg.jpg] "Content-Type" "image/jpeg"
              }
              "/myuflheader.gif" {
                   HTTP::respond 200 content [ifile get myuflheader.gif] "Content-Type" "image/jpeg"
              }
              "/myufllogo.gif" {
                   HTTP::respond 200 content [ifile get myufllogo.gif] "Content-Type" "image/jpeg"
              }
              "/uflwordmark.gif" {
                   HTTP::respond 200 content [ifile get uflwordmark.gif] "Content-Type" "image/jpeg"
              }
         }
    }
    }
    

     

     

    In my HTML file I removed the leading /images/ or /css/ so it just reads image.jpg or ufstyle.css. I then created ifiles with the exact same name that were used in the HTML file on the F5 and created irule files with the exact same names as the ifiles. After doing that it is all working as expected.