/** * Constructor for the plugin. In addition to calling the parent * constructor, we define and 'fix' some settings depending on the * real settings the admin defined. */ public function __construct() { global $CFG; require_once $CFG->libdir . '/ldaplib.php'; // Do our own stuff to fix the config (it's easier to do it // here than using the admin settings infrastructure). We // don't call $this->set_config() for any of the 'fixups' // (except the objectclass, as it's critical) because the user // didn't specify any values and relied on the default values // defined for the user type she chose. $this->load_config(); // Make sure we get sane defaults for critical values. $this->config->ldapencoding = $this->get_config('ldapencoding', 'utf-8'); $this->config->user_type = $this->get_config('user_type', 'default'); $ldap_usertypes = ldap_supported_usertypes(); $this->config->user_type_name = $ldap_usertypes[$this->config->user_type]; unset($ldap_usertypes); $default = ldap_getdefaults(); // Remove the objectclass default, as the values specified there are for // users, and we are dealing with groups here. unset($default['objectclass']); // Use defaults if values not given. Dont use this->get_config() // here to be able to check for 0 and false values too. foreach ($default as $key => $value) { // Watch out - 0, false are correct values too, so we can't use $this->get_config() if (!isset($this->config->{$key}) or $this->config->{$key} == '') { $this->config->{$key} = $value[$this->config->user_type]; } } if (empty($this->config->objectclass)) { // Can't send empty filter. Fix it for now and future occasions $this->set_config('objectclass', '(objectClass=*)'); } else { if (stripos($this->config->objectclass, 'objectClass=') === 0) { // Value is 'objectClass=some-string-here', so just add () // around the value (filter _must_ have them). // Fix it for now and future occasions $this->set_config('objectclass', '(' . $this->config->objectclass . ')'); } else { if (stripos($this->config->objectclass, '(') !== 0) { // Value is 'some-string-not-starting-with-left-parentheses', // which is assumed to be the objectClass matching value. // So build a valid filter with it. $this->set_config('objectclass', '(objectClass=' . $this->config->objectclass . ')'); } else { // There is an additional possible value // '(some-string-here)', that can be used to specify any // valid filter string, to select subsets of users based // on any criteria. For example, we could select the users // whose objectClass is 'user' and have the // 'enabledMoodleUser' attribute, with something like: // // (&(objectClass=user)(enabledMoodleUser=1)) // // In this particular case we don't need to do anything, // so leave $this->config->objectclass as is. } } } }
/** * Init plugin config from database settings depending on the plugin auth type. */ function init_plugin($authtype) { $this->pluginconfig = 'auth/' . $authtype; $this->config = get_config($this->pluginconfig); if (empty($this->config->ldapencoding)) { $this->config->ldapencoding = 'utf-8'; } if (empty($this->config->user_type)) { $this->config->user_type = 'default'; } $ldap_usertypes = ldap_supported_usertypes(); $this->config->user_type_name = $ldap_usertypes[$this->config->user_type]; unset($ldap_usertypes); $default = ldap_getdefaults(); // Use defaults if values not given foreach ($default as $key => $value) { // watch out - 0, false are correct values too if (!isset($this->config->{$key}) or $this->config->{$key} == '') { $this->config->{$key} = $value[$this->config->user_type]; } } // Hack prefix to objectclass if (empty($this->config->objectclass)) { // Can't send empty filter $this->config->objectclass = '(objectClass=*)'; } else { if (stripos($this->config->objectclass, 'objectClass=') === 0) { // Value is 'objectClass=some-string-here', so just add () // around the value (filter _must_ have them). $this->config->objectclass = '(' . $this->config->objectclass . ')'; } else { if (strpos($this->config->objectclass, '(') !== 0) { // Value is 'some-string-not-starting-with-left-parentheses', // which is assumed to be the objectClass matching value. // So build a valid filter with it. $this->config->objectclass = '(objectClass=' . $this->config->objectclass . ')'; } else { // There is an additional possible value // '(some-string-here)', that can be used to specify any // valid filter string, to select subsets of users based // on any criteria. For example, we could select the users // whose objectClass is 'user' and have the // 'enabledMoodleUser' attribute, with something like: // // (&(objectClass=user)(enabledMoodleUser=1)) // // In this particular case we don't need to do anything, // so leave $this->config->objectclass as is. } } } }
/** * Constructor for the plugin. In addition to calling the parent * constructor, we define and 'fix' some settings depending on the * real settings the admin defined. */ public function __construct() { global $CFG; require_once $CFG->libdir . '/ldaplib.php'; // Do our own stuff to fix the config (it's easier to do it // here than using the admin settings infrastructure). We // don't call $this->set_config() for any of the 'fixups' // (except the objectclass, as it's critical) because the user // didn't specify any values and relied on the default values // defined for the user type she chose. $this->load_config(); // Make sure we get sane defaults for critical values. $this->config->ldapencoding = $this->get_config('ldapencoding', 'utf-8'); $this->config->user_type = $this->get_config('user_type', 'default'); $ldap_usertypes = ldap_supported_usertypes(); $this->config->user_type_name = $ldap_usertypes[$this->config->user_type]; unset($ldap_usertypes); $default = ldap_getdefaults(); // The objectclass in the defaults is for a user. // This will be required later, but enrol_ldap uses 'objectclass' for its group objectclass. // Save the normalised user objectclass for later. $this->userobjectclass = ldap_normalise_objectclass($default['objectclass'][$this->get_config('user_type')]); // Remove the objectclass default, as the values specified there are for users, and we are dealing with groups here. unset($default['objectclass']); // Use defaults if values not given. Dont use this->get_config() // here to be able to check for 0 and false values too. foreach ($default as $key => $value) { // Watch out - 0, false are correct values too, so we can't use $this->get_config() if (!isset($this->config->{$key}) or $this->config->{$key} == '') { $this->config->{$key} = $value[$this->config->user_type]; } } // Normalise the objectclass used for groups. if (empty($this->config->objectclass)) { // No objectclass set yet - set a default class. $this->config->objectclass = ldap_normalise_objectclass(null, '*'); $this->set_config('objectclass', $this->config->objectclass); } else { $objectclass = ldap_normalise_objectclass($this->config->objectclass); if ($objectclass !== $this->config->objectclass) { // The objectclass was changed during normalisation. // Save it in config, and update the local copy of config. $this->set_config('objectclass', $objectclass); $this->config->objectclass = $objectclass; } } }
$settings->add(new admin_setting_heading('enrol_ldap_bind_settings', get_string('bind_settings', 'enrol_ldap'), '')); $settings->add(new admin_setting_configtext_trim_lower('enrol_ldap/bind_dn', get_string('bind_dn_key', 'enrol_ldap'), get_string('bind_dn', 'enrol_ldap'), '')); $settings->add(new admin_setting_configpasswordunmask('enrol_ldap/bind_pw', get_string('bind_pw_key', 'enrol_ldap'), get_string('bind_pw', 'enrol_ldap'), '')); //--- role mapping settings --- $settings->add(new admin_setting_heading('enrol_ldap_roles', get_string('roles', 'enrol_ldap'), '')); if (!during_initial_install()) { $settings->add(new admin_setting_ldap_rolemapping('enrol_ldap/role_mapping', get_string('role_mapping_key', 'enrol_ldap'), get_string('role_mapping', 'enrol_ldap'), '')); } $options = $yesno; $settings->add(new admin_setting_configselect('enrol_ldap/course_search_sub', get_string('course_search_sub_key', 'enrol_ldap'), get_string('course_search_sub', 'enrol_ldap'), 0, $options)); $options = $yesno; $settings->add(new admin_setting_configselect('enrol_ldap/memberattribute_isdn', get_string('memberattribute_isdn_key', 'enrol_ldap'), get_string('memberattribute_isdn', 'enrol_ldap'), 0, $options)); $settings->add(new admin_setting_configtext_trim_lower('enrol_ldap/user_contexts', get_string('user_contexts_key', 'enrol_ldap'), get_string('user_contexts', 'enrol_ldap'), '')); $options = $yesno; $settings->add(new admin_setting_configselect('enrol_ldap/user_search_sub', get_string('user_search_sub_key', 'enrol_ldap'), get_string('user_search_sub', 'enrol_ldap'), 0, $options)); $options = ldap_supported_usertypes(); $settings->add(new admin_setting_configselect('enrol_ldap/user_type', get_string('user_type_key', 'enrol_ldap'), get_string('user_type', 'enrol_ldap'), 'default', $options)); $options = array(); $options[LDAP_DEREF_NEVER] = get_string('no'); $options[LDAP_DEREF_ALWAYS] = get_string('yes'); $settings->add(new admin_setting_configselect('enrol_ldap/opt_deref', get_string('opt_deref_key', 'enrol_ldap'), get_string('opt_deref', 'enrol_ldap'), 0, $options)); $settings->add(new admin_setting_configtext_trim_lower('enrol_ldap/idnumber_attribute', get_string('idnumber_attribute_key', 'enrol_ldap'), get_string('idnumber_attribute', 'enrol_ldap'), '', true, true)); //--- course mapping settings --- $settings->add(new admin_setting_heading('enrol_ldap_course_settings', get_string('course_settings', 'enrol_ldap'), '')); $settings->add(new admin_setting_configtext_trim_lower('enrol_ldap/objectclass', get_string('objectclass_key', 'enrol_ldap'), get_string('objectclass', 'enrol_ldap'), '')); $settings->add(new admin_setting_configtext_trim_lower('enrol_ldap/course_idnumber', get_string('course_idnumber_key', 'enrol_ldap'), get_string('course_idnumber', 'enrol_ldap'), '', true, true)); $coursefields = array('shortname', 'fullname', 'summary'); foreach ($coursefields as $field) { $settings->add(new admin_setting_configtext_trim_lower('enrol_ldap/course_' . $field, get_string('course_' . $field . '_key', 'enrol_ldap'), get_string('course_' . $field, 'enrol_ldap'), '', true, true)); } $settings->add(new admin_setting_configcheckbox('enrol_ldap/ignorehiddencourses', get_string('ignorehiddencourses', 'enrol_database'), get_string('ignorehiddencourses_desc', 'enrol_database'), 0));
/** * Init plugin config from database settings depending on the plugin auth type. */ function init_plugin($authtype) { $this->pluginconfig = 'auth/' . $authtype; $this->config = get_config($this->pluginconfig); if (empty($this->config->ldapencoding)) { $this->config->ldapencoding = 'utf-8'; } if (empty($this->config->user_type)) { $this->config->user_type = 'default'; } $ldap_usertypes = ldap_supported_usertypes(); $this->config->user_type_name = $ldap_usertypes[$this->config->user_type]; unset($ldap_usertypes); $default = ldap_getdefaults(); // Use defaults if values not given foreach ($default as $key => $value) { // watch out - 0, false are correct values too if (!isset($this->config->{$key}) or $this->config->{$key} == '') { $this->config->{$key} = $value[$this->config->user_type]; } } // Hack prefix to objectclass $this->config->objectclass = ldap_normalise_objectclass($this->config->objectclass); }