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

(-)a/C4/Auth.pm (-10 / +9 lines)
Lines 2072-2087 Returns 1 if the remote address is in the provided ipset, or 0 otherwise. Link Here
2072
=cut
2072
=cut
2073
2073
2074
sub in_ipset {
2074
sub in_ipset {
2075
 my ($ipset) = @_;
2075
    my ($ipset) = @_;
2076
 my @allowedipranges = split(' ', $ipset);
2076
    my $result = 1;
2077
 if (scalar @allowedipranges > 0) {
2077
    my @allowedipranges = $ipset ? split(' ', $ipset) : ();
2078
    my @rangelist;
2078
    if (scalar @allowedipranges > 0) {
2079
    eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2079
        my @rangelist;
2080
    unless (Net::CIDR::cidrlookup($ENV{'REMOTE_ADDR'}, @rangelist)) {
2080
        eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2081
      return 0;
2081
        eval { $result = Net::CIDR::cidrlookup($ENV{'REMOTE_ADDR'}, @rangelist) } || ( $ENV{DEBUG} && warn 'cidrlookup failed for ' . join(' ',@rangelist) );
2082
    }
2082
     }
2083
 }
2083
     return $result ? 1 : 0;
2084
 return 1;
2085
}
2084
}
2086
2085
2087
sub getborrowernumber {
2086
sub getborrowernumber {
(-)a/t/Auth.t (-3 / +8 lines)
Lines 16-25 Link Here
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use Test::More tests => 10;
19
use Test::More tests => 13;
20
use Test::Warn;
20
21
21
use C4::Auth qw / in_ipset /;
22
use C4::Auth qw / in_ipset /;
22
use warnings;
23
23
24
$ENV{REMOTE_ADDR} = '192.168.1.30';
24
$ENV{REMOTE_ADDR} = '192.168.1.30';
25
my $ipset1 = "192.168.1.30";
25
my $ipset1 = "192.168.1.30";
Lines 34-36 ok(in_ipset("192.168.1.10-192.168.1.30"), 'validly represented ip range with rem Link Here
34
ok(in_ipset("127.0.0.1 192.168.1.30 192.168.2.10-192.168.2.25"), 'multiple ips and ranges, including the remote ip');
34
ok(in_ipset("127.0.0.1 192.168.1.30 192.168.2.10-192.168.2.25"), 'multiple ips and ranges, including the remote ip');
35
ok(!in_ipset("127.0.0.1 8.8.8.8 192.168.2.1/24 192.168.3.1/24 192.168.1.1-192.168.1.29"), "multiple ip and ip ranges, with the remote ip in none of them");
35
ok(!in_ipset("127.0.0.1 8.8.8.8 192.168.2.1/24 192.168.3.1/24 192.168.1.1-192.168.1.29"), "multiple ip and ip ranges, with the remote ip in none of them");
36
ok(in_ipset(""), "blank list given, no preference set - implies everything goes through.");
36
ok(in_ipset(""), "blank list given, no preference set - implies everything goes through.");
37
- 
37
ok(in_ipset(), "no list given, no preference set - implies everything goes through.");
38
ok(in_ipset("192.168.1.1/36"), 'simple invalid ip range/36 with remote ip in it');
39
$ENV{DEBUG} = 1;
40
warning_like { in_ipset("192.168.1.1/36") }
41
    qr/cidrlookup failed for/,
42
    'noisy simple invalid ip range/36 with remote ip in it';

Return to bug 14407