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

(-)a/C4/Auth.pm (-6 / +9 lines)
Lines 1278-1286 sub checkauth { Link Here
1278
1278
1279
                            # we have to check they are coming from the right ip range
1279
                            # we have to check they are coming from the right ip range
1280
                            my $domain = $branches->{$branchcode}->{'branchip'} // q{};
1280
                            my $domain = $branches->{$branchcode}->{'branchip'} // q{};
1281
                            $domain =~ s|\.\*||g;
1281
                            next unless ( $domain );
1282
                            $domain =~ s/\s+//g;
1282
                            if ( ! in_iprange($domain) ) {
1283
                            if ( $domain && $ip !~ /^$domain/ ) {
1284
                                $cookie = $cookie_mgr->replace_in_list(
1283
                                $cookie = $cookie_mgr->replace_in_list(
1285
                                    $cookie,
1284
                                    $cookie,
1286
                                    $query->cookie(
1285
                                    $query->cookie(
Lines 1316-1322 sub checkauth { Link Here
1316
1315
1317
                                #     now we work with the treatment of ip
1316
                                #     now we work with the treatment of ip
1318
                                my $domain = $branches->{$br}->{'branchip'};
1317
                                my $domain = $branches->{$br}->{'branchip'};
1319
                                if ( $domain && $ip =~ /^$domain/ ) {
1318
                                next unless ( $domain );
1319
                                if ( in_iprange($domain) ) {
1320
                                    $branchcode = $branches->{$br}->{'branchcode'};
1320
                                    $branchcode = $branches->{$br}->{'branchcode'};
1321
1321
1322
                                    # new op dev : add the branchname to the cookie
1322
                                    # new op dev : add the branchname to the cookie
Lines 1813-1819 sub check_api_auth { Link Here
1813
1813
1814
                    #     now we work with the treatment of ip
1814
                    #     now we work with the treatment of ip
1815
                    my $domain = $branches->{$br}->{'branchip'};
1815
                    my $domain = $branches->{$br}->{'branchip'};
1816
                    if ( $domain && $ip =~ /^$domain/ ) {
1816
                    next unless ( $domain );
1817
                    if ( in_iprange($domain) ) {
1817
                        $branchcode = $branches->{$br}->{'branchcode'};
1818
                        $branchcode = $branches->{$br}->{'branchcode'};
1818
1819
1819
                        # new op dev : add the branchname to the cookie
1820
                        # new op dev : add the branchname to the cookie
Lines 2472-2478 Returns 1 if the remote address is in the provided iprange, or 0 otherwise. Link Here
2472
2473
2473
sub in_iprange {
2474
sub in_iprange {
2474
    my ($iprange)       = @_;
2475
    my ($iprange)       = @_;
2475
    my $result          = 1;
2476
    my $result          = 0;
2477
    # FIXME remove '*' for backwards compatibility in branchip settings
2478
    $iprange            =~ s|\*||g;
2476
    my @allowedipranges = $iprange ? split( ' ', $iprange ) : ();
2479
    my @allowedipranges = $iprange ? split( ' ', $iprange ) : ();
2477
    if ( scalar @allowedipranges > 0 ) {
2480
    if ( scalar @allowedipranges > 0 ) {
2478
        my @rangelist;
2481
        my @rangelist;
(-)a/Koha/Template/Plugin/Branches.pm (-4 / +2 lines)
Lines 25-30 use base qw( Template::Plugin ); Link Here
25
25
26
use C4::Koha;
26
use C4::Koha;
27
use C4::Context;
27
use C4::Context;
28
use C4::Auth qw(in_iprange);
28
use Koha::Cache::Memory::Lite;
29
use Koha::Cache::Memory::Lite;
29
use Koha::Libraries;
30
use Koha::Libraries;
30
31
Lines 91-103 sub all { Link Here
91
        : Koha::Libraries->search_filtered( $search_params, { order_by => ['branchname'] } )->unblessed;
92
        : Koha::Libraries->search_filtered( $search_params, { order_by => ['branchname'] } )->unblessed;
92
93
93
    if ($ip_limit) {
94
    if ($ip_limit) {
94
        my $ip           = $ENV{'REMOTE_ADDR'};
95
        my @ip_libraries = ();
95
        my @ip_libraries = ();
96
        for my $l (@$libraries) {
96
        for my $l (@$libraries) {
97
            my $domain = $l->{branchip} // '';
97
            my $domain = $l->{branchip} // '';
98
            $domain =~ s|\.\*||g;
98
            unless ( $domain && ! in_iprange($domain) ) {
99
            $domain =~ s/\s+//g;
100
            unless ( $domain && $ip !~ /^$domain/ ) {
101
                push @ip_libraries, $l;
99
                push @ip_libraries, $l;
102
            }
100
            }
103
        }
101
        }
(-)a/api/v1/swagger/definitions/library.yaml (-1 / +1 lines)
Lines 85-91 properties: Link Here
85
      - string
85
      - string
86
      - "null"
86
      - "null"
87
    description: the IP address for your library or branch
87
    description: the IP address for your library or branch
88
    maxLength: 15
88
    maxLength: 120
89
  notes:
89
  notes:
90
    type:
90
    type:
91
      - string
91
      - string
(-)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 1670-1676 CREATE TABLE `branches` ( Link Here
1670
  `branchreturnpath` longtext DEFAULT NULL COMMENT 'the email to be used as Return-Path',
1670
  `branchreturnpath` longtext DEFAULT NULL COMMENT 'the email to be used as Return-Path',
1671
  `branchurl` longtext DEFAULT NULL COMMENT 'the URL for your library or branch''s website',
1671
  `branchurl` longtext DEFAULT NULL COMMENT 'the URL for your library or branch''s website',
1672
  `issuing` tinyint(4) DEFAULT NULL COMMENT 'unused in Koha',
1672
  `issuing` tinyint(4) DEFAULT NULL COMMENT 'unused in Koha',
1673
  `branchip` varchar(15) DEFAULT NULL COMMENT 'the IP address for your library or branch',
1673
  `branchip` mediumtext DEFAULT NULL COMMENT 'the IP address for your library or branch',
1674
  `branchnotes` longtext DEFAULT NULL COMMENT 'notes related to your library or branch',
1674
  `branchnotes` longtext DEFAULT NULL COMMENT 'notes related to your library or branch',
1675
  `geolocation` varchar(255) DEFAULT NULL COMMENT 'geolocation of your library',
1675
  `geolocation` varchar(255) DEFAULT NULL COMMENT 'geolocation of your library',
1676
  `marcorgcode` varchar(16) DEFAULT NULL COMMENT 'MARC Organization Code, see http://www.loc.gov/marc/organizations/orgshome.html, when empty defaults to syspref MARCOrgCode',
1676
  `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 362-370 Link Here
362
                        <label for="branchip">IP: </label>
362
                        <label for="branchip">IP: </label>
363
                    </div>
363
                    </div>
364
                    <div class="fg-input">
364
                    <div class="fg-input">
365
                        <input type="text" name="branchip" id="branchip" size="15" maxlength="15" value="[% library.branchip | html %]" />
365
                        <input type="text" name="branchip" id="branchip" size="60" maxlength="120" value="[% library.branchip | html %]" />
366
                    </div>
366
                    </div>
367
                    <div class="hint">Enter as a single IP address, or a subnet such as 192.168.1.*</div>
367
                    <div class="hint">Enter as a single IP address, 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>
368
                </div>
368
                </div>
369
                <div class="fg-row">
369
                <div class="fg-row">
370
                    <div class="fg-label">
370
                    <div class="fg-label">
371
- 

Return to bug 28657