|
Lines 79-85
sub get_real_ip {
Link Here
|
| 79 |
my @forwarded_for = $header =~ /([^,\s]+)/g; |
79 |
my @forwarded_for = $header =~ /([^,\s]+)/g; |
| 80 |
return $remote_addr unless @forwarded_for; |
80 |
return $remote_addr unless @forwarded_for; |
| 81 |
|
81 |
|
| 82 |
my $trusted_proxies = get_trusted_proxies(); |
82 |
my $trusted_proxies; |
|
|
83 |
# Cache the trusted proxies list |
| 84 |
my $cache = Koha::Caches->get_instance(); |
| 85 |
my $cache_active = $cache->is_cache_active; |
| 86 |
my $cache_key = "trustedproxylist"; |
| 87 |
if ($cache_active) { |
| 88 |
$trusted_proxies = $cache->get_from_cache($cache_key); |
| 89 |
} |
| 90 |
unless ($trusted_proxies) { |
| 91 |
$trusted_proxies = get_trusted_proxies(); |
| 92 |
if ($cache_active) { |
| 93 |
$cache->set_in_cache( $cache_key, $trusted_proxies); |
| 94 |
} |
| 95 |
} |
| 83 |
|
96 |
|
| 84 |
#X-Forwarded-For: <client>, <proxy1>, <proxy2> |
97 |
#X-Forwarded-For: <client>, <proxy1>, <proxy2> |
| 85 |
my $real_ip = shift @forwarded_for; |
98 |
my $real_ip = shift @forwarded_for; |
|
Lines 105-122
the trusted proxies given to Koha.
Link Here
|
| 105 |
|
118 |
|
| 106 |
sub get_trusted_proxies { |
119 |
sub get_trusted_proxies { |
| 107 |
my $proxies_conf = C4::Context->config('koha_trusted_proxies'); |
120 |
my $proxies_conf = C4::Context->config('koha_trusted_proxies'); |
| 108 |
return unless $proxies_conf; |
121 |
my $external_proxies_list_file = C4::Context->config('koha_trusted_proxies_external_list'); |
| 109 |
my @trusted_proxies_ip = split( / /, $proxies_conf ); |
122 |
|
|
|
123 |
return unless ( $external_proxies_list_file || $proxies_conf ); |
| 124 |
|
| 110 |
my @trusted_proxies = (); |
125 |
my @trusted_proxies = (); |
| 111 |
foreach my $ip (@trusted_proxies_ip){ |
126 |
|
| 112 |
my $mask = Net::Netmask->new2($ip); |
127 |
if ($external_proxies_list_file && (-f $external_proxies_list_file)) { |
| 113 |
if ($mask){ |
128 |
if (open my $in, "<", $external_proxies_list_file) { |
| 114 |
push(@trusted_proxies,$mask); |
129 |
while (my $line = <$in>) { |
| 115 |
} |
130 |
chomp $line; |
| 116 |
else { |
131 |
my $finalmask = Net::Netmask->new2($line); |
| 117 |
warn "$Net::Netmask::error"; |
132 |
if ($finalmask) { |
| 118 |
} |
133 |
push(@trusted_proxies, $finalmask); |
|
|
134 |
} |
| 135 |
else { |
| 136 |
warn "$Net::Netmask::error"; |
| 137 |
} |
| 138 |
} |
| 139 |
close $in; |
| 140 |
} else { |
| 141 |
warn "Could not read external proxy list $external_proxies_list_file" |
| 142 |
} |
| 119 |
} |
143 |
} |
|
|
144 |
|
| 145 |
if ($proxies_conf) { |
| 146 |
my @trusted_proxies_ip = split( / /, $proxies_conf ); |
| 147 |
foreach my $ip (@trusted_proxies_ip){ |
| 148 |
my $mask = Net::Netmask->new2($ip); |
| 149 |
if ($mask){ |
| 150 |
push(@trusted_proxies,$mask); |
| 151 |
} |
| 152 |
else { |
| 153 |
warn "$Net::Netmask::error"; |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 120 |
return \@trusted_proxies; |
158 |
return \@trusted_proxies; |
| 121 |
} |
159 |
} |
| 122 |
|
160 |
|
|
Lines 124-129
sub get_trusted_proxies {
Link Here
|
| 124 |
=head1 AUTHORS |
162 |
=head1 AUTHORS |
| 125 |
|
163 |
|
| 126 |
Kyle M Hall <kyle@bywatersolutions.com> |
164 |
Kyle M Hall <kyle@bywatersolutions.com> |
|
|
165 |
Nicholas van Oudtshoorn, 2024 <nicholas@pbc.wa.edu.au> |
| 127 |
|
166 |
|
| 128 |
=cut |
167 |
=cut |
| 129 |
|
168 |
|