]> git.ipfire.org Git - thirdparty/squid.git/blame - contrib/user-agents.pl
Source Format Enforcement (#532)
[thirdparty/squid.git] / contrib / user-agents.pl
CommitLineData
0b88822c 1#!/usr/bin/perl
df3cec97 2#
77b1029d 3# * Copyright (C) 1996-2020 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
14require "getopts.pl";
15&Getopts('FML:');
16
17open (ACCESS, "/opt/Squid/logs/useragent.0");
18
19while (<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;
37if (!$opt_L) {$opt_L=0}
38
39print "Summary of User-Agent Strings\n(greater than $opt_L percent)\n\n";
40
41foreach $browser (keys(%seen)) {
42 $total=$total+$seen{$browser};
43}
44
45foreach $browser (sort keys(%seen)) {
46 $percent=$seen{$browser}/$total*100;
47 if ($percent >= $opt_L) { write; }
48}
49
50print "\n\nTotal entries in log = $total\n";
51
52format STDOUT =
53@>>>>>>> :@##.####% : @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
54$seen{$browser}, $percent, $browser
55.