Пример #1
0
 /**
  * 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;
         }
     }
 }
Пример #2
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);
 }