From 26d288556b0673050abc097e3874064acd5d3808 Mon Sep 17 00:00:00 2001
From: Nikolai Kristiansen
Date: Sun, 6 Jul 2014 01:49:02 +0200
Subject: [PATCH] Pull down v1.7.6 from upstream, rename plugin name to avoid
update nag, testcommit
---
credits.txt | 14 +-
readme.txt | 58 ++--
wpDirAuth.php | 806 +++++++++++++++++++++++++++++++++++++++-----------
3 files changed, 671 insertions(+), 207 deletions(-)
diff --git a/credits.txt b/credits.txt
index 0bf6fba..47d6916 100644
--- a/credits.txt
+++ b/credits.txt
@@ -1,18 +1,18 @@
=== wpDirAuth Credits ===
wpDirAuth is made possible by the following contributors:
-
- Stephane Daury
- Current maintainer
- Montreal, QC, Canada
- http://stephane.daury.org/
-
+
Paul Gilzow
Current maintainer
Columbia, MO, USA
http://profiles.wordpress.org/users/gilzow/
+
+ Stephane Daury
+ Original author
+ Montreal, QC, Canada
+ http://stephane.daury.org/
- Todd Beverly
+ Todd Beverly
wpDirAuth QA and patch contributor
Rochester, NY, USA
See http://wordpress.org/support/topic/129814
diff --git a/readme.txt b/readme.txt
index e719160..95d8b13 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,15 +1,25 @@
=== wpDirAuth ===
-Contributors: stephdau, apokalyptik, gilzow
+Contributors: gilzow, stephdau, apokalyptik
Tags: login, authentication, directory, ldap, ldaps
Requires at least: 2.2
-Tested up to: 3.1
-Stable tag: 1.6.1
+Tested up to: 3.4.2
+Stable tag: 1.7.6
WordPress directory authentication plugin through LDAP and LDAPS (SSL).
== Description ==
-See
+See
+
+PLEASE NOTE
+Beta testers of the 1.7.X branch prior to version 1.7.5, you will need to
+deactivate wpdirauth before you updgrade to this latest version. Once you
+have installed and network activated the plugin, it will copy your options
+from their previous location to the sitemeta table. You will only need to
+do this once. This will also work for anyone who was using the 1.6.X
+branch or older and plans on using it in MULTISITE mode.
+
+Version 1.7.5 brings full MULTISITE support.
wpDirAuth allows users of central directory (LDAP) servers to login to
authorized WordPress instances without having to register. The plugin creates
@@ -67,10 +77,6 @@ Plugin Finder at the following locations:
* Direct download:
* WPPF home:
-You can find all historical releases archived at the following location:
-
-*
-
== Installation ==
@@ -162,20 +168,20 @@ task tracking.
Copyrights are listed in chronological order, by contributions.
-wpDirAuth: WordPress Directory Authentication
-Copyright (c) 2007 [Stephane Daury](http://stephane.daury.org/)
+wpDirAuth: WordPress Directory Authentication, original author
+Copyright (c) 2007 Stephane Daury - http://stephane.daury.org/
wpDirAuth and wpLDAP Patch Contributions
-Copyright (c) 2007 [PKR Internet, LLC](http://www.pkrinternet.com/)
-
+Copyright (c) 2007 PKR Internet, LLC - http://www.pkrinternet.com/
+
wpDirAuth Patch Contributions
Copyright (c) 2007 Todd Beverly
-wpDirAuth Patch Contributions, New Features
-Copyright (c) 2010, 2011 Paul Gilzow
-
wpLDAP: WordPress LDAP Authentication
-Copyright (c) 2007 [Ashay Suresh Manjure](http://ashay.org/)
+Copyright (c) 2007 Ashay Suresh Manjure - http://ashay.org/
+
+wpDirAuth Patch Contribution and current maintainer
+Copyright (c) 2010, 2011, 2012 Paul Gilzow - http://gilzow.com/
wpDirAuth is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -202,14 +208,22 @@ In other words, a classic case of `pimp my lib'` (hopefully for the better).
== Changelog ==
-= 1.5.1 =
-* Remove default password nag for wpdirauth accounts
+PLEASE NOTE Beta testers of the 1.7.X branch prior to version 1.7.5, you will need to deactivate wpdirauth before you updgrade to this latest version. Once you have installed and network activated the plugin, it will copy your options from their previous location to the sitemeta table. You will only need to do this once. This will also work for anyone who was using the 1.6.X branch or older and plans on using it in MULTISITE mode.
-= 1.5.2 =
-* Added ability to limit logins to specific AD groups. Fixed a bug that produced an incorrect filter when using a single Authentication Group
+= 1.7.6 =
+Corrected situation where a new authenticated user logging into a child site in a multisite network was added to the parent site, instead of the child site where they initiated the login. Also, somewhere along the way, I reintroduced a bug that when using authentication groups, the plugin would fail to redirect a successfully logged in user.
+
+= 1.7.5 =
+* MULTISITE support, bug fixes, security enhancements
+
+= 1.6.1 =
+* Corrected a bug that would prevent user profiles from successfully being found. Thanks go to jgiangrande for identifying the problem area.
= 1.6.0 =
* Added `Add Dir Auth User` to Admin User menu. Now able to pre-add Directory Authenticated users and assign roles where previously users would have to log in first, and then have an admin change their role.
-= 1.6.1 =
-* Corrected a bug that would prevent user profiles from successfully being found. Thanks go to jgiangrande for identifying the problem area.
\ No newline at end of file
+= 1.5.2 =
+* Added ability to limit logins to specific AD groups. Fixed a bug that produced an incorrect filter when using a single Authentication Group
+
+= 1.5.1 =
+* Remove default password nag for wpdirauth accounts
\ No newline at end of file
diff --git a/wpDirAuth.php b/wpDirAuth.php
index 2c107f0..4fa6284 100644
--- a/wpDirAuth.php
+++ b/wpDirAuth.php
@@ -15,13 +15,13 @@
* Originally forked from a patched version of wpLDAP.
*
* @package wpDirAuth
- * @version 1.6.1
- * @see http://tekartist.org/labs/wordpress/plugins/wpdirauth/
+ * @version 1.7.6
+ * @see http://wpdirauth.gilzow.com/
* @license GPL
*
* Copyrights are listed in chronological order, by contributions.
*
- * wpDirAuth: WordPress Directory Authentication
+ * wpDirAuth: WordPress Directory Authentication, original author
* Copyright (c) 2007 Stephane Daury - http://stephane.daury.org/
*
* wpDirAuth and wpLDAP Patch Contributions
@@ -30,11 +30,11 @@
* wpDirAuth Patch Contributions
* Copyright (c) 2007 Todd Beverly
*
- * wpDirAuth Patch Contribution and current maintainer
- * Copyright (c) 2010, 2011 Paul Gilzow
- *
* wpLDAP: WordPress LDAP Authentication
* Copyright (c) 2007 Ashay Suresh Manjure - http://ashay.org/
+ *
+ * wpDirAuth Patch Contribution and current maintainer
+ * Copyright (c) 2010, 2011, 2012 Paul Gilzow - http://gilzow.com/
*
* wpDirAuth is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -56,27 +56,27 @@
/*
PLUGIN META INFO FOR WORDPRESS LISTINGS
-Plugin Name: wpDirAuth
-Plugin URI: http://tekartist.org/labs/wordpress/plugins/wpdirauth/
+Plugin Name: wpDirAuth-PosixGroup
+Plugin URI: http://wpdirauth.gilzow.com/
Description: WordPress Directory Authentication (LDAP/LDAPS).
Works with most LDAP enabled directory services, such as OpenLDAP,
Apache Directory, Microsoft Active Directory, Novell eDirectory,
Sun Java System Directory Server, etc.
Originally revived and upgraded from a patched version of wpLDAP.
-Version: 1.6.0
-Author: Stephane Daury, Paul Gilzow and whoever wants to help
-Author URI: http://stephane.daury.org/ http://gilzow.com/
+Version: 1.7.6
+Author: Paul Gilzow
+Author URI: http://gilzow.com/
*/
/**
* wpDirAuth version.
*/
-define('WPDIRAUTH_VERSION', '1.6.1');
+define('WPDIRAUTH_VERSION', '1.7.6');
/**
* wpDirAuth signature.
*/
-define('WPDIRAUTH_SIGNATURE', 'wpDirAuth '.WPDIRAUTH_VERSION);
+define('WPDIRAUTH_SIGNATURE', 'wpDirAuth '.WPDIRAUTH_VERSION);
/**
* Default LDAP field to search against when locating the user's profile.
@@ -104,8 +104,32 @@ define('WPDIRAUTH_LDAP_RETURN_KEYS',serialize(array('sn', 'givenname', 'mail')))
define('WPDIRAUTH_EMAIL_NEWUSER_NOTIFY','You have been added to the site %s as %s %s. You may login to the site using your institution\'s %s (%s) and password at the following address: %s');
-/* Debugging */
-define('WPDIRAUTH_DEBUG', false);
+/**
+ *My fail-safe method for determing if we are running in multisite mode
+ */
+define('WPDIRAUTH_MULTISITE',(defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE && function_exists('switch_to_blog')) ? TRUE : FALSE);
+
+/**
+ *List of option keys we store in wp_sitemeta/wp_options
+ */
+define('WPDIRAUTH_OPTIONS', serialize(array(
+ 'dirAuthEnable',
+ 'dirAuthRequiresSsl',
+ 'dirAuthTOS',
+ 'dirAuthUseGroups',
+ 'dirAuthEnableSsl',
+ 'dirAuthControllers',
+ 'dirAuthBaseDn',
+ 'dirAuthPreBindUser',
+ 'dirAuthAccountSuffix',
+ 'dirAuthFilter',
+ 'dirAuthInstitution',
+ 'dirAuthGroups',
+ 'dirAuthMarketingSSOID',
+ 'dirAuthLoginScreenMsg',
+ 'dirAuthChangePassMsg'
+)));
+
if (function_exists('wp_authenticate') || function_exists('wp_setcookie') || !function_exists('ldap_connect')) {
/**
@@ -216,7 +240,7 @@ else {
.$_SERVER['HTTP_USER_AGENT']
.$_SERVER['REMOTE_ADDR']
).uniqid(microtime(),true);
- update_option("dirAuthCookieMarker",$cookieMarker);
+ update_site_option("dirAuthCookieMarker",$cookieMarker);
return $cookieMarker;
}
@@ -237,7 +261,7 @@ else {
{
$password = strtr($password, array("\'"=>"'"));
if ( ($isBound = @ldap_bind($connection, $username, $password)) === false ) {
- // @see wpLDAP comment at http://ashay.org/?page_id=133#comment-558
+ // @see http://weblogs.valsania.it/andreav/2008/07/24/wpdirauth-14-patch/
$isBound = @ldap_bind($connection,"uid=$username,$baseDn", $password);
}
return $isBound;
@@ -337,17 +361,17 @@ else {
$errorTitle = WPDIRAUTH_ERROR_TITLE;
- $controllers = explode(',', get_option('dirAuthControllers'));
- $baseDn = get_option('dirAuthBaseDn');
- $preBindUser = get_option('dirAuthPreBindUser');
- $preBindPassword = get_option('dirAuthPreBindPassword');
- $accountSuffix = get_option('dirAuthAccountSuffix');
- $filter = get_option('dirAuthFilter');
- $enableSsl = get_option('dirAuthEnableSsl');
- $boolUseGroups = get_option('dirAuthUseGroups');
+ $controllers = explode(',', get_site_option('dirAuthControllers'));
+ $baseDn = get_site_option('dirAuthBaseDn');
+ $preBindUser = get_site_option('dirAuthPreBindUser');
+ $preBindPassword = get_site_option('dirAuthPreBindPassword');
+ $accountSuffix = get_site_option('dirAuthAccountSuffix');
+ $filter = get_site_option('dirAuthFilter');
+ $enableSsl = get_site_option('dirAuthEnableSsl');
+ $boolUseGroups = get_site_option('dirAuthUseGroups');
if($boolUseGroups == 1){
- $strAuthGroups = get_option('dirAuthGroups');
+ $strAuthGroups = get_site_option('dirAuthGroups');
}
$returnKeys = unserialize(WPDIRAUTH_LDAP_RETURN_KEYS);
@@ -443,40 +467,46 @@ else {
}
- else {
- if($boolUseGroups == 1){
- //the user is authenticated, but we want to make sure they are a member of the groups given
- /**
- * We need to get the DN's for each Authentication Group CN that was given to us.
- */
- $aryAuthGroupsDN = array();
- $aryAuthGroups = explode(',',$strAuthGroups);
- $aryAttribs = array('posixGroup');
- $isMember = false;
- foreach($aryAuthGroups as $strAuthGroup){
- $strAuthGroup = 'cn='.$strAuthGroup;
- $rscLDAPSearch = ldap_search($connection,$baseDn,$strAuthGroup,$aryAttribs);
- $arySearchResults = ldap_get_entries($connection,$rscLDAPSearch);
- wpDirAuthPrintDebug($arySearchResults,'search results for ' . $strAuthGroup);
- if( isset($arySearchResults[0]['memberuid'])) {
- wpDirAuthPrintDebug($arySearchResults[0]['memberuid'], "memberUid");
- if ( in_array($username, $arySearchResults[0]['memberuid']) ){
- $isMember = true;
- }
- }
-
- if(isset($arySearchResults[0]['dn'])){
- $aryAuthGroupsDN[] = $arySearchResults[0]['dn'];
- }
- }
- if(count($aryAuthGroupsDN) == 0){
- return new WP_Error('no_auth_groups_found',$errorTitle.__('No Authentication Groups found based on given group CN'));
- }
-
- if( $isMember === false ){
- return new WP_Error('not member of auth grou', __('Could not log you in because you are not a member of the specified group.'));
- }
- }
+ else {
+ if($boolUseGroups == 1){
+ //the user is authenticated, but we want to make sure they are a member of the groups given
+ /**
+ * We need to get the DN's for each Authentication Group CN that was given to us.
+ */
+ $aryAuthGroupsDN = array();
+ $aryAuthGroups = explode(',',$strAuthGroups);
+ $aryAttribs = array('distinguishedname');
+ foreach($aryAuthGroups as $strAuthGroup){
+ $strAuthGroup = 'cn='.$strAuthGroup;
+ $rscLDAPSearch = ldap_search($connection,$baseDn,$strAuthGroup,$aryAttribs);
+ $arySearchResults = ldap_get_entries($connection,$rscLDAPSearch);
+ if(isset($arySearchResults[0]['dn'])){
+ $aryAuthGroupsDN[] = $arySearchResults[0]['dn'];
+ }
+ }
+
+ if(count($aryAuthGroupsDN) == 0){
+ return new WP_Error('no_auth_groups_found',$errorTitle.__('No Authentication Groups found based on given group CN'));
+ }
+
+ // 2014-07-06 Nikolai R Kristiansen
+ // Modify for posixGroup lookup
+
+ // (&(memberUid=nikolark)(cn=dns-aktiv))
+ $strFilterQuery = '(&'.$filterQuery.'(|';
+ foreach($aryAuthGroupsDN as $strAuthGroupDN){
+ $strFilterQuery .= '(cn='.$strAuthGroupDN.')';
+ }
+ $strFilterQuery .= '))';
+ if(($rscLDAPSearchGroupMember = ldap_search($connection,$baseDn,$strFilterQuery)) !== false){
+ $arySearchResultsMember = ldap_get_entries($connection,$rscLDAPSearchGroupMember);
+ if($arySearchResultsMember['count'] !== 1){
+ return new WP_Error('not_member_of_auth_group',$errorTitle
+ . __('User authenticated but is not a member of an Authentication Group(s)'));
+ }
+ }
+
+ }
/**
@@ -588,32 +618,32 @@ ____________EOS;
$loginScreenMsg = wpDirAuth_sanitize($_POST['dirAuthLoginScreenMsg'], true);
$changePassMsg = wpDirAuth_sanitize($_POST['dirAuthChangePassMsg'], true);
- update_option('dirAuthEnable', $enable);
- update_option('dirAuthEnableSsl', $enableSsl);
- update_option('dirAuthRequireSsl', $requireSsl);
- update_option('dirAuthControllers', $controllers);
- update_option('dirAuthBaseDn', $baseDn);
- update_option('dirAuthPreBindUser', $preBindUser);
- update_option('dirAuthAccountSuffix', $accountSuffix);
- update_option('dirAuthFilter', $filter);
- update_option('dirAuthInstitution', $institution);
- update_option('dirAuthLoginScreenMsg', $loginScreenMsg);
- update_option('dirAuthChangePassMsg', $changePassMsg);
- update_option('dirAuthTOS', $TOS);
- update_option('dirAuthUseGroups', $boolUseGroups);
- update_option('dirAuthGroups', $strAuthGroups);
- update_option('dirAuthMarketingSSOID', $strMarketingSSOID);
+ update_site_option('dirAuthEnable', $enable);
+ update_site_option('dirAuthEnableSsl', $enableSsl);
+ update_site_option('dirAuthRequireSsl', $requireSsl);
+ update_site_option('dirAuthControllers', $controllers);
+ update_site_option('dirAuthBaseDn', $baseDn);
+ update_site_option('dirAuthPreBindUser', $preBindUser);
+ update_site_option('dirAuthAccountSuffix', $accountSuffix);
+ update_site_option('dirAuthFilter', $filter);
+ update_site_option('dirAuthInstitution', $institution);
+ update_site_option('dirAuthLoginScreenMsg', $loginScreenMsg);
+ update_site_option('dirAuthChangePassMsg', $changePassMsg);
+ update_site_option('dirAuthTOS', $TOS);
+ update_site_option('dirAuthUseGroups', $boolUseGroups);
+ update_site_option('dirAuthGroups', $strAuthGroups);
+ update_site_option('dirAuthMarketingSSOID', $strMarketingSSOID);
// Only store/override the value if a new one is being sent a bind user is set.
if ( $preBindUser && $preBindPassword && ($preBindPassCheck == $preBindPassword) )
- update_option('dirAuthPreBindPassword', $preBindPassword);
+ update_site_option('dirAuthPreBindPassword', $preBindPassword);
// Clear the stored password if the Bind DN is null
elseif ( ! $preBindUser)
- update_option('dirAuthPreBindPassword', '');
+ update_site_option('dirAuthPreBindPassword', '');
- if (get_option('dirAuthEnable') && !get_option('dirAuthCookieMarker'))
+ if (get_site_option('dirAuthEnable') && !get_site_option('dirAuthCookieMarker'))
wpDirAuth_makeCookieMarker();
echo 'Your new settings were saved successfully.
';
@@ -623,27 +653,27 @@ ____________EOS;
}
else {
// Booleans
- $enable = intval(get_option('dirAuthEnable')) == 1 ? 1 : 0;
- $requireSsl = intval(get_option('dirAuthRequireSsl')) == 1 ? 1 : 0;
- $TOS = intval(get_option('dirAuthTOS')) == 1 ? 1 : 0;
- $boolUseGroups = intval(get_option('dirAuthUseGroups')) == 1 ? 1 : 0;
+ $enable = intval(get_site_option('dirAuthEnable')) == 1 ? 1 : 0;
+ $requireSsl = intval(get_site_option('dirAuthRequireSsl')) == 1 ? 1 : 0;
+ $TOS = intval(get_site_option('dirAuthTOS')) == 1 ? 1 : 0;
+ $boolUseGroups = intval(get_site_option('dirAuthUseGroups')) == 1 ? 1 : 0;
//integers
- $enableSsl = intval(get_option('dirAuthEnableSsl',0));
+ $enableSsl = intval(get_site_option('dirAuthEnableSsl',0));
// Strings, no HTML
- $controllers = wpDirAuth_sanitize(get_option('dirAuthControllers'));
- $baseDn = wpDirAuth_sanitize(get_option('dirAuthBaseDn'));
- $preBindUser = wpDirAuth_sanitize(get_option('dirAuthPreBindUser'));
- $accountSuffix = wpDirAuth_sanitize(get_option('dirAuthAccountSuffix'));
- $filter = wpDirAuth_sanitize(get_option('dirAuthFilter'));
- $institution = wpDirAuth_sanitize(get_option('dirAuthInstitution'));
- $strAuthGroups = wpDirAuth_sanitize((get_option('dirAuthGroups')));
- $strMarketingSSOID = wpDirAuth_sanitize((get_option('dirAuthMarketingSSOID')));
+ $controllers = wpDirAuth_sanitize(get_site_option('dirAuthControllers'));
+ $baseDn = wpDirAuth_sanitize(get_site_option('dirAuthBaseDn'));
+ $preBindUser = wpDirAuth_sanitize(get_site_option('dirAuthPreBindUser'));
+ $accountSuffix = wpDirAuth_sanitize(get_site_option('dirAuthAccountSuffix'));
+ $filter = wpDirAuth_sanitize(get_site_option('dirAuthFilter'));
+ $institution = wpDirAuth_sanitize(get_site_option('dirAuthInstitution'));
+ $strAuthGroups = wpDirAuth_sanitize((get_site_option('dirAuthGroups')));
+ $strMarketingSSOID = wpDirAuth_sanitize((get_site_option('dirAuthMarketingSSOID')));
// Have to be allowed to contain some HTML
- $loginScreenMsg = wpDirAuth_sanitize(get_option('dirAuthLoginScreenMsg'), true);
- $changePassMsg = wpDirAuth_sanitize(get_option('dirAuthChangePassMsg'), true);
+ $loginScreenMsg = wpDirAuth_sanitize(get_site_option('dirAuthLoginScreenMsg'), true);
+ $changePassMsg = wpDirAuth_sanitize(get_site_option('dirAuthChangePassMsg'), true);
}
$controllers = htmlspecialchars($controllers);
@@ -898,16 +928,6 @@ ________EOS;
'wpDirAuth_optionsPanel'
);
}
-
- if(function_exists('add_users_page')){
- add_users_page(
- 'Add Directory Authentication Users',
- 'Add Dir Auth User',
- 'administrator',
- basename(__FILE__),
- 'wpDirAuth_add_user_panel'
- );
- }
}
@@ -920,7 +940,7 @@ ________EOS;
*/
function wpDirAuth_loginFormExtra()
{
- if (get_option('dirAuthEnable')) {
+ if (get_site_option('dirAuthEnable')) {
if (isset($_SERVER['SCRIPT_URI']) && preg_match('|^http|',$_SERVER['SCRIPT_URI'])) {
$selfURL = $_SERVER['SCRIPT_URI'];
@@ -943,7 +963,10 @@ ________EOS;
);
}
- if (get_option('dirAuthRequireSsl') && (!preg_match('|^https|',$selfURL))) {
+ //_log('contents of selfurl: '.$selfURL);
+
+
+ if (get_site_option('dirAuthRequireSsl') && (!preg_match('|^https|',$selfURL))) {
$sslURL = str_replace('http://','https://',$selfURL);
$refreshJS = '" />';
@@ -964,13 +987,13 @@ ________EOS;
exit;
}
- $dirAuthInstitution = stripslashes(get_option('dirAuthInstitution'));
+ $dirAuthInstitution = stripslashes(get_site_option('dirAuthInstitution'));
if (!$dirAuthInstitution) $dirAuthInstitution = __('Directory');
- $loginScreenMsg = stripslashes(get_option('dirAuthLoginScreenMsg'));
+ $loginScreenMsg = stripslashes(get_site_option('dirAuthLoginScreenMsg'));
if (!$loginScreenMsg) $loginScreenMsg = __(sprintf(
WPDIRAUTH_DEFAULT_LOGINSCREENMSG,
- get_option('dirAuthInstitution')
+ get_site_option('dirAuthInstitution')
));
echo '
@@ -1000,15 +1023,15 @@ ________EOS;
}
else {
// Editing directory user profile, show password msg
- $message = stripslashes(get_option('dirAuthChangePassMsg'));
+ $message = stripslashes(get_site_option('dirAuthChangePassMsg'));
if (!$message) {
$message = __(sprintf(
WPDIRAUTH_DEFAULT_CHANGEPASSMSG,
- stripslashes(get_option('dirAuthInstitution'))
+ stripslashes(get_site_option('dirAuthInstitution'))
));
}
- if (get_option('dirAuthTOS')) {
+ if (get_site_option('dirAuthTOS')) {
// TOS option is ON
if (($TOSDate = get_usermeta($profileuser->ID, 'wpDirAuthTOS')) === '') {
if ($userdata->ID == $profileuser->ID) {
@@ -1075,26 +1098,38 @@ ________EOS;
*/
function wp_authenticate($username, $password)
{
+ //echo 'authenticating';exit;
+ $boolRestoreBlog = false;
+ if(defined('WPDIRAUTH_MULTISITE') && WPDIRAUTH_MULTISITE){
+ //echo 'I should switch blogs!';exit;
+ global $blog_id;
+ $intOriginalBlog = $blog_id;
+ switch_to_blog(1); //switch to the parent blog
+ $boolRestoreBlog = true;
+ }
/**
* @desc wp-hack for some reason, this function is being called even when a user just goes to the login page. added the next 3 lines so that
* if the user arrives via $_GET, then we simply tell them to login
*/
if($_SERVER['REQUEST_METHOD'] != 'POST'){
+ if($boolRestoreBlog) restore_current_blog();
return new WP_Error('incorrect_method',__('Please Login'));
}
if (!$username) {
+ if($boolRestoreBlog) restore_current_blog();
return new WP_Error('empty_username', __('Login Error:
The username field is empty.'));
}
if (!$password) {
+ if($boolRestoreBlog) restore_current_blog();
return new WP_Error('empty_password', __('Login Error:
The password field is empty.'));
}
- $enable = get_option('dirAuthEnable');
- $cookieMarker = get_option('dirAuthCookieMarker');
+ $enable = get_site_option('dirAuthEnable');
+ $cookieMarker = get_site_option('dirAuthCookieMarker');
if (!$cookieMarker) {
$cookieMarker = wpDirAuth_makeCookieMarker();
@@ -1111,6 +1146,7 @@ ________EOS;
/*
* Existing directory user, but directory access has now been disabled.
*/
+ if($boolRestoreBlog) restore_current_blog();
do_action( 'wp_login_failed', $username );
return new WP_Error('login_disabled',__('Directory Login Error:
Sorry, but the site administrators have disabled
@@ -1140,48 +1176,59 @@ ________EOS;
/*
* Username exists.
*/
+ if($boolRestoreBlog) restore_current_blog();
do_action( 'wp_login_failed', $username );
return new WP_Error('username_exists',__('Directory Login Error:
Could not create a new WP user account
- because the directory username ' . $userLogin . ' is already
+ because the directory username ' . htmlentities($userLogin,ENT_QUOTES,'UTF-8') . ' is already
registered on this site.'));
}
elseif (email_exists($userEmail)) {
/*
* Email exists.
*/
+ if($boolRestoreBlog) restore_current_blog();
do_action( 'wp_login_failed', $username );
return new WP_Error('email_exists',__('Directory Login Error:
Could not create a new WP account because
- the email ' . $userEmail . ' is
+ the email ' . htmlentities($userEmail,ENT_QUOTES,'UTF-8') . ' is
already registered with this site.'));
}
- elseif ($userID = wp_create_user($userLogin, $password, $userEmail)) {
- $userData['ID'] = $userID;
- $tmpAr = split('@',$userData['email']);
- $userData['nickname'] = str_replace('.','_',$tmpAr[0]);
- $userData['display_name'] = $userData['first_name'].' '.$userData['last_name'];
- unset($userData['email']);
-
- wp_update_user($userData);
- update_usermeta($userID, 'wpDirAuthFlag', 1);
- wpDirAuth_remove_password_nag($userID);
- return new WP_User($userID);
- }
else {
- /*
- * Unknown error.
- */
- do_action( 'wp_login_failed', $username );
- return new WP_Error('creation_unknown_error',__('Directory Login Error:
- Could not create a new user account.
- Unknown error. [user: ' . $userLogin . ', email: ' . $userEmail . ']'));
+ if(defined('WPDIRAUTH_MULTISITE') && WPDIRAUTH_MULTISITE && isset($boolRestoreBlog) && $boolRestoreBlog){
+ restore_current_blog();
+ }
+
+ if ($userID = wp_create_user($userLogin, $password, $userEmail)) {
+ $userData['ID'] = $userID;
+ $tmpAr = split('@',$userData['email']);
+ $userData['nickname'] = str_replace('.','_',$tmpAr[0]);
+ $userData['display_name'] = $userData['first_name'].' '.$userData['last_name'];
+ unset($userData['email']);
+
+ wp_update_user($userData);
+ update_usermeta($userID, 'wpDirAuthFlag', 1);
+ wpDirAuth_remove_password_nag($userID);
+ //if($boolRestoreBlog) restore_current_blog();
+ return new WP_User($userID);
+ }
+ else {
+ /*
+ * Unknown error.
+ */
+ //if($boolRestoreBlog) restore_current_blog();
+ do_action( 'wp_login_failed', $username );
+ return new WP_Error('creation_unknown_error',__('Directory Login Error:
+ Could not create a new user account.
+ Unknown error. [user: ' . htmlentities($userLogin,ENT_QUOTES,'UTF-8') . ', email: ' . htmlentities($userEmail,ENT_QUOTES,'UTF-8') . ']'));
+ }
}
}
else {
/*
* Did not pass dir auth, and no login present in WP
*/
+ if($boolRestoreBlog) restore_current_blog();
do_action( 'wp_login_failed', $username );
return $userData;
}
@@ -1198,12 +1245,14 @@ ________EOS;
/*
* WP user, password okay.
*/
+ if($boolRestoreBlog) restore_current_blog();
return new WP_User($login->ID);
}
else {
/*
* WP user, wrong pass
*/
+ if($boolRestoreBlog) restore_current_blog();
do_action( 'wp_login_failed', $username );
return new WP_Error('incorrect_password',__('WordPress Login Error:
Incorrect password.'));
@@ -1220,12 +1269,14 @@ ________EOS;
* Directory user, password okay.
*/
wpDirAuth_remove_password_nag($login->ID);
+ if($boolRestoreBlog) restore_current_blog();
return new WP_User($login->ID);
}
else {
/*
* Directory user, wrong pass
*/
+ if($boolRestoreBlog) restore_current_blog();
do_action( 'wp_login_failed', $username );
return $userData;
}
@@ -1240,6 +1291,7 @@ ________EOS;
/**
* No existing account record found
*/
+ if($boolRestoreBlog) restore_current_blog();
do_action( 'wp_login_failed', $username );
return new WP_Error('failed_login',__('WordPress Login Error:
Could not authenticate user.
@@ -1253,12 +1305,14 @@ ________EOS;
/*
* WP user, password okay.
*/
+ if($boolRestoreBlog) restore_current_blog();
return new WP_User($login->ID);
}
else {
/*
* WP user, wrong pass
*/
+ if($boolRestoreBlog) restore_current_blog();
do_action( 'wp_login_failed', $username );
return new WP_Error('incorrect_password',__('WordPress Login Error:
Incorrect password.'));
@@ -1298,8 +1352,8 @@ ________EOS;
/**
* Get wpsDirAuth options
*/
- $enable = get_option('dirAuthEnable');
- $cookieMarker = get_option('dirAuthCookieMarker');
+ $enable = get_site_option('dirAuthEnable');
+ $cookieMarker = get_site_option('dirAuthCookieMarker');
if (!$cookieMarker) {
$cookieMarker = wpDirAuth_makeCookieMarker();
@@ -1364,9 +1418,7 @@ ________EOS;
* @param string $strMsg
*/
function wpDirAuthPrintDebug($mxdVar,$strMsg){
- if (WPDIRAUTH_DEBUG) {
- echo PHP_EOL,'',PHP_EOL;
- }
+ echo PHP_EOL,'',PHP_EOL;
}
/**
@@ -1406,6 +1458,12 @@ ________EOS;
$rscResult = ldap_search($rscConnection,$strBaseDn,$strFilterQuery,unserialize(WPDIRAUTH_LDAP_RETURN_KEYS));
}
+ /**
+ * At this point, we will no longer use $strFilterQuery EXCEPT in the output of an error message. To ensure we dont introduce an injection point, we will encode any
+ * html entities that might be present.
+ */
+ $strFilterQuery = htmlentities($strFilterQuery,ENT_QUOTES,'UTF-8');
+
if(!$rscResult){
return new WP_Error ('noprofile_search', __('Directory authentication initially succeeded, but no valid profile was found (search procedure).')
." [$strFilter]");
@@ -1445,12 +1503,12 @@ ________EOS;
function wpDirAuth_ConnectAndLookupUser($strSSOID){
$boolFound = false;
- $strBaseDn = get_option('dirAuthBaseDn');
- $strPreBindUser = get_option('dirAuthPreBindUser','');
- $strPreBindPassword = get_option('dirAuthPreBindPassword','');
- $strAccountSuffix = get_option('dirAuthAccountSuffix');
- $strFilter = get_option('dirAuthFilter');
- $intEnableSSL = get_option('dirAuthEnableSsl');
+ $strBaseDn = get_site_option('dirAuthBaseDn');
+ $strPreBindUser = get_site_option('dirAuthPreBindUser','');
+ $strPreBindPassword = get_site_option('dirAuthPreBindPassword','');
+ $strAccountSuffix = get_site_option('dirAuthAccountSuffix');
+ $strFilter = get_site_option('dirAuthFilter');
+ $intEnableSSL = get_site_option('dirAuthEnableSsl');
if ($strAccountSuffix) $strSSOID .= $strAccountSuffix;
@@ -1458,7 +1516,7 @@ ________EOS;
$strFilterQuery = "($strFilter=$strSSOID)";
- $aryControllers = wpDirAuth_shuffleControllers(explode(',', get_option('dirAuthControllers')));
+ $aryControllers = wpDirAuth_shuffleControllers(explode(',', get_site_option('dirAuthControllers')));
if(is_wp_error($aryControllers)){
return $aryControllers; //there werent any controllers to connect to
@@ -1476,7 +1534,7 @@ ________EOS;
if(!wpDirAuth_bindTest($rscConnection,$strPreBindUser,$strPreBindPassword,$strBaseDn)){
return new WP_Error('login_failed',__('Error Connecting to LDAP Server'
- . 'There was an error connecting to your LDAP server ('.$strDC.'). Please see the LDAP error message below for troubleshooting:
'
+ . 'There was an error connecting to your LDAP server ('. htmlentities($strDC,ENT_QUOTES,'UTF-8').'). Please see the LDAP error message below for troubleshooting:
'
. ldap_error($rscConnection)));
}
@@ -1492,17 +1550,18 @@ ________EOS;
* @param string $strRole Role chosen to give the new user
* @return mixed array of user details on success or WP_Error object on failure
*/
- function wpDirAuth_add_new_user($strSSOID,$strRole){
+ function wpDirAuth_add_new_user($strSSOID,$strRole,$intBlogID = 0){
/**
* We need to see if the user name already exists. if not, then we need to see if the email address is already in use, if not, then we need to try and look
* up the user. then if we actually found something, then we'll add them into wordpress
*/
$strSSOID = sanitize_user($strSSOID);
+ $intBlogID = is_int($intBlogID) ? $intBlogID : (int) $intBlogID; //just to make sure
if(username_exists($strSSOID)){
echo 'user already exists
';
return new WP_Error('username_exists',__('Could not create a new Wordpress account because the directory username '
- . $strSSOID . ' is already registered on this site.'));
+ . htmlentities($strSSOID,ENT_QUOTES,'UTF-8') . ' is already registered on this site.
'));
}
//we'll have to go ahead and look them up in LDAP in order to check their email address
@@ -1515,7 +1574,7 @@ ________EOS;
if(email_exists($strUserEmail)){
echo 'Email address already exists
';
return new WP_Error('email_exists',__('Could not create a new WP account because the email '
- . $strUserEmail . ' is already registered with this site.'));
+ . htmlentities($strUserEmail,ENT_QUOTES,'UTF-8') . ' is already registered with this site.'));
}
$aryUserDetails['user_pass'] = mt_rand();//we're going to store a random password in WP since directory users will never use it to log in anyway'
@@ -1529,7 +1588,11 @@ ________EOS;
$aryUserDetails['display_name'] = $aryUserDetails['first_name'].' '.$aryUserDetails['last_name'];
$aryUserDetails['role'] = $strRole;
- $intUserID = wp_update_user($aryUserDetails);
+ /**
+ * Switch to the blog we want to insert the user into
+ */
+ if(defined('MULTISITE') && MULTISITE && function_exists('switch_to_blog')) switch_to_blog($intBlogID);
+ $intUserID = wp_insert_user($aryUserDetails);
if(!is_int($intUserID)){
return new WP_Error('createuser_failed',__('For an unknow reason, WP failed to create a new user.'
@@ -1538,8 +1601,15 @@ ________EOS;
$aryUserDetails['ID'] = $intUserID;
update_usermeta($intUserID, 'wpDirAuthFlag', 1);
- wpDirAuth_remove_password_nag($intUserID);
+ wpDirAuth_remove_password_nag($intUserID);
+ //for situations where an admin is adding a user from a site edit screen
+ /**
+ if($intBlogID != 0){
+ add_user_to_blog($intBlogID,$intUserID,$strRole);
+ } */
+
+ if(defined('MULTISITE') && MULTISITE && function_exists('switch_to_blog')) restore_current_blog();
return $aryUserDetails;
}
@@ -1562,14 +1632,24 @@ ________EOS;
*
* @param string $strSSOID User's Single Sign On ID
* @param integer $strUserID user's wordpress user ID
- * @param string $strRole the role the user has been set to
+ * @param array Data on the sites and roles that the user has been added to
* @return string
* @uses wpDirAuth_determine_A_or_An
*
*/
- function wpDirAuth_construct_success_msg($strSSOID,$strUserID,$strRole){
- $strMsg = 'Just created user %s as %s %s.
';
- return sprintf($strMsg,$strUserID,$strSSOID,wpDirAuth_determine_A_or_An($strRole),$strRole);
+ function wpDirAuth_construct_success_msg($strSSOID,$strUserID,$arySitesData,$strExtraMsg=''){
+ //$arySitesData = array('blogname','role','siteurl');
+ $strMsg = '
+
Just created user %s as %s. %s
+
';
+
+ $strSiteMessage = '%s for site %s';
+ $arySiteMsgParts = array();
+ foreach($arySitesData as $arySiteData){
+ $arySiteMsgParts[] = sprintf($strSiteMessage,$arySiteData['role'],$arySiteData['siteurl'],$arySiteData['blogname']);
+ }
+
+ return sprintf($strMsg,$strUserID,$strSSOID,implode($arySiteMsgParts,', '),$strExtraMsg);
}
/**
@@ -1593,7 +1673,7 @@ ________EOS;
*
*/
function wpDirAuth_add_user_contextual_help(){
- $strMarketingSSOID = get_option('dirAuthMarketingSSOID','Username');
+ $strMarketingSSOID = get_site_option('dirAuthMarketingSSOID','Username');
add_contextual_help('users_page_'.basename(__FILE__,'.php'),
'' . __('To add a directory authenticated user from your institution to your site, fill in the form on this screen. If you’re not sure which role to assign, you can use the link below to review the different roles and their capabilities. Here is a basic overview of roles:') . '
' .
'' .
@@ -1616,35 +1696,156 @@ ________EOS;
* @return void
*/
function wpDirAuth_add_user_panel(){
- $strMarketingSSOID = get_option('dirAuthMarketingSSOID','Username');
+ _log('WPDIRAUTH - function ' . __FUNCTION__ . ' activated. ');
+ /**
+ * Still needed?
+ */
+ global $id;
+ /**
+ * get_current_screen()->id = site-users-network will let us know if we are on the sites,edit,user tab
+ */
+ $strScreenID = get_current_screen()->id;
+ /**
+ * Are we running in a wordpress network and in the network area?
+ */
+ $boolIsNetworkAdminScreen = (is_network_admin() && $strScreenID != 'site-users-network') ? true : false;
+ /**
+ * How do we refer to their SSOID?
+ */
+ $strMarketingSSOID = get_site_option('dirAuthMarketingSSOID','Username');
+
+ $strReferer = wpDirAuth_get_referer();
+
/**
* defaults
*/
$strWpDirAuthSSOID = '';
$strWpDirAuthRole = '';
$boolConfirmationEmail = true;
- $mxdErrors = '';
+ $objErrors = new WP_Error;
$strSuccess = '';
+ if($boolIsNetworkAdminScreen){
+ $arySitesData = wpDirAuth_retrieve_multisite_blog_data();
+ }
if($_POST){
if(wp_verify_nonce($_POST['_wpnonce_add-da-user'],'add-da-user')){
+ /**
+ * We gots a problem.... if they've checked all the boxes and chosen roles but forgot to enter the pawprint (it happens, you did
+ * it yourself!) then we cant rebuild the list of which sites were checked/not checked later because we're jumping out before
+ * we get to the point where we build that data.
+ */
if(isset($_POST['ssoid']) && $_POST['ssoid'] == ''){
- $mxdErrors = new WP_Error('blank_ssoid',__(''.$strMarketingSSOID.' can not be left blank.
'));
+ $objErrors->add('blank_ssoid',__(''.$strMarketingSSOID.' can not be left blank.
'));
} else {
$strWpDirAuthSSOID = wpDirAuth_sanitize($_POST['ssoid']);
- $strWpDirAuthRole = in_array($_POST['role'],array_keys(get_editable_roles())) ? $_POST['role'] : get_option('default_role');
+
+ if($boolIsNetworkAdminScreen && $strReferer != 'site-users.php'){
+ $arySitesAndRoles = array();
+ $aryValidSiteIDs = array_keys($arySitesData);
+ $aryValidRoles = array_keys(get_editable_roles());
+ _log('contents of the post in function ' . __FUNCTION__.' at line ' . __LINE__ . ':'.PHP_EOL.var_export($_POST,true));
+ //we SHOULD have at least one site set.
+ for($i=0;$i0 && $intCountPostSite<3){
+ if($intCountPostSite == 1 && is_string(current($_POST[$strPostSite]))){
+ /**
+ * If the array has only one element, then this site wasnt selected as one we want to add the user to. but we
+ * need, for simplicity sake, to make the array contain two elements before we do input validation
+ */
+ $_POST[$strPostSite] = array('',current($_POST[$strPostSite]));
+ /**
+ * Since we know that the array has two elements, we'll test to make sure the siteid is valid'
+ */
+ } elseif(!is_numeric($_POST[$strPostSite][0]) || !in_array($_POST[$strPostSite][0],$aryValidSiteIDs)) {
+ $_POST[$strPostSite][0] = '';
+ }
+
+ /**
+ *
+ */
+ if(!in_array($_POST[$strPostSite][1],$aryValidRoles)){
+ $_POST[$strPostSite][1] = '';
+ }
+
+ /**
+ * If we now have non-empty values for both elements, we'll add them to our array to be used for inserting the user into sites
+ */
+ if($_POST[$strPostSite][0] != '' && $_POST[$strPostSite][1] != ''){
+ $arySitesAndRoles[$i] = array('blog_id'=>$_POST[$strPostSite][0],'role'=>$_POST[$strPostSite][1]);
+ }
+
+ }
+ }
+
+ }
+
+ $strWpDirAuthRole = (isset($_POST['role']) && in_array($_POST['role'],array_keys(get_editable_roles()))) ? $_POST['role'] : get_site_option('default_role');
+ $intBlogID = (isset($_POST['id']) && is_numeric($_POST['id'])) ? intval($_POST['id']) : '';
if(isset($_POST['noconfirmation']) && $_POST['noconfirmation'] == 1) $boolConfirmationEmail = false;
- $aryUserData = wpDirAuth_add_new_user($strWpDirAuthSSOID,$strWpDirAuthRole);
- if(is_wp_error($aryUserData)){
- $mxdErrors = $aryUserData;
+ if(!isset($arySitesAndRoles) || !$boolIsNetworkAdminScreen){
+ $aryUserData = wpDirAuth_add_new_user($strWpDirAuthSSOID,$strWpDirAuthRole,$intBlogID);
+ _log('adding a standard user (' . $strWpDirAuthSSOID .')from either inside a site, or from the edit section of a site');
+ _log('user data from newly added user is : ' . PHP_EOL . var_export($aryUserData,true) . PHP_EOL);
+ } elseif(count($arySitesAndRoles)<1) {
+ $aryUserData = new WP_Error('no_site_role_selected','You will need to select at least one site to add this user to.
');
} else {
- $strSuccess = wpDirAuth_construct_success_msg($strWpDirAuthSSOID,$aryUserData['ID'],$strWpDirAuthRole);
+ $aryUserData = wpDirAuth_add_new_user_to_multi_sites($strWpDirAuthSSOID,$arySitesAndRoles);
+ _log('adding a user (' . $strWpDirAuthSSOID .')from the network Add Dir Auth user section');
+ }
+
+ if(is_wp_error($aryUserData)){
+ //foreach($objErrors->)
+
+ //$mxdErrors = $aryUserData;
+ $objErrors->add($aryUserData->get_error_code(),$aryUserData->get_error_message(),$aryUserData->get_error_data());
+ } else {
+ $arySitesAddedTo = array();
+ if(isset($arySitesAndRoles) && count($arySitesAndRoles)!=0){
+ foreach($arySitesAndRoles as $arySiteData){
+ $arySitesAddedTo[] = array(
+ 'blogname'=>$arySitesData[$arySiteData['blog_id']],
+ 'aoran' =>wpDirAuth_determine_A_or_An($arySiteData['role']),
+ 'role' =>$arySiteData['role'],
+ 'siteurl' =>get_site_url($arySiteData['blog_id'],'','https')
+
+ );
+ }
+ } else {
+ $arySitesAddedTo[] = array(
+ 'blogname' =>get_site_option('blogname'),
+ 'aoran' =>wpDirAuth_determine_A_or_An($strWpDirAuthRole),
+ 'role' =>$strWpDirAuthRole,
+ 'siteurl' =>site_url()
+ );
+ }
+
+ /**
+ * ok, the admin has just successfully added a user to a site from the sites->edit->users tab. Since we cant seem to
+ * redirect them back to the screen automatically, let's give them a link to go back.'
+ */
+ if($strReferer == 'site-users.php' && $boolIsNetworkAdminScreen){
+ $strReturnToURL = wp_get_referer();
+ $strExtraMessage = 'Return to the User tab of the '. $arySitesData[$intBlogID] . ' site.';
+ } else {
+ $strExtraMessage = '';
+ }
+
+ $strSuccess = wpDirAuth_construct_success_msg($strWpDirAuthSSOID,$aryUserData['ID'],$arySitesAddedTo,$strExtraMessage);
+ _log('for user ' . $strWpDirAuthSSOID . ', added them to ' . var_export($arySitesAddedTo,true).'.');
if($boolConfirmationEmail){
- $strBlogName = get_option('blogname');
- $strMsg = sprintf(WPDIRAUTH_EMAIL_NEWUSER_NOTIFY,$strBlogName,wpDirAuth_determine_A_or_An($strWpDirAuthRole),$strWpDirAuthRole,$strMarketingSSOID,$strWpDirAuthSSOID,site_url().'/wp-login.php');
- wp_mail($aryUserData['email'],'['.$strBlogName.'] You\'ve been added!',$strMsg);
+ foreach($arySitesAddedTo as $arySiteAddedToData){
+ $strMsg = sprintf(WPDIRAUTH_EMAIL_NEWUSER_NOTIFY,$arySiteAddedToData['blogname'],$arySiteAddedToData['aoran'],$arySiteAddedToData['role'],$strMarketingSSOID,$strWpDirAuthSSOID,$arySiteAddedToData['siteurl'].'/wp-login.php');
+ wp_mail($aryUserData['email'],'['.$arySiteAddedToData['blogname'].'] You\'ve been added!',$strMsg);
+ }
}
//reset back to defaults
@@ -1654,23 +1855,30 @@ ________EOS;
}
}
} else {
- $mxdErrors = new WP_Error('invalid-nonce',__('Invalid nonce value'));
+ $objErrors->add('invalid-nonce',__('Invalid nonce value'));
}
}
+
+
+
?>
Add New Directory Authentication User
errors) != 0) {
+ wpDirAuth_print_error_messages($objErrors);
} elseif($strSuccess != ''){
echo $strSuccess;
}
-?>
-
+?>
Directory Auth settings page.') ?>
-