Untitled diff

创建于 差异永不过期
0 删除
587
0 添加
587
<?php
<?php
/*
/*
Plugin Name: Active Directory Integration
Plugin Name: Active Directory Integration
Version: 1.1.4
Version: 1.1.4
Plugin URI: http://www.steindorff.de/wp-ad-integration
Plugin URI: http://www.steindorff.de/wp-ad-integration
Description: Allows WordPress to authenticate, authorize, create and update users through Active Directory
Description: Allows WordPress to authenticate, authorize, create and update users through Active Directory
Author: Christoph Steindorff
Author: Christoph Steindorff
Author URI: http://www.steindorff.de/
Author URI: http://www.steindorff.de/
The work is derived from version 1.0.5 of the plugin Active Directory Authentication:
The work is derived from version 1.0.5 of the plugin Active Directory Authentication:
OriginalPlugin URI: http://soc.qc.edu/jonathan/wordpress-ad-auth
OriginalPlugin URI: http://soc.qc.edu/jonathan/wordpress-ad-auth
OriginalDescription: Allows WordPress to authenticate users through Active Directory
OriginalDescription: Allows WordPress to authenticate users through Active Directory
OriginalAuthor: Jonathan Marc Bearak
OriginalAuthor: Jonathan Marc Bearak
OriginalAuthor URI: http://soc.qc.edu/jonathan
OriginalAuthor URI: http://soc.qc.edu/jonathan
*/
*/
/*
/*
This library is free software; you can redistribute it and/or
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
Lesser General Public License for more details.
*/
*/
if (!class_exists('ADIntegrationPlugin')) {
if (!class_exists('ADIntegrationPlugin')) {
// LOG LEVEL
// LOG LEVEL
define('ADI_LOG_DEBUG', 6);
define('ADI_LOG_DEBUG', 6);
define('ADI_LOG_INFO', 5);
define('ADI_LOG_INFO', 5);
define('ADI_LOG_NOTICE',4);
define('ADI_LOG_NOTICE',4);
define('ADI_LOG_WARN', 3);
define('ADI_LOG_WARN', 3);
define('ADI_LOG_ERROR', 2);
define('ADI_LOG_ERROR', 2);
define('ADI_LOG_FATAL', 1);
define('ADI_LOG_FATAL', 1);
define('ADI_LOG_NONE', 0);
define('ADI_LOG_NONE', 0);
define('ADI_DUPLICATE_EMAIL_ADDRESS_PREVENT', 'prevent');
define('ADI_DUPLICATE_EMAIL_ADDRESS_PREVENT', 'prevent');
define('ADI_DUPLICATE_EMAIL_ADDRESS_ALLOW', 'allow');
define('ADI_DUPLICATE_EMAIL_ADDRESS_ALLOW', 'allow');
define('ADI_DUPLICATE_EMAIL_ADDRESS_CREATE', 'create');
define('ADI_DUPLICATE_EMAIL_ADDRESS_CREATE', 'create');
class ADIntegrationPlugin {
class ADIntegrationPlugin {
// version of needed DB table structure
// version of needed DB table structure
const DB_VERSION = '0.9';
const DB_VERSION = '0.9';
const ADI_VERSION = '1.1.4';
const ADI_VERSION = '1.1.4';
// name of our own table
// name of our own table
const TABLE_NAME = 'adintegration';
const TABLE_NAME = 'adintegration';
// is the user authenticated?
// is the user authenticated?
public $_authenticated = false;
public $_authenticated = false;
protected $_minium_WPMU_version = '3.0';
protected $_minium_WPMU_version = '3.0';
protected $_minium_WP_version = '3.0';
protected $_minium_WP_version = '3.0';
// log level
// log level
protected $_loglevel = ADI_LOG_NONE;
protected $_loglevel = ADI_LOG_NONE;
protected $_logfile = '';
protected $_logfile = '';
// adLDAP-object
// adLDAP-object
protected $_adldap;
protected $_adldap;
// Should a new user be created automatically if not already in the WordPress database?
// Should a new user be created automatically if not already in the WordPress database?
protected $_auto_create_user = false;
protected $_auto_create_user = false;
// Should the users be updated in the WordPress database everytime they logon? (Works only if automatic user creation is set.
// Should the users be updated in the WordPress database everytime they logon? (Works only if automatic user creation is set.
protected $_auto_update_user = false;
protected $_auto_update_user = false;
// Account Suffix (will be appended to all usernames created in WordPress, as well as used in the Active Directory authentication process
// Account Suffix (will be appended to all usernames created in WordPress, as well as used in the Active Directory authentication process
protected $_account_suffix = '';
protected $_account_suffix = '';
// Should the account suffix be appended to the usernames created in WordPress?
// Should the account suffix be appended to the usernames created in WordPress?
protected $_append_suffix_to_new_users = false;
protected $_append_suffix_to_new_users = false;
// Domain Controllers (separate with semicolons)
// Domain Controllers (separate with semicolons)
protected $_domain_controllers = '';
protected $_domain_controllers = '';
// LDAP/AD BASE DN
// LDAP/AD BASE DN
protected $_base_dn = '';
protected $_base_dn = '';
// Role Equivalent Groups (wp-role1=ad-group1;wp-role2=ad-group2;...)
// Role Equivalent Groups (wp-role1=ad-group1;wp-role2=ad-group2;...)
protected $_role_equivalent_groups = '';
protected $_role_equivalent_groups = '';
// Default Email Domain (eg. 'domain.tld')
// Default Email Domain (eg. 'domain.tld')
protected $_default_email_domain = '';
protected $_default_email_domain = '';
// Port on which AD listens (default 389)
// Port on which AD listens (default 389)
protected $_port = 389;
protected $_port = 389;
// Secure the connection between the Drupal and the LDAP servers using TLS.
// Secure the connection between the Drupal and the LDAP servers using TLS.
protected $_use_tls = false;
protected $_use_tls = false;
// network timeout (LDAP_OPT_NETWORK_TIMEOUT) in seconds
// network timeout (LDAP_OPT_NETWORK_TIMEOUT) in seconds
protected $_network_timeout = 5;
protected $_network_timeout = 5;
// Check Login authorization by group membership
// Check Login authorization by group membership
protected $_authorize_by_group = false;
protected $_authorize_by_group = false;
// Group name for authorization.
// Group name for authorization.
protected $_authorization_group = '';
protected $_authorization_group = '';
// Maximum number of failed login attempts before the account is blocked
// Maximum number of failed login attempts before the account is blocked
protected $_max_login_attempts = 3;
protected $_max_login_attempts = 3;
// Number of seconds an account is blocked after the maximum number of failed login attempts is reached.
// Number of seconds an account is blocked after the maximum number of failed login attempts is reached.
protected $_block_time = 30;
protected $_block_time = 30;
// Send email to user if his account is blocked.
// Send email to user if his account is blocked.
protected $_user_notification = false;
protected $_user_notification = false;
// Send email to admin if a user account is blocked.
// Send email to admin if a user account is blocked.
protected $_admin_notification = false;
protected $_admin_notification = false;
// Administrator's e-mail address(es) where notifications should be sent to.
// Administrator's e-mail address(es) where notifications should be sent to.
protected $_admin_email = '';
protected $_admin_email = '';
// Set user's display_name to an AD attribute or to username if left blank
// Set user's display_name to an AD attribute or to username if left blank
// Possible values: description, displayname, mail, sn, cn, givenname, samaccountname, givenname sn
// Possible values: description, displayname, mail, sn, cn, givenname, samaccountname, givenname sn
protected $_display_name = '';
protected $_display_name = '';
// Enable/Disable password changes
// Enable/Disable password changes
protected $_enable_password_change = false;
protected $_enable_password_change = false;
// How to deal with duplicate email addresses
// How to deal with duplicate email addresses
protected $_duplicate_email_prevention = ADI_DUPLICATE_EMAIL_ADDRESS_PREVENT;
protected $_duplicate_email_prevention = ADI_DUPLICATE_EMAIL_ADDRESS_PREVENT;
// Update users description if $_auto_update_user is true
// Update users description if $_auto_update_user is true
protected $_auto_update_description = false;
protected $_auto_update_description = false;
// default attributes to be read from AD (Windows 2000/20003)
// default attributes to be read from AD (Windows 2000/20003)
protected $_default_user_attributes = array (
protected $_default_user_attributes = array (
'cn', // Common Name
'cn', // Common Name
'givenname', // First name
'givenname', // First name
'sn', // Last name
'sn', // Last name
'displayname', // Display name
'displayname', // Display name
'description', // Description
'description', // Description
'mail', // E-mail
'mail', // E-mail
'samaccountname', // User logon name
'samaccountname', // User logon name
'userprincipalname', // userPrincipalName
'userprincipalname', // userPrincipalName
'useraccountcontrol' // userAccountControl
'useraccountcontrol' // userAccountControl
);
);
// List of additional user attributes that can be defined by the admin
// List of additional user attributes that can be defined by the admin
// The attributes are seperated by a new line and have the format:
// The attributes are seperated by a new line and have the format:
// <Attribute name>:<type>
// <Attribute name>:<type>
// where type can be one of the following: string, integer, bool, image, time, timestamp
// where type can be one of the following: string, integer, bool, image, time, timestamp
// thumbnailphoto:image
// thumbnailphoto:image
// whencreated:time
// whencreated:time
protected $_additional_user_attributes = '';
protected $_additional_user_attributes = '';
// Merged array of _user_attributes and _additional_user_attributes
// Merged array of _user_attributes and _additional_user_attributes
protected $_all_user_attributes = array();
protected $_all_user_attributes = array();
// Add all user attributes from AD to WP table usermeta
// Add all user attributes from AD to WP table usermeta
protected $_write_usermeta = true;
protected $_write_usermeta = true;
// Prefix for user meta Data from AD
// Prefix for user meta Data from AD
protected $_usermeta_prefix = 'adi_';
protected $_usermeta_prefix = 'adi_';
// Overwrite local values even if values in Active Directory are empty.
// Overwrite local values even if values in Active Directory are empty.
protected $_usermeta_empty_overwrite = false;
protected $_usermeta_empty_overwrite = false;
// Enable Sync Back
// Enable Sync Back
protected $_syncback = false;
protected $_syncback = false;
// Use global Sync Back User
// Use global Sync Back User
protected $_syncback_use_global_user = false;
protected $_syncback_use_global_user = false;
// Account name of global sync back user
// Account name of global sync back user
protected $_syncback_global_user = '';
protected $_syncback_global_user = '';
// Password of global sync back user
// Password of global sync back user
protected $_syncback_global_pwd = '';
protected $_syncback_global_pwd = '';
// Show AD attributes in user profile
// Show AD attributes in user profile
protected $_show_attributes = false;
protected $_show_attributes = false;
// List of AD attributes in the order they should appear on users profile page
// List of AD attributes in the order they should appear on users profile page
// Attributes are separated by semicolon or linefeed / newline and have to format:
// Attributes are separated by semicolon or linefeed / newline and have to format:
// <Attribute name>:<desription>
// <Attribute name>:<desription>
// <description> is used on the profile page
// <description> is used on the profile page
protected $_attributes_to_show = '';
protected $_attributes_to_show = '';
// Use the real password when a user is created
// Use the real password when a user is created
protected $_no_random_password = false;
protected $_no_random_password = false;
// Update password on every successfull login
// Update password on every successfull login
protected $_auto_update_password = false;
protected $_auto_update_password = false;
// Enable lost password recovery
// Enable lost password recovery
protected $_enable_lost_password_recovery = false;
protected $_enable_lost_password_recovery = false;
// enable Bulk Import
// enable Bulk Import
protected $_bulkimport_enabled = false;
protected $_bulkimport_enabled = false;
// AUTHCODE for Bulk Import. Bulk Import will only work, if this AUTHCODE is send as as get-parameter to bulkimport.php
// AUTHCODE for Bulk Import. Bulk Import will only work, if this AUTHCODE is send as as get-parameter to bulkimport.php
protected $_bulkimport_authcode = '';
protected $_bulkimport_authcode = '';
// generate a new AUTHCODE for Bulk Import
// generate a new AUTHCODE for Bulk Import
protected $_bulkimport_new_authcode = false;
protected $_bulkimport_new_authcode = false;
// Import members of these security groups (separated by semicolons)
// Import members of these security groups (separated by semicolons)
protected $_bulkimport_security_groups = '';
protected $_bulkimport_security_groups = '';
// name of Bulk Import User in Active Directory
// name of Bulk Import User in Active Directory
protected $_bulkimport_user = '';
protected $_bulkimport_user = '';
// password for Bulk Import User (will be stored encrypted)
// password for Bulk Import User (will be stored encrypted)
protected $_bulkimport_pwd = '';
protected $_bulkimport_pwd = '';
// use user disabling
// use user disabling
protected $_disable_users = false;
protected $_disable_users = false;
// use local (WordPress) password as fallback if authentication against AD fails
// use local (WordPress) password as fallback if authentication against AD fails
protected $_fallback_to_local_password = false;
protected $_fallback_to_local_password = false;
// show disabled and ADI user status on user list
// show disabled and ADI user status on user list
protected $_show_user_status = true;
protected $_show_user_status = true;
// Prevent email change by ADI Users (not for admins)
// Prevent email change by ADI Users (not for admins)
protected $_prevent_email_change = false;
protected $_prevent_email_change = false;
// protected $_sso_enabled = false; // TODO: for auto login/SSO feature, has to be added to _load_options(), admin.php etc.
// protected $_sso_enabled = false; // TODO: for auto login/SSO feature, has to be added to _load_options(), admin.php etc.
// All options and its types
// All options and its types
// Has to be static for static call of method uninstall()
// Has to be static for static call of method uninstall()
protected static $_all_options = array(
protected static $_all_options = array(
array('name' => 'AD_Integration_version', 'type' => 'string'),
array('name' => 'AD_Integration_version', 'type' => 'string'),
// Server
// Server
array('name' => 'AD_Integration_domain_controllers', 'type' => 'string'),
array('name' => 'AD_Integration_domain_controllers', 'type' => 'string'),
array('name' => 'AD_Integration_port', 'type' => 'int'),
array('name' => 'AD_Integration_port', 'type' => 'int'),
array('name' => 'AD_Integration_use_tls', 'type' => 'bool'),
array('name' => 'AD_Integration_use_tls', 'type' => 'bool'),
array('name' => 'AD_Integration_network_timeout', 'type' => 'integer'),
array('name' => 'AD_Integration_network_timeout', 'type' => 'integer'),
array('name' => 'AD_Integration_base_dn', 'type' => 'string'),
array('name' => 'AD_Integration_base_dn', 'type' => 'string'),
// User
// User
array('name' => 'AD_Integration_account_suffix', 'type' => 'string'),
array('name' => 'AD_Integration_account_suffix', 'type' => 'string'),
array('name' => 'AD_Integration_append_suffix_to_new_users', 'type' => 'bool'),
array('name' => 'AD_Integration_append_suffix_to_new_users', 'type' => 'bool'),
array('name' => 'AD_Integration_auto_create_user', 'type' => 'bool'),
array('name' => 'AD_Integration_auto_create_user', 'type' => 'bool'),
array('name' => 'AD_Integration_auto_update_user', 'type' => 'bool'),
array('name' => 'AD_Integration_auto_update_user', 'type' => 'bool'),
array('name' => 'AD_Integration_auto_update_description', 'type' => 'bool'),
array('name' => 'AD_Integration_auto_update_description', 'type' => 'bool'),
array('name' => 'AD_Integration_default_email_domain', 'type' => 'string'),
array('name' => 'AD_Integration_default_email_domain', 'type' => 'string'),
array('name' => 'AD_Integration_duplicate_email_prevention', 'type' => 'string'),
array('name' => 'AD_Integration_duplicate_email_prevention', 'type' => 'string'),
array('name' => 'AD_Integration_prevent_email_change', 'type' => 'bool'),
array('name' => 'AD_Integration_prevent_email_change', 'type' => 'bool'),
array('name' => 'AD_Integration_display_name', 'type' => 'string'),
array('name' => 'AD_Integration_display_name', 'type' => 'string'),
array('name' => 'AD_Integration_show_user_status', 'type' => 'bool'),
array('name' => 'AD_Integration_show_user_status', 'type' => 'bool'),
array('name' => 'AD_Integration_enable_password_change', 'type' => 'bool'),
array('name' => 'AD_Integration_enable_password_change', 'type' => 'bool'),
array('name' => 'AD_Integration_no_random_password', 'type' => 'bool'),
array('name' => 'AD_Integration_no_random_password', 'type' => 'bool'),
array('name' => 'AD_Integration_auto_update_password', 'type' => 'bool'),
array('name' => 'AD_Integration_auto_update_password', 'type' => 'bool'),
// Authorization
// Authorization
array('name' => 'AD_Integration_authorize_by_group', 'type' => 'bool'),
array('name' => 'AD_Integration_authorize_by_group', 'type' => 'bool'),
array('name' => 'AD_Integration_authorization_group', 'type' => 'string'),
array('name' => 'AD_Integration_authorization_group', 'type' => 'string'),
array('name' => 'AD_Integration_role_equivalent_groups', 'type' => 'string'),
array('name' => 'AD_Integration_role_equivalent_groups', 'type' => 'string'),
// Security
// Security
array('name' => 'AD_Integration_fallback_to_local_password', 'type' => 'bool'),
array('name' => 'AD_Integration_fallback_to_local_password', 'type' => 'bool'),
array('name' => 'AD_Integration_enable_lost_password_recovery', 'type' => 'bool'),
array('name' => 'AD_Integration_enable_lost_password_recovery', 'type' => 'bool'),
array('name' => 'AD_Integration_max_login_attempts', 'type' => 'int'),
array('name' => 'AD_Integration_max_login_attempts', 'type' => 'int'),
array('name' => 'AD_Integration_block_time', 'type' => 'int'),
array('name' => 'AD_Integration_block_time', 'type' => 'int'),
array('name' => 'AD_Integration_user_notification', 'type' => 'bool'),
array('name' => 'AD_Integration_user_notification', 'type' => 'bool'),
array('name' => 'AD_Integration_admin_notification', 'type' => 'bool'),
array('name' => 'AD_Integration_admin_notification', 'type' => 'bool'),
array('name' => 'AD_Integration_admin_email', 'type' => 'string'),
array('name' => 'AD_Integration_admin_email', 'type' => 'string'),
// User Meta
// User Meta
array('name' => 'AD_Integration_additional_user_attributes', 'type' => 'string'),
array('name' => 'AD_Integration_additional_user_attributes', 'type' => 'string'),
array('name' => 'AD_Integration_usermeta_empty_overwrite', 'type' => 'bool'),
array('name' => 'AD_Integration_usermeta_empty_overwrite', 'type' => 'bool'),
array('name' => 'AD_Integration_show_attributes', 'type' => 'bool'),
array('name' => 'AD_Integration_show_attributes', 'type' => 'bool'),
array('name' => 'AD_Integration_attributes_to_show', 'type' => 'bool'),
array('name' => 'AD_Integration_attributes_to_show', 'type' => 'bool'),
array('name' => 'AD_Integration_syncback', 'type' => 'bool'),
array('name' => 'AD_Integration_syncback', 'type' => 'bool'),
array('name' => 'AD_Integration_syncback_use_global_user', 'type' => 'bool'),
array('name' => 'AD_Integration_syncback_use_global_user', 'type' => 'bool'),
array('name' => 'AD_Integration_syncback_global_user', 'type' => 'string'),
array('name' => 'AD_Integration_syncback_global_user', 'type' => 'string'),
array('name' => 'AD_Integration_syncback_global_pwd', 'type' => 'string'),
array('name' => 'AD_Integration_syncback_global_pwd', 'type' => 'string'),
// Bulk Import
// Bulk Import
array('name' => 'AD_Integration_bulkimport_enabled', 'type' => 'bool'),
array('name' => 'AD_Integration_bulkimport_enabled', 'type' => 'bool'),
array('name' => 'AD_Integration_bulkimport_authcode', 'type' => 'string'),
array('name' => 'AD_Integration_bulkimport_authcode', 'type' => 'string'),
array('name' => 'AD_Integration_bulkimport_new_authcode', 'type' => 'bool'),
array('name' => 'AD_Integration_bulkimport_new_authcode', 'type' => 'bool'),
array('name' => 'AD_Integration_bulkimport_security_groups', 'type' => 'string'),
array('name' => 'AD_Integration_bulkimport_security_groups', 'type' => 'string'),
array('name' => 'AD_Integration_bulkimport_user', 'type' => 'string'),
array('name' => 'AD_Integration_bulkimport_user', 'type' => 'string'),
array('name' => 'AD_Integration_bulkimport_pwd', 'type' => 'string'),
array('name' => 'AD_Integration_bulkimport_pwd', 'type' => 'string'),
array('name' => 'AD_Integration_disable_users', 'type' => 'bool')
array('name' => 'AD_Integration_disable_users', 'type' => 'bool')
);
);
public $errors = false;
public $errors = false;
/**
/**
* Constructor
* Constructor
*/
*/
public function __construct() {
public function __construct() {
global $wp_version, $wpmu_version, $wpdb, $wpmuBaseTablePrefix;
global $wp_version, $wpmu_version, $wpdb, $wpmuBaseTablePrefix;
if (!defined('IS_WPMU')) {
if (!defined('IS_WPMU')) {
define('IS_WPMU', ($wpmu_version != ''));
define('IS_WPMU', ($wpmu_version != ''));
}
}
// define folder constant
// define folder constant
if (!defined('ADINTEGRATION_FOLDER')) {
if (!defined('ADINTEGRATION_FOLDER')) {
define('ADINTEGRATION_FOLDER', basename(dirname(__FILE__)));
define('ADINTEGRATION_FOLDER', basename(dirname(__FILE__)));
}
}
$this->setLogFile(dirname(__FILE__).'/adi.log');
$this->setLogFile(dirname(__FILE__).'/adi.log');
$this->errors = new WP_Error();
$this->errors = new WP_Error();
// Load Options
// Load Options
$this->_load_options();
$this->_load_options();
// Generate authcode if necessary
// Generate authcode if necessary
if (strlen($this->_bulkimport_authcode) < 20) {
if (strlen($this->_bulkimport_authcode) < 20) {
$this->_generate_authcode();
$this->_generate_authcode();
}
}
if (isset($_GET['activate']) and $_GET['activate'] == 'true') {
if (isset($_GET['activate']) and $_GET['activate'] == 'true') {
add_action('init', array(&$this, 'initialize_options'));
add_action('init', array(&$this, 'initialize_options'));
}
}
add_action('admin_init', array(&$this, 'register_adi_settings'));
add_action('admin_init', array(&$this, 'register_adi_settings'));
add_action('admin_menu', array(&$this, 'add_options_page'));
add_action('admin_menu', array(&$this, 'add_options_page'));
add_filter('contextual_help', array(&$this, 'contextual_help'), 10, 2);
add_filter('contextual_help', array(&$this, 'contextual_help'), 10, 2);
// DO WE HAVE LDAP SUPPORT?
// DO WE HAVE LDAP SUPPORT?
if (function_exists('ldap_connect')) {
if (function_exists('ldap_connect')) {
add_filter('authenticate', array(&$this, 'authenticate'), 10, 3);
add_filter('authenticate', array(&$this, 'authenticate'), 10, 3);
if (!$this->_enable_lost_password_recovery) {
if (!$this->_enable_lost_password_recovery) {
add_action('lost_password', array(&$this, 'disable_function'));
add_action('lost_password', array(&$this, 'disable_function'));
add_action('retrieve_password', array(&$this, 'disable_function'));
add_action('retrieve_password', array(&$this, 'disable_function'));
add_action('password_reset', array(&$this, 'disable_function'));
add_action('password_reset', array(&$this, 'disable_function'));
}
}
add_action('admin_print_styles', array(&$this, 'load_styles'));
add_action('admin_print_styles', array(&$this, 'load_styles'));
add_action('admin_print_scripts', array(&$this, 'load_scripts'));
add_action('admin_print_scripts', array(&$this, 'load_scripts'));
// Add new column to the user list
// Add new column to the user list
if ($this->_show_user_status) {
if ($this->_show_user_status) {
add_filter( 'manage_users_columns', array( &$this, 'manage_users_columns' ) );
add_filter( 'manage_users_columns', array( &$this, 'manage_users_columns' ) );
add_filter( 'manage_users_custom_column', array( &$this, 'manage_users_custom_column' ), 10, 3 );
add_filter( 'manage_users_custom_column', array( &$this, 'manage_users_custom_column' ), 10, 3 );
}
}
// actions for user disabling
// actions for user disabling
add_action('personal_options_update', array(&$this, 'profile_update_disable_user'));
add_action('personal_options_update', array(&$this, 'profile_update_disable_user'));
add_action('edit_user_profile_update', array(&$this, 'profile_update_disable_user'));
add_action('edit_user_profile_update', array(&$this, 'profile_update_disable_user'));
add_action('edit_user_profile', array(&$this, 'show_user_profile_disable_user'));
add_action('edit_user_profile', array(&$this, 'show_user_profile_disable_user'));
add_action('show_user_profile', array(&$this, 'show_user_profile_disable_user'));
add_action('show_user_profile', array(&$this, 'show_user_profile_disable_user'));
// Sync Back?
// Sync Back?
if ($this->_syncback === true) {
if ($this->_syncback === true) {
add_action('personal_options_update', array(&$this, 'profile_update'));
add_action('personal_options_update', array(&$this, 'profile_update'));
add_action('edit_user_profile_update', array(&$this, 'profile_update'));
add_action('edit_user_profile_update', array(&$this, 'profile_update'));
}
}
// TODO: auto_login feature must be tested
// TODO: auto_login feature must be tested
/*
/*
if ($this->_auto_login) {
if ($this->_auto_login) {
add_action('init', array(&$this, 'auto_login'));
add_action('init', array(&$this, 'auto_login'));
}
}
*/
*/
add_filter('check_password', array(&$this, 'override_password_check'), 10, 4);
add_filter('check_password', array(&$this, 'override_password_check'), 10, 4);
// Is local password change disallowed?
// Is local password change disallowed?
if (!$this->_enable_password_change) {
if (!$this->_enable_password_change) {
// disable password fields
// disable password fields
add_filter('show_password_fields', array(&$this, 'disable_password_fields'));
add_filter('show_password_fields', array(&$this, 'disable_password_fields'));
// generate a random password for manually added users
// generate a random password for manually added users
add_action('check_passwords', array(&$this, 'generate_password'), 10, 3);
add_action('check_passwords', array(&$this, 'generate_password'), 10, 3);
}
}
if (!class_exists('adLDAP')) {
if (!class_exists('adLDAP')) {
require 'ad_ldap/adLDAP.php';
require 'ad_ldap/adLDAP.php';
}
}
} else {
} else {
$this->_log(ADI_LOG_WARN,'openLDAP not installed or activated in PHP.');
$this->_log(ADI_LOG_WARN,'openLDAP not installed or activated in PHP.');
}
}
// Adding AD attributes to profile page
// Adding AD attributes to profile page
if ($this->_show_attributes) {
if ($this->_show_attributes) {
add_action( 'edit_user_profile', array(&$this, 'show_AD_attributes'));
add_action( 'edit_user_profile', array(&$this, 'show_AD_attributes'));
add_action( 'show_user_profile', array(&$this, 'show_AD_attributes'));
add_action( 'show_user_profile', array(&$this, 'show_AD_attributes'));
}
}
$this->_all_user_attributes = $this->_get_user_attributes();
$this->_all_user_attributes = $this->_get_user_attributes();
// Prevent email change
// Prevent email change
if ($this->_prevent_email_change) {
if ($this->_prevent_email_change) {
add_action( 'edit_user_profile', array(&$this, 'user_profile_prevent_email_change')); // cosmetic
add_action( 'edit_user_profile', array(&$this, 'user_profile_prevent_email_change')); // cosmetic
add_action( 'show_user_profile', array(&$this, 'user_profile_prevent_email_change')); // cosmetic
add_action( 'show_user_profile', array(&$this, 'user_profile_prevent_email_change')); // cosmetic
add_action( 'user_profile_update_errors', array(&$this, 'prevent_email_change'), 10, 3 ); // true prevention
add_action( 'user_profile_update_errors', array(&$this, 'prevent_email_change'), 10, 3 ); // true prevention
}
}
}
}
public function load_styles() {
public function load_styles() {
wp_register_style('adintegration', plugins_url('css/adintegration.css', __FILE__ ) ,false, '1.7.1', 'screen');
wp_register_style('adintegration', plugins_url('css/adintegration.css', __FILE__ ) ,false, '1.7.1', 'screen');
wp_enqueue_style('adintegration');
wp_enqueue_style('adintegration');
}
}
public function load_scripts() {
public function load_scripts() {
wp_enqueue_script('jquery-ui-tabs'); // this is a wp default script
wp_enqueue_script('jquery-ui-tabs'); // this is a wp default script
wp_enqueue_script('jquery-ui-dialog'); // this is a wp default script
wp_enqueue_script('jquery-ui-dialog'); // this is a wp default script
}
}
/*************************************************************
/*************************************************************
* Plugin hooks
* Plugin hooks
*************************************************************/
*************************************************************/
/**
/**
* Add options for this plugin to the database.
* Add options for this plugin to the database.
*/
*/
public function initialize_options() {
public function initialize_options() {
if (IS_WPMU) {
if (IS_WPMU) {
if (is_super_admin()) {
if (is_super_admin()) {
add_site_option('AD_Integration_account_suffix', '');
add_site_option('AD_Integration_account_suffix', '');
add_site_option('AD_Integration_auto_create_user', false);
add_site_option('AD_Integration_auto_create_user', false);
add_site_option('AD_Integration_auto_update_user', false);
add_site_option('AD_Integration_auto_update_user', false);
add_site_option('AD_Integration_append_suffix_to_new_users', false);
add_site_option('AD_Integration_append_suffix_to_new_users', false);
add_site_option('AD_Integration_domain_controllers', '');
add_site_option('AD_Integration_domain_controllers', '');
add_site_option('AD_Integration_base_dn', '');
add_site_option('AD_Integration_base_dn', '');
add_site_option('AD_Integration_role_equivalent_groups', '');
add_site_option('AD_Integration_role_equivalent_groups', '');
add_site_option('AD_Integration_default_email_domain', '');
add_site_option('AD_Integration_default_email_domain', '');
add_site_option('AD_Integration_port', '389');
add_site_option('AD_Integration_port', '389');
add_site_option('AD_Integration_use_tls', false);
add_site_option('AD_Integration_use_tls', false);
add_site_option('AD_Integration_network_timeout', 5);
add_site_option('AD_Integration_network_timeout', 5);
// User
// User
add_site_option('AD_Integration_authorize_by_group', false);
add_site_option('AD_Integration_authorize_by_group', false);
add_site_option('AD_Integration_authorization_group', '');
add_site_option('AD_Integration_authorization_group', '');
add_site_option('AD_Integration_display_name', '');
add_site_option('AD_Integration_display_name', '');
add_site_option('AD_Integration_enable_password_change', false);
add_site_option('AD_Integration_enable_password_change', false);
add_site_option('AD_Integration_duplicate_email_prevention', ADI_DUPLICATE_EMAIL_ADDRESS_PREVENT);
add_site_option('AD_Integration_duplicate_email_prevention', ADI_DUPLICATE_EMAIL_ADDRESS_PREVENT);
add_site_option('AD_Integration_prevent_email_change', false);
add_site_option('AD_Integration_prevent_email_change', false);
add_site_option('AD_Integration_auto_update_description', false);
add_site_option('AD_Integration_auto_update_description', false);
add_site_option('AD_Integration_show_user_status', false);
add_site_option('AD_Integration_show_user_status', false);
add_site_option('AD_Integration_show_attributes', false);
add_site_option('AD_Integration_show_attributes', false);
add_site_option('AD_Integration_attributes_to_show', '');
add_site_option('AD_Integration_attributes_to_show', '');
add_site_option('AD_Integration_additionl_user_attributes', '');
add_site_option('AD_Integration_additionl_user_attributes', '');
add_site_option('AD_Integration_usermeta_empty_overwrite', false);
add_site_option('AD_Integration_usermeta_empty_overwrite', false);
add_site_option('AD_Integration_no_random_password', false);
add_site_option('AD_Integration_no_random_password', false);
add_site_option('AD_Integration_auto_update_password', false);
add_site_option('AD_Integration_auto_update_password', false);
add_site_option('AD_Integration_max_login_attempts', '3');
add_site_option('AD_Integration_max_login_attempts', '3');
add_site_option('AD_Integration_block_time', '30');
add_site_option('AD_Integration_block_time', '30');
add_site_option('AD_Integration_user_notification', false);
add_site_option('AD_Integration_user_notification', false);
add_site_option('AD_Integration_admin_notification', false);
add_site_option('AD_Integration_admin_notification', false);
add_site_option('AD_Integration_admin_email', '');
add_site_option('AD_Integration_admin_email', '');
add_site_option('AD_Integration_disable_users', false);
add_site_option('AD_Integration_disable_users', false);
add_site_option('AD_Integration_fallback_to_local_password', false);
add_site_option('AD_Integration_fallback_to_local_password', false);
add_site_option('AD_Integration_enable_lost_password_recovery', false);
add_site_option('AD_Integration_enable_lost_password_recovery', false);
add_site_option('AD_Integration_syncback', false);
add_site_option('AD_Integration_syncback', false);
add_site_option('AD_Integration_syncback_use_global_user', false);
add_site_option('AD_Integration_syncback_use_global_user', false);
add_site_option('AD_Integration_syncback_global_user', '');
add_site_option('AD_Integration_syncback_global_user', '');
add_site_option('AD_Integration_syncback_global_pwd', '');
add_site_option('AD_Integration_syncback_global_pwd', '');
add_site_option('AD_Integration_bulkimport_enabled', false);
add_site_option('AD_Integration_bulkimport_enabled', false);
add_site_option('AD_Integration_bulkimport_authcode', '');
add_site_option('AD_Integration_bulkimport_authcode', '');
add_site_option('AD_Integration_bulkimport_new_authcode', false);
add_site_option('AD_Integration_bulkimport_new_authcode', false);
add_site_option('AD_Integration_bulkimport_security_groups', '');
add_site_option('AD_Integration_bulkimport_security_groups', '');
add_site_option('AD_Integration_bulkimport_user', '');
add_site_option('AD_Integration_bulkimport_user', '');
add_site_option('AD_Integration_bulkimport_pwd', '');
add_site_option('AD_Integration_bulkimport_pwd', '');
}
}
} else {
} else {
if (current_user_can('manage_options')) {
if (current_user_can('manage_options')) {
add_option('AD_Integration_account_suffix', '');
add_option('AD_Integration_account_suffix', '');
add_option('AD_Integration_auto_create_user', false);
add_option('AD_Integration_auto_create_user', false);
add_option('AD_Integration_auto_update_user', false);
add_option('AD_Integration_auto_update_user', false);
add_option('AD_Integration_append_suffix_to_new_users', false);
add_option('AD_Integration_append_suffix_to_new_users', false);
add_option('AD_Integration_domain_controllers', '');
add_option('AD_Integration_domain_controllers', '');
add_option('AD_Integration_base_dn', '');
add_option('AD_Integration_base_dn', '');
add_option('AD_Integration_role_equivalent_groups', '');
add_option('AD_Integration_role_equivalent_groups', '');
add_option('AD_Integration_default_email_domain', '');
add_option('AD_Integration_default_email_domain', '');
add_option('AD_Integration_port', '389');
add_option('AD_Integration_port', '389');
add_option('AD_Integration_use_tls', false);
add_option('AD_Integration_use_tls', false);
add_option('AD_Integration_network_timeout', 5);
add_option('AD_Integration_network_timeout', 5);
add_option('AD_Integration_authorize_by_group', false);
add_option('AD_Integration_authorize_by_group', false);
add_option('AD_Integration_authorization_group', '');
add_option('AD_Integration_authorization_group', '');
add_option('AD_Integration_display_name', '');
add_option('AD_Integration_display_name', '');
add_option('AD_Integration_enable_password_change', false);
add_option('AD_Integration_enable_password_change', false);
add_option('AD_Integration_duplicate_email_prevention', ADI_DUPLICATE_EMAIL_ADDRESS_PREVENT);
add_option('AD_Integration_duplicate_email_prevention', ADI_DUPLICATE_EMAIL_ADDRESS_PREVENT);
add_option('AD_Integration_prevent_email_change', false);
add_option('AD_Integration_prevent_email_change', false);
add_option('AD_Integration_auto_update_description', false);
add_option('AD_Integration_auto_update_description', false);
add_option('AD_Integration_show_user_status', false);
add_option('AD_Integration_show_user_status', false);
add_option('AD_Integration_show_attributes', false);
add_option('AD_Integration_show_attributes', false);
add_option('AD_Integration_attributes_to_show', '');
add_option('AD_Integration_attributes_to_show', '');
add_option('AD_Integration_additional_user_attributes', '');
add_option('AD_Integration_additional_user_attributes', '');
add_option('AD_Integration_usermeta_empty_overwrite', false);
add_option('AD_Integration_usermeta_empty_overwrite', false);
add_option('AD_Integration_no_random_password', false);
add_option('AD_Integration_no_random_password', false);
add_option('AD_Integration_auto_update_password', false);
add_option('AD_Integration_auto_update_password', false);
add_option('AD_Integration_max_login_attempts', '3');
add_option('AD_Integration_max_login_attempts', '3');
add_option('AD_Integration_block_time', '30');
add_option('AD_Integration_block_time', '30');
add_option('AD_Integration_user_notification', false);
add_option('AD_Integration_user_notification', false);
add_option('AD_Integration_admin_notification', false);
add_option('AD_Integration_admin_notification', false);
add_option('AD_Integration_admin_email', '');
add_option('AD_Integration_admin_email', '');
add_option('AD_Integration_disable_users', false);
add_option('AD_Integration_disable_users', false);
add_option('AD_Integration_fallback_to_local_password', false);
add_option('AD_Integration_fallback_to_local_password', false);
add_option('AD_Integration_enable_lost_password_recovery', false);
add_option('AD_Integration_enable_lost_password_recovery', false);
add_option('AD_Integration_syncback', false);
add_option('AD_Integration_syncback', false);
add_option('AD_Integration_syncback_use_global_user', false);
add_option('AD_Integration_syncback_use_global_user', false);
add_option('AD_Integration_syncback_global_user', '');
add_option('AD_Integration_syncback_global_user', '');
add_option('AD_Integration_syncback_global_pwd', '');
add_option('AD_Integration_syncback_global_pwd', '');
add_option('AD_Integration_bulkimport_enabled', false);
add_option('AD_Integration_bulkimport_enabled', false);
add_option('AD_Integration_bulkimport_authcode', '');
add_option('AD_Integration_bulkimport_authcode', '');
add_option('AD_Integration_bulkimport_new_authcode', false);
add_option('AD_Integration_bulkimport_new_authcode', false);
add_option('AD_Integration_bulkimport_security_groups', '');
add_option('AD_Integration_bulkimport_security_groups', '');
add_option('AD_Integration_bulkimport_user', '');
add_option('AD_Integration_bulkimport_user', '');
add_option('AD_Integration_bulkimport_pwd', '');
add_option('AD_Integration_bulkimport_pwd', '');
}
}
}
}
}
}
public function register_adi_settings()
public function register_adi_settings()
{
{
// Server
// Server
register_setting('ADI-server-settings', 'AD_Integration_domain_controllers');
register_setting('ADI-server-settings', 'AD_Integration_domain_controllers');
register_setting('ADI-server-settings', 'AD_Integration_port', array(&$this, 'sanitize_port'));
register_setting('ADI-server-settings', 'AD_Integration_port', array(&$this, 'sanitize_port'));
register_setting('ADI-server-settings', 'AD_Integration_use_tls', array(&$this, 'sanitize_bool'));
register_setting('ADI-server-settings', 'AD_Integration_use_tls', array(&$this, 'sanitize_bool'));
register_setting('ADI-server-settings', 'AD_Integration_base_dn');
register_setting('ADI-server-settings', 'AD_Integration_base_dn');
register_setting('ADI-server-settings', 'AD_Integration_network_timeout', array(&$this, 'sanitize_network_timeout'));
register_setting('ADI-server-settings', 'AD_Integration_network_timeout', array(&$this, 'sanitize_network_timeout'));
// User
// User
register_setting('ADI-user-settings', 'AD_Integration_auto_create_user', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_auto_create_user', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_auto_update_user', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_auto_update_user', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_auto_update_description', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_auto_update_description', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_default_email_domain', array(&$this, 'sanitize_default_email_domain'));
register_setting('ADI-user-settings', 'AD_Integration_default_email_domain', array(&$this, 'sanitize_default_email_domain'));
register_setting('ADI-user-settings', 'AD_Integration_account_suffix', array(&$this, 'sanitize_account_suffix'));
register_setting('ADI-user-settings', 'AD_Integration_account_suffix', array(&$this, 'sanitize_account_suffix'));
register_setting('ADI-user-settings', 'AD_Integration_append_suffix_to_new_users', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_append_suffix_to_new_users', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_display_name');
register_setting('ADI-user-settings', 'AD_Integration_display_name');
register_setting('ADI-user-settings', 'AD_Integration_enable_password_change', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_enable_password_change', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_duplicate_email_prevention');
register_setting('ADI-user-settings', 'AD_Integration_duplicate_email_prevention');
register_setting('ADI-user-settings', 'AD_Integration_prevent_email_change', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_prevent_email_change', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_no_random_password', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_no_random_password', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_auto_update_password', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_auto_update_password', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_show_user_status', array(&$this, 'sanitize_bool'));
register_setting('ADI-user-settings', 'AD_Integration_show_user_status', array(&$this, 'sanitize_bool'));
// Authorization
// Authorization
register_setting('ADI-auth-settings', 'AD_Integration_authorize_by_group', array(&$this, 'sanitize_bool'));
register_setting('ADI-auth-settings', 'AD_Integration_authorize_by_group', array(&$this, 'sanitize_bool'));
register_setting('ADI-auth-settings', 'AD_Integration_authorization_group');
register_setting('ADI-auth-settings', 'AD_Integration_authorization_group');
register_setting('ADI-auth-settings', 'AD_Integration_role_equivalent_groups', array(&$this, 'sanitize_role_equivalent_groups'));
register_setting('ADI-auth-settings', 'AD_Integration_role_equivalent_groups', array(&$this, 'sanitize_role_equivalent_groups'));
// Security
// Security
register_setting('ADI-security-settings', 'AD_Integration_fallback_to_local_password', array(&$this, 'sanitize_bool'));
register_setting('ADI-security-settings', 'AD_Integration_fallback_to_local_password', array(&$this, 'sanitize_bool'));
register_setting('ADI-security-settings', 'AD_Integration_enable_lost_password_recovery', array(&$this, 'sanitize_bool'));
register_setting('ADI-security-settings', 'AD_Integration_enable_lost_password_recovery', array(&$this, 'sanitize_bool'));
register_setting('ADI-security-settings', 'AD_Integration_max_login_attempts', array(&$this, 'sanitize_max_login_attempts'));
register_setting('ADI-security-settings', 'AD_Integration_max_login_attempts', array(&$this, 'sanitize_max_login_attempts'));
register_setting('ADI-security-settings', 'AD_Integration_block_time', array(&$this, 'sanitize_block_time'));
register_setting('ADI-security-settings', 'AD_Integration_block_time', array(&$this, 'sanitize_block_time'));
register_setting('ADI-security-settings', 'AD_Integration_user_notification', array(&$this, 'sanitize_bool'));
register_setting('ADI-security-settings', 'AD_Integration_user_notification', array(&$this, 'sanitize_bool'));
register_setting('ADI-security-settings', 'AD_Integration_admin_notification', array(&$this, 'sanitize_bool'));
register_setting('ADI-security-settings', 'AD_Integration_admin_notification', array(&$this, 'sanitize_bool'));
register_setting('ADI-security-settings',
register_setting('ADI-security-settings',