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

(-)a/C4/Auth.pm (-6 / +10 lines)
Lines 1186-1193 sub checkauth { Link Here
1186
1186
1187
                        # we have to check they are coming from the right ip range
1187
                        # we have to check they are coming from the right ip range
1188
                        my $domain = $branches->{$branchcode}->{'branchip'};
1188
                        my $domain = $branches->{$branchcode}->{'branchip'};
1189
                        $domain =~ s|\.\*||g;
1189
                        next unless ( $domain );
1190
                        if ( $ip !~ /^$domain/ ) {
1190
                        if ( ! in_iprange($domain) ) {
1191
                            $loggedin = 0;
1191
                            $loggedin = 0;
1192
                            $cookie = $cookie_mgr->replace_in_list( $cookie, $query->cookie(
1192
                            $cookie = $cookie_mgr->replace_in_list( $cookie, $query->cookie(
1193
                                -name     => 'CGISESSID',
1193
                                -name     => 'CGISESSID',
Lines 1204-1210 sub checkauth { Link Here
1204
1204
1205
                        #     now we work with the treatment of ip
1205
                        #     now we work with the treatment of ip
1206
                        my $domain = $branches->{$br}->{'branchip'};
1206
                        my $domain = $branches->{$br}->{'branchip'};
1207
                        if ( $domain && $ip =~ /^$domain/ ) {
1207
                        next unless ( $domain );
1208
                        if ( in_iprange($domain) ) {
1208
                            $branchcode = $branches->{$br}->{'branchcode'};
1209
                            $branchcode = $branches->{$br}->{'branchcode'};
1209
1210
1210
                            # new op dev : add the branchname to the cookie
1211
                            # new op dev : add the branchname to the cookie
Lines 1647-1653 sub check_api_auth { Link Here
1647
1648
1648
                    #     now we work with the treatment of ip
1649
                    #     now we work with the treatment of ip
1649
                    my $domain = $branches->{$br}->{'branchip'};
1650
                    my $domain = $branches->{$br}->{'branchip'};
1650
                    if ( $domain && $ip =~ /^$domain/ ) {
1651
                    next unless ( $domain );
1652
                    if ( in_iprange($domain) ) {
1651
                        $branchcode = $branches->{$br}->{'branchcode'};
1653
                        $branchcode = $branches->{$br}->{'branchcode'};
1652
1654
1653
                        # new op dev : add the branchname to the cookie
1655
                        # new op dev : add the branchname to the cookie
Lines 2260-2268 Returns 1 if the remote address is in the provided iprange, or 0 otherwise. Link Here
2260
2262
2261
sub in_iprange {
2263
sub in_iprange {
2262
    my ($iprange) = @_;
2264
    my ($iprange) = @_;
2263
    my $result = 1;
2265
    my $result = 0;
2266
    # FIXME remove '*' for backwards compatibility in branchip settings
2267
    $iprange =~ s|\*||g;
2264
    my @allowedipranges = $iprange ? split(' ', $iprange) : ();
2268
    my @allowedipranges = $iprange ? split(' ', $iprange) : ();
2265
    if (scalar @allowedipranges > 0) {
2269
    if (@allowedipranges) {
2266
        my @rangelist;
2270
        my @rangelist;
2267
        eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2271
        eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2268
        eval { $result = Net::CIDR::cidrlookup($ENV{'REMOTE_ADDR'}, @rangelist) } || Koha::Logger->get->warn('cidrlookup failed for ' . join(' ',@rangelist) );
2272
        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 1536-1542 CREATE TABLE `branches` ( Link Here
1536
  `branchreturnpath` longtext DEFAULT NULL COMMENT 'the email to be used as Return-Path',
1536
  `branchreturnpath` longtext DEFAULT NULL COMMENT 'the email to be used as Return-Path',
1537
  `branchurl` longtext DEFAULT NULL COMMENT 'the URL for your library or branch''s website',
1537
  `branchurl` longtext DEFAULT NULL COMMENT 'the URL for your library or branch''s website',
1538
  `issuing` tinyint(4) DEFAULT NULL COMMENT 'unused in Koha',
1538
  `issuing` tinyint(4) DEFAULT NULL COMMENT 'unused in Koha',
1539
  `branchip` varchar(15) DEFAULT NULL COMMENT 'the IP address for your library or branch',
1539
  `branchip` mediumtext DEFAULT NULL COMMENT 'the IP address for your library or branch',
1540
  `branchnotes` longtext DEFAULT NULL COMMENT 'notes related to your library or branch',
1540
  `branchnotes` longtext DEFAULT NULL COMMENT 'notes related to your library or branch',
1541
  `geolocation` varchar(255) DEFAULT NULL COMMENT 'geolocation of your library',
1541
  `geolocation` varchar(255) DEFAULT NULL COMMENT 'geolocation of your library',
1542
  `marcorgcode` varchar(16) DEFAULT NULL COMMENT 'MARC Organization Code, see http://www.loc.gov/marc/organizations/orgshome.html, when empty defaults to syspref MARCOrgCode',
1542
  `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 253-260 Libraries › Administration › Koha Link Here
253
                </li>
253
                </li>
254
                <li>
254
                <li>
255
                    <label for="branchip">IP: </label>
255
                    <label for="branchip">IP: </label>
256
                    <input type="text" name="branchip" id="branchip"  size="15" maxlength="15" value="[% library.branchip | html %]" />
256
                    <input type="text" name="branchip" id="branchip"  size="60" maxlength="60" value="[% library.branchip | html %]" />
257
                    <div class="hint">Can be entered as a single IP, or a subnet such as 192.168.1.*</div>
257
                    <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>
258
                </li>
258
                </li>
259
                <li>
259
                <li>
260
                    <label for="marcorgcode">MARC organization code</label>
260
                    <label for="marcorgcode">MARC organization code</label>
261
- 

Return to bug 28657