View | Details | Raw Unified | Return to bug 41892
Collapse All | Expand All

(-)a/C4/Auth.pm (-3 / +5 lines)
Lines 43-48 use C4::Languages; Link Here
43
use C4::Search::History;
43
use C4::Search::History;
44
use C4::Output qw( output_and_exit );
44
use C4::Output qw( output_and_exit );
45
use Koha;
45
use Koha;
46
use Koha::Context::RemoteAddress;
47
use Koha::Context::Preferences;
46
use Koha::Logger;
48
use Koha::Logger;
47
use Koha::Caches;
49
use Koha::Caches;
48
use Koha::AuthUtils qw( get_script_name hash_password );
50
use Koha::AuthUtils qw( get_script_name hash_password );
Lines 71-80 use Koha::Session; Link Here
71
use vars qw($ldap $cas $caslogout);
73
use vars qw($ldap $cas $caslogout);
72
74
73
BEGIN {
75
BEGIN {
74
    C4::Context->set_remote_address;
76
    Koha::Context::RemoteAddress->set;
75
77
76
    $cas       = C4::Context->preference('casAuthentication');
78
    $cas       = Koha::Context::Preferences->get_value('casAuthentication');
77
    $caslogout = C4::Context->preference('casLogout');
79
    $caslogout = Koha::Context::Preferences->get_value('casLogout');
78
80
79
    if ($cas) {
81
    if ($cas) {
80
        require C4::Auth_with_cas;    # no import
82
        require C4::Auth_with_cas;    # no import
(-)a/C4/Context.pm (-20 lines)
Lines 878-903 sub temporary_directory { Link Here
878
    return C4::Context->config('tmp_path') || File::Spec->tmpdir;
878
    return C4::Context->config('tmp_path') || File::Spec->tmpdir;
879
}
879
}
880
880
881
=head3 set_remote_address
882
883
set_remote_address should be called at the beginning of every script
884
that is *not* running under plack in order to the REMOTE_ADDR environment
885
variable to be set correctly.
886
887
=cut
888
889
sub set_remote_address {
890
    if ( C4::Context->config('koha_trusted_proxies') ) {
891
        require CGI;
892
        my $header = CGI->http('HTTP_X_FORWARDED_FOR');
893
894
        if ($header) {
895
            require Koha::Middleware::RealIP;
896
            $ENV{REMOTE_ADDR} = Koha::Middleware::RealIP::get_real_ip( $ENV{REMOTE_ADDR}, $header );
897
        }
898
    }
899
}
900
901
=head3 https_enabled
881
=head3 https_enabled
902
882
903
https_enabled should be called when checking if a HTTPS connection
883
https_enabled should be called when checking if a HTTPS connection
(-)a/Koha/Context/RemoteAddress.pm (-1 / +54 lines)
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;

Return to bug 41892