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', '- ');
+
+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
+
+
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.'