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

(-)a/C4/Auth.pm (-6 / +10 lines)
Lines 1180-1187 sub checkauth { Link Here
1180
1180
1181
                        # we have to check they are coming from the right ip range
1181
                        # we have to check they are coming from the right ip range
1182
                        my $domain = $branches->{$branchcode}->{'branchip'};
1182
                        my $domain = $branches->{$branchcode}->{'branchip'};
1183
                        $domain =~ s|\.\*||g;
1183
                        next unless ( $domain );
1184
                        if ( $ip !~ /^$domain/ ) {
1184
                        if ( ! in_iprange($domain) ) {
1185
                            $loggedin = 0;
1185
                            $loggedin = 0;
1186
                            $cookie = $query->cookie(
1186
                            $cookie = $query->cookie(
1187
                                -name     => 'CGISESSID',
1187
                                -name     => 'CGISESSID',
Lines 1197-1203 sub checkauth { Link Here
1197
1197
1198
                        #     now we work with the treatment of ip
1198
                        #     now we work with the treatment of ip
1199
                        my $domain = $branches->{$br}->{'branchip'};
1199
                        my $domain = $branches->{$br}->{'branchip'};
1200
                        if ( $domain && $ip =~ /^$domain/ ) {
1200
                        next unless ( $domain );
1201
                        if ( in_iprange($domain) ) {
1201
                            $branchcode = $branches->{$br}->{'branchcode'};
1202
                            $branchcode = $branches->{$br}->{'branchcode'};
1202
1203
1203
                            # new op dev : add the branchname to the cookie
1204
                            # new op dev : add the branchname to the cookie
Lines 1603-1609 sub check_api_auth { Link Here
1603
1604
1604
                    #     now we work with the treatment of ip
1605
                    #     now we work with the treatment of ip
1605
                    my $domain = $branches->{$br}->{'branchip'};
1606
                    my $domain = $branches->{$br}->{'branchip'};
1606
                    if ( $domain && $ip =~ /^$domain/ ) {
1607
                    next unless ( $domain );
1608
                    if ( in_iprange($domain) ) {
1607
                        $branchcode = $branches->{$br}->{'branchcode'};
1609
                        $branchcode = $branches->{$br}->{'branchcode'};
1608
1610
1609
                        # new op dev : add the branchname to the cookie
1611
                        # new op dev : add the branchname to the cookie
Lines 2167-2175 Returns 1 if the remote address is in the provided iprange, or 0 otherwise. Link Here
2167
2169
2168
sub in_iprange {
2170
sub in_iprange {
2169
    my ($iprange) = @_;
2171
    my ($iprange) = @_;
2170
    my $result = 1;
2172
    my $result = 0;
2173
    # FIXME remove '*' for backwards compatibility in branchip settings
2174
    $iprange =~ s|\*||g;
2171
    my @allowedipranges = $iprange ? split(' ', $iprange) : ();
2175
    my @allowedipranges = $iprange ? split(' ', $iprange) : ();
2172
    if (scalar @allowedipranges > 0) {
2176
    if (@allowedipranges) {
2173
        my @rangelist;
2177
        my @rangelist;
2174
        eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2178
        eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2175
        eval { $result = Net::CIDR::cidrlookup($ENV{'REMOTE_ADDR'}, @rangelist) } || Koha::Logger->get->warn('cidrlookup failed for ' . join(' ',@rangelist) );
2179
        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 1511-1517 CREATE TABLE `branches` ( Link Here
1511
  `branchreturnpath` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the email to be used as Return-Path',
1511
  `branchreturnpath` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the email to be used as Return-Path',
1512
  `branchurl` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the URL for your library or branch''s website',
1512
  `branchurl` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the URL for your library or branch''s website',
1513
  `issuing` tinyint(4) DEFAULT NULL COMMENT 'unused in Koha',
1513
  `issuing` tinyint(4) DEFAULT NULL COMMENT 'unused in Koha',
1514
  `branchip` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the IP address for your library or branch',
1514
  `branchip` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the IP address(s) for your library or branch',
1515
  `branchnotes` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'notes related to your library or branch',
1515
  `branchnotes` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'notes related to your library or branch',
1516
  `opac_info` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'HTML that displays in OPAC',
1516
  `opac_info` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'HTML that displays in OPAC',
1517
  `geolocation` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'geolocation of your library',
1517
  `geolocation` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'geolocation of your library',
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-3 / +2 lines)
Lines 238-245 Libraries › Administration › Koha Link Here
238
                <li><label for="opac_info">OPAC info: </label><textarea name="opac_info" id="opac_info">[% library.opac_info | $raw %]</textarea></li>
238
                <li><label for="opac_info">OPAC info: </label><textarea name="opac_info" id="opac_info">[% library.opac_info | $raw %]</textarea></li>
239
                <li>
239
                <li>
240
                    <label for="branchip">IP: </label>
240
                    <label for="branchip">IP: </label>
241
                    <input type="text" name="branchip" id="branchip"  size="15" maxlength="15" value="[% library.branchip | html %]" />
241
                    <input type="text" name="branchip" id="branchip"  size="60" maxlength="60" value="[% library.branchip | html %]" />
242
                    <div class="hint">Can be entered as a single IP, or a subnet such as 192.168.1.*</div>
242
                    <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>
243
                </li>
243
                </li>
244
                <li>
244
                <li>
245
                    <label for="marcorgcode">MARC organization code</label>
245
                    <label for="marcorgcode">MARC organization code</label>
246
- 

Return to bug 28657