This file is indexed.

/usr/share/perl5/Lire/WWW/UserAgent.pm is in lire 2:2.1.1-2.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package Lire::WWW::UserAgent;

use strict;

use vars qw/$REVISION $VERSION/;

use Lire::WWW::UserAgent::Robot;
use Lire::WWW::UserAgent::Browser;
use Lire::WWW::UserAgent::OS;
use Lire::WWW::UserAgent::Language;

use Carp;

BEGIN {
    $REVISION  = '$Id: UserAgent.pm,v 1.2 2006/07/23 13:16:36 vanbaal Exp $';
    $VERSION   = "0.2.0";
}

my %customOSHash = ();
my %compiledOSHash = ();

my %customRobotHash = ();
my %compiledRobotHash = ();

my %customBrowserHash = ();
my %compiledBrowserHash = ();

# -----------------------------------------------------------------------------
# Functions
# -----------------------------------------------------------------------------

sub new {
     my ($class, %args ) = @_;

     my $self = { 'os_default'	    =>  $args{'os_default'} || "Unknown",
		  'language_default'  => $args{'language_default'} || "Unknown",
		  'browser_default'   => $args{'browser_default'} || "Unknown",
		  'robot_default'	    => $args{'robot_default'} || "Unknown",
		};
     bless $self, $class;

     return $self;
}

sub setUserAgent {
    my ($self, $ua) = @_;

    if (defined $ua) {
        $self->{'user_agent'} = lc($ua);
    }
}


# If the 'browser' is a robot, it returns "Web Robot". Details
# can be obtained with getRobot();
sub getBrowser {
    my ($self) = @_;

    my $user_agent = $self->{'user_agent'};
    if (defined $user_agent) {
        return $self->{'browser_default'}
	  if ($self->{'notInBrowserHash'}{$user_agent});

        if (defined Lire::WWW::UserAgent::Robot::getRobot($user_agent)) {
            # browser is a robot. Do not specify which one.
            return "Web Robot";
        } elsif (defined (my $browser = Lire::WWW::UserAgent::Browser::getBrowser($user_agent))) {
            return $browser;
        } else {
            # check custom hash
            foreach my $key (keys %customBrowserHash) {
		my $re = $compiledBrowserHash{$key};
                if ($user_agent =~ /$re/) {
                    return $customBrowserHash{$key};
                }
            }
            $self->{'notInBrowserHash'}{$user_agent} = "1";
            return $self->{'browser_default'};
        }
    }
    return undef;
}

sub addBrowser {
    my ($self, $code, $value) = @_;

    croak "Must supply both code and value!\n"
      unless $code eq "" || $value eq "";

    $code = lc $code;
    $customBrowserHash{$code} = $value;
    $compiledBrowserHash{$code} = qr/$code/;
}

sub addBrowserHash {
    my ($self, %bhash) = @_;

    foreach my $code (keys %bhash) {
        $self->addBrowser($code, $bhash{$code});
    }
}

sub getRobot {
    my ($self) = @_;

    my $user_agent = $self->{'user_agent'};
    if (defined $user_agent) {
        return $self->{'robot_default'}
	  if ($self->{'notInRobotHash'}{$user_agent});

        if (defined (my $robot = Lire::WWW::UserAgent::Robot::getRobot($user_agent))) {
            return $robot;
        } else {
            # check custom hash
            foreach my $key (keys %customRobotHash) {
		my $re = $compiledRobotHash{$key};
                if ($user_agent =~ /$re/) {
                    return $customRobotHash{$key};
                }
            }
            $self->{'notInRobotHash'}{$user_agent} = "1";
            return $self->{'robot_default'};
        }
    }
    return undef;
}

sub addRobot {
    my ($self, $code, $value) = @_;

    croak "Must supply both code and value!\n"
      unless $code eq "" || $value eq "";

    $code = lc $code;
    $customRobotHash{$code} = $value;
    $compiledRobotHash{$code} = qr/$code/;
}

sub addRobotHash {
    my ($self, %rhash) = @_;

    foreach my $code (keys %rhash) {
        $self->addRobot($code, $rhash{$code});
    }
}

sub getOS {
    my ($self) = @_;

    my $user_agent = $self->{'user_agent'};
    if (defined $user_agent) {
        return $self->{'os_default'} if ($self->{'notInOSHash'}{$user_agent});

        if (defined (my $os = Lire::WWW::UserAgent::OS::getOS($user_agent))) {
            return $os;
        } else {
            # check custom hash
            foreach my $key (keys %customOSHash) {
		my $re = $compiledOSHash{$key};
                if ($user_agent =~ /$re/) {
                    return $customOSHash{$key};
                }
            }
            $self->{'notInOSHash'}{$user_agent} = "1";
            return $self->{'os_default'};
        }
    }
    return undef;
}

sub addOS {
    my ($self, $code, $value) = @_;

    croak "Must supply both code and value!\n"
      unless $code eq "" || $value eq "";

    $code = lc $code;
    $customOSHash{$code} = $value;
    $compiledOSHash{$code} = qr/$code/;
}

sub addOSHash {
    my ($self, %ohash) = @_;

    foreach my $code (keys %ohash) {
        $self->addOS($code, $ohash{$code});
    }
}

sub getLanguage {
    my ($self) = @_;

    my $user_agent = $self->{'user_agent'};
    return $self->{'language_default'} unless defined $user_agent;
    return $self->{'language_default'}
      if ($self->{'notInLanguageHash'}{$user_agent});

    my $lang = Lire::WWW::UserAgent::Language::getLanguage($user_agent);
    return $lang if $lang;

    $self->{'notInLanguageHash'}{$user_agent} = "1";
    return $self->{'language_default'};
}

1;

__END__

=pod

=head1 NAME

WWW::UserAgent - detect browser, operating system and more from the user agent string

=head1 SYNOPSIS

 use Lire::WWW::UserAgent;

 my $test_string = "Mozilla/5.0 (compatible; Konqueror/2.1.2; X11)";

 my $analyzer = new Lire::WWW::UserAgent();
 $analyzer->setUserAgent($test_string);

 print " Operating System      : " . $analyzer->getOS() . "\n";
 print " Browser               : " . $analyzer->getBrowser() . "\n";
 print "   using GUI language  : " . $analyzer->getLanguage() . "\n";
 print "   (opt) Web Robot name: " . $analyzer->getRobot() . "\n";

 %customBrowserHash = ("CustomWebBrowser" => "Custom Web Browser 2005");
 $analyzer->addBrowserHash(%testhash);

 $analyzer->addBrowser("LastMinuteBrowser", "Lastest Released LM Browser");

=head1 DESCRIPTION

This module offers an interface to databases with known browsers, operating
systems and other information useful in analyzing user agent strings as found
in Apache combined logfiles.

The default values used when no match can be found from the databases
can be set using parameters:

    my $analyzer = new Lire::WWW::UserAgent( 'os_default'	      => "Unknown OS",
					     'robot_default'    => "No Robot",
					     'language_default' => "Unknown",
					     'browser_default'  => "Unknown",
					    );


Optionally, the user can add custom information to the database with
the addX() and addXHash() functions, where X is the type of database.

This module is based on ideas as seen in AWStats.

=head1 SEE ALSO

RFC 1945 and RFC 2068, Mozilla's user-agent strings policy on
http://www.mozilla.org/build/revised-user-agent-strings.html .

=head1 VERSION

$Id: UserAgent.pm,v 1.2 2006/07/23 13:16:36 vanbaal Exp $

=head1 COPYRIGHT

Copyright (C) 2001, 2002  Stichting LogReport Foundation LogReport@LogReport.org

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program (see COPYING); if not, check with
http://www.gnu.org/copyleft/gpl.html.

=head1 AUTHORS

Egon Willighagen <egonw@logreport.org> and
Francis Lacoste <flacoste@logreport.org>

=cut