Phoebe/DebugIpNumbers.pm untested

filter: Statementstmt 0.0% 0 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 20 CC 1 SCAR 6.9
CC
1
Cov
0%
handle_request
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 # -*- mode: perl -*-
2 # Copyright (C) 2017–2021 Alex Schroeder <alex@gnu.org>
3  
4 # This program is free software: you can redistribute it and/or modify it under
5 # the terms of the GNU Affero General Public License as published by the Free
6 # Software Foundation, either version 3 of the License, or (at your option) any
7 # later version.
8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU Affero General Public License along
15 # with this program. If not, see <https://www.gnu.org/licenses/>.
16  
17 =head1 NAME
18  
19 App::Phoebe::DebugIpNumbers - log visitor IP numbers for Phoebe
20  
21 =head1 DESCRIPTION
22  
23 By default the IP numbers of your visitors are not logged. This small extensions
24 allows you to log them anyway if you're trying to figure out whether a bot is
25 going crazy.
26  
27 There is no configuration. Simply add it to your F<config> file:
28  
29 use App::Phoebe::DebugIpNumbers;
30  
31 Phoebe tries not to collect visitor data. Logging visitor IP numbers goes
32 against this. If your aim is detect and block crazy bots by having C<fail2ban>
33 watch the log files, consider using L<App::Phoebe::SpeedBump> instead.
34  
35 =cut
36  
37 package App::Phoebe::DebugIpNumbers;
38 use App::Phoebe qw($log);
39 use Modern::Perl;
40  
41 # We have to override the copy that was imported into the main namespace in the
42 # start_servers subroutine.
43 no warnings 'redefine';
44 *old_handle_request = \&main::handle_request;
45 *main::handle_request = \&handle_request;
46  
47 sub handle_request {
48 my ($stream) = @_;
49 my $address = $stream->handle->peerhost;
50 $log->debug("Visitor: $address");
51 return old_handle_request(@_);
52 }
53  
54 1;