@@ -, +, @@ only certain IPs or IP ranges Fixed the QA items raised in comment 2 > DELETE FROM systempreferences; > SOURCE ~/kohaclone/installer/data/mysql/sysprefs.sql; -- Should be no errors. > SELECT * FROM systempreferences WHERE variable='SelfCheckAllowByIPRanges'; -- Should see 1 entry > QUIT; > SELECT * FROM systempreferences WHERE variable='SelfCheckAllowByIPRanges'; -- should see the same entry as above --- .../bug_14407-add_selfcheckallowbyipranges_syspref.sql | 2 ++ installer/data/mysql/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/circulation.pref | 4 ++++ opac/sco/help.pl | 10 ++++++++++ opac/sco/sco-main.pl | 9 +++++++++ opac/sco/sco-patron-image.pl | 11 +++++++++++ 6 files changed, 37 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug_14407-add_selfcheckallowbyipranges_syspref.sql --- a/installer/data/mysql/atomicupdate/bug_14407-add_selfcheckallowbyipranges_syspref.sql +++ a/installer/data/mysql/atomicupdate/bug_14407-add_selfcheckallowbyipranges_syspref.sql @@ -0,0 +1,2 @@ +INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES + ('SelfCheckAllowByIPRanges','',NULL,'(Leave blank if not used. Use ranges or simple ip addresses separated by spaces, like 192.168.1.1 192.168.0.0/24.)','Short'); --- a/installer/data/mysql/sysprefs.sql +++ a/installer/data/mysql/sysprefs.sql @@ -373,6 +373,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('SCOUserJS','',NULL,'Define custom javascript for inclusion in the SCO module','free'), ('SearchMyLibraryFirst','0',NULL,'If ON, OPAC searches return results limited by the user\'s library by default if they are logged in','YesNo'), ('SearchWithISBNVariations','0',NULL,'If enabled, search on all variations of the ISBN','YesNo'), +('SelfCheckAllowByIPRanges','',NULL,('Leave blank if not used. Use ranges or simple ip addresses separated by spaces, like 192.168.1.1 192.168.0.0/24.)','Short'), ('SelfCheckHelpMessage','','70|10','Enter HTML to include under the basic Web-based Self Checkout instructions on the Help page','Textarea'), ('SelfCheckReceiptPrompt','1','NULL','If ON, print receipt dialog pops up when self checkout is finished','YesNo'), ('SelfCheckTimeout','120','','Define the number of seconds before the Web-based Self Checkout times out a patron','Integer'), --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -681,6 +681,10 @@ Circulation: yes: Show no: "Don't show" - "the print receipt popup dialog when self checkout is finished" + - + - pref: SelfCheckAllowByIPRanges + class: short + - (Leave blank if not used. Use ranges or simple ip addresses separated by spaces, like 192.168.1.1 192.168.0.0/24.) Course Reserves: - --- a/opac/sco/help.pl +++ a/opac/sco/help.pl @@ -24,11 +24,21 @@ use strict; use warnings; use CGI qw ( -utf8 ); +use Net::IP::Match::XS; use C4::Auth qw(get_template_and_user); use C4::Output qw(output_html_with_http_headers); my $query = new CGI; + +my @allowedipranges = split(' ', C4::Context->preference('SelfCheckAllowByIPRanges')); +if (scalar @allowedipranges > 0) { + unless (match_ip($ENV{'REMOTE_ADDR'}, @allowedipranges)) { + print $query->redirect("/cgi-bin/koha/opac-main.pl"); + exit; + } +} + my ($template, $borrowernumber, $cookie) = get_template_and_user({ template_name => "sco/help.tt", query => $query, --- a/opac/sco/sco-main.pl +++ a/opac/sco/sco-main.pl @@ -36,6 +36,7 @@ use warnings; use CGI qw ( -utf8 ); use Digest::MD5 qw(md5_base64); +use Net::IP::Match::XS; use C4::Auth qw(get_template_and_user checkpw); use C4::Koha; @@ -54,6 +55,14 @@ unless (C4::Context->preference('WebBasedSelfCheck')) { exit; } +my @allowedipranges = split(' ', C4::Context->preference('SelfCheckAllowByIPRanges')); +if (scalar @allowedipranges > 0) { + unless (match_ip($ENV{'REMOTE_ADDR'}, @allowedipranges)) { + print $query->redirect("/cgi-bin/koha/opac-main.pl"); + exit; + } +} + if (C4::Context->preference('AutoSelfCheckAllowed')) { my $AutoSelfCheckID = C4::Context->preference('AutoSelfCheckID'); --- a/opac/sco/sco-patron-image.pl +++ a/opac/sco/sco-patron-image.pl @@ -19,6 +19,8 @@ use strict; use warnings; +use Net::IP::Match::XS; + use C4::Service; use C4::Members; @@ -33,6 +35,15 @@ unless (C4::Context->preference('ShowPatronImageInWebBasedSelfCheck')) { exit; } +my @allowedipranges = split(' ', C4::Context->preference('SelfCheckAllowByIPRanges')); +if (scalar @allowedipranges > 0) { + unless (match_ip($ENV{'REMOTE_ADDR'}, @allowedipranges)) { + print $query->header(status => '403 Forbidden - functionality not available from your location'); + exit; + } +} + + my ($borrowernumber) = C4::Service->require_params('borrowernumber'); my ($imagedata, $dberror) = GetPatronImage($borrowernumber); --