]>
Commit | Line | Data |
---|---|---|
0b88822c | 1 | #!/usr/bin/perl |
df3cec97 | 2 | # |
4ac4a490 | 3 | # * Copyright (C) 1996-2017 The Squid Software Foundation and contributors |
df3cec97 AJ |
4 | # * |
5 | # * Squid software is distributed under GPLv2+ license and includes | |
6 | # * contributions from numerous individuals and organizations. | |
7 | # * Please see the COPYING and CONTRIBUTORS files for details. | |
8 | # | |
9 | ||
0b88822c | 10 | # |
11 | # John@MCC.ac.uk | |
12 | # John@Pharmweb.NET | |
13 | ||
14 | require "getopts.pl"; | |
15 | &Getopts('FML:'); | |
16 | ||
17 | open (ACCESS, "/opt/Squid/logs/useragent.0"); | |
18 | ||
19 | while (<ACCESS>) { | |
20 | ($host, $timestamp, $agent) = | |
21 | /^(\S+) \[(.+)\] \"(.+)\"\s/; | |
22 | if ($agent ne '-') { | |
23 | if ($opt_M) { | |
24 | $agent =~ tr/\// /; | |
25 | $agent =~ tr/\(/ /; | |
26 | } | |
27 | if ($opt_F) { | |
28 | next unless $seen{$agent}++; | |
29 | } else { | |
30 | @inline=split(/ /, $agent); | |
31 | next unless $seen{$inline[0]}++; | |
32 | } | |
33 | } | |
34 | } | |
35 | ||
36 | $total=0; | |
37 | if (!$opt_L) {$opt_L=0} | |
38 | ||
39 | print "Summary of User-Agent Strings\n(greater than $opt_L percent)\n\n"; | |
40 | ||
41 | foreach $browser (keys(%seen)) { | |
42 | $total=$total+$seen{$browser}; | |
43 | } | |
44 | ||
45 | foreach $browser (sort keys(%seen)) { | |
46 | $percent=$seen{$browser}/$total*100; | |
47 | if ($percent >= $opt_L) { write; } | |
48 | } | |
49 | ||
50 | print "\n\nTotal entries in log = $total\n"; | |
51 | ||
52 | format STDOUT = | |
53 | @>>>>>>> :@##.####% : @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | |
54 | $seen{$browser}, $percent, $browser | |
55 | . |