TimRiker

rule_ifile-star.example.org

Mar 9th, 2021 (edited)
767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 2.76 KB | None | 0 0
  1. # rule_ifile-star.example.org
  2. # This file allows browsing iFile content in a web browser
  3. # add the rule to shared-* and add dns alias to shared-* for any F5
  4. # Tim Riker <[email protected]>
  5.  
  6. when HTTP_REQUEST {
  7.     switch -glob -- [HTTP::host] {
  8.         ifile-*.example.org {
  9.             set uri [HTTP::uri]
  10.             set contenttype "text/html; charset=utf-8"
  11.             switch -- [getfield $uri . 2] {
  12.                 svg {
  13.                     set contenttype "image/svg+xml"
  14.                 }
  15.             }
  16.             if { [catch { HTTP::respond 200 content [ifile get $uri] Content-Type $contenttype Connection close} ] } {
  17.                 if { ([class match [IP::client_addr] equals private_net]) } {
  18.                     # browse only from private_net
  19.                     set response "<!DOCTYPE html><html lang=\"en\"><head><title>[HTTP::host]</title>"
  20.                     append response "<script src=\"//code.jquery.com/jquery-3.3.1.js\"></script>\n"
  21.                     append response "<script src=\"//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js\"></script>\n"
  22.                     append response "<script>\$(document).ready(function() {\$('#ifiles').DataTable();} );</script>\n"
  23.                     append response "<link rel=\"stylesheet\" type=\"text/css\" href=\"//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css\">"
  24.                     append response "</head><body><h1>[HTTP::host]</h1>"
  25.                     append response "<p>[virtual name]</p>"
  26.                     append response "<table id='ifiles'><thead><tr><th>file</th><th>size</th><th>who</th><th>date</th><th>ver</th></tr></thead><tbody>\n"
  27.                     foreach {ifile} [ifile listall] {
  28.                         append response "<tr><td><a href=\"$ifile\">$ifile</a></td>"
  29.                         append response "<td>[ifile size $ifile]</td>"
  30.                         append response "<td>[ifile last_updated_by $ifile]</td>"
  31.                         append response "<td>[clock format [ifile last_update_time $ifile] -format "%Y-%m-%d %H:%M:%S"]</td>"
  32.                         append response "<td>[ifile revision $ifile]</td>"
  33.                         append response "</tr>\n"
  34.                     }
  35.                     append response "</tbody></table></body>"
  36.                     HTTP::respond 200 content $response "Content-Type" "text/html" Connection close
  37.                 } else {
  38.                     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"]]
  39.                     HTTP::respond 404 content $error_page "Content-Type" "text/html; charset=utf-8" Connection close
  40.                 }
  41.             }
  42.             event disable
  43.             return
  44.         }
  45.     }
  46. }
Add Comment
Please, Sign In to add comment