From 8cf5a897209b44047c616405db48fa77725ffc6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Rodr=C3=ADguez?= Date: Wed, 24 Apr 2024 12:28:15 +0200 Subject: [PATCH 1/1] 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 HTTPS_Proxy. Sometimes some of the z39.50 servers don't work with the proxy, so we have added a column at server level so you can specify which ones won't use the proxy. To use the proxy the preference must be configured and the "Do not use proxy" checkbox in the z39.50 must be unchecked. Test plan 1 Check searching agains z39.50 No results. 2 Apply patch, restart services 3 Configure system preference HTTPS_Proxy 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 +++++++++++++++++++ .../admin/preferences/web_services.pref | 5 +++++ .../prog/en/modules/admin/z3950servers.tt | 8 +++++++ 6 files changed, 51 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..94e3534566 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('HTTPS_Proxy') ne "" && !$server->{not_proxy}){ + my $proxy = C4::Context->preference('HTTPS_Proxy'); + $proxy =~ s/http(s)?\:\/\///g; + $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..bb1386d808 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 not_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 }, + "not_proxy", + { data_type => "smallint", is_nullable => 1 }, ); =head1 PRIMARY KEY diff --git a/admin/z3950servers.pl b/admin/z3950servers.pl index d1113c8b21..0c2f42ab65 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 not_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..c5584b4bbd --- /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 + ('HTTPS_Proxy', '', '', 'HTTPS proxy URL', 'free') + }); + + unless ( column_exists( 'z3950servers', 'not_proxy' ) ) { + $dbh->do( + "ALTER TABLE z3950servers ADD COLUMN not_proxy TINYINT(1) DEFAULT NULL" + ); + } + }, +}; \ No newline at end of file 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..4eeb649191 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: HTTPS_Proxy + class: url + - HTTPS proxy URL for connections with Z3950 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..4f9b877b0e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt @@ -196,6 +196,14 @@ [% END %]
  • +
  • + + [% IF ( server.not_proxy ) %] + + [% ELSE %] + + [% END %] +
  • Separate multiple filenames by commas.
    -- 2.30.2