예제 #1
0
 /**
  * Function that try to load from the SSO server the user information...
  *
  * @since version 0.84
  **/
 function getFromSSO()
 {
     global $DB, $CFG_GLPI;
     $a_field = array();
     foreach ($CFG_GLPI as $key => $value) {
         if (!is_array($value) && !empty($value) && strstr($key, "_ssofield")) {
             $key = str_replace('_ssofield', '', $key);
             $a_field[$key] = $value;
         }
     }
     if (count($a_field) == 0) {
         return true;
     }
     $this->fields['_ruleright_process'] = true;
     foreach ($a_field as $field => $value) {
         if (!isset($_SERVER[$value]) || empty($_SERVER[$value])) {
             switch ($field) {
                 case "title":
                     $this->fields['usertitles_id'] = 0;
                     break;
                 case "category":
                     $this->fields['usercategories_id'] = 0;
                     break;
                 default:
                     $this->fields[$field] = "";
             }
         } else {
             switch ($field) {
                 case "email1":
                 case "email2":
                 case "email3":
                 case "email4":
                     // Manage multivaluable fields
                     if (!preg_match('/count/', $_SERVER[$value])) {
                         $this->fields["_emails"][] = addslashes($_SERVER[$value]);
                     }
                     // Only get them once if duplicated
                     $this->fields["_emails"] = array_unique($this->fields["_emails"]);
                     break;
                 case "language":
                     $language = Config::getLanguage($_SERVER[$value]);
                     if ($language != '') {
                         $this->fields[$field] = $language;
                     }
                     break;
                 case "title":
                     $this->fields['usertitles_id'] = Dropdown::importExternal('UserTitle', addslashes($_SERVER[$value]));
                     break;
                 case "category":
                     $this->fields['usercategories_id'] = Dropdown::importExternal('UserCategory', addslashes($_SERVER[$value]));
                     break;
                 default:
                     $this->fields[$field] = $_SERVER[$value];
                     break;
             }
         }
     }
     ///Only process rules if working on the master database
     if (!$DB->isSlave()) {
         //Instanciate the affectation's rule
         $rule = new RuleRightCollection();
         $this->fields = $rule->processAllRules(array(), Toolbox::stripslashes_deep($this->fields), array('type' => 'SSO', 'email' => $this->fields["_emails"], 'login' => $this->fields["name"]));
         //If rule  action is ignore import
         if (isset($this->fields["_stop_import"])) {
             return false;
         }
     }
     return true;
 }
예제 #2
0
 /**
  * Function that try to load from IMAP the user information...
  *
  * @param $mail_method mail method description array
  * @param $name login of the user
  **/
 function getFromIMAP($mail_method, $name)
 {
     global $DB;
     // we prevent some delay..
     if (empty($mail_method["host"])) {
         return false;
     }
     // some defaults...
     $this->fields['password'] = "";
     if (strpos($name, "@")) {
         $this->fields['email'] = $name;
     } else {
         $this->fields['email'] = $name . "@" . $mail_method["host"];
     }
     $this->fields['name'] = $name;
     //Store date_sync
     $this->fields['date_sync'] = $_SESSION['glpi_currenttime'];
     if (!$DB->isSlave()) {
         //Instanciate the affectation's rule
         $rule = new RuleRightCollection();
         //Process affectation rules :
         //we don't care about the function's return because all the datas are stored in session temporary
         if (isset($this->fields["_groups"])) {
             $groups = $this->fields["_groups"];
         } else {
             $groups = array();
         }
         $this->fields = $rule->processAllRules($groups, $this->fields, array('type' => 'MAIL', 'mail_server' => $mail_method["id"], 'email' => $this->fields["email"]));
         $this->fields['_ruleright_process'] = true;
     }
     return true;
 }