From aedd09d6463cce18ef25b2b4c1f61aef3e95a659 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 18 Jul 2017 12:05:07 +0000 Subject: [PATCH] Bug 18950 - Elasticsearch - Add password access for admin functions To test: 1 - Load 'Search engine configuration' from admin page http://localhost:8081/cgi-bin/koha/admin/searchengine/elasticsearch/mappings.pl 2 - Verify this works as before the patch 3 - Add to koha-conf.xml 4 - Reload search config page, note additional option to reset mappings 5 - Attempt reset with bad password 6 - Attempt reset with correct password Note: the action is a drop down as reindexing will be added, however, code needs some refactoring before this option can be implemented --- admin/searchengine/elasticsearch/mappings.pl | 21 +++++++++++++++------ debian/scripts/koha-create | 3 +++ debian/templates/koha-conf-site.xml.in | 4 ++++ .../admin/searchengine/elasticsearch/mappings.tt | 21 ++++++++++++++++++++- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/admin/searchengine/elasticsearch/mappings.pl b/admin/searchengine/elasticsearch/mappings.pl index 7d63002..567451e 100755 --- a/admin/searchengine/elasticsearch/mappings.pl +++ b/admin/searchengine/elasticsearch/mappings.pl @@ -37,6 +37,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( my $index = $input->param('index') || 'biblios'; my $op = $input->param('op') || 'list'; +my $action = $input->param('action') || ''; my @messages; my $database = Koha::Database->new(); @@ -97,12 +98,19 @@ if ( $op eq 'edit' ) { $schema->storage->txn_commit; } } -elsif( $op eq 'reset' ) { - # TODO Move this feature to the interface - my $sure = $input->param('i_know_what_i_am_doing'); - if ( $sure ) { - Koha::SearchMarcMaps->search->delete; - Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings; +elsif( $op eq 'admin') { + if( $input->param('admin_password') eq C4::Context->config('elasticsearch_admin_password') ){ + if ( $action eq 'reset' ) { + Koha::SearchMarcMaps->search->delete; + Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings; + $template->param( mappings_reset = 1 ); + } + elsif ( $action eq 'reindex' ) { + #TODO reindex needs some refactorig to allow this option + } + } + else { + $template->param( admin_badpassword => 1 ); } } @@ -139,6 +147,7 @@ $template->param( indexes => \@indexes, all_search_fields => \@all_search_fields, messages => \@messages, + show_admin_options => C4::Context->config('elasticsearch_admin_password') ? 1 : 0, ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create index ba4f043..0b927be 100755 --- a/debian/scripts/koha-create +++ b/debian/scripts/koha-create @@ -106,6 +106,7 @@ generate_config_file() { -e "s/__START_AUTHORITIES_RETRIEVAL_INFO__/`echo $START_AUTHORITIES_RETRIEVAL_INFO`/g" \ -e "s/__END_AUTHORITIES_RETRIEVAL_INFO__/`echo $END_AUTHORITIES_RETRIEVAL_INFO`/g" \ -e "s/__API_SECRET__/$API_SECRET/g" \ + -e "s/__ES_ADMIN_PASSWORD__/$ES_ADMIN_PASSWORD/g" \ -e "s/__DB_NAME__/$mysqldb/g" \ -e "s/__DB_HOST__/$mysqlhost/g" \ -e "s/__DB_USER__/$mysqluser/g" \ @@ -406,6 +407,8 @@ UPLOAD_DIR="uploads" UPLOAD_PATH="" # Generate a randomizaed API secret API_SECRET="$(pwgen -s 64 1)" +# Generate a randomizaed ES Admin Password secret +ES_ADMIN_PASSWORD="$(pwgen -s 16 1)" # SRU server variables ENABLE_SRU="no" SRU_SERVER_PORT="" diff --git a/debian/templates/koha-conf-site.xml.in b/debian/templates/koha-conf-site.xml.in index 8e8204f..e990b33 100644 --- a/debian/templates/koha-conf-site.xml.in +++ b/debian/templates/koha-conf-site.xml.in @@ -326,6 +326,10 @@ __END_SRU_PUBLICSERVER__ localhost:9200 koha___KOHASITE__ + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt index 25535d9..45ee750 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt @@ -1,3 +1,4 @@ +[% USE Koha %] [% INCLUDE 'doc-head-open.inc' %] Koha › Administration › Elastic Search mappings [% INCLUDE 'doc-head-close.inc' %] @@ -88,7 +89,25 @@ a.add, a.delete {

Search engine configuration

- Warning: Any modification in these configurations will need a total reindexation to be fully taken into account ! + Warning: Any modification in these configurations will need a total reindexation to be fully taken into account !
+ [% IF (show_admin_options) %] + [% IF (admin_badpassword) %]

The password you entered was incorrect!

[% END %] + [% IF (reindex_launched) %]

A rebuild has been started

+ [% ELSIF (mappings_reset) %]

Mappings have been reset

+ [% ELSE %] +

+
[% IF errors %]
-- 2.1.4