getEntityIDByDomain() 정적인 공개 메소드

static public getEntityIDByDomain ( $value )
$value
예제 #1
0
 /**
  * @see Rule::executeActions()
  **/
 function executeActions($output, $params)
 {
     if (count($this->actions)) {
         foreach ($this->actions as $action) {
             switch ($action->fields["action_type"]) {
                 case "assign":
                     switch ($action->fields["field"]) {
                         default:
                             $output[$action->fields["field"]] = $action->fields["value"];
                             break;
                         case "_affect_entity_by_user_entity":
                             //3 cases :
                             //1 - rule contains a criteria like : Profil is XXXX
                             //    -> in this case, profiles_id is stored in
                             //       $this->criterias_results['PROFILES'] (one value possible)
                             //2-   rule contains criteria "User has only one profile"
                             //    -> in this case, profiles_id is stored in
                             //       $this->criterias_results['PROFILES'] (one value possible) (same as 1)
                             //3   -> rule contains only one profile
                             $profile = 0;
                             //Case 2:
                             if (isset($this->criterias_results['ONE_PROFILE'])) {
                                 $profile = $this->criterias_results['ONE_PROFILE'];
                                 //Case 3
                             } else {
                                 if (isset($this->criterias_results['UNIQUE_PROFILE'])) {
                                     $profile = $this->criterias_results['UNIQUE_PROFILE'];
                                     //Case 1
                                 } else {
                                     if (isset($this->criterias_results['PROFILES'])) {
                                         $profile = $this->criterias_results['PROFILES'];
                                     }
                                 }
                             }
                             if ($profile) {
                                 $entities = array();
                                 if (isset($params['_users_id_requester'])) {
                                     // Not set when testing
                                     $entities = Profile_User::getEntitiesForProfileByUser($params['_users_id_requester'], $profile);
                                 }
                                 //Case 2 : check if there's only one profile for this user
                                 if (isset($this->criterias_results['ONE_PROFILE']) && count($entities) == 1 || !isset($this->criterias_results['ONE_PROFILE'])) {
                                     if (count($entities) == 1) {
                                         //User has right on only one entity
                                         $output['entities_id'] = array_pop($entities);
                                     } else {
                                         if (isset($this->criterias_results['UNIQUE_PROFILE'])) {
                                             $output['entities_id'] = array_pop($entities);
                                         } else {
                                             //Rights on more than one entity : get the user's prefered entity
                                             if (isset($params['_users_id_requester'])) {
                                                 // Not set when testing
                                                 $user = new User();
                                                 $user->getFromDB($params['_users_id_requester']);
                                                 $tmpid = $user->getField('entities_id');
                                                 // Retrieve all the entities (pref could be set on a child)
                                                 $entities = Profile_User::getEntitiesForProfileByUser($params['_users_id_requester'], $profile, true);
                                                 // If an entity is defined in user's preferences,
                                                 // and this entity allowed for this profile, use this one
                                                 // else do not set the rule as matched
                                                 if (in_array($tmpid, $entities)) {
                                                     $output['entities_id'] = $user->fields['entities_id'];
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                     }
                     break;
                 case "regex_result":
                     foreach ($this->regex_results as $regex_result) {
                         $entity_found = -1;
                         $res = RuleAction::getRegexResultById($action->fields["value"], $regex_result);
                         if ($res != null) {
                             switch ($action->fields["field"]) {
                                 case "_affect_entity_by_domain":
                                     $entity_found = Entity::getEntityIDByDomain(addslashes($res));
                                     break;
                                 case "_affect_entity_by_tag":
                                     $entity_found = Entity::getEntityIDByTag(addslashes($res));
                                     break;
                             }
                             //If an entity was found
                             if ($entity_found > -1) {
                                 $output['entities_id'] = $entity_found;
                                 break;
                             }
                         }
                     }
                     // switch (field)
                     break;
             }
         }
     }
     return $output;
 }
예제 #2
0
 /**
  * Execute the actions as defined in the rule
  *
  * @see Rule::executeActions()
  *
  * @param $output the result of the actions
  * @param $params the parameters
  *
  * @return the fields modified
  **/
 function executeActions($output, $params)
 {
     global $CFG_GLPI;
     $entity = '';
     $right = '';
     $is_recursive = 0;
     $continue = true;
     $output_src = $output;
     if (count($this->actions)) {
         $entity = array();
         foreach ($this->actions as $action) {
             switch ($action->fields["action_type"]) {
                 case "assign":
                     switch ($action->fields["field"]) {
                         case "entities_id":
                             $entity[] = $action->fields["value"];
                             break;
                         case "profiles_id":
                             $right = $action->fields["value"];
                             break;
                         case "is_recursive":
                             $is_recursive = $action->fields["value"];
                             break;
                         case "is_active":
                             $output["is_active"] = $action->fields["value"];
                             break;
                         case "_ignore_user_import":
                             $continue = false;
                             $output_src["_stop_import"] = true;
                             break;
                     }
                     // switch (field)
                     break;
                 case "regex_result":
                     switch ($action->fields["field"]) {
                         case "_affect_entity_by_dn":
                         case "_affect_entity_by_tag":
                         case "_affect_entity_by_domain":
                         case "_affect_entity_by_completename":
                             foreach ($this->regex_results as $regex_result) {
                                 $res = RuleAction::getRegexResultById($action->fields["value"], $regex_result);
                                 if ($res != null) {
                                     switch ($action->fields["field"]) {
                                         case "_affect_entity_by_dn":
                                             $entity_found = Entity::getEntityIDByDN(addslashes($res));
                                             break;
                                         case "_affect_entity_by_tag":
                                             $entity_found = Entity::getEntityIDByTag(addslashes($res));
                                             break;
                                         case "_affect_entity_by_domain":
                                             $entity_found = Entity::getEntityIDByDomain(addslashes($res));
                                             break;
                                         case "_affect_entity_by_completename":
                                             $res = Toolbox::unclean_cross_side_scripting_deep($res);
                                             $entity_found = Entity::getEntityIDByCompletename(addslashes($res));
                                             break;
                                         default:
                                             $entity_found = -1;
                                             break;
                                     }
                                     //If an entity was found
                                     if ($entity_found > -1) {
                                         $entity[] = $entity_found;
                                     }
                                 }
                             }
                             if (!count($entity)) {
                                 //Not entity assigned : action processing must be stopped for this rule
                                 $continue = false;
                             }
                             break;
                     }
                     // switch (field)
                     break;
             }
             // switch (action_type)
         }
         // foreach (action)
     }
     // count (actions)
     if ($continue) {
         //Nothing to be returned by the function :
         //Store in session the entity and/or right
         if (count($entity)) {
             if ($right != '') {
                 foreach ($entity as $entID) {
                     $output["_ldap_rules"]["rules_entities_rights"][] = array($entID, $right, $is_recursive);
                 }
             } else {
                 foreach ($entity as $entID) {
                     $output["_ldap_rules"]["rules_entities"][] = array($entID, $is_recursive);
                 }
             }
         } else {
             if ($right != '') {
                 $output["_ldap_rules"]["rules_rights"][] = $right;
             }
         }
         return $output;
     }
     return $output_src;
 }
 /**
  * @see RuleCollection::prepareInputDataForProcess()
  **/
 function prepareInputDataForProcess($input, $params)
 {
     $input['mailcollector'] = $params['mailcollector'];
     $input['_users_id_requester'] = $params['_users_id_requester'];
     $fields = $this->getFieldsToLookFor();
     //Add needed ticket datas for rules processing
     if (isset($params['ticket']) && is_array($params['ticket'])) {
         foreach ($params['ticket'] as $key => $value) {
             if (in_array($key, $fields) && !isset($input[$key])) {
                 $input[$key] = $value;
             }
         }
     }
     //Add needed headers for rules processing
     if (isset($params['headers']) && is_array($params['headers'])) {
         foreach ($params['headers'] as $key => $value) {
             if (in_array($key, $fields) && !isset($input[$key])) {
                 $input[$key] = $value;
             }
         }
     }
     //Add all user's groups
     if (in_array('groups', $fields)) {
         foreach (Group_User::getUserGroups($input['_users_id_requester']) as $group) {
             $input['GROUPS'][] = $group['id'];
         }
     }
     //Add all user's profiles
     if (in_array('profiles', $fields)) {
         foreach (Profile_User::getForUser($input['_users_id_requester']) as $profile) {
             $input['PROFILES'][$profile['profiles_id']] = $profile['profiles_id'];
         }
     }
     //If the criteria is "user has only one time the profile xxx"
     if (in_array('unique_profile', $fields)) {
         //Get all profiles
         $profiles = Profile_User::getForUser($input['_users_id_requester']);
         foreach ($profiles as $profile) {
             if (Profile_User::haveUniqueRight($input['_users_id_requester'], $profile['profiles_id'])) {
                 $input['UNIQUE_PROFILE'][$profile['profiles_id']] = $profile['profiles_id'];
             }
         }
     }
     //Store the number of profiles of which the user belongs to
     if (in_array('one_profile', $fields)) {
         $profiles = Profile_User::getForUser($input['_users_id_requester']);
         if (count($profiles) == 1) {
             $tmp = array_pop($profiles);
             $input['ONE_PROFILE'] = $tmp['profiles_id'];
         }
     }
     //Store the number of profiles of which the user belongs to
     if (in_array('known_domain', $fields)) {
         if (preg_match("/@(.*)/", $input['from'], $results)) {
             if (Entity::getEntityIDByDomain($results[1]) != -1) {
                 $input['KNOWN_DOMAIN'] = 1;
             } else {
                 $input['KNOWN_DOMAIN'] = 0;
             }
         }
     }
     return $input;
 }