From 2f1f5ac3fb4c51704efd832acb4ac8bae4527218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Rodr=C3=ADguez?= Date: Tue, 30 Apr 2024 10:57:00 +0200 Subject: [PATCH] bug 12620 Allows to search in z39.50 servers using a proxy In some environments it is necessary to use a proxy to search in z39.50 servers wether it's because it doesn't have access to Internet or that the z39.50 ports are blocked. This commit allows to configure a proxy in a new system preference HttpForwardProxy. Sometimes some of the z39.50 servers don't work with the forward proxy, so we have added a column at the z39.50 server level so you can specify which ones won't use the proxy (z3950servers.do_not_use_proxy) To use the proxy, the preference must be configured and the "Do not use proxy" checkbox (z3950servers.do_not_use_proxy) in the z39.50 must be unchecked. The option "Do not use proxy" in the z39.50 server only appears when the system preference is configured. Test plan: 1 Check searching agains z39.50 No results. 2 Apply patch, restart services 3 Configure system preference HttpForwardProxy 4 Check searching agains z39.50 and see that you get results. --- C4/Breeding.pm | 8 ++++++- Koha/Schema/Result/Z3950server.pm | 9 ++++++++ admin/z3950servers.pl | 2 +- .../data/mysql/atomicupdate/bug_12620.pl | 21 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/mandatory/sysprefs.sql | 1 + .../admin/preferences/web_services.pref | 5 +++++ .../prog/en/modules/admin/z3950servers.tt | 11 ++++++++++ 8 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_12620.pl diff --git a/C4/Breeding.pm b/C4/Breeding.pm index 8dbaae9fff..555bc7c4a5 100644 --- a/C4/Breeding.pm +++ b/C4/Breeding.pm @@ -435,7 +435,13 @@ sub _create_connection { } $obj->connect( $host.':'.$server->{port}.'/'.$server->{db} ); } else { - $obj->connect( $server->{host}, $server->{port} ); + if (C4::Context->preference('HttpForwardProxy') ne "" && !$server->{do_not_use_proxy}){ + my $proxy = C4::Context->preference('HttpForwardProxy'); + $proxy =~ s/^http(s)?\:\/\///; + $obj->connect( "connect:$proxy,tcp:".$server->{host}.":".$server->{port} ); + }else{ + $obj->connect( $server->{host}, $server->{port} ); + } } return $obj; } diff --git a/Koha/Schema/Result/Z3950server.pm b/Koha/Schema/Result/Z3950server.pm index f03ab2bf80..9d922e000b 100644 --- a/Koha/Schema/Result/Z3950server.pm +++ b/Koha/Schema/Result/Z3950server.pm @@ -162,6 +162,13 @@ zero or more paths to XSLT files to be processed on the search results additional attributes passed to PQF queries +=head2 do_not_use_proxy + + data_type: 'smallint' + is_nullable: 1 + +do not use proxy + =cut __PACKAGE__->add_columns( @@ -211,6 +218,8 @@ __PACKAGE__->add_columns( { data_type => "longtext", is_nullable => 1 }, "attributes", { data_type => "varchar", is_nullable => 1, size => 255 }, + "do_not_use_proxy", + { data_type => "smallint", is_nullable => 1 }, ); =head1 PRIMARY KEY diff --git a/admin/z3950servers.pl b/admin/z3950servers.pl index d1113c8b21..f93a66f73b 100755 --- a/admin/z3950servers.pl +++ b/admin/z3950servers.pl @@ -66,7 +66,7 @@ if( $op eq 'cud-delete_confirmed' && $id ) { } elsif ( $op eq 'cud-add_validated' ) { my @fields=qw/host port db userid password rank syntax encoding timeout recordtype checked servername servertype sru_options sru_fields attributes - add_xslt/; + add_xslt do_not_use_proxy/; my $formdata = _form_data_hashref( $input, \@fields ); if( $id ) { my $server = Koha::Z3950Servers->find($id); diff --git a/installer/data/mysql/atomicupdate/bug_12620.pl b/installer/data/mysql/atomicupdate/bug_12620.pl new file mode 100644 index 0000000000..92058b9eb1 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_12620.pl @@ -0,0 +1,21 @@ +use Modern::Perl; + +return { + bug_number => "12620", + description => "System preference for HTTPS proxy and column in table z3950servers not_proxy", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do(q{ + INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES + ('HttpForwardProxy', '', '', 'HTTP Forward Proxy', 'free') + }); + + unless ( column_exists( 'z3950servers', 'do_not_use_proxy' ) ) { + $dbh->do( + "ALTER TABLE z3950servers ADD COLUMN do_not_use_proxy TINYINT(1) DEFAULT NULL" + ); + } + }, +}; \ No newline at end of file diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index cfcce6f665..495d8e5563 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -6585,6 +6585,7 @@ CREATE TABLE `z3950servers` ( `sru_fields` longtext DEFAULT NULL COMMENT 'contains the mapping between the Z3950 search fields and the specific SRU server indexes', `add_xslt` longtext DEFAULT NULL COMMENT 'zero or more paths to XSLT files to be processed on the search results', `attributes` varchar(255) DEFAULT NULL COMMENT 'additional attributes passed to PQF queries', + `do_not_use_proxy` tinyint(1) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 4c372bad78..f605692d07 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -308,6 +308,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('HTML5MediaExtensions','webm|ogg|ogv|oga|vtt','','Media file extensions','free'), ('HTML5MediaYouTube',0,'Embed|Don\'t embed','YouTube links as videos','YesNo'), ('IdRef','0','','Disable/enable the IdRef webservice from the OPAC detail page.','YesNo'), +('HttpForwardProxy', '', '', 'HTTP Forward Proxy', 'free'), ('ILLCheckAvailability', 0, '', 'If ON, during the ILL request process third party sources will be checked for current availability', 'YesNo'), ('ILLDefaultStaffEmail', '', NULL, 'Fallback email address for staff ILL notices to be sent to in the absence of a branch address', 'Free'), ('ILLHiddenRequestStatuses', NULL, NULL, 'ILL statuses that are considered finished and should not be displayed in the ILL module', 'multiple'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref index d5c7c1feb2..22fd479d25 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref @@ -135,3 +135,8 @@ Web services: 0: Disable - the IdRef web service from the OPAC detail page. IdRef allows requests for authorities from the Sudoc database. - Please note that this feature is available only for UNIMARC. + Proxy: + - + - pref: HttpForwardProxy + class: url + - HTTP forward proxy URL for connections with Z39.50 servers. \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt index 518161b51d..df35beecd2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt @@ -1,4 +1,5 @@ [% USE raw %] +[% USE Koha %] [% USE Asset %] [% USE HtmlTags %] [% PROCESS 'i18n.inc' %] @@ -195,6 +196,16 @@ [% END %] + [% IF Koha.Preference('HttpForwardProxy') && (server.servertype||type) == 'zed' %] +
  • + + [% IF ( server.do_not_use_proxy ) %] + + [% ELSE %] + + [% END %] +
  • + [% END %]
  • -- 2.30.2