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

(-)a/C4/Auth.pm (-7 / +10 lines)
Lines 1218-1226 sub checkauth { Link Here
1218
                        if ( C4::Context->preference('StaffLoginRestrictLibraryByIP') ) {
1218
                        if ( C4::Context->preference('StaffLoginRestrictLibraryByIP') ) {
1219
                            # we have to check they are coming from the right ip range
1219
                            # we have to check they are coming from the right ip range
1220
                            my $domain = $branches->{$branchcode}->{'branchip'} // q{};
1220
                            my $domain = $branches->{$branchcode}->{'branchip'} // q{};
1221
                            $domain =~ s|\.\*||g;
1221
                            next unless ( $domain );
1222
                            $domain =~ s/\s+//g;
1222
                            if ( ! in_iprange($domain) ) {
1223
                            if ( $domain && $ip !~ /^$domain/ ) {
1224
                                $cookie = $cookie_mgr->replace_in_list( $cookie, $query->cookie(
1223
                                $cookie = $cookie_mgr->replace_in_list( $cookie, $query->cookie(
1225
                                    -name     => 'CGISESSID',
1224
                                    -name     => 'CGISESSID',
1226
                                    -value    => '',
1225
                                    -value    => '',
Lines 1253-1259 sub checkauth { Link Here
1253
1252
1254
                                #     now we work with the treatment of ip
1253
                                #     now we work with the treatment of ip
1255
                                my $domain = $branches->{$br}->{'branchip'};
1254
                                my $domain = $branches->{$br}->{'branchip'};
1256
                                if ( $domain && $ip =~ /^$domain/ ) {
1255
                                next unless ( $domain );
1256
                                if ( in_iprange($domain) ) {
1257
                                    $branchcode = $branches->{$br}->{'branchcode'};
1257
                                    $branchcode = $branches->{$br}->{'branchcode'};
1258
1258
1259
                                    # new op dev : add the branchname to the cookie
1259
                                    # new op dev : add the branchname to the cookie
Lines 1730-1736 sub check_api_auth { Link Here
1730
1730
1731
                    #     now we work with the treatment of ip
1731
                    #     now we work with the treatment of ip
1732
                    my $domain = $branches->{$br}->{'branchip'};
1732
                    my $domain = $branches->{$br}->{'branchip'};
1733
                    if ( $domain && $ip =~ /^$domain/ ) {
1733
                    next unless ( $domain );
1734
                    if ( in_iprange($domain) ) {
1734
                        $branchcode = $branches->{$br}->{'branchcode'};
1735
                        $branchcode = $branches->{$br}->{'branchcode'};
1735
1736
1736
                        # new op dev : add the branchname to the cookie
1737
                        # new op dev : add the branchname to the cookie
Lines 2363-2371 Returns 1 if the remote address is in the provided iprange, or 0 otherwise. Link Here
2363
2364
2364
sub in_iprange {
2365
sub in_iprange {
2365
    my ($iprange) = @_;
2366
    my ($iprange) = @_;
2366
    my $result = 1;
2367
    my $result = 0;
2368
    # FIXME remove '*' for backwards compatibility in branchip settings
2369
    $iprange =~ s|\*||g;
2367
    my @allowedipranges = $iprange ? split(' ', $iprange) : ();
2370
    my @allowedipranges = $iprange ? split(' ', $iprange) : ();
2368
    if (scalar @allowedipranges > 0) {
2371
    if (@allowedipranges) {
2369
        my @rangelist;
2372
        my @rangelist;
2370
        eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2373
        eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2371
        eval { $result = Net::CIDR::cidrlookup($ENV{'REMOTE_ADDR'}, @rangelist) } || Koha::Logger->get->warn('cidrlookup failed for ' . join(' ',@rangelist) );
2374
        eval { $result = Net::CIDR::cidrlookup($ENV{'REMOTE_ADDR'}, @rangelist) } || Koha::Logger->get->warn('cidrlookup failed for ' . join(' ',@rangelist) );
(-)a/installer/data/mysql/atomicupdate/bug_28657.perl (+23 lines)
Line 0 Link Here
1
$DBversion = 'XXX'; # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do( "ALTER TABLE `branches` MODIFY `branchip` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the IP address(s) for your library or branch'" );
4
5
    my $sth = $dbh->prepare("
6
        SELECT branchip,branchcode
7
        FROM branches
8
        WHERE branchip like '%*%'
9
    ");
10
    $sth->execute;
11
    my $results = $sth->fetchall_arrayref({});
12
    $sth = $dbh->prepare("
13
        UPDATE branches
14
	SET branchip = ?
15
        WHERE branchcode = ?
16
    ");
17
    foreach(@$results) {
18
	$_->{branchip} =~ s|\*||g;
19
        $sth->execute($_->{branchip}, $_->{branchcode});
20
    }
21
22
    NewVersion( $DBversion, 28657, "expand branches.branchip to allow for multiple ip ranges and remove '*'");
23
}
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 1658-1664 CREATE TABLE `branches` ( Link Here
1658
  `branchreturnpath` longtext DEFAULT NULL COMMENT 'the email to be used as Return-Path',
1658
  `branchreturnpath` longtext DEFAULT NULL COMMENT 'the email to be used as Return-Path',
1659
  `branchurl` longtext DEFAULT NULL COMMENT 'the URL for your library or branch''s website',
1659
  `branchurl` longtext DEFAULT NULL COMMENT 'the URL for your library or branch''s website',
1660
  `issuing` tinyint(4) DEFAULT NULL COMMENT 'unused in Koha',
1660
  `issuing` tinyint(4) DEFAULT NULL COMMENT 'unused in Koha',
1661
  `branchip` varchar(15) DEFAULT NULL COMMENT 'the IP address for your library or branch',
1661
  `branchip` mediumtext DEFAULT NULL COMMENT 'the IP address for your library or branch',
1662
  `branchnotes` longtext DEFAULT NULL COMMENT 'notes related to your library or branch',
1662
  `branchnotes` longtext DEFAULT NULL COMMENT 'notes related to your library or branch',
1663
  `geolocation` varchar(255) DEFAULT NULL COMMENT 'geolocation of your library',
1663
  `geolocation` varchar(255) DEFAULT NULL COMMENT 'geolocation of your library',
1664
  `marcorgcode` varchar(16) DEFAULT NULL COMMENT 'MARC Organization Code, see http://www.loc.gov/marc/organizations/orgshome.html, when empty defaults to syspref MARCOrgCode',
1664
  `marcorgcode` varchar(16) DEFAULT NULL COMMENT 'MARC Organization Code, see http://www.loc.gov/marc/organizations/orgshome.html, when empty defaults to syspref MARCOrgCode',
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-3 / +2 lines)
Lines 250-257 Link Here
250
                </li>
250
                </li>
251
                <li>
251
                <li>
252
                    <label for="branchip">IP: </label>
252
                    <label for="branchip">IP: </label>
253
                    <input type="text" name="branchip" id="branchip"  size="15" maxlength="15" value="[% library.branchip | html %]" />
253
                    <input type="text" name="branchip" id="branchip"  size="60" maxlength="60" value="[% library.branchip | html %]" />
254
                    <div class="hint">Can be entered as a single IP, or a subnet such as 192.168.1.*</div>
254
                    <div class="hint">Can be entered as a single IP, an IP range such as 192.168.1. or 192.168.1.10-192.168.1.50 or 192.168.1.0/24, or multiple space separated IP addresses or ranges.</div>
255
                </li>
255
                </li>
256
                <li>
256
                <li>
257
                    <label for="marcorgcode">MARC organization code</label>
257
                    <label for="marcorgcode">MARC organization code</label>
258
- 

Return to bug 28657