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

(-)a/C4/Auth.pm (-5 / +5 lines)
Lines 498-504 sub get_template_and_user { Link Here
498
            advancedMARCEditor           => C4::Context->preference("advancedMARCEditor"),
498
            advancedMARCEditor           => C4::Context->preference("advancedMARCEditor"),
499
            AllowMultipleCovers          => C4::Context->preference('AllowMultipleCovers'),
499
            AllowMultipleCovers          => C4::Context->preference('AllowMultipleCovers'),
500
            AmazonCoverImages            => C4::Context->preference("AmazonCoverImages"),
500
            AmazonCoverImages            => C4::Context->preference("AmazonCoverImages"),
501
            AutoLocation                 => C4::Context->preference("AutoLocation"),
501
            StaffLoginRestrictBranchByIP => C4::Context->preference("StaffLoginRestrictBranchByIP"),
502
            can_see_cataloguing_module   => haspermission( $user, get_cataloguing_page_permissions() ) ? 1 : 0,
502
            can_see_cataloguing_module   => haspermission( $user, get_cataloguing_page_permissions() ) ? 1 : 0,
503
            canreservefromotherbranches  => C4::Context->preference('canreservefromotherbranches'),
503
            canreservefromotherbranches  => C4::Context->preference('canreservefromotherbranches'),
504
            EasyAnalyticalRecords        => C4::Context->preference('EasyAnalyticalRecords'),
504
            EasyAnalyticalRecords        => C4::Context->preference('EasyAnalyticalRecords'),
Lines 1216-1222 sub checkauth { Link Here
1216
                    }
1216
                    }
1217
                    if ( $type ne 'opac' ) {
1217
                    if ( $type ne 'opac' ) {
1218
                        my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search->as_list };
1218
                        my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search->as_list };
1219
                        if ( C4::Context->preference('AutoLocation') ) {
1219
                        if ( C4::Context->preference('StaffLoginRestrictBranchByIP') ) {
1220
                            # we have to check they are coming from the right ip range
1220
                            # we have to check they are coming from the right ip range
1221
                            my $domain = $branches->{$branchcode}->{'branchip'};
1221
                            my $domain = $branches->{$branchcode}->{'branchip'};
1222
                            $domain =~ s|\.\*||g;
1222
                            $domain =~ s|\.\*||g;
Lines 1236-1245 sub checkauth { Link Here
1236
1236
1237
                        if (
1237
                        if (
1238
                            (
1238
                            (
1239
                                  !C4::Context->preference('AutoLocation')
1239
                                  !C4::Context->preference('StaffLoginRestrictBranchByIP')
1240
                                && C4::Context->preference('StaffLoginBranchBasedOnIP')
1240
                                && C4::Context->preference('StaffLoginBranchBasedOnIP')
1241
                            )
1241
                            )
1242
                            || ( C4::Context->preference('AutoLocation') && $auth_state ne 'failed' )
1242
                            || ( C4::Context->preference('StaffLoginRestrictBranchByIP') && $auth_state ne 'failed' )
1243
                            )
1243
                            )
1244
                        {
1244
                        {
1245
                            my @branchcodes = sort { lc $a cmp lc $b } keys %$branches;
1245
                            my @branchcodes = sort { lc $a cmp lc $b } keys %$branches;
Lines 1438-1444 sub checkauth { Link Here
1438
        IntranetUserCSS                       => C4::Context->preference("IntranetUserCSS"),
1438
        IntranetUserCSS                       => C4::Context->preference("IntranetUserCSS"),
1439
        IntranetUserJS                        => C4::Context->preference("IntranetUserJS"),
1439
        IntranetUserJS                        => C4::Context->preference("IntranetUserJS"),
1440
        IndependentBranches                   => C4::Context->preference("IndependentBranches"),
1440
        IndependentBranches                   => C4::Context->preference("IndependentBranches"),
1441
        AutoLocation                          => C4::Context->preference("AutoLocation"),
1441
        StaffLoginRestrictBranchByIP          => C4::Context->preference("StaffLoginRestrictBranchByIP"),
1442
        wrongip                               => $info{'wrongip'},
1442
        wrongip                               => $info{'wrongip'},
1443
        PatronSelfRegistration                => C4::Context->preference("PatronSelfRegistration"),
1443
        PatronSelfRegistration                => C4::Context->preference("PatronSelfRegistration"),
1444
        PatronSelfRegistrationDefaultCategory => C4::Context->preference("PatronSelfRegistrationDefaultCategory"),
1444
        PatronSelfRegistrationDefaultCategory => C4::Context->preference("PatronSelfRegistrationDefaultCategory"),
(-)a/C4/UsageStats.pm (-1 / +1 lines)
Lines 146-152 sub _shared_preferences { Link Here
146
        noItemTypeImages
146
        noItemTypeImages
147
        OpacNoItemTypeImages
147
        OpacNoItemTypeImages
148
        virtualshelves
148
        virtualshelves
149
        AutoLocation
149
        StaffLoginRestrictBranchByIP
150
        IndependentBranches
150
        IndependentBranches
151
        SessionStorage
151
        SessionStorage
152
        Persona
152
        Persona
(-)a/installer/data/mysql/atomicupdate/bug_26176.pl (+18 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
3
4
return {
5
    bug_number  => "26176",
6
    description => "Rename AutoLocation to StaffLoginRestrictBranchByIP",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        $dbh->do(q{
12
            UPDATE systempreferences SET variable = "StaffLoginRestrictBranchByIP"
13
            WHERE variable = "AutoLocation"
14
        });
15
16
        say $out "Renamed system preference 'AutoLocation' to 'StaffLoginRestrictBranchByIP'";
17
    },
18
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (-2 / +2 lines)
Lines 90-96 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
90
('AutoCreditNumber', '', '', 'Automatically generate a number for account credits', 'Choice'),
90
('AutoCreditNumber', '', '', 'Automatically generate a number for account credits', 'Choice'),
91
('AutoEmailNewUser','0',NULL,'Send an email to newly created patrons.','YesNo'),
91
('AutoEmailNewUser','0',NULL,'Send an email to newly created patrons.','YesNo'),
92
('AutoLinkBiblios','0',NULL,'If enabled, link biblio to authorities on creation and edit','YesNo'),
92
('AutoLinkBiblios','0',NULL,'If enabled, link biblio to authorities on creation and edit','YesNo'),
93
('AutoLocation','0',NULL,'If ON, IP authentication is enabled, blocking access to the staff interface from unauthorized IP addresses','YesNo'),
94
('AutomaticCheckinAutoFill','0',NULL,'Automatically fill the next hold with an automatic check in.','YesNo'),
93
('AutomaticCheckinAutoFill','0',NULL,'Automatically fill the next hold with an automatic check in.','YesNo'),
95
('AutomaticConfirmTransfer','0',NULL,'Defines whether transfers should be automatically confirmed at checkin if modal dismissed','YesNo'),
94
('AutomaticConfirmTransfer','0',NULL,'Defines whether transfers should be automatically confirmed at checkin if modal dismissed','YesNo'),
96
('AutomaticItemReturn','1',NULL,'If ON, Koha will automatically set up a transfer of this item to its homebranch','YesNo'),
95
('AutomaticItemReturn','1',NULL,'If ON, Koha will automatically set up a transfer of this item to its homebranch','YesNo'),
Lines 736-743 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
736
('StaffDetailItemSelection', '1', NULL, 'Enable item selection in record detail page', 'YesNo'),
735
('StaffDetailItemSelection', '1', NULL, 'Enable item selection in record detail page', 'YesNo'),
737
('StaffHighlightedWords','1','','Highlight search terms on staff interface','YesNo'),
736
('StaffHighlightedWords','1','','Highlight search terms on staff interface','YesNo'),
738
('StaffLangSelectorMode','footer','top|both|footer','Select the location to display the language selector in staff interface','Choice'),
737
('StaffLangSelectorMode','footer','top|both|footer','Select the location to display the language selector in staff interface','Choice'),
739
('StaffLoginInstructions', '', NULL, 'HTML to go into the login box for the staff interface','Free'),
740
('StaffLoginBranchBasedOnIP', '0','', 'Set the logged in branch for the user based on their current IP','YesNo'),
738
('StaffLoginBranchBasedOnIP', '0','', 'Set the logged in branch for the user based on their current IP','YesNo'),
739
('StaffLoginInstructions', '', NULL, 'HTML to go into the login box for the staff interface','Free'),
740
('StaffLoginRestrictBranchByIP','0',NULL,'If ON, IP authentication is enabled, blocking access to the staff interface from unauthorized IP addresses based on branch','YesNo'),
741
('StaffSearchResultsDisplayBranch','holdingbranch','holdingbranch|homebranch','Controls the display of the home or holding branch for staff search results','Choice'),
741
('StaffSearchResultsDisplayBranch','holdingbranch','holdingbranch|homebranch','Controls the display of the home or holding branch for staff search results','Choice'),
742
('StaffSerialIssueDisplayCount','3','','Number of serial issues to display per subscription in the staff interface','Integer'),
742
('StaffSerialIssueDisplayCount','3','','Number of serial issues to display per subscription in the staff interface','Integer'),
743
('staffShibOnly','0','','If ON enables shibboleth only authentication for the staff client','YesNo'),
743
('staffShibOnly','0','','If ON enables shibboleth only authentication for the staff client','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc (-2 / +2 lines)
Lines 95-101 Link Here
95
                        [% SET is_superlibrarian = CAN_user_superlibrarian ? 'is_superlibrarian' : '' %]
95
                        [% SET is_superlibrarian = CAN_user_superlibrarian ? 'is_superlibrarian' : '' %]
96
                        <span class="loggedinusername [% is_superlibrarian | html %]">[% logged_in_user.userid | html %]</span>
96
                        <span class="loggedinusername [% is_superlibrarian | html %]">[% logged_in_user.userid | html %]</span>
97
                        <span class="loggedincategorycode content_hidden">[% logged_in_user.categorycode | html %]</span>
97
                        <span class="loggedincategorycode content_hidden">[% logged_in_user.categorycode | html %]</span>
98
                        [% IF ( AutoLocation ) %]
98
                        [% IF ( StaffLoginRestrictBranchByIP ) %]
99
                            <brand>
99
                            <brand>
100
                                [% Branches.GetLoggedInBranchname | html %]
100
                                [% Branches.GetLoggedInBranchname | html %]
101
                            </brand>
101
                            </brand>
Lines 133-139 Link Here
133
                        <span class="loggedinusername">[% logged_in_user.userid | html %]</span>
133
                        <span class="loggedinusername">[% logged_in_user.userid | html %]</span>
134
                    </li>
134
                    </li>
135
                    <li class="loggedin-menu-label">
135
                    <li class="loggedin-menu-label">
136
                        [% IF ( AutoLocation ) %]
136
                        [% IF ( StaffLoginRestrictBranchByIP ) %]
137
                            <brand>
137
                            <brand>
138
                                [% Branches.GetLoggedInBranchname | html %]
138
                                [% Branches.GetLoggedInBranchname | html %]
139
                            </brand>
139
                            </brand>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref (-2 / +2 lines)
Lines 92-98 Administration: Link Here
92
            - Adding d will specify it in days, e.g. 1d is timeout of one day.
92
            - Adding d will specify it in days, e.g. 1d is timeout of one day.
93
        -
93
        -
94
            - "Require staff to log in from a computer in the IP address range specified by their library or the branch chosen at login (if any): "
94
            - "Require staff to log in from a computer in the IP address range specified by their library or the branch chosen at login (if any): "
95
            - pref: AutoLocation
95
            - pref: StaffLoginRestrictBranchByIP
96
              default: 0
96
              default: 0
97
              choices:
97
              choices:
98
                  1: "Yes"
98
                  1: "Yes"
Lines 115-121 Administration: Link Here
115
                  1: "Yes"
115
                  1: "Yes"
116
                  0: "No"
116
                  0: "No"
117
            - "Note: If IPs overlap, the first found match will be used."
117
            - "Note: If IPs overlap, the first found match will be used."
118
            - 'This setting will be overridden by <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=AutoLocation">AutoLocation</a> system preference. In the event of multiple branches with matching IPs, branchcode (alphabetically) will be the tie breaker.'
118
            - 'This setting will be overridden by <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=StaffLoginRestrictBranchByIP">StaffLoginRestrictBranchByIP</a> system preference. In the event of multiple branches with matching IPs, branchcode (alphabetically) will be the tie breaker.'
119
        # PostgreSQL is supported by CGI::Session but not by Koha.
119
        # PostgreSQL is supported by CGI::Session but not by Koha.
120
        -
120
        -
121
            - "Storage of login session information: "
121
            - "Storage of login session information: "
(-)a/t/db_dependent/Auth.t (-14 / +12 lines)
Lines 1298-1305 subtest 'StaffLoginBranchBasedOnIP' => sub { Link Here
1298
1298
1299
    $schema->storage->txn_begin;
1299
    $schema->storage->txn_begin;
1300
1300
1301
    t::lib::Mocks::mock_preference( 'AutoLocation',              0 );
1301
    t::lib::Mocks::mock_preference( 'StaffLoginRestrictBranchByIP', 0 );
1302
    t::lib::Mocks::mock_preference( 'StaffLoginBranchBasedOnIP', 0 );
1302
    t::lib::Mocks::mock_preference( 'StaffLoginBranchBasedOnIP',    0 );
1303
1303
1304
    my $patron   = $builder->build_object( { class => 'Koha::Patrons',   value => { flags    => 1 } } );
1304
    my $patron   = $builder->build_object( { class => 'Koha::Patrons',   value => { flags    => 1 } } );
1305
    my $branch   = $builder->build_object( { class => 'Koha::Libraries', value => { branchip => "127.0.0.1" } } );
1305
    my $branch   = $builder->build_object( { class => 'Koha::Libraries', value => { branchip => "127.0.0.1" } } );
Lines 1331-1346 subtest 'StaffLoginBranchBasedOnIP' => sub { Link Here
1331
    $session = C4::Auth::get_session($sessionID);
1331
    $session = C4::Auth::get_session($sessionID);
1332
    is( $session->param('branch'), $branch->branchcode, "Logged in branch is set based on the IP from REMOTE_ADDR " );
1332
    is( $session->param('branch'), $branch->branchcode, "Logged in branch is set based on the IP from REMOTE_ADDR " );
1333
1333
1334
    # AutoLocation overrides StaffLoginBranchBasedOnIP
1334
    # StaffLoginRestrictBranchByIP overrides StaffLoginBranchBasedOnIP
1335
    t::lib::Mocks::mock_preference( 'AutoLocation', 1 );
1335
    t::lib::Mocks::mock_preference( 'StaffLoginRestrictBranchByIP', 1 );
1336
    ( $userid, $cookie, $sessionID, $flags, $template ) =
1336
    ( $userid, $cookie, $sessionID, $flags, $template ) =
1337
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } );
1337
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } );
1338
    is(
1338
    is(
1339
        $template->{VARS}->{wrongip}, 1,
1339
        $template->{VARS}->{wrongip}, 1,
1340
        "AutoLocation prevents StaffLoginBranchBasedOnIP from logging user in to another branch"
1340
        "StaffLoginRestrictBranchByIP prevents StaffLoginBranchBasedOnIP from logging user in to another branch"
1341
    );
1341
    );
1342
1342
1343
    t::lib::Mocks::mock_preference( 'AutoLocation', 0 );
1343
    t::lib::Mocks::mock_preference( 'StaffLoginRestrictBranchByIP', 0 );
1344
    my $other_branch = $builder->build_object(
1344
    my $other_branch = $builder->build_object(
1345
        { class => 'Koha::Libraries', value => { branchip => "127.0.0.1", branchcode => "z" . $branch->branchcode } } );
1345
        { class => 'Koha::Libraries', value => { branchip => "127.0.0.1", branchcode => "z" . $branch->branchcode } } );
1346
    ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' );
1346
    ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' );
Lines 1353-1365 subtest 'StaffLoginBranchBasedOnIP' => sub { Link Here
1353
1353
1354
};
1354
};
1355
1355
1356
subtest 'AutoLocation' => sub {
1356
subtest 'StaffLoginRestrictBranchByIP' => sub {
1357
1357
1358
    plan tests => 10;
1358
    plan tests => 10;
1359
1359
1360
    $schema->storage->txn_begin;
1360
    $schema->storage->txn_begin;
1361
1361
1362
    t::lib::Mocks::mock_preference( 'AutoLocation', 0 );
1362
    t::lib::Mocks::mock_preference( 'StaffLoginRestrictBranchByIP', 0 );
1363
1363
1364
    my $patron   = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } );
1364
    my $patron   = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } );
1365
    my $password = 'password';
1365
    my $password = 'password';
Lines 1377-1388 subtest 'AutoLocation' => sub { Link Here
1377
1377
1378
    $ENV{REMOTE_ADDR} = '127.0.0.1';
1378
    $ENV{REMOTE_ADDR} = '127.0.0.1';
1379
    my ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' );
1379
    my ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' );
1380
    is( $userid, $patron->userid, "Standard login without AutoLocation" );
1380
    is( $userid, $patron->userid, "Standard login without StaffLoginRestrictBranchByIP" );
1381
1381
1382
    my $template;
1382
    my $template;
1383
    t::lib::Mocks::mock_preference( 'AutoLocation', 1 );
1383
    t::lib::Mocks::mock_preference( 'StaffLoginRestrictBranchByIP', 1 );
1384
1384
1385
    # AutoLocation: "Require staff to log in from a computer in the IP address range specified by their library (if any)"
1385
    # StaffLoginRestrictBranchByIP: "Require staff to log in from a computer in the IP address range specified by their library (if any)"
1386
    $patron->library->branchip('')->store;    # There is none, allow access from anywhere
1386
    $patron->library->branchip('')->store;    # There is none, allow access from anywhere
1387
    ( $userid, $cookie, $sessionID, $flags, $template ) =
1387
    ( $userid, $cookie, $sessionID, $flags, $template ) =
1388
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' );
1388
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' );
Lines 1419-1425 subtest 'AutoLocation' => sub { Link Here
1419
    $session = C4::Auth::get_session($sessionID);
1419
    $session = C4::Auth::get_session($sessionID);
1420
    is(
1420
    is(
1421
        $session->param('branch'), $other_library->branchcode,
1421
        $session->param('branch'), $other_library->branchcode,
1422
        "AutoLocation allows specifying a branch as long as the IP matches"
1422
        "StaffLoginRestrictBranchByIP allows specifying a branch as long as the IP matches"
1423
    );
1423
    );
1424
1424
1425
    $other_library->branchip('129.0.0.1')->store;
1425
    $other_library->branchip('129.0.0.1')->store;
Lines 1427-1433 subtest 'AutoLocation' => sub { Link Here
1427
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } );
1427
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } );
1428
    is( $template->{VARS}->{wrongip}, 1, "Login denied when branch specified and IP does not match branch IP" );
1428
    is( $template->{VARS}->{wrongip}, 1, "Login denied when branch specified and IP does not match branch IP" );
1429
1429
1430
1431
    $ENV{REMOTE_ADDR} = '129.0.0.1';          # Set current IP to match other_branch
1430
    $ENV{REMOTE_ADDR} = '129.0.0.1';          # Set current IP to match other_branch
1432
    $cgi->param( 'branch', undef );           # Do not pass a branch
1431
    $cgi->param( 'branch', undef );           # Do not pass a branch
1433
    $patron->library->branchip('')->store;    # Unset user branch IP, to allow IP matching on any branch
1432
    $patron->library->branchip('')->store;    # Unset user branch IP, to allow IP matching on any branch
1434
- 

Return to bug 26176