on 01-Jun-2021 11:23
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 Rikerwhen 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 "" 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 } } }
\n" foreach {ifile} [ifile listall] { append response " file size who date ver \n" } append response " $ifile " append response "[ifile size $ifile] " append response "[ifile last_updated_by $ifile] " append response "[clock format [ifile last_update_time $ifile] -format "%Y-%m-%d %H:%M:%S"] " append response "[ifile revision $ifile] " append response "
Tested this on version:
15.1