'Active Directory Server Settings',
'adauthint_user_opts' => 'User Information Settings',
'adauthint_auth_opts' => 'Authorization and Authentication Settings',
'adauthint_security_opts' => 'Brute Force Security Settings',
);
/**
* Has the user been authenticated already?
* @var bool
* @access private
*/
protected $_authenticated = false;
/**
* adLDAP Object
* @var adLDAP
* @access private
*/
protected $_adldap = NULL;
/**
* Logging/Debug Level
*/
protected $_loglevel = ADAI_LOG_NONE;
/**
* Debug Log
* @var string
*/
protected $_debug = '';
/**
* Whether or not to mask passwords in the log
* @var bool
*/
protected $_mask_passwords_in_log = true;
/**
* An array indicating which sets of options were saved successfully.
*/
protected $updated = array();
/**
* Build our new ADAuthInt_Plugin object in PHP4
*
* Simply calls and returns the PHP5 __construct() function
* @uses ADAuthInt_Plugin::__construct()
* @deprecated
*/
function ADAuthInt_Plugin() {
return $this->__construct();
} /* ADAuthInt_Plugin() function */
/**
* Build our new ADAuthInt_Plugin object
* @uses load_plugin_textdomain()
* @uses is_plugin_active_for_network()
* @uses ADAuthInt_Plugin::_load_options()
*/
function __construct() {
global $wp_version, $wpdb;
if( !defined( 'ADAI_MU_PLUGIN' ) )
define( 'ADAI_MU_PLUGIN', stristr( 'mu-plugins/', __FILE__ ) );
if( !defined( 'ADAI_IS_WPMU' ) )
define( 'ADAI_IS_WPMU', is_multisite() );
if( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
$this->setLogLevel( ADAI_LOG_DEBUG );
}
add_filter('plugin_action_links_' . ADAUTHINT_PLUGIN_BASENAME, array($this, 'add_settings_link'));
add_filter('network_admin_plugin_action_links_' . ADAUTHINT_PLUGIN_BASENAME, array($this, 'add_settings_link'));
add_action('init', array($this, 'init_plugin'));
add_action( 'network_admin_menu', array( $this, 'setup_admin' ) );
add_action('admin_menu', array($this, 'setup_admin') );
add_action('admin_init', array($this, 'init_admin'));
if( is_admin() && $_REQUEST['page'] == ADAUTHINT_OPTIONS_PAGE ) {
wp_register_script(
/*$handle = */'adauthint-scripts',
/*$src = */plugins_url( '/scripts/active-directory-authentication-integration.js', __FILE__ ),
/*$deps = */array( 'jquery', 'post' ),
/*$ver = */ADAI_PLUGIN_VERSION,
/*$in_footer = */true
);
wp_enqueue_script( 'adauthint-scripts' );
}
$this->_load_options();
$tablename = $this->get_table_name();
if ( false === $this->_get_option( 'adauthint_removed_old_table', false ) ) {
if( 1 == $wpdb->get_var( $wpdb->prepare( "SELECT 1 res FROM " . $tablename . " LIMIT 1" ) ) ) {
/**
* This table is no longer used as of version 0.6, so we should remove it
* if it exists.
*/
$wpdb->query( 'DROP TABLE IF EXISTS ' . $tablename );
}
/**
* Insert an option to indicate we've checked for the table, so
* we don't have to check for the table again in the future
*/
if ( ADAI_IS_MULTINETWORK && function_exists( 'add_mnetwork_option' ) ) {
add_mnetwork_option( 'adauthint_removed_old_table', 1 );
} else if ( ADAI_IS_NETWORK_ACTIVE ) {
add_site_option( 'adauthint_removed_old_table', 1 );
} else {
add_option( 'adauthint_removed_old_table', 1 );
}
}
add_action( 'admin_notices', array( $this, '_flush_log_to_notice' ) );
if( !function_exists( 'ldap_connect' ) ) {
add_action( 'admin_notices', array( $this, '_ldap_not_supported' ) );
return;
}
add_action( 'add_user_to_blog', array( &$this, '_add_user_to_blog' ), 10, 2 );
add_action( 'lost_password', array( &$this, 'disable_function' ) );
add_action( 'retrieve_password', array( &$this, 'disable_function' ) );
add_action( 'password_reset', array( &$this, 'disable_function' ) );
if( is_admin() ) {
add_action( 'init', array( $this, 'is_user_member_of_blog' ) );
}
if( !$this->allow_local_password ) {
// disable password fields
add_filter('show_password_fields', array(&$this, 'disable_password_fields'));
// generate a random passwords for manually added users
add_action('check_passwords', array(&$this, 'generate_password'), 10, 3);
}
if( !class_exists( 'adLDAPE' ) )
require_once( 'inc/adLDAP-extended.php' );
// WP 2.8 and above?
if (version_compare($wp_version, '2.8', '>=')) {
add_filter('authenticate', array(&$this, 'authenticate'), 10, 3);
} else {
add_action('wp_authenticate', array(&$this, 'authenticate'), 10, 2);
}
add_filter( 'shake_error_codes', array( &$this, 'add_error_shakes' ) );
} /* __construct() function */
/**
* Get the message that should be displayed when someone tries to retrieve/reset their password
* @return string the message to be displayed
*/
function _get_lost_password_message() {
if( !empty( $this->_lost_password_message ) )
return $this->_lost_password_message;
return __( 'The passwords used within this installation of WordPress are managed within Active Directory. To reset or retrieve your password, please visit the help system for your organization\'s Active Directory.', ADAUTHINT_TEXT_DOMAIN );
}
/**
* Set the message that should be displayed when someone tries to retrieve/reset their password
* @return void
*/
function _set_lost_password_message( $message ) {
if( is_string( $message ) )
$this->_lost_password_message = $message;
return;
}
/**
* Print an Admin Notice about lack of LDAP Support
*/
function _ldap_not_supported() {
echo '
' . __( 'LDAP Not Supported', ADAUTHINT_TEXT_DOMAIN ) . '
' . __( 'Your PHP configuration does not appear to support LDAP connections; therefore, the Active Directory Authentication Integration plug-in will not work at all. It is recommended that you deactivate the plug-in until you are able to update your PHP configuration to support LDAP.', ADAUTHINT_TEXT_DOMAIN ) . '
';
} /* _ldap_not_supported() function */
/**
* Print the current log to an admin notice
*/
function _flush_log_to_notice() {
if( $this->_loglevel && !empty( $this->_debug ) ) {
echo '
' . __( 'If any groups indicate they were not successfully updated, that could be because no options within that group were modified. If you did make modifications to those groups; you should check to verify that those modifications were correctly committed.' ) . '
_log_flush();
return true;
} /* display_admin_page() function */
/**
* Update options for a whole network
*
* Only invoked when the plugin is network-active. If
* the plugin is only active on one blog/site, or the
* multi-site functions of WordPress are not set up,
* this function is not called.
*/
function update_wpms_options() {
if( !is_network_admin() )
return;
if( ADAI_IS_NETWORK_ACTIVE ) {
/* If the WP Multi Network plug-in is installed and active,
* then we should propagate the settings to all other networks
*/
if( ADAI_IS_MULTINETWORK && $this->update_all_networks ) {
global $wpdb;
$networks = $wpdb->get_results( $wpdb->prepare( 'SELECT DISTINCT id FROM ' . $wpdb->site ) );
if( is_array( $networks ) ) { /* We retrieved an array of site IDs */
if( !method_exists( $this, 'switch_to_site' ) )
continue;
foreach( $networks as $network ) {
global $adai_current_network, $adai_original_network, $site_id;
$adai_current_network = $network->id;
$adai_original_network = $site_id;
$this->_log( ADAI_LOG_INFO, 'Preparing to update sitewide options for ' . $network->id );
$this->switch_to_site( $adai_current_network );
if( current_user_can( 'delete_users' ) ) {
$this->update_site_options( $adai_current_network, $adai_original_network );
} else {
$this->_log( ADAI_LOG_ERROR, 'The current user does not appear to be a super admin for the network with an ID of ' . $adai_current_network . ', therefore, the site options for that network were not updated.' );
}
$this->restore_current_site();
}
} elseif( current_user_can( 'delete_users' ) ) { /* We only found one network */
$this->_log( ADAI_LOG_INFO, 'WPMN plugin was found, but only one network seems to exist, so only options for the current network are updated.' );
$this->update_site_options();
} else {
$this->_log( ADAI_LOG_ERROR, 'Multiple networks were not found, so an attempt was made to update the current network. However, the current user does not appear to have the appropriate permissions to perform this action. Therefore, no options were updated.' );
}
} else { /* The WPMN plugin is not installed or active */
$this->_log( ADAI_LOG_INFO, 'The WPMN plugin was not found, so only options for current network are updated' );
if( current_user_can( 'delete_users' ) )
$this->update_site_options();
else
$this->_log( ADAI_LOG_ERROR, 'The current user does not appear to have the appropriate permissions to update these options.' );
}
} else {
foreach( array_keys( $this->options_info ) as $optgroup ) {
$this->updated[$optgroup] = update_option( $optgroup, $this->options[$optgroup] );
}
}
} /* update_wpms_options() function */
function update_site_options( $current_network=NULL, $original_network=NULL ) {
foreach( array_keys( $this->options_info ) as $optgroup ) {
if( $current_network == $original_network || ( array_key_exists( 'update_all_networks', $_POST[ $optgroup ] ) && $_POST[$optgroup]['update_all_networks'] == 'true' ) ) {
$this->_log( ADAI_LOG_INFO, 'The network options for ' . $optgroup . ' were updated' . ( ( !empty( $current_network ) ) ? ' on the network with an ID of ' . $current_network : '' ) . '.' );
if( false === get_site_option( $optgroup ) )
$this->updated[$current_network][$optgroup] = add_site_option( $optgroup, $this->options[$optgroup] );
else
$this->updated[$current_network][$optgroup] = update_site_option( $optgroup, $this->options[$optgroup] );
}
}
if( is_null( $current_network ) && is_null( $original_network ) ) {
$tmp = array();
foreach( $this->updated[$current_network] as $k=>$v ) {
$tmp[$k] = $v;
}
$this->updated = $tmp;
}
}
/**
* Initiate our admin page
* @uses ADAuthInt_Plugin::options
* @uses register_setting()
* @uses add_settings_section()
* @uses add_settings_field()
*/
function init_admin(){
if( !count( $this->options_objs ) )
$this->_load_options();
foreach( $this->options_info as $optgroup=>$options ) {
if( ADAI_IS_NETWORK_ACTIVE && !is_network_admin() && 'adauthint_auth_opts' != $optgroup ) {
continue;
}
if( is_array( $options ) ) {
if( function_exists( 'add_meta_box' ) ) {
add_meta_box( 'meta-' . $optgroup, __( $this->subtitles[$optgroup], ADAUTHINT_TEXT_DOMAIN ), array( $this, 'make_settings_meta_boxes' ), ADAUTHINT_OPTIONS_PAGE, 'normal', 'high', array( 'id' => $optgroup ) );
}
register_setting( ADAUTHINT_OPTIONS_PAGE, $optgroup, array( $this, 'validate_options_' . $optgroup ) );
add_settings_section(
/*$id = */$optgroup . '_group',
/*$title = */__( $this->subtitles[$optgroup], ADAUTHINT_TEXT_DOMAIN ),
/*$callback = */array( $this, 'build_options_' . $optgroup ),
/*$page = */ADAUTHINT_OPTIONS_PAGE
);
foreach( array_keys( $options ) as $k ) {
add_settings_field(
/*$id =*/ $k,
/*$title =*/ __( $this->options_objs[$optgroup][$k]->opt_label, ADAUTHINT_TEXT_DOMAIN ),
/*$callback =*/ array( &$this->options_objs[$optgroup][$k], 'build_field' ),
/*$page =*/ ADAUTHINT_OPTIONS_PAGE,
/*$section =*/ $optgroup . '_group',
/*$args =*/ array( 'label_for' => $this->options_objs[$optgroup][$k]->opt_section . '_' . $k )
);
}
}
}
} /* init_admin() function */
/**
* Output the appropriate meta box for our settings
*/
function make_settings_meta_boxes() {
$opt = func_get_args();
$opt = array_pop( $opt );
$id = str_replace( 'meta-', '', $opt['id'] );
$section_notes = array(
'adauthint_server_opts' => 'Information about the active directory server.',
'adauthint_user_opts' => 'Information about how to handle individual user accounts',
'adauthint_security_opts' => 'Various security options to help prevent brute-force attacks',
'adauthint_auth_opts' => 'Authorization options, allowing you to set up specific user groups based on Active Directory groups, etc.',
);
?>
build_options_group( $this->options_info['adauthint_server_opts'], 'adauthint_server_opts' );
return;
} /* build_options_adauthint_server_opts function */
/**
* Build the User Options group
* @uses ADAuthInt_Plugin::build_options_group()
*/
function build_options_adauthint_user_opts() {
$this->build_options_group( $this->options_info['adauthint_user_opts'], 'adauthint_user_opts' );
return;
} /* build_options_adauthint_user_opts function */
/**
* Build the Authority Options group
* @uses ADAuthInt_Plugin::build_options_group()
*/
function build_options_adauthint_auth_opts() {
$this->build_options_group( $this->options_info['adauthint_auth_opts'], 'adauthint_auth_opts' );
return;
} /* build_options_adauthint_auth_opts function */
/**
* Build the Security Options group
* @uses ADAuthInt_Plugin::build_options_group()
*/
function build_options_adauthint_security_opts() {
$this->build_options_group( $this->options_info['adauthint_security_opts'], 'adauthint_security_opts' );
return;
} /* build_options_adauthint_security_opts function */
/**
* General options building function
*
* This function is used to build each of the options groups for this plug-in
* @param array $group The appropriate portion of the ADAuthInt_Plugin::options_info array for this group of options
* @param string $sect The name of the options group to build
*/
function build_options_group( $group=array(), $sect ) {
if( $this->_loglevel >= ADAI_LOG_DEBUG ) {
ob_start();
var_dump( $this->options_objs );
$this->_log( ADAI_LOG_DEBUG, ob_get_contents() );
ob_end_clean();
}
$section_notes = array(
'adauthint_server_opts' => 'Information about the active directory server.',
'adauthint_user_opts' => 'Information about how to handle individual user accounts',
'adauthint_security_opts' => 'Various security options to help prevent brute-force attacks',
'adauthint_auth_opts' => 'Authorization options, allowing you to set up specific user groups based on Active Directory groups, etc.',
);
echo '