From 89996d58c6ef47fdba1944a4d4c6fde026f07d63 Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Fri, 4 Feb 2011 13:25:30 +0100 Subject: [PATCH] Add client logic and admin pages to support SP In the node configuration it's now possible to specify optional Service-Proxy username and password, if none is specified the ipauthentication will be used instead. Also, Provided are DB shema migration hooks and the module is versioned (as those two seem to go together somewhow). To update the module's DB table one need to run the update.php from the root of the Drupla vhost. --- mkdru.client.js | 42 ++++++++++++++++++++++++++++++++++++++---- mkdru.info | 1 + mkdru.install | 17 +++++++++++++++++ mkdru.module | 23 ++++++++++++++++++++--- 4 files changed, 76 insertions(+), 7 deletions(-) diff --git a/mkdru.client.js b/mkdru.client.js index ae07fe6..7357102 100644 --- a/mkdru.client.js +++ b/mkdru.client.js @@ -33,7 +33,8 @@ var mkdru = { query:null, recid:null }, - state: {} + state: {}, + realm: '' }; @@ -305,7 +306,7 @@ $(document).ready(function () { mkdru.pz2 = new pz2( { "onshow": mkdru.pz2Show, "showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way - "pazpar2path": mkdru.pazpar2path, + "pazpar2path": mkdru.pazpar2Path, "oninit": mkdru.pz2Init, "onstat": mkdru.pz2Status, "onterm": mkdru.pz2Term, @@ -325,13 +326,46 @@ $(document).ready(function () { if (typeof(Drupal.settings.mkdru.query) !== "undefined") { mkdru.state.query = Drupal.settings.mkdru.query } - + //not running against SP? init, otherwise authenticate if (mkdru.useSessions) { mkdru.pz2.init(); + } else { + //runnin against SP + var user = Drupal.settings.mkdru.sp_user; + var pass = Drupal.settings.mkdru.sp_pass; + var params = {}; + params['command'] = 'auth'; + if (user && pass) { + params['action'] = 'login'; + params['username'] = user; + params['password'] = pass; + } else { + params['action'] = 'ipauth'; + } + var authReq = new pzHttpRequest(mkdru.pazpar2Path, + function (err) { + alert("Authentication against metasearch gateway failed: " +err); + } + ); + authReq.get(params, + function (data) { + var s = data.getElementsByTagName('status'); + if (s.length && Element_getTextContent(s[0]) == "OK") { + mkdru.realm = data.getElementsByTagName('realm'); + mkdru.pz2Init(); + } else { + alert("Malformed response when authenticating against the metasearch" + + " gateway"); + } + } + ); } - else if (mkdru.state.recid) { + + //I'm not sure how this can work, it assumes the search is in a proper state? + if (mkdru.state.recid) { mkdru.pz2.record(mkdru.state.recid); } + //mkdru.onInit deals with this in a more proper way else if (mkdru.state.query) { mkdru.search(); } diff --git a/mkdru.info b/mkdru.info index a5c816f..8502d14 100644 --- a/mkdru.info +++ b/mkdru.info @@ -1,3 +1,4 @@ name = Pazpar2 metasearch integration description = Metasearching of Z39.50, SRU and SOLR targets via Index Data's Pazpar2 and associated tool stack. core = 6.x +version = 6.x-1.0 diff --git a/mkdru.install b/mkdru.install index cdbf86b..e136c59 100644 --- a/mkdru.install +++ b/mkdru.install @@ -55,6 +55,16 @@ function mkdru_schema() { 'unsigned' => TRUE, 'not null' => TRUE, ), + 'sp_user' => array( + 'type' => 'text', + 'not null' => FALSE, + 'description' => t('Service Proxy username') + ), + 'sp_pass' => array( + 'type' => 'text', + 'not null' => FALSE, + 'description' => t('Service Proxy password') + ), ), 'primary key' => array('nid', 'vid'), 'unique keys' => array('vid' => array('vid')), @@ -82,3 +92,10 @@ function mkdru_uninstall() { // Delete variables variable_del('pz2_js_path'); } + +function mkdru_update_6100() { + $ret = array(); + db_add_field($ret, 'mkdru', 'sp_user', array('type' => 'varchar', 'length' => 32, 'not null' => FALSE, 'default' => '') ); + db_add_field($ret, 'mkdru', 'sp_pass', array('type' => 'varchar', 'length' => 32, 'not null' => FALSE, 'default' => '') ); + return $ret; +} diff --git a/mkdru.module b/mkdru.module index cb20ab0..e7541ab 100644 --- a/mkdru.module +++ b/mkdru.module @@ -117,6 +117,22 @@ function mkdru_form(&$node, $form_state) { '#required' => TRUE, '#default_value' => isset($node->mkdru->pz2_path) ? $node->mkdru->pz2_path : '/pazpar2/search.pz2', ); + $form['search_settings']['sp_user'] = array( + '#type' => 'textfield', + '#title' => t('Service Proxy username (optional)'), + '#description' => t('Service-Proxy username'), + '#required' => FALSE, + '#default_value' => isset($node->mkdru->sp_user) ? + $node->mkdru->sp_user : '', + ); + $form['search_settings']['sp_pass'] = array( + '#type' => 'textfield', + '#title' => t('Service Proxy password (optional)'), + '#description' => t('Service-Proxy password'), + '#required' => FALSE, + '#default_value' => isset($node->mkdru->sp_pass) ? + $node->mkdru->sp_pass : '', + ); $form['search_settings']['use_sessions'] = array( '#type' => 'checkbox', '#title' => t('Session handling'), @@ -177,8 +193,9 @@ function mkdru_validate($node) { * Implementation of hook_insert(). */ function mkdru_insert($node) { - db_query("INSERT INTO {mkdru} (nid, vid, pz2_path, use_sessions, source_max, author_max, subject_max) VALUES (%d, %d, '%s', %d, %d, %d, %d)", - $node->nid, $node->vid, $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max); + db_query("INSERT INTO {mkdru} (nid, vid, pz2_path, use_sessions, source_max, author_max, subject_max, sp_user, sp_pass) ". + "VALUES (%d, %d, '%s', %d, %d, %d, %d, '%s', '%s')", + $node->nid, $node->vid, $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max, $node->sp_user, $node->sp_pass); } /** @@ -190,7 +207,7 @@ function mkdru_update($node) { mkdru_insert($node); } else { - db_query("UPDATE {mkdru} SET pz2_path = '%s', use_sessions = %d, source_max = %d, author_max = %d, subject_max = %d WHERE vid = %d", $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max, $node->vid); + db_query("UPDATE {mkdru} SET pz2_path = '%s', use_sessions = %d, source_max = %d, author_max = %d, subject_max = %d, sp_user = '%s', sp_pass = '%s' WHERE vid = %d", $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max, $node->vid); } } -- 1.7.10.4