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

(-)a/C4/Auth.pm (-6 / +10 lines)
Lines 1213-1220 sub checkauth { Link Here
1213
1213
1214
                        # we have to check they are coming from the right ip range
1214
                        # we have to check they are coming from the right ip range
1215
                        my $domain = $branches->{$branchcode}->{'branchip'};
1215
                        my $domain = $branches->{$branchcode}->{'branchip'};
1216
                        $domain =~ s|\.\*||g;
1216
                        next unless ( $domain );
1217
                        if ( $ip !~ /^$domain/ ) {
1217
                        if ( ! in_iprange($domain) ) {
1218
                            $loggedin = 0;
1218
                            $loggedin = 0;
1219
                            $cookie = $cookie_mgr->replace_in_list( $cookie, $query->cookie(
1219
                            $cookie = $cookie_mgr->replace_in_list( $cookie, $query->cookie(
1220
                                -name     => 'CGISESSID',
1220
                                -name     => 'CGISESSID',
Lines 1231-1237 sub checkauth { Link Here
1231
1231
1232
                        #     now we work with the treatment of ip
1232
                        #     now we work with the treatment of ip
1233
                        my $domain = $branches->{$br}->{'branchip'};
1233
                        my $domain = $branches->{$br}->{'branchip'};
1234
                        if ( $domain && $ip =~ /^$domain/ ) {
1234
                        next unless ( $domain );
1235
                        if ( in_iprange($domain) ) {
1235
                            $branchcode = $branches->{$br}->{'branchcode'};
1236
                            $branchcode = $branches->{$br}->{'branchcode'};
1236
1237
1237
                            # new op dev : add the branchname to the cookie
1238
                            # new op dev : add the branchname to the cookie
Lines 1665-1671 sub check_api_auth { Link Here
1665
1666
1666
                    #     now we work with the treatment of ip
1667
                    #     now we work with the treatment of ip
1667
                    my $domain = $branches->{$br}->{'branchip'};
1668
                    my $domain = $branches->{$br}->{'branchip'};
1668
                    if ( $domain && $ip =~ /^$domain/ ) {
1669
                    next unless ( $domain );
1670
                    if ( in_iprange($domain) ) {
1669
                        $branchcode = $branches->{$br}->{'branchcode'};
1671
                        $branchcode = $branches->{$br}->{'branchcode'};
1670
1672
1671
                        # new op dev : add the branchname to the cookie
1673
                        # new op dev : add the branchname to the cookie
Lines 2232-2240 Returns 1 if the remote address is in the provided iprange, or 0 otherwise. Link Here
2232
2234
2233
sub in_iprange {
2235
sub in_iprange {
2234
    my ($iprange) = @_;
2236
    my ($iprange) = @_;
2235
    my $result = 1;
2237
    my $result = 0;
2238
    # FIXME remove '*' for backwards compatibility in branchip settings
2239
    $iprange =~ s|\*||g;
2236
    my @allowedipranges = $iprange ? split(' ', $iprange) : ();
2240
    my @allowedipranges = $iprange ? split(' ', $iprange) : ();
2237
    if (scalar @allowedipranges > 0) {
2241
    if (@allowedipranges) {
2238
        my @rangelist;
2242
        my @rangelist;
2239
        eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2243
        eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2240
        eval { $result = Net::CIDR::cidrlookup($ENV{'REMOTE_ADDR'}, @rangelist) } || Koha::Logger->get->warn('cidrlookup failed for ' . join(' ',@rangelist) );
2244
        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 1514-1520 CREATE TABLE `branches` ( Link Here
1514
  `branchreturnpath` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the email to be used as Return-Path',
1514
  `branchreturnpath` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the email to be used as Return-Path',
1515
  `branchurl` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the URL for your library or branch''s website',
1515
  `branchurl` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the URL for your library or branch''s website',
1516
  `issuing` tinyint(4) DEFAULT NULL COMMENT 'unused in Koha',
1516
  `issuing` tinyint(4) DEFAULT NULL COMMENT 'unused in Koha',
1517
  `branchip` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the IP address for your library or branch',
1517
  `branchip` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the IP address(s) for your library or branch',
1518
  `branchnotes` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'notes related to your library or branch',
1518
  `branchnotes` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'notes related to your library or branch',
1519
  `opac_info` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'HTML that displays in OPAC',
1519
  `opac_info` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'HTML that displays in OPAC',
1520
  `geolocation` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'geolocation of your library',
1520
  `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