* 1.2 16 Nov 2012 added support for nested groups * 1.2.1 18 Nov 2012 improved for LDAP directories with mixed case attributes names (i.e. sAMMAccountName) * and values (i.e. username=JDoe) * 1.3 07 March 2013 also work when authentication is LDAP and not CAS */ define('CLI_SCRIPT', true); require dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php'; require dirname(dirname(__FILE__)) . '/locallib.php'; // Ensure errors are well explained $CFG->debug = DEBUG_NORMAL; if (!is_enabled_auth('cas') && !is_enabled_auth('ldap')) { error_log('[AUTH CAS] ' . get_string('pluginnotenabled', 'auth_ldap')); die; } $starttime = microtime(); $plugin = new auth_plugin_cohort(); $ldap_groups = $plugin->ldap_get_grouplist(); if ($CFG->debug_ldap_groupes) { pp_print_object('plugin group names cache ', $plugin->groups_dn_cache); } foreach ($ldap_groups as $group => $groupname) { print "processing LDAP group " . $groupname . PHP_EOL; $params = array('idnumber' => $groupname); // not that we search for cohort IDNUMBER and not name for a match // thus it we do not autocreate cohorts, admin MUST create cohorts beforehand // and set their IDNUMBER to the exact value of the corresponding attribute in LDAP if (!($cohort = $DB->get_record('cohort', $params, '*'))) { if (empty($plugin->config->cohort_synching_ldap_groups_autocreate_cohorts)) { print "ignoring {$groupname} that does not exist in Moodle (autocreation is off)" . PHP_EOL; continue; }
*/ /** * REVISIONS * 1.0 08 March 2013 initial release based on code synchying cohorts with LDAP groups */ define('CLI_SCRIPT', true); require dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php'; require dirname(dirname(__FILE__)) . '/locallib.php'; // Ensure errors are well explained $CFG->debug = DEBUG_NORMAL; if (!is_enabled_auth('cas') && !is_enabled_auth('ldap')) { error_log('[AUTH CAS] ' . get_string('pluginnotenabled', 'auth_ldap')); die; } $starttime = microtime(); $plugin = new auth_plugin_cohort(); $cohort_names = $plugin->get_attribute_distinct_values(); if ($CFG->debug_ldap_groupes) { pp_print_object("cohort idnumbers", $cohort_names); } foreach ($cohort_names as $n => $cohortname) { print "processing cohort " . $cohortname . PHP_EOL; $params = array('idnumber' => $cohortname); // not that we search for cohort IDNUMBER and not name for a match // thus it we do not autocreate cohorts, admin MUST create cohorts beforehand // and set their IDNUMBER to the exact value of the corresponding attribute in LDAP if (!($cohort = $DB->get_record('cohort', $params, '*'))) { if (empty($plugin->config->cohort_synching_ldap_attribute_autocreate_cohorts)) { print "ignoring {$cohortname} that does not exist in Moodle (autocreation is off)" . PHP_EOL; continue; }