From 42b2084bda48f0c00cbfab7f35835ba13c13949c Mon Sep 17 00:00:00 2001 From: Nikolai Kristiansen Date: Wed, 20 Apr 2011 13:39:28 +0200 Subject: [PATCH] first commit, unpatched --- COPYING | 339 ++++++++++ credits.txt | 38 ++ readme.txt | 215 ++++++ wpDirAuth.php | 1735 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 2327 insertions(+) create mode 100755 COPYING create mode 100644 credits.txt create mode 100644 readme.txt create mode 100644 wpDirAuth.php diff --git a/COPYING b/COPYING new file mode 100755 index 0000000..d511905 --- /dev/null +++ b/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/credits.txt b/credits.txt new file mode 100644 index 0000000..0bf6fba --- /dev/null +++ b/credits.txt @@ -0,0 +1,38 @@ +=== 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/ + + Todd Beverly + wpDirAuth QA and patch contributor + Rochester, NY, USA + See http://wordpress.org/support/topic/129814 + + Richard Bullington-McGuire + wpDirAuth patch contributor + wpLDAP SSL patch author + Arlington, VA, USA + Managing Partner, PKR Internet, LLC + http://www.pkrinternet.com/ + + Richard Valk + wpDirAuth QA contributor + http://richard5.net + +== wpLDAP Credits == + +wpDirAuth was started (2007) from a patched version of wpLDAP 1.02. + + Ashay Suresh Manjure + Original wpLDAP author + Los Angeles, CA, USA + http://ashay.org/ \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..e719160 --- /dev/null +++ b/readme.txt @@ -0,0 +1,215 @@ +=== wpDirAuth === +Contributors: stephdau, apokalyptik, gilzow +Tags: login, authentication, directory, ldap, ldaps +Requires at least: 2.2 +Tested up to: 3.1 +Stable tag: 1.6.1 + +WordPress directory authentication plugin through LDAP and LDAPS (SSL). + +== Description == + +See + +wpDirAuth allows users of central directory (LDAP) servers to login to +authorized WordPress instances without having to register. The plugin creates +a new account for each directory user on first login so that they have full +access to preferences and functions, as any WP user would. + +Activating the plugin will not restrict you to using directory authentication +and you will still be able to both create new WP-only users as well as turn on +public registration in WordPress. You can also assign any privilege levels to +your directory users, and the those users will be referred to their +institutional password policy whenever they would normally able to update +their WP passwords (on the profile screen, in user edit, etc). + += LDAP/LDAPS = + +Authentication should work with most LDAP enabled directory services, such as +OpenLDAP, Apache Directory, Microsoft Active Directory, Novell eDirectory, +Sun Java System Directory Server, and more. + +wpDirAuth supports LDAP and LDAPS (SSL) connectivity and can force SSL for +WordPress authentication if it is available on the Web server. It also supports +server connection pools, for pseudo load balancing and fault tolerance, or +multiple source directory authentication. + +Because the key used to locate a user's profile in the LDAP server is not +always the same, depending on your LDAP server type and institutional choices, +you can define your own through the wpDirAuth administration tool. + +When logging in as a directory user, the WP "remember me" feature is downgraded +from 6 months for regular WP users to only 1 hour, so that institutional +passwords are not overly endangered when accessing WP from public terminals. + += Branding & Notifications = + +You can define notifications addressed to your directory users in key WordPress +areas, such as the login screen and the profile edit screen. + +Since these admin-editable values support HTML (admin, coders, beware of xss!), +you can point your directory users to central support information related to +functions such as changing their institutional password, a WordPress usage +related policy, etc. + +There is also a simple and optional terms of services concept, only implemented +for directory users, which will simply record a one-time acceptance date when +agreed upon. Note that agreeing to the TOS has no effect on the user's level of +access in the system, fact which could change in future version if there is a +demand for it, or through direct code contribution to that effect. + + +== Download == + +You can download the latest stable version of wpDirAuth from the WordPress +Plugin Finder at the following locations: + +* Direct download: +* WPPF home: + +You can find all historical releases archived at the following location: + +* + + +== Installation == + +Installing should be a piece of cake and take fewer than ten minutes, provided +you know your directory server(s) information, and that your blog is allowed to +connect and bind to it/them. + +Please refer to your friendly neighbourhood LDAP sysadmin for more information. + +1. Upload the `wpDirAuth` directory to the `/wp-content/plugins/` directory. +1. Login to your WordPress instance as an admin user. +1. Activate the plugin through the 'Plugins' menu in WordPress. +1. Go to the `Directory Auth.` menu found in the WordPress `Options` section. +1. Enter your directory server(s) information and set your preferences. + +You should now be able to login as a directory user. + + +== Using wpDirAuth == + +Once installed and activated, you will be able to administer your directory +settings through the dedicated plugin configuration tool found under the +`Directory Auth.` menu found in the WordPress `Options` admin section. + +Directory Authenticated users can now be pre-added to your wordpress system +and granted roles by going to the `Add Dir Auth User` menu found in the +Wordpress `Users` admin section. Contextual help for this section is +available for this section within Wordpress' built-in help menu. + +See the inline help found in the tool for more information on the settings. + +There is a secondary activation toggle, so you can install and activate the +plugin, check out the options panel, but not immediately accept directory +authentication, or even simply turn the feature on or off at any time. + + +== Help and Support == + +Please post questions, request for help to the Wordpress plugins forum or +email . Please be sure to include 'wpdirauth' in the +subject line. + +== TO-DO's == + + +== Source and Development == + +wpDirAuth welcomes friendly contributors wanting to lend a hand, be it in +the form of code through SVN patches, user support, platform portability +testing, security consulting, localization help, etc. + +The [current] goal is to keep the plugin self-contained (ie: no 3rd-party lib) +for easier security maintenance, while keeping the code clean and extensible. + +Focus is on security, features, security, and let's not forget, security. +Unit tests will hopefully be developed and constant security audit performed. + +Recurring quality patch contributions will lead to commit privileges to the +project source repository. + +Please post questions/requests for help to the wordpress forums and/or +email + +The project source code is available on the WordPress Plugin Repository: + +* Stable: +* Unstable: +* Historical: + +The Sybversion repository can be browsed and tracked (RSS, etc) through the +WP Plugin Repo source browser at: + +* + +The generated code documentation can be found at: + +* + +The WP Plugin Repo also offers a convenient ticketing system for bug and +task tracking. + +* Existing tickets: +* Open a new ticket: + + +== License == + +[General Public License](http://www.gnu.org/licenses/gpl.html) + +Copyrights are listed in chronological order, by contributions. + +wpDirAuth: WordPress Directory Authentication +Copyright (c) 2007 [Stephane Daury](http://stephane.daury.org/) + +wpDirAuth and wpLDAP Patch Contributions +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/) + +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 Free Software Foundation. + +wpDirAuth is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + + +== Project History == + +Originally started from a patched version of wpLDAP (1.02+patch), wpDirAuth has +since then been heavily overhauled and features have been modified and added. +In other words, a classic case of `pimp my lib'` (hopefully for the better). + +* Current: wpDirAuth: +* Original: wpLDAP: +* wpLDAP Patch: + +== Changelog == + += 1.5.1 = +* Remove default password nag for wpdirauth accounts + += 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.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 diff --git a/wpDirAuth.php b/wpDirAuth.php new file mode 100644 index 0000000..48481aa --- /dev/null +++ b/wpDirAuth.php @@ -0,0 +1,1735 @@ + + * + * Copyrights are listed in chronological order, by contributions. + * + * wpDirAuth: WordPress Directory Authentication + * Copyright (c) 2007 Stephane Daury - http://stephane.daury.org/ + * + * wpDirAuth and wpLDAP Patch Contributions + * Copyright (c) 2007 PKR Internet, LLC - http://www.pkrinternet.com/ + * + * 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 is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation. + * + * wpDirAuth is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + * + * @todo Always stay on top of security and user input validation while + * staying backwards compatible enough until PHP4 support is dropped in + * WP (serious patches welcomed, please see code). Note that we do + * heavily rely on WP's admin ACL scheme, by necessity. + */ + +/* +PLUGIN META INFO FOR WORDPRESS LISTINGS +Plugin Name: wpDirAuth +Plugin URI: http://tekartist.org/labs/wordpress/plugins/wpdirauth/ +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/ +*/ + +/** + * wpDirAuth version. + */ +define('WPDIRAUTH_VERSION', '1.6.1'); + +/** + * wpDirAuth signature. + */ +define('WPDIRAUTH_SIGNATURE', 'wpDirAuth '.WPDIRAUTH_VERSION); + +/** + * Default LDAP field to search against when locating the user's profile. + */ +define('WPDIRAUTH_DEFAULT_FILTER', 'samAccountName'); + +/** + * Default login screen message. + */ +define('WPDIRAUTH_DEFAULT_LOGINSCREENMSG', '%s members can login directly using their institutional password.'); + +/** + * Default password change message. + */ +define('WPDIRAUTH_DEFAULT_CHANGEPASSMSG', 'To change a %s password, please refer to the official institutional password policy.'); + +/** + * Allowed HTML (messages) + */ +define('WPDIRAUTH_ALLOWED_TAGS', '

    1. '); + +define('WPDIRAUTH_ERROR_TITLE',__('Directory Authentication Error: ')); + +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'); + + +if (function_exists('wp_authenticate') || function_exists('wp_setcookie') || !function_exists('ldap_connect')) { +/** + * SAFE MODE + */ + + /** + * SAFE MODE: wpDirAuth plugin configuration panel. + * Processes and outputs the wpDirAuth configuration form, with a conflict message. + * + * @return void + */ + function wpDirAuth_safeConflictMessage() + { + $wpDARef = WPDIRAUTH_SIGNATURE; + + if (!function_exists('ldap_connect')) { + $message = <<<________EOS +

      Sorry, but your PHP install does not seem to have access to the LDAP features.

      +

      +
      wpDirAuth is now running in safe mode.' +

      +

      + Quote from the PHP manual LDAP section: +

      + LDAP support in PHP is not enabled by default. You will need to use the + --with-ldap[=DIR] configuration option when compiling PHP to enable LDAP + support. DIR is the LDAP base install directory. To enable SASL support, + be sure --with-ldap-sasl[=DIR] is used, and that sasl.h exists on the system. +
      +

      +________EOS; + } + else { + $message = <<<________EOS +

      Sorry, but another plugin seems to be conflicting with wpDirAuth.

      +

      +
      wpDirAuth is now running in safe mode as to not impair the other plugin's operations.' +

      +

      + The wp_authenticate and wp_setcookie WordPress + pluggable functions + have already been redefined, and wpDirAuth cannot provide directory authentication + without having access to these functions. +

      +

      + Please disable any WP plugins that deal with authentication in order to use wpDirAuth. + Unfortunately, we cannot provide you with more info as to which plugin is in conflict. +

      +________EOS; + } + + echo <<<________EOS +
      +

      Directory Authentication Options: Plugin Conflict

      + $message +

      $wpDARef

      +
      +________EOS; + } + + + /** + * SAFE MODE: Adds the `Directory Auth.` menu entry in the Wordpress Admin section. + * Also activates the wpDirAuth config panel, with a conflict message, as a callback function. + * + * @uses wpDirAuth_safeConflictMessage + */ + function wpDirAuth_safeAddMenu() + { + if (function_exists('add_options_page')) { + add_options_page( + 'Directory Authentication Options: Plugin Conflict', + '!! Directory Auth. !!', + 9, + basename(__FILE__), + 'wpDirAuth_safeConflictMessage' + ); + } + } + + + /** + * SAFE MODE: Add custom WordPress actions. + * + * @uses wpDirAuth_safeAddMenu + */ + if (function_exists('add_action')) { + add_action('admin_menu', 'wpDirAuth_safeAddMenu'); + } +} +else { +/** + * STANDARD MODE + */ + + /** + * Cookie marker. + * Generates a random string to be used as salt for the password + * hash cookie checks in wp_setcookie and wp_authenticate + * + * @return string 55 chars-long salty goodness (md5 + uniqid) + */ + function wpDirAuth_makeCookieMarker() + { + $cookieMarker = md5( + $_SERVER['SERVER_SIGNATURE'] + .$_SERVER['HTTP_USER_AGENT'] + .$_SERVER['REMOTE_ADDR'] + ).uniqid(microtime(),true); + update_option("dirAuthCookieMarker",$cookieMarker); + return $cookieMarker; + } + + + /** + * LDAP bind test + * Tries two different documented method of php-based ldap binding. + * Note: passing params by reference, no need for copies (unlike in + * wpDirAuth_auth where it is desirable). + * + * @param object &$connection LDAP connection + * @param string &$username LDAP username + * @param string &$password LDAP password + * @param string $baseDn + * @return boolean Binding status + * */ + function wpDirAuth_bindTest(&$connection, &$username, &$password,$baseDn) + { + $password = strtr($password, array("\'"=>"'")); + if ( ($isBound = @ldap_bind($connection, $username, $password)) === false ) { + // @see wpLDAP comment at http://ashay.org/?page_id=133#comment-558 + $isBound = @ldap_bind($connection,"uid=$username,$baseDn", $password); + } + return $isBound; + } + + /** + * put your comment there... + * + * @param string $dc name of domain controller to connect to + * @param integer $enableSsl ssl config option + * @return resource + */ + function wpDirAuth_establishConnection($dc,$enableSsl){ + /** + * Only setup protocol value if ldaps is required to help with older AD + * @see http://groups.google.com/group/wpdirauth-support/browse_thread/thread/7b744c7ad66a4829 + */ + $protocol = ($enableSsl) ? 'ldaps://' : ''; + + /** + * Scan for and use alternate server port, but only if ssl is disabled. + * @see Parameters constraint at http://ca.php.net/ldap_connect + */ + + if (strstr($dc, ':')) list($dc, $port) = explode(':', $dc); + + switch($enableSsl){ + case 1: + $connection = ldap_connect($protocol.$dc); + break; + case 2: + case 0: + default: + if(isset($port)){ + $connection = ldap_connect($dc,$port); + } else { + $connection = ldap_connect($dc); + } + break; + + } + + /** + * Copes with W2K3/AD issue. + * @see http://bugs.php.net/bug.php?id=30670 + */ + if (@ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3)) { + @ldap_set_option($connection, LDAP_OPT_REFERRALS, 0); + } + + //they want to start TLS + if($enableSsl == 2){ + if(!ldap_start_tls($connection)){ + return new WP_Error('tls_failed_to_start',__('wpDirAuth error: tls failed to start')); + } + } + + return $connection; + } + + /** + * put your comment there... + * + * @param array $controllers list of domain controllers to connect to + * @return mixed array of shuffled controllers or WP_Error + */ + function wpDirAuth_shuffleControllers($controllers){ + if (count($controllers) > 1) { + // shuffle the domain controllers for pseudo load balancing and fault tolerance. + shuffle($controllers); + } elseif (count($controllers) == 0) { + return new WP_Error('no_controllers',__(' wpDirAuth config error: no domain controllers specified.')); + } + + return $controllers; + } + + /** + * Custom LDAP authentication module. + * The returned keys are in the same format used by WP for + * the wp_insert_user and wp_update_user functions. + * + * @param string $username LDAP username + * @param string $password LDAP password + * @return WP_Error object OR array Directory email, last_name and first_name + * + * @uses WPDIRAUTH_DEFAULT_FILTER + * @uses WPDIRAUTH_ERROR_TITLE + * @uses wpDirAuth_bindTest + * @uses wpDirAuth_retrieveUserDetails + * @uses wpDirAuth_shuffleControllers + * @uses wpDirAuth_establishConnection + */ + function wpDirAuth_auth($username, $password) + { + global $error, $pwd; + + $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'); + + if($boolUseGroups == 1){ + $strAuthGroups = get_option('dirAuthGroups'); + } + + $returnKeys = unserialize(WPDIRAUTH_LDAP_RETURN_KEYS); + + $isBound = $isPreBound = $isLoggedIn = false; + + if ($accountSuffix) $username .= $accountSuffix; + + if (!$filter) $filter = WPDIRAUTH_DEFAULT_FILTER; + + $filterQuery = "($filter=$username)"; + + $controllers = wpDirAuth_shuffleControllers($controllers); + + if(is_wp_error($controllers)){ + return $controllers; + } + + // Connection pool loop - Haha, PooL LooP + foreach ($controllers as $dc) { + + $connection = wpDirAuth_establishConnection($dc,$enableSsl); + + if(is_wp_error($connection)){ + return $connection; + } + + if ($preBindUser && $preBindPassword) { + /** + * Use case 1: Servers requiring pre-binding with admin defined + * credentials to search for the user's full DN before attempting + * to login. + * @see http://dev.wp-plugins.org/ticket/681 + */ + if ( $isPreBound = wpDirAuth_bindTest($connection, $preBindUser, $preBindPassword,$baseDn) === true ) { + if ( ($results = @ldap_search($connection, $baseDn, $filterQuery, $returnKeys)) !== false ) { + if ( ($userDn = @ldap_get_dn($connection, ldap_first_entry($connection, $results))) !== false ) { + if ( ($isBound = wpDirAuth_bindTest($connection, $userDn, $password,$baseDn)) === true ) { + $isLoggedIn = true; // valid server, valid login, move on + break; // valid server, valid login, move on + } + } + } + } + } + elseif ( ($isBound = wpDirAuth_bindTest($connection, $username, $password,$baseDn)) === true ) { + /** + * Use case 2: Servers that will not let you bind anonymously + * but will let the end user bind directly. + * @see http://groups.google.com/group/wpdirauth-support/browse_thread/thread/8fd16c05266fc832 + */ + $isLoggedIn = true; + break; // valid server, valid login, move on + } + elseif ( ($isBound = @ldap_bind($connection)) === true ) { + /** + * Use case 3: Servers that might require a full user DN to + * actually login and therefore let you bind anonymously first . + * Try ldap_search + ldap_get_dn before attempting a login. + * @see http://wordpress.org/support/topic/129814?replies=34#post-603644 + */ + if ( ($results = @ldap_search($connection, $baseDn, $filterQuery, $returnKeys)) !== false ) { + if ( ($userDn = @ldap_get_dn($connection, ldap_first_entry($connection, $results))) !== false ) { + $isInDirectory = true; // account exists in directory + if ( ($isBound = wpDirAuth_bindTest($connection, $userDn, $password,$baseDn)) === true ) { + $isLoggedIn = true; // valid server, valid login, move on + break; // valid server, valid login, move on + } + } + } + } + } + + if ( ($preBindUser && $preBindPassword) && ( ! $isPreBound ) ) { + return new WP_Error ('no_directory_or_prebinding', $errorTitle + . __(' wpDirAuth config error: No directory server available for authentication, OR pre-binding credentials denied.')); + } + elseif ( ( $isInDirectory ) && ( ! $isBound ) ) { + return new WP_Error ('could_not_bind_as_user', $errorTitle + . __(' Incorrect password.')); + } + elseif ( ! $isBound && ! $isPreBound ) { + return new WP_Error ('no_directory_available', $errorTitle + . __(' wpDirAuth config error: No directory server available for authentication.')); + } + elseif ( ! $isLoggedIn) { + /** + * @desc wp-hack was echo'ing out $username verbatim which allowed a XSS vulnerability. Encoded $username before echoing' + */ + return new WP_Error ('could_not_authenticate', $errorTitle + . __(' Could not authenticate user. Please check your credentials.') + . " [" . htmlentities($username,ENT_QUOTES,'UTF-8') . "]"); + + + } + 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); + wpDirAuthPrintDebug($arySearchResults,'search results for ' . $strAuthGroup); + 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')); + } + + + $strFilterQuery = '(&'.$filterQuery.'(|'; + foreach($aryAuthGroupsDN as $strAuthGroupDN){ + $strFilterQuery .= '(memberOf='.$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)')); + } + } + + } + + + /** + * Search for profile, if still needed. + * @see $results in preceding loop: Use case 3 + */ + if (!$results){ + return wpDirAuth_retrieveUserDetails($connection,$baseDn,$filterQuery); + } else { + return wpDirAuth_retrieveUserDetails($connection,$baseDn,$filterQuery,$results); + } + } + } + + + /** + * Runs stripslashes, html_entity_decode, then strip_tags with + * allowed html if requested. + * + * No input sashimi for us (hopefully). + * + * @param string $value Value to `sanitize` + * @param boolean $allowed Set to true for WPDIRAUTH_ALLOWED_TAGS + * @return string Cleaner value. + * + * @uses WPDIRAUTH_ALLOWED_TAGS + */ + function wpDirAuth_sanitize($value, $allowed = false) + { + $allowed = ($allowed) ? WPDIRAUTH_ALLOWED_TAGS : ''; + return strip_tags(html_entity_decode(stripslashes($value)), $allowed); + } + + + /** + * wpDirAuth plugin configuration panel. + * Processes and outputs the wpDirAuth configuration form. + * + * @return void + * + * @uses WPDIRAUTH_DEFAULT_FILTER + * @uses WPDIRAUTH_DEFAULT_LOGINSCREENMSG + * @uses WPDIRAUTH_DEFAULT_CHANGEPASSMSG + * @uses WPDIRAUTH_ALLOWED_TAGS + * @uses wpDirAuth_makeCookieMarker + * @uses wpDirAuth_sanitize + */ + function wpDirAuth_optionsPanel() + { + global $userdata; + + $wpDARef = WPDIRAUTH_SIGNATURE; + $allowedHTML = htmlentities(WPDIRAUTH_ALLOWED_TAGS); + + $curUserIsDirUser = get_usermeta($userdata->ID, 'wpDirAuthFlag'); + + if ($curUserIsDirUser) { + echo <<<____________EOS +
      +

      Directory Authentication Options

      +

      + Because any changes made to directory authentication + options can adversly affect your session when logged in + as a directory user, you must be logged in as a + WordPress-only administrator user to update these settings. +

      +

      + If such a user no longer exists in the database, please + create a new one + using the appropriate WordPress admin tool. +

      +

      $wpDARef

      +
      +____________EOS; + return; + } + + if ($_POST) { + $enableSsl = 0; //default + $boolUseGroups = 0; //default + // Booleans + $enable = intval($_POST['dirAuthEnable']) == 1 ? 1 : 0; + $requireSsl = intval($_POST['dirAuthRequireSsl']) == 1 ? 1 : 0; + $TOS = intval($_POST['dirAuthTOS']) == 1 ? 1 : 0; + + //integers + if(intval($_POST['dirAuthEnableSsl']) == 1 || intval($_POST['dirAuthEnableSsl']) == 2){ + $enableSsl = intval($_POST['dirAuthEnableSsl']); + } + + + // Strings, no HTML + $controllers = wpDirAuth_sanitize($_POST['dirAuthControllers']); + $baseDn = wpDirAuth_sanitize($_POST['dirAuthBaseDn']); + $preBindUser = wpDirAuth_sanitize($_POST['dirAuthPreBindUser']); + $preBindPassword = wpDirAuth_sanitize($_POST['dirAuthPreBindPassword']); + $preBindPassCheck = wpDirAuth_sanitize($_POST['dirAuthPreBindPassCheck']); + $accountSuffix = wpDirAuth_sanitize($_POST['dirAuthAccountSuffix']); + $filter = wpDirAuth_sanitize($_POST['dirAuthFilter']); + $institution = wpDirAuth_sanitize($_POST['dirAuthInstitution']); + $strAuthGroups = wpDirAuth_sanitize($_POST['dirAuthGroups']); + $strMarketingSSOID= wpDirAuth_sanitize(($_POST['dirAuthMarketingSSOID'])); + + if($strAuthGroups != ''){ + $boolUseGroups = 1; + } + + // Have to be allowed to contain some HTML + $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); + + + // 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); + + // Clear the stored password if the Bind DN is null + elseif ( ! $preBindUser) + update_option('dirAuthPreBindPassword', ''); + + if (get_option('dirAuthEnable') && !get_option('dirAuthCookieMarker')) + wpDirAuth_makeCookieMarker(); + + echo '

      Your new settings were saved successfully.

      '; + + // Be sure to clear $preBindPassword, not to be displayed onscreen or in source + unset($preBindPassword); + } + 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; + + //integers + $enableSsl = intval(get_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'))); + + // Have to be allowed to contain some HTML + $loginScreenMsg = wpDirAuth_sanitize(get_option('dirAuthLoginScreenMsg'), true); + $changePassMsg = wpDirAuth_sanitize(get_option('dirAuthChangePassMsg'), true); + } + + $controllers = htmlspecialchars($controllers); + $baseDn = htmlspecialchars($baseDn); + $preBindUser = htmlspecialchars($preBindUser); + $accountSuffix = htmlspecialchars($accountSuffix); + $filter = htmlspecialchars($filter); + $institution = htmlspecialchars($institution); + $loginScreenMsg = htmlspecialchars($loginScreenMsg); + $changePassMsg = htmlspecialchars($changePassMsg); + $strAuthGroups = htmlspecialchars($strAuthGroups); + + if ($enable) { + $tEnable = "checked"; + } + else { + $fEnable = "checked"; + } + + $defaultFilter = WPDIRAUTH_DEFAULT_FILTER; + if (!$filter) { + $filter = $defaultFilter; + } + + if (!$institution) { + $institution = '[YOUR INSTITUTION]'; + } + + if (!$loginScreenMsg) { + $loginScreenMsg = sprintf(WPDIRAUTH_DEFAULT_LOGINSCREENMSG, $institution); + } + + if (!$changePassMsg) { + $changePassMsg = sprintf(WPDIRAUTH_DEFAULT_CHANGEPASSMSG, $institution); + } + + /* + if ($enableSsl) { + $tSsl = "checked"; + } + else { + $fSsl = "checked"; + } + */ + $strNoSSL =''; + $strSSL = ''; + $strTLS = ''; + $strOptionSelected = 'selected="selected"'; + switch($enableSsl){ + case 1: + $strSSL = $strOptionSelected; + break; + case 2: + $strTLS = $strOptionSelected; + break; + case 0: + default: + $strNoSSL = $strOptionSelected; + break; + + } + + if ($requireSsl) { + $tWpSsl = "checked"; + } + else { + $fWpSsl = "checked"; + } + + if ($TOS) { + $tTOS = "checked"; + } + else { + $fTOS = "checked"; + } + + $wpDAV = WPDIRAUTH_VERSION; + + echo <<<________EOS +
      +

      Directory Authentication Options

      +
      +

      +
      + WordPress Settings +
        +
      • + +
        + Yes   + No +
        + Note 1: Users created in WordPress are not affected by your directory authentication settings. +
        + Note 2: You will still be able to login with standard WP users if the LDAP server(s) go offline. +
      • +
      • + +
        + Yes   + No +
        + Force the WordPress login screen to require encryption (SSL, https:// URL)? +
      • +
      +
      +
      + Directory Settings +
        +
      • + +
        + + +
        + Use encryption (TLS, SSL, ldaps:// URL) when WordPress connects to the directory server(s)? +
      • +
      • + +
        +
        + The DNS name or IP address of the directory server(s).
        + NOTE: Separate multiple entries by a comma and/or alternate ports with a colon (eg: my.server1.org, my.server2.edu:387). + Unfortunately, alternate ports will be ignored when using LDAP/SSL, because of the way PHP handles the protocol. + +
      • +
      • + +
        + + (Defaults to $defaultFilter) +
        + What LDAP field should we search the username against to locate the user's profile after successful login? +
      • +
      • + +
        +
        + Suffix to be automatically appended to the username if desired. e.g. @domain.com
        + NOTE: Changing this value will cause your existing directory users to have new accounts created the next time they login. +
      • +
      • + +
        +
        + The base DN for carrying out LDAP searches. +
      • +
      • + +
        +
        + Enter a valid user account/DN to pre-bind with if your LDAP server does not allow anonymous profile searches, or requires a user with specific privileges to search. +
      • +
      • + +
        +
        + Enter a password for the above Bind DN if a value is needed.
        + Note 1: this value will be stored in clear text in your WordPress database.
        + Note 2: Simply clear the Bind DN value if you wish to delete the stored password altogether. +
      • +
      • + +
        +
        + Confirm the above Bind Password if you are setting a new value. +
      • +
      • +
        +
        + Enter each group CN that the user must be a member of in order to authenticate.
        + NOTE: Separate multiple CNs by a comma. +
      • +
      +
      +
      + Branding Settings +
        +
      • + +
        + +
        + Name of your institution/company. Displayed on the login screen. +
      • + +
      • + +
        + +
        + How your institution/company refers to the single-sign-on ID you use. +
      • +
      • + +
        + +
        + Displayed on the login screen, underneath the username/password fields.
        + Note: Some HTML allowed: $allowedHTML +
      • +
      • + +
        + +
        + Displayed wherever user passwords can be changed, for directory users only.
        + Note: Some HTML allowed: $allowedHTML + +
      • +
      • + +
        + Yes   + No +
        + Ask directory users to agree to terms of services that you link to in the message above?
        + Note: Checkbox disappears once checked, date of agreement is stored and users are no longer prompted. +
      • +
      +
      +

      +
      +

      Powered by $wpDARef.

      +
      +________EOS; + } + + + /** + * Adds the `Directory Auth.` menu entry in the Wordpress Admin section, and the `Add Directory Authenticated User` to the Users menu + * Also activates the wpDirAuth config panel as a callback function. + * + * @uses wpDirAuth_optionsPanel + * @uses wpDirAuth_add_user_panel + */ + function wpDirAuth_addMenu() + { + if (function_exists('add_options_page')) { + add_options_page( + 'Directory Authentication Options', + 'Directory Auth.', + 9, + basename(__FILE__), + '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' + ); + } + } + + + /** + * Extending WP's login_form. + * Enforces the admin defined SSL login preferences and adds a directory + * login related message to the standard WP login screen. + * + * @uses WPDIRAUTH_DEFAULT_LOGINSCREENMSG + */ + function wpDirAuth_loginFormExtra() + { + if (get_option('dirAuthEnable')) { + + if (isset($_SERVER['SCRIPT_URI']) && preg_match('|^http|',$_SERVER['SCRIPT_URI'])) { + $selfURL = $_SERVER['SCRIPT_URI']; + } + else { + /** + * $_SERVER['SCRIPT_URI'] seems to be unavilable in some PHP + * installs, and $_SERVER['REQUEST_URI'] and $_SERVER['PHP_SELF'] + * have been known to sometimes have the same issue. + * Thanks to Todd Beverly for helping out with this one. :) + * @see http://wordpress.org/support/topic/129814?replies=27#post-605423 + */ + $selfURL = sprintf( + 'http%s://%s%s', + (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : ''), + $_SERVER['HTTP_HOST'], + (isset($_SERVER['REQUEST_URI']) + ? $_SERVER['REQUEST_URI'] + : $_SERVER["SCRIPT_NAME"].'?'.$_SERVER['QUERY_STRING']) + ); + } + + if (get_option('dirAuthRequireSsl') && (!preg_match('|^https|',$selfURL))) { + $sslURL = str_replace('http://','https://',$selfURL); + + $refreshJS = '" />'; + $refreshMeta = ''; + $refreshMsg = 'Please access the encrypted version of this page.'; + + if (headers_sent()) { + echo $refreshJS.$refreshMeta.'

      '.$refreshMsg.'

      '; + } + else { + @ob_end_clean(); + if (!@header('Location:'.$sslURL)) { + echo ''.$refreshJS.$refreshMeta.'' + . ''.$refreshMsg.''; + } + } + + exit; + } + + $dirAuthInstitution = stripslashes(get_option('dirAuthInstitution')); + if (!$dirAuthInstitution) $dirAuthInstitution = __('Directory'); + + $loginScreenMsg = stripslashes(get_option('dirAuthLoginScreenMsg')); + if (!$loginScreenMsg) $loginScreenMsg = __(sprintf( + WPDIRAUTH_DEFAULT_LOGINSCREENMSG, + get_option('dirAuthInstitution') + )); + + echo ' + +

      '.$loginScreenMsg.'

      + '; + } + } + + + /** + * Extending WP's show_password_fields. + * Displays the directory password change message in profile.php and user.php. + * + * @return boolean Return format as expected by WP's show_password_fields() + * + * @uses WPDIRAUTH_DEFAULT_CHANGEPASSMSG + */ + function wpDirAuth_hidePassFields() + { + global $profileuser, $userdata; + + $editUserIsDirUser = get_usermeta($profileuser->ID, 'wpDirAuthFlag'); + + if (!$editUserIsDirUser) { + return true; + } + else { + // Editing directory user profile, show password msg + $message = stripslashes(get_option('dirAuthChangePassMsg')); + if (!$message) { + $message = __(sprintf( + WPDIRAUTH_DEFAULT_CHANGEPASSMSG, + stripslashes(get_option('dirAuthInstitution')) + )); + } + + if (get_option('dirAuthTOS')) { + // TOS option is ON + if (($TOSDate = get_usermeta($profileuser->ID, 'wpDirAuthTOS')) === '') { + if ($userdata->ID == $profileuser->ID) { + // Only show TOS acceptance checkbox to the owner of the profile. + $message .= '

      ' + . ' ' + . __('Accept terms of services.') + . '

      '; + } + else { + // Show generic message to other admins. + $message .= '

      ' + . __('User has not yet agreed to the terms of services.') + . '

      '; + } + } + else { + // Show TOS acceptance date + $message .= '

      ' + . __('Terms of services accepted on') + . ' '.$TOSDate + . '

      '; + } + } + + echo '

      ' + . __('Directory Password Update') + . '

      ' + . $message + . '

      '; + + return false; + } + } + + + /** + * Extending WP's profile_update. + * Saves the TOS acceptance if sent. + * + * @param integer $userID Sent by WP profile_update action + * @return boolean Return format as expected by WP's profile_update() + */ + function wpDirAuth_profileUpdate($userID){ + if (intval($_POST['wpDirAuthTOS']) === 1) { + update_usermeta($userID, 'wpDirAuthTOS', date('Y-m-d H:i:s')); + } + return true; + } + + + /** + * WP's wp_authenticate overwrite. + * Processes the directory login and creates a new user on first access. + * + * @param string $username Login form username. + * @param string $password Login form password + * @return WP_Error|WP_User WP_User object if login successful, otherwise WP_Error object. + * + * @uses wpDirAuth_makeCookieMarker + * @uses wpDirAuth_auth + * + * @see http://codex.wordpress.org/Pluggable_Functions + */ + function wp_authenticate($username, $password) + { + /** + * @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'){ + return new WP_Error('incorrect_method',__('Please Login')); + } + + if (!$username) { + return new WP_Error('empty_username', __('Login Error: + The username field is empty.')); + } + + if (!$password) { + return new WP_Error('empty_password', __('Login Error: + The password field is empty.')); + } + + $enable = get_option('dirAuthEnable'); + $cookieMarker = get_option('dirAuthCookieMarker'); + + if (!$cookieMarker) { + $cookieMarker = wpDirAuth_makeCookieMarker(); + } + + /** + * Get the login object. We will use it for first user insertion or when the + * directory auth option is not activated. + */ + $login = get_userdatabylogin($username); + $loginUserIsDirUser = ($login) ? get_usermeta($login->ID, 'wpDirAuthFlag') : 0; + + if (!$enable && $loginUserIsDirUser) { + /* + * Existing directory user, but directory access has now been disabled. + */ + do_action( 'wp_login_failed', $username ); + return new WP_Error('login_disabled',__('Directory Login Error: + Sorry, but the site administrators have disabled + directory access in this WordPress install.')); + } + elseif ($enable) { + /** + * Directory auth == true + */ + + if (!$login) { + /** + * No existing account record found, try dir auth + */ + $userData = wpDirAuth_auth($username,$password); + + if ( !is_wp_error($userData) ) { + /** + * Passed directory signin, so create a new WP user + */ + require_once(ABSPATH . WPINC . '/registration.php'); + + $userLogin = sanitize_user($username); + $userEmail = apply_filters('user_registration_email', $userData['email']); + + if (username_exists($userLogin)) { + /* + * Username exists. + */ + 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 + registered on this site.')); + } + elseif (email_exists($userEmail)) { + /* + * Email exists. + */ + 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 + 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 . ']')); + } + } + else { + /* + * Did not pass dir auth, and no login present in WP + */ + do_action( 'wp_login_failed', $username ); + return $userData; + } + } + else { + /* + * Dealing with an existing WP account + */ + if (!$loginUserIsDirUser) { + /* + * WP-only user + */ + if ( wp_check_password($password, $login->user_pass, $login->ID) ) { + /* + * WP user, password okay. + */ + return new WP_User($login->ID); + } + else { + /* + * WP user, wrong pass + */ + do_action( 'wp_login_failed', $username ); + return new WP_Error('incorrect_password',__('WordPress Login Error: + Incorrect password.')); + } + } + else { + /** + * Directory user, try ldap binding + */ + $userData = wpDirAuth_auth($username,$password); + + if ( !is_wp_error($userData) ) { + /* + * Directory user, password okay. + */ + wpDirAuth_remove_password_nag($login->ID); + return new WP_User($login->ID); + } + else { + /* + * Directory user, wrong pass + */ + do_action( 'wp_login_failed', $username ); + return $userData; + } + } + } + } + else { + /** + * Directory auth == false + */ + if (!$login || ($login->user_login != $username) ) { + /** + * No existing account record found + */ + do_action( 'wp_login_failed', $username ); + return new WP_Error('failed_login',__('WordPress Login Error: + Could not authenticate user. + Please check your credentials.')); + } + else { + /* + * Found an existing WP account. + */ + if ( wp_check_password($password, $login->user_pass, $login->ID) ) { + /* + * WP user, password okay. + */ + return new WP_User($login->ID); + } + else { + /* + * WP user, wrong pass + */ + do_action( 'wp_login_failed', $username ); + return new WP_Error('incorrect_password',__('WordPress Login Error: + Incorrect password.')); + } + } + } + } + + + /** + * WordPress wp_setcookie overwrite. + * Sets the WP session cookies. + * + * @param string $username Login form username. + * @param string $password Login form password + * @param boolean $already_md5 Has the pswd been double-hashed already? + * @param string $home + * @param string $siteurl + * @param boolean $remember + * @return void + * + * @uses wpDirAuth_makeCookieMarker + * + * @see http://codex.wordpress.org/Pluggable_Functions + */ + function wp_setcookie($username, $password, $already_md5 = false, $home = '', $siteurl = '', $remember = false) + { + global $wpdb; + + /** + * Try to locate the user's record and define if it is an existing directory user + */ + $login = get_userdatabylogin($username); + //$login = $wpdb->get_row('SELECT ID FROM $wpdb->users WHERE user_login = '$username''); + $loginUserIsDirUser = ($login) ? get_usermeta($login->ID, 'wpDirAuthFlag') : 0; + + /** + * Get wpsDirAuth options + */ + $enable = get_option('dirAuthEnable'); + $cookieMarker = get_option('dirAuthCookieMarker'); + + if (!$cookieMarker) { + $cookieMarker = wpDirAuth_makeCookieMarker(); + } + + /** + * Set the password hash cookie + */ + if (($enable) && ($loginUserIsDirUser)) { + $password = md5($username).md5($cookieMarker); + } + else { + if (!$already_md5) { + $password = md5( md5($password) ); // Double hash the password in the cookie. + } + } + + /** + * Updated WP remember me option for directory users to only be + * remembered for 1 hour so that institutional passwords are not + * overly endangered when accessing the blog from a public terminal. + */ + if ( $remember ){ + $duration = ($loginUserIsDirUser) ? strtotime('1 hour') : strtotime('6 months'); + $expire = time() + $duration; + } + else { + $expire = 0; + } + + /** + * The rest of the logic is from the original WP wp_setcookie + * function, from /wp-inlcudes/pluggable.php version 2.2.2 + */ + if ( empty($home) ) + $cookiepath = COOKIEPATH; + else + $cookiepath = preg_replace('|https?://[^/]+|i', '', $home . '/' ); + + if ( empty($siteurl) ) { + $sitecookiepath = SITECOOKIEPATH; + $cookiehash = COOKIEHASH; + } else { + $sitecookiepath = preg_replace('|https?://[^/]+|i', '', $siteurl . '/' ); + $cookiehash = md5($siteurl); + } + + setcookie(USER_COOKIE, $username, $expire, $cookiepath, COOKIE_DOMAIN); + setcookie(PASS_COOKIE, $password, $expire, $cookiepath, COOKIE_DOMAIN); + + if ( $cookiepath != $sitecookiepath ) { + setcookie(USER_COOKIE, $username, $expire, $sitecookiepath, COOKIE_DOMAIN); + setcookie(PASS_COOKIE, $password, $expire, $sitecookiepath, COOKIE_DOMAIN); + } + + } + + /** + * Prints data on a variable into a comments block in the source code of a page. Used for debugging purposes only. + * + * @param mixed $mxdVar + * @param string $strMsg + */ + function wpDirAuthPrintDebug($mxdVar,$strMsg){ + echo PHP_EOL,'',PHP_EOL; + } + + /** + * Removes the "you're using a default password"" nag for dirauth accounts + * + * @param integer $userID + * @return void + */ + function wpDirAuth_remove_password_nag($userID){ + if(get_user_option('default_password_nag',$userID)){ + update_user_option($userID, 'default_password_nag', false, true); + } + } + + /** + * Retrieves values given in WPDIRAUTH_LDAP_RETURN_KEYS from a valid, bound LDAP connection + * + * @param resource $rscConnection verified LDAP connection resource + * @param string $strBaseDn + * @param string $strFilterQuery + * @param mixed $rscReult if LDAP search was already performed. default null + * @return mixed WP_Error object if there was an error encountered, otherwise an array of user details + * + * @TODO right now it's actually coded such that what is returned is always the same, even if you change the keys in WPDIRAUTH_LDAP_RETURN_KEYS. Rewrite it so + * it will dynamically retrieve the values. idea is that WPDIRAUTH_LDAP_RETURN_KEYS would become an associative array of key names to return => LDAP keys to retrieve. + * WPDIRAUTH_LDAP_RETURN_KEYS = serialize(array( + * 'first_name' =>'givenname', + * 'last_name' =>'sn', + * 'email' =>'mail' + * )); + * of course, we'll need to somehow require at least the email key since we need that one in order to add the user. + */ + function wpDirAuth_retrieveUserDetails($rscConnection,$strBaseDn,$strFilterQuery,$rscResult=NULL){ + //now that we have a valid connection and are bound, we need to find the user. + + if(is_null($rscResult)){ + $rscResult = ldap_search($rscConnection,$strBaseDn,$strFilterQuery,unserialize(WPDIRAUTH_LDAP_RETURN_KEYS)); + } + + if(!$rscResult){ + return new WP_Error ('noprofile_search', __('Directory authentication initially succeeded, but no valid profile was found (search procedure).') + ." [$strFilter]"); + } else { + $aryUserDetails = @ldap_get_entries($rscConnection, $rscResult); + + $intCount = intval($aryUserDetails['count']); + if ($intCount < 1) { + return new WP_Error ('noprofile_getentries', __('Directory authentication initially succeeded, but no valid profile was found ("get entries" procedure).') + ." [$strFilterQuery]"); + } elseif ($intCount > 1) { + return new WP_Error ('not_unique', __('Directory authentication initially succeeded, but the username you sent is not a unique profile identifier.') + . " [$strFilterQuery]"); + } else { + $strEmail = isset($aryUserDetails[0]['mail'][0]) ? $aryUserDetails[0]['mail'][0] : ''; + + $strLastName = isset($aryUserDetails[0]['sn'][0]) ? $aryUserDetails[0]['sn'][0] : ''; + + $strFirstName = isset($aryUserDetails[0]['givenname'][0]) ? $aryUserDetails[0]['givenname'][0] : ''; + + return array( + 'email' => $strEmail, + 'last_name' => $strLastName, + 'first_name' => $strFirstName + ); + } + } + } + + /** + * Handles connecting to LDAP and performing a search for the given SSOID + * + * @param string $strSSOID + * @return mixed WP_Error object on failure, array of user details on success + * @TODO this function shares a LOT with wpDirAuth_auth. see if you cant combine them some more + */ + 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'); + + if ($strAccountSuffix) $strSSOID .= $strAccountSuffix; + + if (!$strFilter || empty($strFilter)) $strFilter = WPDIRAUTH_DEFAULT_FILTER; + + $strFilterQuery = "($strFilter=$strSSOID)"; + + $aryControllers = wpDirAuth_shuffleControllers(explode(',', get_option('dirAuthControllers'))); + + if(is_wp_error($aryControllers)){ + return $aryControllers; //there werent any controllers to connect to + } + + /** + * @todo if we get a successful connection, cant we break out of the loop before we go through binding and a search? Or is it possible that one DC in the + * list might not allow anonymous searching and/or the pre-bind user/pass isnt valid on one of them and we need to try the next in the list? + */ + foreach($aryControllers as $strDC){ + $rscConnection = wpDirAuth_establishConnection($strDC,$intEnableSSL); + if(is_wp_error($rscConnection)){ + return $rscConnection; //tls failed to start on the DC + } + + 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:

      ' + . ldap_error($rscConnection))); + } + + //successfully bound, now we need to get the user details + return wpDirAuth_retrieveUserDetails($rscConnection,$strBaseDn,$strFilterQuery); + } + } + + /** + * Checks to make sure the user doesnt already exist and that the email associated with a SSOID isnt already in use in the blog, and if not, adds the user. + * + * @param string $strSSOID Single Sign On ID + * @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){ + /** + * 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); + + 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.')); + } + + //we'll have to go ahead and look them up in LDAP in order to check their email address + $aryUserDetails = wpDirAuth_ConnectAndLookupUser($strSSOID); + if(is_wp_error($aryUserDetails)){ + return $aryUserDetails; + } + $strUserEmail = apply_filters('user_registration_email', $aryUserDetails['email']); + + 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.')); + } + + $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' + $aryUserDetails['user_login'] = $strSSOID; + $aryUserDetails['user_email'] = $aryUserDetails['email'] = $strUserEmail; + /** + * @TODO ask Stephen why he's replacing .'s with _'s in the user name of the email address. Does nickname not allow spaces? + */ + $tmpAr = split('@',$aryUserDetails['email']); + $aryUserDetails['nickname'] = str_replace('.','_',$tmpAr[0]); + $aryUserDetails['display_name'] = $aryUserDetails['first_name'].' '.$aryUserDetails['last_name']; + $aryUserDetails['role'] = $strRole; + + $intUserID = wp_update_user($aryUserDetails); + + if(!is_int($intUserID)){ + return new WP_Error('createuser_failed',__('For an unknow reason, WP failed to create a new user.' + .' Failure occurred at line ' . __LINE__ . ' in the function ' . __FUNCTION__ . ' in the file ' . basename(__FILE__) . '.')); + } + + $aryUserDetails['ID'] = $intUserID; + update_usermeta($intUserID, 'wpDirAuthFlag', 1); + wpDirAuth_remove_password_nag($intUserID); + + return $aryUserDetails; + } + + /** + * Loops through the WP_Error object and prints out the error messages it contains + * + * @param object $objError + * @return void + */ + function wpDirAuth_print_error_messages($objError){ + echo PHP_EOL,'
      ',WPDIRAUTH_ERROR_TITLE,'
        ',PHP_EOL; + foreach($objError->get_error_messages() as $strErrMsg){ + echo '
      • ',$strErrMsg,'
      • ',PHP_EOL; + } + echo '
      ',PHP_EOL; + } + + /** + * Constructs the message to be displayed when a new user has been added successfully + * + * @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 + * @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); + } + + /** + * Just determines if the word $strWord should be prefaced with 'a' or 'an'. + * Yea, i know it's picky, but I work with editors who complain about this type of stuff all the time =P + * + * @param string $strWord + * @return string + */ + function wpDirAuth_determine_A_or_An($strWord){ + $strAorAn = 'a'; + if(in_array(substr($strWord,0,1),array('a','e','i','o','u'))){ + $strAorAn .= 'n'; + } + + return $strAorAn; + } + + /** + * Adds contextual help to the Add Dir Auth page under the Users menu + * + */ + function wpDirAuth_add_user_contextual_help(){ + $strMarketingSSOID = get_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:') . '

      ' . + '
        ' . + '
      • ' . __('Administrators have access to all the administration features.') . '
      • ' . + '
      • ' . __('Editors can publish posts, manage posts as well as manage other people’s posts, etc.') . '
      • ' . + '
      • ' . __('Authors can publish and manage their own posts.') . '
      • ' . + '
      • ' . __('Contributors can write and manage their posts but not publish posts or upload media files.') . '
      • ' . + '
      • ' . __('Subscribers can read comments/comment/receive newsletters, etc.') . '
      • ' . + '
      ' . + '

      ' . __('The user\'s insitutional single-sign-on ID (e.g. ' . $strMarketingSSOID .') will become the user\'s Wordpress username.') . '

      ' . + '

      ' . __('New users will receive an email letting them know they’ve been added as a user for your site.') . '

      ' . + '

      ' . __('Remember to click the Add User button at the bottom of this screen when you are finished.') . '

      ' . + '

      ' . __('For more information:') . '

      ' . + '

      ' . __('Support Forums') . '

      ' + ); + } + + /** + * Processes and outputs the Add Dir Auth user form. + * @return void + */ + function wpDirAuth_add_user_panel(){ + $strMarketingSSOID = get_option('dirAuthMarketingSSOID','Username'); + /** + * defaults + */ + $strWpDirAuthSSOID = ''; + $strWpDirAuthRole = ''; + $boolConfirmationEmail = true; + $mxdErrors = ''; + $strSuccess = ''; + + if($_POST){ + if(wp_verify_nonce($_POST['_wpnonce_add-da-user'],'add-da-user')){ + if(isset($_POST['ssoid']) && $_POST['ssoid'] == ''){ + $mxdErrors = new WP_Error('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(isset($_POST['noconfirmation']) && $_POST['noconfirmation'] == 1) $boolConfirmationEmail = false; + + $aryUserData = wpDirAuth_add_new_user($strWpDirAuthSSOID,$strWpDirAuthRole); + if(is_wp_error($aryUserData)){ + $mxdErrors = $aryUserData; + } else { + $strSuccess = wpDirAuth_construct_success_msg($strWpDirAuthSSOID,$aryUserData['ID'],$strWpDirAuthRole); + + 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); + } + + //reset back to defaults + $strWpDirAuthSSOID = ''; + $strWpDirAuthRole = ''; + $boolConfirmationEmail = true; + } + } + } else { + $mxdErrors = new WP_Error('invalid-nonce',__('Invalid nonce value')); + } + } + +?> +

      Add New Directory Authentication User

      + +

      +

      Directory Auth settings page.') ?>

      + +
      > + + + + + + + + + + + + + + + +
      + + + +
      +
      + + 'createusersub' ) ); ?> + +
      + \ No newline at end of file