From 2574a38ea86c35fd0a41c46dc87aaeafdb194806 Mon Sep 17 00:00:00 2001 From: oren Date: Tue, 4 Feb 2014 11:30:55 -0500 Subject: [PATCH 01/16] Add and rename pinserver_plus to modules/pinserver_ldap --- modules/pinserver_ldap/README.md | 40 + .../includes/pinserver_ldap.api.inc | 64 ++ .../pinserver_ldap/pinserver_ldap.admin.inc | 130 ++++ modules/pinserver_ldap/pinserver_ldap.info | 6 + modules/pinserver_ldap/pinserver_ldap.install | 67 ++ modules/pinserver_ldap/pinserver_ldap.js | 74 ++ modules/pinserver_ldap/pinserver_ldap.module | 709 ++++++++++++++++++ 7 files changed, 1090 insertions(+) create mode 100644 modules/pinserver_ldap/README.md create mode 100644 modules/pinserver_ldap/includes/pinserver_ldap.api.inc create mode 100644 modules/pinserver_ldap/pinserver_ldap.admin.inc create mode 100644 modules/pinserver_ldap/pinserver_ldap.info create mode 100644 modules/pinserver_ldap/pinserver_ldap.install create mode 100644 modules/pinserver_ldap/pinserver_ldap.js create mode 100644 modules/pinserver_ldap/pinserver_ldap.module diff --git a/modules/pinserver_ldap/README.md b/modules/pinserver_ldap/README.md new file mode 100644 index 0000000..26a05b8 --- /dev/null +++ b/modules/pinserver_ldap/README.md @@ -0,0 +1,40 @@ +This is a Drupal 7 module for allowing HUID login. It is an +adaptation of the Drupal 6 module pinserver, from IQSS, +and pinserver\_osc by Reinhard Engels. Note that although this module +works, it is not currently in use on a production site. The Drupal 6 +two-module predecessor to this one is working on the Office for +Scholarly Communication's sites, however. + +This module implements PIN 1 and 2, but not 3. + +A D7 version of pinserver is at +https://github.com/openscholar/pinserver. A later version of this +module may break out the additional functionality in order to take +advantage of the current IQSS module. + +Installation +------------ + + cd sites/all/modules/ + git clone git@git.huit.harvard.edu:pin-server-module-for-drupal-7/pinserver_plus.git + drush en pinserver_plus + +Or enable the module in the UI. + +Configuration +------------- + +Go to http://yoursite/#overlay=admin/settings/pinserver_plus. You will need an +application name and target, GPG, and LDAP login credentials. Instructions are +linked at https://github.com/openscholar/pinserver/blob/7.x-3.x/README.md. + +The salt is added to the HUID when creating a hash. In the case of +the OSC, this had to match the salt used in DASH, so Drupal users +could be mapped to DASH users. Your application may vary. + +TODO +---- + +- Put search string in configuration +- Add facility for putting HUID users in a role? +- Take some or all config out of UI? diff --git a/modules/pinserver_ldap/includes/pinserver_ldap.api.inc b/modules/pinserver_ldap/includes/pinserver_ldap.api.inc new file mode 100644 index 0000000..7f17732 --- /dev/null +++ b/modules/pinserver_ldap/includes/pinserver_ldap.api.inc @@ -0,0 +1,64 @@ +uid == '1') { + //return TRUE; // for testing purposes + } + if (isset($_SESSION['pinserver_plus']['reg_time']) && isset($_SESSION['pinserver_plus']['huid'])) { + return $reg_time = ((REQUEST_TIME - (int)$_SESSION['pinserver_plus']['reg_time']) < 120) ? TRUE : FALSE; + } + return FALSE; +} + +/** + * API function - Return all session values (set after successful pinserver_plus login) + */ +function pinserver_plus_get_session() { + //returns array with pinserver_plus session values if not empty + if (!empty($_SESSION['pinserver_plus'])) { + foreach ($_SESSION['pinserver_plus'] as $key => $val) { + $session_values['key'] = $val; + } + return $session_values; + } + else { + return FALSE; + } +} + +/** + * API function - Returns huid (set after successful pinserver_plus login) + */ +function pinserver_plus_get_session_huid() { + //returns array with pinserver_plus session values + if ($_SESSION['pinserver_plus']['huid']) { + return $_SESSION['pinserver_plus']['huid']; + } + else { + return FALSE; + } +} + +/** + * API function - Remove session values set after successful pinserver_plus login + */ +function pinserver_plus_remove_session() { + //removing session values when new site is created + if (isset($_SESSION['pinserver_plus'])) { + unset($_SESSION['pinserver_plus']); + } +} \ No newline at end of file diff --git a/modules/pinserver_ldap/pinserver_ldap.admin.inc b/modules/pinserver_ldap/pinserver_ldap.admin.inc new file mode 100644 index 0000000..a5032b9 --- /dev/null +++ b/modules/pinserver_ldap/pinserver_ldap.admin.inc @@ -0,0 +1,130 @@ + 'fieldset', + '#title' => t('Harvard Pinserver Plus Configuration'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + ); + + $form['pinserver_plus']['pinserver_plus_pin_url'] = array( + '#type' => 'textfield', + '#required' => TRUE, + '#title' => t('Harvard PIN Server URL'), + '#default_value' => variable_get('pinserver_plus_pin_url', ''), + '#description' => t('Enter PIN server URL. For example: https://www.pin1.harvard.edu/pin/authenticate'), + ); + + $form['pinserver_plus']['pinserver_plus_app_name'] = array( + '#type' => 'textfield', + '#title' => t('Harvard PIN server application name'), + '#required' => TRUE, + '#default_value' => variable_get('pinserver_plus_app_name', ''), + '#description' => t('Enter the application name given to you by Harvard Directory Services.' ), + ); + + $form['pinserver_plus']['pinserver_plus_target'] = array( + '#type' => 'textfield', + '#title' => t('Harvard PIN server target path'), + '#required' => TRUE, + '#default_value' => variable_get('pinserver_plus_target', ''), + '#description' => t('Enter the path given to you by Harvard Directory Services, e.g. "pinserver/auth".' ), + ); + + $form['pinserver_plus']['pinserver_plus_salt'] = array( + '#type' => 'textfield', + '#title' => t('Harvard PIN server salt'), + '#required' => TRUE, + '#default_value' => variable_get('pinserver_plus_salt', ''), + '#description' => t('Enter the salt used to encode HUIDs.' ), + ); + + $form['pinserver_plus']['pinserver_plus_ldap_url'] = array( + '#type' => 'textfield', + '#title' => t('Harvard LDAP URL'), + '#required' => TRUE, + '#default_value' => variable_get('pinserver_plus_ldap_url', ''), + '#description' => t('Enter the LDAP URL given to you by Harvard Directory Services, something like "ldaps://hu-ldap.harvard.edu".' ), + ); + + $form['pinserver_plus']['pinserver_plus_ldap_user'] = array( + '#type' => 'textfield', + '#title' => t('Harvard LDAP user string'), + '#required' => TRUE, + '#default_value' => variable_get('pinserver_plus_ldap_user', ''), + '#description' => t('Enter the LDAP user string given to you by Harvard Directory Services, something like "uid=xyzzy,ou=applications,o=Harvard University Core,dc=huid,dc=harvard,dc=edu".' ), + ); + + $form['pinserver_plus']['pinserver_plus_ldap_password'] = array( + '#type' => 'textfield', + '#title' => t('Harvard LDAP password'), + '#required' => TRUE, + '#default_value' => variable_get('pinserver_plus_ldap_password', ''), + '#description' => t('Enter the LDAP password given to you by Harvard Directory Services.' ), + ); + + $form['pinserver_plus']['pinserver_plus_gpg_dir'] = array( + '#type' => 'textfield', + '#title' => t('Host server path to public key directory'), + '#required' => TRUE, + '#default_value' => variable_get('pinserver_plus_gpg_dir', ''), + '#description' => t('Enter the absolute path to the GPG directory on your web server where the PIN Server or AuthProxy public key information is stored.' ), + ); + + $form['pinserver_plus']['pinserver_plus_landing_path'] = array( + '#type' => 'textfield', + '#title' => t('Landing Path'), + '#required' => TRUE, + '#default_value' => variable_get('pinserver_plus_landing_path', ''), + '#description' => t('Specify the path to redirect the user after all pinserver_plus module processing is complete. Use a relative path that comes after !base_url' . '/', array('!base_url' => $base_url)), + ); + + $form['pinserver_plus']['pinserver_plus_auth_str'] = array( + '#type' => 'radios', + '#title' => t('PIN Authentication Server Setup'), + '#default_value' => variable_get('pinserver_plus_auth_str', ''), + '#options' => array( + 'Good signature from "Harvard University PIN System' => t('PIN only'), + 'Good signature from "authzproxy"' => t('PIN with AuthProxy'), + ), + '#required' => TRUE, + '#description' => t('The server that is returning the user back to this site after successful PIN login.'), + ); + + $form['pinserver_plus']['pinserver_plus_support_contact'] = array( + '#type' => 'textfield', + '#title' => t('E-mail address for technical support'), + '#required' => FALSE, + '#default_value' => variable_get('pinserver_plus_support_contact', ''), + '#description' => t('Optionally specify contact person to be displayed to user if PIN authentication fails.'), + ); + + //pinsever GPG logging fields + + $form['pinserver_plus_logging'] = array( + '#type' => 'fieldset', + '#title' => t('Harvard Pinserver Plus Logging'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + ); + + $form['pinserver_plus_logging']['pinserver_plus_error_log'] = array( + '#type' => 'textfield', + '#title' => t('Text file to use for logging GPG stderror output'), + '#required' => FALSE, + '#default_value' => variable_get('pinserver_plus_error_log', ''), + '#description' => t('Optionally specify full filename and path from server\'s root directory (not the website\'s root directory). The file should always be below the root directory, and it is recommended only for development sites. Leave blank to disable. Include the first / to indicate the root directory of the webserver.'), + ); + + return system_settings_form($form); +} \ No newline at end of file diff --git a/modules/pinserver_ldap/pinserver_ldap.info b/modules/pinserver_ldap/pinserver_ldap.info new file mode 100644 index 0000000..f4fe474 --- /dev/null +++ b/modules/pinserver_ldap/pinserver_ldap.info @@ -0,0 +1,6 @@ +; $Id$ +name = Pinserver Plus +description = Maps a Pinserver HUID account to a Drupal account so you can log in. +package = Harvard PIN Authentication +core = 7.x +files[] = includes/pinserver_plus.api.inc diff --git a/modules/pinserver_ldap/pinserver_ldap.install b/modules/pinserver_ldap/pinserver_ldap.install new file mode 100644 index 0000000..b933b9f --- /dev/null +++ b/modules/pinserver_ldap/pinserver_ldap.install @@ -0,0 +1,67 @@ + 'Maps unique encrypted HUID identifier to Drupal user ID', + 'fields' => array( + 'uid' => array( + 'description' => 'Drupal user ID', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), + 'huid' => array( + 'description' => "Holds the Harvard ID of returning users", + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'reg_time' => array( + 'description' => "The time of user registration", + 'type' => 'int', + ), + ), + 'unique keys' => array( + 'huid' => array('huid'), + ), + 'primary key' => array( 'uid') , + ); + return $schema; +} diff --git a/modules/pinserver_ldap/pinserver_ldap.js b/modules/pinserver_ldap/pinserver_ldap.js new file mode 100644 index 0000000..9e4432b --- /dev/null +++ b/modules/pinserver_ldap/pinserver_ldap.js @@ -0,0 +1,74 @@ +(function ($) { + +// global PIN object. + +PIN = {}; +PIN.swapId= "content-area"; +PIN.loginFormId="user-login"; +PIN.drupalHtml=""; + +PIN.createCookie = function(name,value,days) { + if (days) { + var date = new Date(); + date.setTime(date.getTime()+(days*24*60*60*1000)); + var expires = "; expires="+date.toGMTString(); + } else { + var expires = ""; + } + document.cookie = name+"="+value+expires+"; path=/"; +}; + +PIN.drupalLogin = function(){ + $('#' + PIN.swapId).html(PIN.drupalHtml); +}; + +PIN.gotoPin =function(){ + // app should be set in Drupal + document.location = "https://www.pin1.harvard.edu/pin/authenticate?__authen_application="+Drupal.settings.app; +}; + +PIN.chooseLogin = function() { + // email should be set in Drupal + //alert("chooseLogin: " + window.location.hostname); + var pin_dest = document.location.href; + // extract node url from login url + pin_dest = pin_dest.replace("/user/login?destination=","/").replace("%2F","/"); + //$.cookie("pin_dest",pin_dest, {path: '/'}); + PIN.createCookie("pin_dest",pin_dest,1); // drupal js api. + if ( $('#'+PIN.swapId).length === 0 ) { + PIN.swapId = "pinLoginDiv"; + $('#'+PIN.loginFormId).wrap('
'); + //alert("Yeah, dude!"); + } + //alert("Hi Reinhard 2: " + PIN.swapId + " NOW length: " + $('#'+PIN.swapId).length); + PIN.drupalHtml=$('#'+PIN.swapId).html(); + //alert("drupalHtml: " + PIN.drupalHtml); + var html=""; + html += "
"; + html += "
"; + html += "