Forum Discussion
Problem with b64decode lindex in Version 10.2.1
I would like to send a sorry page when all pool members are down. I found a solution contributed by citizen_elah .
1. Generate base64 encoded file from a screen shot .
2. Remove the newlines from the file
3. Copy the file to /var/class/
4. Create a DataGroup Extern File Type String , Mode ReadOnly (Version 10)
5. Apply the rule to the virtual server
Anything is working fine in version 9.4.7 but not in version 10.2.1 Hotfix-3.
when HTTP_REQUEST {
if {[active_members myPool] == 0} {
HTTP::respond 200 content [b64decode [lindex $::sorrypage_class 0]] "Content-Type" "image/png" }
}
}
In Version 10 I tried to access the lindex with $:: and without both was not working.
In Version 10.2.1 I always got the error message:
TEST_maintenance_site - conversion error invoked from within "b64decode [lindex sorrypage 0]"
I also tried to decode the file at rule init.
when RULE_INIT { log local0. "[b64decode [lindex test_base64 0]]" }
Produced this error: local/tmm err tmm[4831]: 01220001:3: TCL error: Test_base64_File - conversion error invoked from within "b64decode [lindex $::test_base64 0]" Encoding and decoding under linux with base64 works fine.
Any idea how to solve this ?
Thanks.
Regards Klaus
9 Replies
- hoolio
Cirrostratus
Hi Klaus,
For 9.4.4+, you'll want to remove the $:: prefix to preserve CMP compatibility:
http://devcentral.f5.com/wiki/default.aspx/iRules/CMPCompatibility.html
For 10.x you can't use the $:: prefix--it returns the datagroup name instead of the contents. In v10, if you want to get the contents of a datagroup as a TCL list you can use class get. However, it's simpler to use class element:
http://devcentral.f5.com/wiki/default.aspx/iRules/class.html
HTTP::respond 200 content [b64decode [class element -value 0 sorrypage_class]] "Content-Type" "image/png"
I think that update to the class wiki page was from Jason in this post:
http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/18521/showtab/groupforums/Default.aspx
Aaron - Klaus_Gerthein1
Nimbostratus
Hi Aaron,
thanks for help, it is working now.
Regrads
Klaus - greenasp_41938
Nimbostratus
I have tried every combination possible and can get an image to display. I placed the images in the data group list as a string, but the images do not get displayed. However, the rest of the page shows.
when HTTP_REQUEST {
set VSPool [LB::server pool]
if { [active_members $VSPool] < 1 } {
log local0. "Client [IP::client_addr] requested [HTTP::uri] no active nodes available..."
if { [HTTP::uri] ends_with "/logo.png" } {
HTTP::respond 200 content [b64decode [class element -value 0 logo_image_class]] "Content-Type" "image/png"
} else {
if { [HTTP::uri] ends_with "?offlineimage.png" } {
HTTP::respond 200 content [b64decode [class element -value 0 offlineimage_class]] "Content-Type" "image/png"
} else {
HTTP::respond 200 content "
We'll Be BackThe website is offline for scheduled maintenance. We apologize for any inconvenience.
We expect to be online shortly. Please check again in a few hours.
"
}
}
}
} - greenasp_41938
Nimbostratus
I have tried every combination possible and can get an image to display. I placed the images in the data group list as a string, but the images do not get displayed. However, the rest of the page shows.
when HTTP_REQUEST {
set VSPool [LB::server pool]
if { [active_members $VSPool] < 1 } {
log local0. "Client [IP::client_addr] requested [HTTP::uri] no active nodes available..."
if { [HTTP::uri] ends_with "/logo.png" } {
HTTP::respond 200 content [b64decode [class element -value 0 logo_image_class]] "Content-Type" "image/png"
} else {
if { [HTTP::uri] ends_with "?offlineimage.png" } {
HTTP::respond 200 content [b64decode [class element -value 0 offlineimage_class]] "Content-Type" "image/png"
} else {
HTTP::respond 200 content "
We'll Be BackThe website is offline for scheduled maintenance. We apologize for any inconvenience.
We expect to be online shortly. Please check again in a few hours.
"
}
}
}
} - greenasp_41938
Nimbostratus
I have tried every combination possible and can get an image to display. I placed the images in the data group list as a string, but the images do not get displayed. However, the rest of the page shows.
when HTTP_REQUEST {
set VSPool [LB::server pool]
if { [active_members $VSPool] < 1 } {
log local0. "Client [IP::client_addr] requested [HTTP::uri] no active nodes available..."
if { [HTTP::uri] ends_with "/logo.png" } {
HTTP::respond 200 content [b64decode [class element -value 0 logo_image_class]] "Content-Type" "image/png"
} else {
if { [HTTP::uri] ends_with "?offlineimage.png" } {
HTTP::respond 200 content [b64decode [class element -value 0 offlineimage_class]] "Content-Type" "image/png"
} else {
HTTP::respond 200 content "
We'll Be BackThe website is offline for scheduled maintenance. We apologize for any inconvenience.
We expect to be online shortly. Please check again in a few hours.
"
}
}
}
} - Kevin_Stewart
Employee
I would recommend a slightly different approach. Create a single data group with all of your base64-encoded image content, indexed with the name of the image.
ex.
logo.png := /9j/4AAQSkZJRgABAQEASABIAAD/4QDSR...
offlineimage.png := DEBAgALAAAASgAAADIBAgAUAA...
Then use iRule logic like the following:if { [HTTP::uri] ends_with "/logo.png" } { HTTP::respond 200 content [b64decode [class lookup "logo.png" image_class]] "Content-Type" "image/png" } - greenasp_41938
Nimbostratus
I get this error:
01070151:3: Rule [offline] error: line 6: [can't find value_list] [class lookup "logo.png" image_class] line 9: [can't find value_list] [class lookup "offlineimage.png" image_class] - Kevin_Stewart
Employee
Apologies. I should have been more explicit. The "image_class" string is the name of a string-based class. Assuming you've created a separate class for each image, this new class can hold all of your images. - greenasp_41938
Nimbostratus
Thanks! It actually worked for the first time..... I was setting the data objects up wrong.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
