ifile
9 TopicsSolution: Create a F5 Maintenance Page with Image (iRule/iFile) - A step by step procedure.
I have read many articles, questions and solutions to create a maintenance page and publish that page with an image when all members in a pool are down, I found it is not that easy, So I would like to combine all that stuff and put them in one place to make it more understandable. I am going to use HTML code directly in the iRule rather than uploading as an 'iFile' to show you in detail. Prerequisite: An image with any format. Example: mylogo.png Procedure: Navigate to System > File Management > iFile List and Click on Import and upload an Image with name mylogo.png (or you can name it as 'mylogo' but make sure you should use same in the entire process) Navigate to Local Traffic > iRules > iFile List and Click on Create and enter name 'mylogo.png' and select 'mylogo.png' from the drop down list. Now Create an iRule (see below) and attach it to the respective Virtual Server and test it by disabling all members in the pool. You can change HTML code in the iRule as per your requirement but make sure you define in the HTML body. when HTTP_REQUEST { if { [active_members [LB::server pool]] < 1 } { switch [HTTP::uri] { "/mylogo.png" {HTTP::respond 200 content [ifile get "mylogo.png"]} default {HTTP::respond 200 content { Site Maintenance We’ll be back soon! Sorry for the inconvenience but we’re performing some maintenance at the moment. If you need to you can always , otherwise we’ll be back online shortly! — IT Security } } } } } OPTIONAL: You can also HTML code as the ifile like 'mylogo.png'. For that, you must follow same procedure from the beginning. Then you will have 'mypage.html' and 'mylogo.png' in your iFile list. Then create your iRule as below. The drawback for this is, you cannot change the HTML code instantly like in the above iRule. For every change you need to upload HTML file as an ifile. when HTTP_REQUEST { if {[active_members [LB::server pool]] < 1} { switch [HTTP::uri] { "/mylogo.png" {HTTP::respond 200 content [ifile get "mylogo.png"] } default {HTTP::respond 200 content [ifile get "mypage.html"] } } } } That is it. Any ideas/suggestions would be highly appreciated. Thank you, Harsha Potharaju.5.2KViews0likes9CommentsCreate a IFile {system level} via API - Powershell
Hi All, Attempting the following: 1: Create iFile system level 2: Update existing iRule-> iFile referance the the file uploaded in step 1. Im getting stuck at step 1, any assistance creatly apprecuated. What I have tried: Get Auth Token: # Get API token $big_ip = 'https://[REDACTED]' $url = "{0}{1}" -f $big_ip, '/mgmt/shared/authn/login' $body = @{ username = "[REDACTED]" password = '[REDACTED]' loginProviderName = "tmos" } | ConvertTo-Json $result = Invoke-RestMethod -Method 'POST' -Uri $url -ContentType 'application/json' -Body $body $token = $($result.token.token) Works. Next, Upload my file: $File_Name = 'MyFile' $File_Upload = 'C:\Temp\MyFile' $url = "{0}{1}{2}" -f $big_ip, "/mgmt/shared/file-transfer/uploads/", $File_Name $filelength = (Get-Item $File_Upload).length $headers = @{ 'Content-Type' = 'application/octet-stream' 'X-F5-Auth-Token' = $token 'Content-Range' = "0-$($filelength-1)/$filelength" } $result = Invoke-RestMethod -Method Post -Uri $url -Headers $headers -InFile $File_Upload Works fine too I am returned with: remainingByteCount : 0 usedChunks : @{0=46321} totalByteCount : 46321 localFilePath : /var/config/rest/downloads/MyFile temporaryFilePath : /var/config/rest/downloads/tmp/MyFile generation : 0 lastUpdateMicros : 1661257236246203 Next is where im stuck, creation of the iFile system level from the uploaded file. Ive re-typed the below from the Curl samples here:Syncing local repositories and ifiles using iContr... - DevCentral (f5.com) ### Create a iFile {system level} - does not yet work $File_Name = 'MyFile' $url = "{0}{1}{2}" -f $big_ip, "/mgmt/tm/sys/file/ifile/", $File_Name $headers = @{ 'Content-Type' = 'application/json' 'X-F5-Auth-Token' = $token } $body = @{ 'name' = $File_Name 'source-path' = "file:///var/config/rest/downloads/$File_Name" } | ConvertTo-Json $result = Invoke-RestMethod -Method put -Uri $url -Headers $headers -Body $body Next I am recieving that the file cannot be found. So this query is incorrectly tructured ? Translated these examples to powershell: Syncing local repositories and ifiles using iContr... - DevCentral (f5.com) Invoke-RestMethod : {"code":404,"message":"01020036:3: The requested iFile (/Common/MyFile) was not found.","errorStack":[],"apiError":3} At line:1 char:11 + $result = Invoke-RestMethod -Method put -Uri $url -Headers $headers - ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand Any assistance appreated with the above & next up updating the iRule file refence.Solved1.9KViews1like10CommentsMaintenance page with an image using iRule and iFile, image never gets displayed
Hello, Having an issue getting image to display...Have created an iFile and selected an image previously uploaded, iRule calls for that file, however, image never displays, only text. Any assistance would be greatly appreciated. Used following article as a starting point: https://community.f5.com/t5/technical-forum/solution-create-a-f5-maintenance-page-with-image-irule-ifile-a/td-p/243434 when HTTP_REQUEST { if { [active_members [LB::server pool]] < 1 } { switch [HTTP::uri] { "/maintenance.png" {HTTP::respond 200 content [ifile get "maintenance.png"] "Content-Type" "image/png" } default {HTTP::respond 200 content { www.website.com is currently in maintenance, sorry for any inconvenience. } } } } } I have tried specifying /Common/maintenance.png, still no show. When I browse the file system, that image is actually under: /config/filestore/files_d/Common_d/ifile_d/Common:maintenance.png_62680_1 Many thanks in advance.799Views0likes1CommentiFile maintenance page issue with longer paths
Hi all, We are using ifiles to serve static maintenance page for our web services. Everything works fine when user navigates to "domain.com/", but if the path contains second "/" (domain.com/abc/) then ifile image won't load. when HTTP_REQUEST { if {([active_members Pool-X]) < 1} { switch [string tolower [HTTP::uri]] { "/image.png" { HTTP::respond 200 content [ifile get "image.png"] "Content-Type" "image/png" } default { HTTP::respond 200 content [ifile get "maintenance_page"] "Content-Type" "text/html" connection close event disable } } } } What should I do to make this irule work with any path? Thanks, Jani375Views0likes2CommentsPresenting a page from F5 - passing in variables/parameters
As per my other thread I'm looking for a solution to closeing a site to traffic and presenting a page. Part of the criteria for the page is pass in parameters for when the site will be back up. In our old method we would pass this as a query string on the redirect and use javascript to populate the fields. Is something possible if presenting the page from an iFile? I have been following this pages so far: https://devcentral.f5.com/s/articles/irules-recipe-4-static-maintenance-page-23131359Views0likes0CommentsCustom Role does not work using REST API on Ft LTM
I am only using LTM module version 13.1.0.8. After creating custom resource-group, custom role and associate user to the custom role, the result is not what I expect. Can anyone helps? I need a specific user account with RW permission to any iFile and nothing else. If I could disable read access to common partition, this is even better (not possible as I am ware as of now). create a "testuser" under TEST partition with guest role I have given all access to following paths for custom resource-groups and also tried to PUT into custom role as well: "resourceMask": "/mgmt/tm/sys/file/ifile/**" "resourceMask": "/mgmt/tm/ltm/ifile/**" the custom role name is not showing up in GUI but the API command works when creating custom role with userReferences. logout and login for testuser. I cannot modify/ upload the ifile under TEST partition. Am I missing more steps here guys. Plz enlighten.245Views0likes0Commentsirule maintanance page issue
Can anyone out there tell me what could be wrong with this code for an irule to reference HTML for a maintance splash page? when HTTP_REQUEST { if { [active_members [LB::server pool]] == 0 } { check if client access from internal subnet if { [IP::addr [IP::client_addr]/8 equals 10.0.0.0] } { pool alternate_pool } else { HTTP::respond 200 content { Sorry Page Sorry, The website is not available. Please try again later } } } I am losing my mind over trying to figure it out. it is giving me a missing bracket error and when I input it into notepad++ it isn't showing any error. here is the errors it is giving me 01070151:3: Rule [/Common/test_maintanance] error: /Common/test_maintanance:1: error: [parse error: missing close-brace][{ if { [active_members [LB::server pool]] == 0 } { check if client access from internal subnet if { [IP::addr [IP::client_addr]/8 equals 10.0.0.0] } { pool alternate_pool } else { HTTP::respond 200 content { Sorry Page Sorry, The website is not available. Please try again later } } }] /Common/test_maintanance:2: error: [command is not valid in the current scope][if { [active_members [LB::server pool]] == 0 } { check if client access from internal subnet if { [IP::addr [IP::client_addr]/8 equals 10.0.0.0] } { pool alternate_pool } else { HTTP::respond 200 content { Sorry Page Sorry, The website is not available. Please try again later } }226Views0likes1Comment