|
Line 0
Link Here
|
| 0 |
- |
1 |
package Koha::Context::RemoteAddress; |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <https://www.gnu.org/licenses>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use Koha::Config; |
| 21 |
|
| 22 |
=head1 NAME |
| 23 |
|
| 24 |
Koha::Context::RemoteAddress - Set the remote address |
| 25 |
|
| 26 |
=head1 SYNOPSIS |
| 27 |
|
| 28 |
Koha::Context::RemoteAddress->set; |
| 29 |
|
| 30 |
=head1 METHODS |
| 31 |
|
| 32 |
=cut |
| 33 |
|
| 34 |
=head3 set |
| 35 |
|
| 36 |
Koha::Context::RemoteAddress->set should be called at the beginning of every script |
| 37 |
that is *not* running under plack in order to the REMOTE_ADDR environment |
| 38 |
variable to be set correctly. |
| 39 |
|
| 40 |
=cut |
| 41 |
|
| 42 |
sub set { |
| 43 |
if ( Koha::Config->get_instance->get('koha_trusted_proxies') ) { |
| 44 |
require CGI; |
| 45 |
my $header = CGI->http('HTTP_X_FORWARDED_FOR'); |
| 46 |
|
| 47 |
if ($header) { |
| 48 |
require Koha::Middleware::RealIP; |
| 49 |
$ENV{REMOTE_ADDR} = Koha::Middleware::RealIP::get_real_ip( $ENV{REMOTE_ADDR}, $header ); |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
1; |