\n
1: when RULE_INIT {
2: set static::response_header \"<html><head><title>Top referrers</title></head><body>\"
3: set static::response_footer \"</body></html>\"
4: }
5:
6: when HTTP_REQUEST {
7: set referrer_host [URI::host [HTTP::header value Referer]]
8:
9: if { $referrer_host eq \"\" } {
10: set referrer_host \"none\"
11: }
12:
13: if { [table incr -subtable referrers -mustexist $referrer_host] eq \"\" } {
14: table set -subtable referrers $referrer_host 1 indefinite indefinite
15: } else {
16: table incr -subtable referrers $referrer_host
17: }
18:
19: if { [HTTP::path] eq \"/admin\" } {
20: binary scan [md5 [HTTP::password]] H* password
21:
22: if { [class lookup [HTTP::username] $::authorized_users] equals $password } {
23: log local0. \"User [HTTP::username] has been authorized to access virtual server [virtual name]\"
24:
25: switch -glob [URI::query [HTTP::uri] action] {
26: reset_referrers {
27: foreach referrer [table keys -subtable referrers] {
28: table delete -subtable referrers $referrer
29: }
30:
31: HTTP::respond 200 content \"$static::response_header <center><br><h2>Referrer counters \\
32: reset</h2><br><a href=\\\"/admin?action=report_referrers\\\">Back to referrer chart</a> \\
33: </center>$static::response_footer\"
34: }
35: report_referrers -
36: default {
37: set chart \"http://chart.apis.google.com/chart?cht=pc&chs=550x300&chts=003399,20&\"
38: append chart \"chco=003399,CCFFFF&chtt=Top%20referrers%20for%20[HTTP::host]\"
39:
40: set chd \"\"
41: set chl \"\"
42:
43: foreach referrer [table keys -subtable referrers] {
44: append chd \",\" [table lookup -subtable referrers $referrer]
45: append chl \"|\" [URI::encode \"$referrer ([table lookup -subtable referrers $referrer] hits)\"]
46: }
47:
48: append chart \"&\" \"chd=t:[string trimleft $chd ,]\"
49: append chart \"&\" \"chl=[string trimleft $chl |]\"
50:
51: HTTP::respond 200 content \"$static::response_header <center><br><img src=\\\"$chart\\\" /><br> \\
52: <br><a href=\\\"/admin?action=reset_referrers\\\">Reset referrer counters</a></center> \\
53: $static::response_footer\"
54: }
55: }
56: } else {
57: if { [string length [HTTP::password]] != 0 } {
58: log local0. \"User [HTTP::username] has been denied access to virtual server [virtual name]\"
59: }
60:
61: HTTP::respond 401 WWW-Authenticate \"Basic realm=\\\"Secured Area\\\"\"
62: }
63:
64: }
65: }