From a0c14f9404c9e53cc945886ef0ba8a58676f9565 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 | 2 +- installer/data/mysql/kohastructure.sql | 2 +- koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index c449c318a9..eb9ee3dcd6 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -1199,7 +1199,7 @@ sub checkauth { # we have to check they are coming from the right ip range my $domain = $branches->{$branchcode}->{'branchip'}; $domain =~ s|\.\*||g; - if ( $ip !~ /^$domain/ ) { + if ( !(in_iprange($domain) ) { $loggedin = 0; $cookie = $cookie_mgr->replace_in_list( $cookie, $query->cookie( -name => 'CGISESSID', diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 16310f0f44..11fa93e2c5 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1648,7 +1648,7 @@ CREATE TABLE `branches` ( `branchreturnpath` longtext DEFAULT NULL COMMENT 'the email to be used as Return-Path', `branchurl` longtext DEFAULT NULL COMMENT 'the URL for your library or branch''s website', `issuing` tinyint(4) DEFAULT NULL COMMENT 'unused in Koha', - `branchip` varchar(15) DEFAULT NULL COMMENT 'the IP address for your library or branch', + `branchip` varchar(255) DEFAULT NULL COMMENT 'the IP address for your library or branch', `branchnotes` longtext DEFAULT NULL COMMENT 'notes related to your library or branch', `geolocation` varchar(255) DEFAULT NULL COMMENT 'geolocation of your library', `marcorgcode` varchar(16) DEFAULT NULL COMMENT 'MARC Organization Code, see http://www.loc.gov/marc/organizations/orgshome.html, when empty defaults to syspref MARCOrgCode', 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 c8d547097d..11e8127a67 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt @@ -248,7 +248,7 @@
  • - +
    Can be entered as a single IP, or a subnet such as 192.168.1.*
  • -- 2.30.2