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

(-)a/C4/Auth.pm (-6 / +7 lines)
Lines 1209-1216 sub checkauth { Link Here
1209
1209
1210
                        # we have to check they are coming from the right ip range
1210
                        # we have to check they are coming from the right ip range
1211
                        my $domain = $branches->{$branchcode}->{'branchip'};
1211
                        my $domain = $branches->{$branchcode}->{'branchip'};
1212
                        $domain =~ s|\.\*||g;
1212
                        if ( ! in_iprange($domain) ) {
1213
                        if ( $ip !~ /^$domain/ ) {
1214
                            $loggedin = 0;
1213
                            $loggedin = 0;
1215
                            $cookie = $query->cookie(
1214
                            $cookie = $query->cookie(
1216
                                -name     => 'CGISESSID',
1215
                                -name     => 'CGISESSID',
Lines 1226-1232 sub checkauth { Link Here
1226
1225
1227
                        #     now we work with the treatment of ip
1226
                        #     now we work with the treatment of ip
1228
                        my $domain = $branches->{$br}->{'branchip'};
1227
                        my $domain = $branches->{$br}->{'branchip'};
1229
                        if ( $domain && $ip =~ /^$domain/ ) {
1228
                        if ( in_iprange($domain) ) {
1230
                            $branchcode = $branches->{$br}->{'branchcode'};
1229
                            $branchcode = $branches->{$br}->{'branchcode'};
1231
1230
1232
                            # new op dev : add the branchname to the cookie
1231
                            # new op dev : add the branchname to the cookie
Lines 1682-1688 sub check_api_auth { Link Here
1682
1681
1683
                    #     now we work with the treatment of ip
1682
                    #     now we work with the treatment of ip
1684
                    my $domain = $branches->{$br}->{'branchip'};
1683
                    my $domain = $branches->{$br}->{'branchip'};
1685
                    if ( $domain && $ip =~ /^$domain/ ) {
1684
                    if ( in_iprange($domain) ) {
1686
                        $branchcode = $branches->{$br}->{'branchcode'};
1685
                        $branchcode = $branches->{$br}->{'branchcode'};
1687
1686
1688
                        # new op dev : add the branchname to the cookie
1687
                        # new op dev : add the branchname to the cookie
Lines 2249-2257 Returns 1 if the remote address is in the provided iprange, or 0 otherwise. Link Here
2249
2248
2250
sub in_iprange {
2249
sub in_iprange {
2251
    my ($iprange) = @_;
2250
    my ($iprange) = @_;
2252
    my $result = 1;
2251
    my $result = 0;
2252
    # FIXME remove '*' for backwards compatibility in branchip settings
2253
    $iprange =~ s|\*||g;
2253
    my @allowedipranges = $iprange ? split(' ', $iprange) : ();
2254
    my @allowedipranges = $iprange ? split(' ', $iprange) : ();
2254
    if (scalar @allowedipranges > 0) {
2255
    if (@allowedipranges) {
2255
        my @rangelist;
2256
        my @rangelist;
2256
        eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2257
        eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2257
        eval { $result = Net::CIDR::cidrlookup($ENV{'REMOTE_ADDR'}, @rangelist) } || ( $ENV{DEBUG} && warn 'cidrlookup failed for ' . join(' ',@rangelist) );
2258
        eval { $result = Net::CIDR::cidrlookup($ENV{'REMOTE_ADDR'}, @rangelist) } || ( $ENV{DEBUG} && 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 1488-1494 CREATE TABLE `branches` ( Link Here
1488
  `branchreturnpath` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the email to be used as Return-Path',
1488
  `branchreturnpath` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the email to be used as Return-Path',
1489
  `branchurl` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the URL for your library or branch''s website',
1489
  `branchurl` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the URL for your library or branch''s website',
1490
  `issuing` tinyint(4) DEFAULT NULL COMMENT 'unused in Koha',
1490
  `issuing` tinyint(4) DEFAULT NULL COMMENT 'unused in Koha',
1491
  `branchip` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the IP address for your library or branch',
1491
  `branchip` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the IP address(s) for your library or branch',
1492
  `branchnotes` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'notes related to your library or branch',
1492
  `branchnotes` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'notes related to your library or branch',
1493
  `opac_info` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'HTML that displays in OPAC',
1493
  `opac_info` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'HTML that displays in OPAC',
1494
  `geolocation` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'geolocation of your library',
1494
  `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