*
* Copyrights are listed in chronological order, by contributions.
*
* wpDirAuth: WordPress Directory Authentication, original author
* Copyright (c) 2007 Stephane Daury - http://stephane.daury.org/
*
* wpDirAuth and wpLDAP Patch Contributions
* Copyright (c) 2007 PKR Internet, LLC - http://www.pkrinternet.com/
*
* wpDirAuth Patch Contributions
* Copyright (c) 2007 Todd Beverly
*
* wpLDAP: WordPress LDAP Authentication
* Copyright (c) 2007 Ashay Suresh Manjure - http://ashay.org/
*
* wpDirAuth Patch Contribution and current maintainer
* Copyright (c) 2010, 2011, 2012 Paul Gilzow - http://gilzow.com/
*
* wpDirAuth is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* 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-PosixGroup
Plugin URI: http://wpdirauth.gilzow.com/
Description: WordPress Directory Authentication (LDAP/LDAPS).
Works with most LDAP enabled directory services, such as OpenLDAP,
Apache Directory, Microsoft Active Directory, Novell eDirectory,
Sun Java System Directory Server, etc.
Originally revived and upgraded from a patched version of wpLDAP.
Version: 1.9.4
Author: Paul Gilzow
Author URI: http://www.gilzow.com/
*/
/**
* Prevent direct access. Technically, they'd get a white screen anyway since the bulk of this plugin is function
* definitions, but let's make sure. In addition, we'll give them a 404
*/
if(!defined('ABSPATH')){
http_response_code(404);
exit;
}
/**
* wpDirAuth version.
*/
define('WPDIRAUTH_VERSION', '1.9.4');
/**
* 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',__('wpDirAuth 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');
//meta key used for determing if we have checked a directory-auth'ed users password
define('WPDIRAUTH_UPASSWORD_CHECKED','wpdirauth_prnd');
//default length of time, IN HOURS, the cookie should be set for when a directory-authed user logs in
define('WPDIRAUTH_COOKIE_EXPIRE_TIME_DEFAULT', 1);
/**
*My fail-safe method for determing if we are running in multisite mode
*/
define('WPDIRAUTH_MULTISITE',(defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE && function_exists('switch_to_blog')) ? TRUE : FALSE);
/**
*List of option keys we store in wp_sitemeta/wp_options
*/
define('WPDIRAUTH_OPTIONS', serialize(array(
'dirAuthEnable',
'dirAuthRequiresSsl',
'dirAuthTOS',
'dirAuthUseGroups',
'dirAuthEnableSsl',
'dirAuthControllers',
'dirAuthBaseDn',
'dirAuthPreBindUser',
'dirAuthAccountSuffix',
'dirAuthFilter',
'dirAuthInstitution',
'dirAuthGroups',
'dirAuthMarketingSSOID',
'dirAuthLoginScreenMsg',
'dirAuthChangePassMsg',
'dirAuthCookieExpire',
)));
if(function_exists('add_filter')){
add_filter('authenticate','wpDirAuth_authenticate',10,3);
if(function_exists('wp_authenticate')){
//we need to at least warn them that the plugin might not work correctly. total hack until we rewrite
define('WPDIRAUTH_PLUGGABLE_WARN',true);
}
} elseif(!function_exists('wp_authenticate')) {
function wp_authenticate($strUserName,$strPassword){
return wpDirAuth_authenticate(null,$strUserName,$strPassword);
}
} else {
//no hooks, and something has overridden the wp_authenticate menu
$boolAuthOverridden = true;
}
if (!function_exists('ldap_connect') || (isset($boolAuthOverridden) && $boolAuthOverridden) ) {
/**
* 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.'
You are running an older version of WordPress that does not support Hooks
and another plugin has overridden the wp_authenticate pluggable function.
wpDirAuth cannot provide directory authentication without having access to this function.
Please disable any WP plugins that deal with authentication in order to use wpDirAuth, or upgrade your instance
of WordPress to one that supports Hooks. Unfortunately, we cannot provide you with more info as to which plugin is in conflict.
________EOS;
}
echo <<<________EOS
wpDirAuth Directory Authentication Options: Plugin Conflict
$message
$wpDARef
________EOS;
}
/**
* SAFE MODE: Adds the `wpDirAuth` 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(
'wpDirAuth Directory Authentication Options: Plugin Conflict',
'!! wpDirAuth !!',
'manage_options',
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
*/
/**
* @param $objUser WP_User
* @param $strPassword string
* @return void
*/
function wpDirAuth_check_oldpassword($objUser,$strPassword)
{
if(!wpdirauth_already_changed_password($objUser)){
//does their current directory password match the one in wordpress?
if(wp_check_password($strPassword,$objUser->data->user_pass,$objUser->ID)){
//it does, so let's give them a new random one
wp_set_password(wp_generate_password(24));
}
wpDirAuth_mark_password_as_checked($objUser->ID);
}
}
/**
* Have we already checked a user's password at some point?
*
* @param $objUser WP_User
* @return bool
*/
function wpDirAuth_already_changed_password($objUser)
{
return (1 == get_user_meta($objUser->ID,WPDIRAUTH_UPASSWORD_CHECKED,true) ? true : false);
}
/**
* @param $objUser
* @return void
*/
function wpDirAuth_mark_password_as_checked($intUserID)
{
add_user_meta($intUserID,WPDIRAUTH_UPASSWORD_CHECKED,1,true);
}
/**
* 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_site_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 resource &$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("\'"=>"'"));
/**
* Why stripslashes on the password? Because wordpress.
* @see: https://codex.wordpress.org/Function_Reference/stripslashes_deep#Good_Coding_Practice
*/
$password = stripslashes_deep($password);
if ( ($isBound = @ldap_bind($connection, $username, $password)) === false ) {
// @see http://weblogs.valsania.it/andreav/2008/07/24/wpdirauth-14-patch/
$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|WP_Error
*/
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|array WP_Error object or array of 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;
$isInDirectory = false;
$results = false;
$controllers = explode(',', get_site_option('dirAuthControllers'));
$baseDn = get_site_option('dirAuthBaseDn');
$preBindUser = get_site_option('dirAuthPreBindUser');
$preBindPassword = get_site_option('dirAuthPreBindPassword');
$accountSuffix = get_site_option('dirAuthAccountSuffix');
$filter = get_site_option('dirAuthFilter');
$enableSsl = get_site_option('dirAuthEnableSsl');
$boolUseGroups = get_site_option('dirAuthUseGroups');
if($boolUseGroups == 1){
$strAuthGroups = get_site_option('dirAuthGroups');
}
$returnKeys = wpDirAuth_retrieveReturnFilterKeys();
$isBound = $isPreBound = $isLoggedIn = false;
if ($accountSuffix) $username .= $accountSuffix;
if (!$filter) $filter = WPDIRAUTH_DEFAULT_FILTER;
$filterQuery = "($filter=$username)";
$filterQuery = apply_filters('wpdirauth_filterquery',$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);
if(isset($arySearchResults[0]['dn'])){
$aryAuthGroupsDN[] = $strAuthGroup;
}
}
if(count($aryAuthGroupsDN) == 0){
return new WP_Error('no_auth_groups_found',$errorTitle.__('No Authentication Groups found based on given group CN'));
}
$memberFilterQuery = "(memberUid=".$username.")";
$strFilterQuery = '(&'.$memberFilterQuery.'(|';
foreach($aryAuthGroupsDN as $strAuthGroupDN){
$strFilterQuery .= "(".$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.
* $result is set to false by default. reset to a resource or false again in lines 403-437
* wpDirAuth_retrieveUserDetails() now checks the value of $results before continuing
*/
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_user_meta($userdata->ID, 'wpDirAuthFlag',true);
if ($curUserIsDirUser) {
echo <<<____________EOS
wpDirAuth 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;
$boolAutoRegister = intval($_POST['dirAuthAutoRegistration'])== 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;
if(1 == $boolAutoRegister){
//they are using authgroups, but they also want us to autoregister. sorry, cant do that.
$boolAutoRegister = 0;
}
}
// Have to be allowed to contain some HTML
$loginScreenMsg = wpDirAuth_sanitize($_POST['dirAuthLoginScreenMsg'], true);
$changePassMsg = wpDirAuth_sanitize($_POST['dirAuthChangePassMsg'], true);
$fltCookieExpire = (is_numeric($_POST['dirAuthCookieExpire'])) ? floatval($_POST['dirAuthCookieExpire']) : WPDIRAUTH_COOKIE_EXPIRE_TIME_DEFAULT;
update_site_option('dirAuthEnable', $enable);
update_site_option('dirAuthEnableSsl', $enableSsl);
update_site_option('dirAuthRequireSsl', $requireSsl);
update_site_option('dirAuthAutoRegister', $boolAutoRegister);
update_site_option('dirAuthControllers', $controllers);
update_site_option('dirAuthBaseDn', $baseDn);
update_site_option('dirAuthPreBindUser', $preBindUser);
update_site_option('dirAuthAccountSuffix', $accountSuffix);
update_site_option('dirAuthFilter', $filter);
update_site_option('dirAuthInstitution', $institution);
update_site_option('dirAuthLoginScreenMsg', $loginScreenMsg);
update_site_option('dirAuthChangePassMsg', $changePassMsg);
update_site_option('dirAuthTOS', $TOS);
update_site_option('dirAuthUseGroups', $boolUseGroups);
update_site_option('dirAuthGroups', $strAuthGroups);
update_site_option('dirAuthMarketingSSOID', $strMarketingSSOID);
update_site_option('dirAuthCookieExpire', $fltCookieExpire);
// Only store/override the value if a new one is being sent a bind user is set.
if ( $preBindUser && $preBindPassword && ($preBindPassCheck == $preBindPassword) )
update_site_option('dirAuthPreBindPassword', $preBindPassword);
// Clear the stored password if the Bind DN is null
elseif ( ! $preBindUser)
update_site_option('dirAuthPreBindPassword', '');
if (get_site_option('dirAuthEnable') && !get_site_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_site_option('dirAuthEnable')) == 1 ? 1 : 0;
$requireSsl = intval(get_site_option('dirAuthRequireSsl')) == 1 ? 1 : 0;
$TOS = intval(get_site_option('dirAuthTOS')) == 1 ? 1 : 0;
$boolUseGroups = intval(get_site_option('dirAuthUseGroups')) == 1 ? 1 : 0;
$boolAutoRegister= intval(get_site_option('dirAuthAutoRegister'))== 1 ? 1 : 0;
//integers
$enableSsl = intval(get_site_option('dirAuthEnableSsl',0));
// Strings, no HTML
$controllers = wpDirAuth_sanitize(get_site_option('dirAuthControllers'));
$baseDn = wpDirAuth_sanitize(get_site_option('dirAuthBaseDn'));
$preBindUser = wpDirAuth_sanitize(get_site_option('dirAuthPreBindUser'));
$accountSuffix = wpDirAuth_sanitize(get_site_option('dirAuthAccountSuffix'));
$filter = wpDirAuth_sanitize(get_site_option('dirAuthFilter'));
$institution = wpDirAuth_sanitize(get_site_option('dirAuthInstitution'));
$strAuthGroups = wpDirAuth_sanitize((get_site_option('dirAuthGroups')));
$strMarketingSSOID = wpDirAuth_sanitize((get_site_option('dirAuthMarketingSSOID')));
//Floats
$fltCookieExpire = floatval(get_site_option('dirAuthCookieExpire'));
// Have to be allowed to contain some HTML
$loginScreenMsg = wpDirAuth_sanitize(get_site_option('dirAuthLoginScreenMsg'), true);
$changePassMsg = wpDirAuth_sanitize(get_site_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);
$tEnable = $fEnable = $tWpSsl = $fWpSsl = $tTOS = $fTOS = '';
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 they are using authentication groups we will not automaticaly register authed users that dont already have an account
*/
if('' != $strAuthGroups && $boolAutoRegister == 1){
$boolAutoRegister = 0;
}
/*
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";
}
$strYesAutoRegister = '';
$strNoAutoRegister = '';
if($boolAutoRegister){
$strYesAutoRegister = 'checked';
} else {
$strNoAutoRegister = 'checked';
}
/**
* you have to cast the 0 to a float because the zero you get back from above has been cast to a float
*/
if(floatval(0) === $fltCookieExpire){
$fltCookieExpire = WPDIRAUTH_COOKIE_EXPIRE_TIME_DEFAULT;
}
//we are running in filtered mode, but some other plugin has defined wp_authenticate
if(defined('WPDIRAUTH_PLUGGABLE_WARN') && WPDIRAUTH_PLUGGABLE_WARN){
$strPluggableWarn = ''.PHP_EOL;
$strPluggableWarn .= '
Just FYI: another plugin has overridden the wp_authenticate pluggable function.';
$strPluggableWarn .= ' If that plugin doesn\'t apply the \'authenticate\' filter, then wpDirAuth will be unable to function.
'.PHP_EOL;
$strPluggableWarn .= '
'.PHP_EOL;
} else {
$strPluggableWarn = '';
}
$strPHPWarn = '';
if(version_compare( PHP_VERSION, '5.3', '<' )){
$strPHPWarn = <<<____PHPWARN
PHP 5.2.X WARNING
Unfortunately, trying to support newer versions of PHP (the upcoming release of 7.2) as well as older version of PHP has become unsustainable. As of wpDirAuth version 2.0
I will no longer be able to support versions of PHP less than 5.3.X. I feel an obligation to strongly suggest you upgrade your PHP install considering 5.2 was released
eleven years ago and has been without support for over six years.
____PHPWARN;
}
/**
* @todo seems like we should loop through these yes/nos are something...
*/
$wpDAV = WPDIRAUTH_VERSION;
echo <<<________EOS
wpDirAuth Directory Authentication Options
$strPluggableWarn
$strPHPWarn
$wpDARef
________EOS;
}
/**
* Adds the `wpDirAuth` 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
*/
function wpDirAuth_addMenu()
{
if (function_exists('add_options_page')) {
$strWpAdminPage = add_options_page(
'wpDirAuth Directory Authentication Options',
'wpDirAuth',
'manage_options',
basename(__FILE__),
'wpDirAuth_optionsPanel'
);
//$strWpAdminPanel is here in case we want to add a contextual help panel later
}
}
/**
* 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_site_option('dirAuthEnable')) {
/**
* If they've enabled the ssl requirement in our plugin, but havent forced ssl admin, or ssl login
* and the url isn't ssl'ed
*/
if(
get_site_option('dirAuthRequireSsl')
&& (
!force_ssl_admin()
|| (function_exists('force_ssl_login') && !force_ssl_login())
)
&& (
(isset($_SERVER['HTTPS']) && 'on' !== $_SERVER['HTTPS'])
||
(isset($_SERVER['REQUEST_SCHEME']) && 'https' !== $_SERVER['REQUEST_SCHEME'])
)
) {
//ok, now that we know we need to redirect them, we need to redirect them back to the right location
if(defined('MULTISITE') && MULTISITE){
$intBlogID = get_current_blog_id();
} else {
$intBlogID = null;
}
$strURL = get_site_url($intBlogID,'','https');
if(1 == preg_match('/\/$/',$strURL)){
$strURL = rtrim($strURL,'/');
}
if(isset($_SERVER['REQUEST_URI'])){
$strURL .= $_SERVER['REQUEST_URI'];
} else {
$strURL .= $_SERVER['SCRIPT_NAME'];
if(isset($_SERVER['QUERY_STRING']) && '' != $_SERVER['QUERY_STRING'] ){
$strURL .= '?'.$_SERVER['QUERY_STRING'];
}
}
$strURL = htmlentities($strURL,ENT_QUOTES,'UTF-8',false);
$refreshJS = '" />';
$refreshMeta = '';
$refreshMsg = 'Please access the encrypted version of this page.';
if (headers_sent()) {
echo $refreshJS.$refreshMeta.''.$refreshMsg.'