For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Link Tracking

Problem this snippet solves:

This iRule application will track URI's that come in through your virtual server and store them in a table with the number of times they have been referenced. The data stored can then be viewed by passing in the "/linkadmin" url which will generate a table of the URI's and their view counts.

Code :

when HTTP_REQUEST {
  set TABLE_LINKDATA "LINK_TRACKING_[virtual name]"
  switch [string tolower [HTTP::uri]] {
    "/linkadmin" {
      set content {
} foreach key [table keys -subtable $TABLE_LINKDATA] { append content ""; } append content "
Clear Data
URI Views
$key [table lookup -subtable $TABLE_LINKDATA $key]
";
      HTTP::respond 200 Content $content;
    }
    "/linkcleardata" {
      table delete -subtable $TABLE_LINKDATA -all;
      HTTP::redirect "http://[HTTP::host]/linkadmin"
    }
    default {
      if { [table incr -subtable $TABLE_LINKDATA -mustexist [HTTP::uri]] eq ""} {
        table set -subtable $TABLE_LINKDATA [HTTP::uri] 1 indefinite indefinite;
      }
    }
  }
}

 

Updated Feb 01, 2023
Version 2.0
No CommentsBe the first to comment