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

(-)a/C4/Auth.pm (-8 / +8 lines)
Lines 63-69 BEGIN { Link Here
63
    @ISA       = qw(Exporter);
63
    @ISA       = qw(Exporter);
64
    @EXPORT    = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions);
64
    @EXPORT    = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions);
65
    @EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &checkpw_internal &checkpw_hash
65
    @EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &checkpw_internal &checkpw_hash
66
      &get_all_subpermissions &get_user_subpermissions track_login_daily &in_ipset
66
      &get_all_subpermissions &get_user_subpermissions track_login_daily &in_iprange
67
    );
67
    );
68
    %EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] );
68
    %EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] );
69
    $ldap      = C4::Context->config('useldapserver') || 0;
69
    $ldap      = C4::Context->config('useldapserver') || 0;
Lines 2118-2137 sub haspermission { Link Here
2118
    #FIXME - This fcn should return the failed permission so a suitable error msg can be delivered.
2118
    #FIXME - This fcn should return the failed permission so a suitable error msg can be delivered.
2119
}
2119
}
2120
2120
2121
=head2 in_ipset
2121
=head2 in_iprange
2122
2122
2123
  $flags = ($ipset);
2123
  $flags = ($iprange);
2124
2124
2125
C<$ipset> A space separated string describing an IP set. Can include single IPs or ranges
2125
C<$iprange> A space separated string describing an IP range. Can include single IPs or ranges
2126
2126
2127
Returns 1 if the remote address is in the provided ipset, or 0 otherwise.
2127
Returns 1 if the remote address is in the provided iprange, or 0 otherwise.
2128
2128
2129
=cut
2129
=cut
2130
2130
2131
sub in_ipset {
2131
sub in_iprange {
2132
    my ($ipset) = @_;
2132
    my ($iprange) = @_;
2133
    my $result = 1;
2133
    my $result = 1;
2134
    my @allowedipranges = $ipset ? split(' ', $ipset) : ();
2134
    my @allowedipranges = $iprange ? split(' ', $iprange) : ();
2135
    if (scalar @allowedipranges > 0) {
2135
    if (scalar @allowedipranges > 0) {
2136
        my @rangelist;
2136
        my @rangelist;
2137
        eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2137
        eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
(-)a/opac/sco/printslip.pl (-1 / +1 lines)
Lines 35-41 use C4::Members; Link Here
35
use C4::Koha;
35
use C4::Koha;
36
36
37
my $input = new CGI;
37
my $input = new CGI;
38
unless ( in_ipset(C4::Context->preference('SelfCheckAllowByIPRanges')) ) {
38
unless ( in_iprange(C4::Context->preference('SelfCheckAllowByIPRanges')) ) {
39
    print $input->header(status => '403 Forbidden - functionality not available from your location');
39
    print $input->header(status => '403 Forbidden - functionality not available from your location');
40
    exit;
40
    exit;
41
}
41
}
(-)a/opac/sco/sco-main.pl (-2 / +2 lines)
Lines 35-41 use Modern::Perl; Link Here
35
35
36
use CGI qw ( -utf8 );
36
use CGI qw ( -utf8 );
37
37
38
use C4::Auth qw(get_template_and_user checkpw in_ipset);
38
use C4::Auth qw(get_template_and_user checkpw in_iprange);
39
use C4::Koha;
39
use C4::Koha;
40
use C4::Circulation;
40
use C4::Circulation;
41
use C4::Reserves;
41
use C4::Reserves;
Lines 59-65 unless (C4::Context->preference('WebBasedSelfCheck')) { Link Here
59
    exit;
59
    exit;
60
}
60
}
61
61
62
unless ( in_ipset(C4::Context->preference('SelfCheckAllowByIPRanges')) ) {
62
unless ( in_iprange(C4::Context->preference('SelfCheckAllowByIPRanges')) ) {
63
    # redirect to OPAC home if self-checkout not permitted from current IP
63
    # redirect to OPAC home if self-checkout not permitted from current IP
64
    print $query->redirect("/cgi-bin/koha/opac-main.pl");
64
    print $query->redirect("/cgi-bin/koha/opac-main.pl");
65
    exit;
65
    exit;
(-)a/opac/sco/sco-patron-image.pl (-2 / +2 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use C4::Auth qw(in_ipset);
21
use C4::Auth qw(in_iprange);
22
use C4::Service;
22
use C4::Service;
23
use C4::Members;
23
use C4::Members;
24
use Koha::Patron::Images;
24
use Koha::Patron::Images;
Lines 36-42 unless (C4::Context->preference('ShowPatronImageInWebBasedSelfCheck')) { Link Here
36
    exit;
36
    exit;
37
}
37
}
38
38
39
unless ( in_ipset(C4::Context->preference('SelfCheckAllowByIPRanges')) ) {
39
unless ( in_iprange(C4::Context->preference('SelfCheckAllowByIPRanges')) ) {
40
    print $query->header(status => '403 Forbidden - functionality not available from your location');
40
    print $query->header(status => '403 Forbidden - functionality not available from your location');
41
    exit;
41
    exit;
42
}
42
}
(-)a/t/Auth.t (-15 / +14 lines)
Lines 19-42 use Modern::Perl; Link Here
19
use Test::More tests => 13;
19
use Test::More tests => 13;
20
use Test::Warn;
20
use Test::Warn;
21
21
22
use C4::Auth qw / in_ipset /;
22
use C4::Auth qw / in_iprange /;
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";
26
26
27
ok(in_ipset("192.168.1.30"), 'simple single ip matching remote ip');
27
ok(in_iprange("192.168.1.30"), 'simple single ip matching remote ip');
28
ok(!in_ipset("192.168.1.31"), 'simple single ip not match remote ip');
28
ok(!in_iprange("192.168.1.31"), 'simple single ip not match remote ip');
29
ok(in_ipset("192.168.1.1/24"), 'simple ip range/24 with remote ip in it');
29
ok(in_iprange("192.168.1.1/24"), 'simple ip range/24 with remote ip in it');
30
ok(!in_ipset("192.168.2.1/24"), 'simple ip range/24 with remote ip not in it');
30
ok(!in_iprange("192.168.2.1/24"), 'simple ip range/24 with remote ip not in it');
31
ok(in_ipset("192.168.2.1/16"), 'simple ip range/16 with remote ip in it');
31
ok(in_iprange("192.168.2.1/16"), 'simple ip range/16 with remote ip in it');
32
ok(!in_ipset("192.168.1.10-30"), 'invalidly represented IP range with remote ip in it');
32
ok(!in_iprange("192.168.1.10-30"), 'invalidly represented IP range with remote ip in it');
33
ok(in_ipset("192.168.1.10-192.168.1.30"), 'validly represented ip range with remote ip in it');
33
ok(in_iprange("192.168.1.10-192.168.1.30"), 'validly represented ip range with remote ip in it');
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_iprange("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_iprange("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_iprange(""), "blank list given, no preference set - implies everything goes through.");
37
ok(in_ipset(), "no list given, no preference set - implies everything goes through.");
37
ok(in_iprange(), "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');
38
ok(in_iprange("192.168.1.1/36"), 'simple invalid ip range/36 with remote ip in it');
39
$ENV{DEBUG} = 1;
39
$ENV{DEBUG} = 1;
40
warning_like { in_ipset("192.168.1.1/36") }
40
warning_like { in_iprange("192.168.1.1/36") }
41
    qr/cidrlookup failed for/,
41
    qr/cidrlookup failed for/,
42
    'noisy simple invalid ip range/36 with remote ip in it';
42
    'noisy simple invalid ip range/36 with remote ip in it';
43
- 

Return to bug 22943