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.
TimRiker
Cirrostratus
Cirrostratus

Problem this snippet solves:

Browse iFiles from internal IPs, serve the files externally by name.

How to use this snippet:

Create DNS name like ifile-*.example.org and point to a vip.

Add iRule to a vip. before other events.

edit iRule host matching.

Code :

# rule_ifile-star.example.org
# This file allows browsing iFile content in a web browser
# add the rule to shared-* and add dns alias to shared-* for any F5
# Tim Riker 

when HTTP_REQUEST {
    switch -glob -- [HTTP::host] {
        ifile-*.example.org {
            set uri [HTTP::uri]
            set contenttype "text/html; charset=utf-8"
            switch -- [getfield $uri . 2] {
                js {
                    set contenttype "application/javascript; charset=utf-8"
                }
                png {
                    set contenttype "image/png"
                }
                svg {
                    set contenttype "image/svg+xml"
                }
            }
            if { [catch { HTTP::respond 200 content [ifile get $uri] Content-Type $contenttype Connection close} ] } {
                if { ([class match [IP::client_addr] equals private_net]) } {
                    # browse only from private_net
                    set response "[HTTP::host]"
                    append response "\n"
                    append response "\n"
                    append response "\n"
                    append response ""
                    append response "

[HTTP::host]

" append response "

[virtual name]

" append response "\n" foreach {ifile} [ifile listall] { append response "" append response "" append response "" append response "" append response "" append response "\n" } append response "
filesizewhodatever
$ifile[ifile size $ifile][ifile last_updated_by $ifile][clock format [ifile last_update_time $ifile] -format "%Y-%m-%d %H:%M:%S"][ifile revision $ifile]
" HTTP::respond 200 content $response "Content-Type" "text/html" Connection close } else { set error_page [string map [list TITLE "Not Found" ERRORURI "[URI::encode "https://[HTTP::host][HTTP::uri]"]" TEXT "Not Found"] [ifile get "/Common/error.html"]] HTTP::respond 404 content $error_page "Content-Type" "text/html; charset=utf-8" Connection close } } event disable return } } }

Tested this on version:

15.1
Version history
Last update:
‎01-Jun-2021 11:23
Updated by:
Contributors