From 1bbf2111923af06d54260b65fc67ebbd00fe8a9e Mon Sep 17 00:00:00 2001 From: George Veranis Date: Fri, 18 Mar 2022 16:24:12 +0100 Subject: [PATCH] Bug 11180: IP branch attribute should accept CIDR notation This patch adds the ability to set more than ip to IP setting of a branch and also CIDR notation can recognised also. Test plan: 1) Change systempreference AutoLocation to "Yes" 2) Go to the library settings ( Administration -> Libraries ) and you can add only one ip at format xxx.xxx.xxx.xxx or xxx.xxx.* 3) Apply patch 4) Go to the library settings and you can enter to IP setting those ip(s) you want seperate by space in any format like xxx.xxx.xxx.xxx or xxx.xxx.xxx.0/24 or xxx.xxx.xxx.* or only one also on the same formats. 3) Logout 4) Try to login from an ip that not belong on the set of ip that you enter before and now CIDR notation can regognized also and also you can have more than one ip for restriction. --- C4/Auth.pm | 19 +++++++++++-------- Koha/Schema/Result/Branch.pm | 2 +- installer/data/mysql/kohastructure.sql | 2 +- .../prog/en/modules/admin/branches.tt | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 872d5b5365..8c9647e031 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -1167,14 +1167,17 @@ sub checkauth { my $domain = $branches->{$branchcode}->{'branchip'}; $domain =~ s|\.\*||g; if ( $ip !~ /^$domain/ ) { - $loggedin = 0; - $cookie = $query->cookie( - -name => 'CGISESSID', - -value => '', - -HttpOnly => 1, - -secure => ( C4::Context->https_enabled() ? 1 : 0 ), - ); - $info{'wrongip'} = 1; + if(!in_iprange($domain)) + { + $loggedin = 0; + $cookie = $query->cookie( + -name => 'CGISESSID', + -value => '', + -HttpOnly => 1, + -secure => ( C4::Context->https_enabled() ? 1 : 0 ), + ); + $info{'wrongip'} = 1; + } } } diff --git a/Koha/Schema/Result/Branch.pm b/Koha/Schema/Result/Branch.pm index b924c94f98..80b67f896f 100644 --- a/Koha/Schema/Result/Branch.pm +++ b/Koha/Schema/Result/Branch.pm @@ -149,7 +149,7 @@ unused in Koha data_type: 'varchar' is_nullable: 1 - size: 15 + size: 255 the IP address for your library or branch diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 69b3613963..6629714ada 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1511,7 +1511,7 @@ CREATE TABLE `branches` ( `branchreturnpath` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the email to be used as Return-Path', `branchurl` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the URL for your library or branch''s website', `issuing` tinyint(4) DEFAULT NULL COMMENT 'unused in Koha', - `branchip` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the IP address for your library or branch', + `branchip` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the IP address for your library or branch', `branchnotes` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'notes related to your library or branch', `opac_info` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'HTML that displays in OPAC', `geolocation` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'geolocation of your library', diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt index 7f5db486e4..985ec1465f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt @@ -238,7 +238,7 @@ Libraries › Administration › Koha
  • - +
    Can be entered as a single IP, or a subnet such as 192.168.1.*
  • -- 2.20.1