Exemplo n.º 1
0
 /**
  * Execute the actions as defined in the rule
  * @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)) {
         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":
                             $match_entity = false;
                             $entity = array();
                             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 = EntityData::getEntityIDByDN($res);
                                             break;
                                         case "_affect_entity_by_tag":
                                             $entity_found = EntityData::getEntityIDByTag($res);
                                             break;
                                         case "_affect_entity_by_domain":
                                             $entity_found = EntityData::getEntityIDByDomain($res);
                                             break;
                                         default:
                                             $entity_found = -1;
                                             break;
                                     }
                                     //If an entity was found
                                     if ($entity_found > -1) {
                                         array_push($entity, array($entity_found, $is_recursive));
                                         $match_entity = true;
                                     }
                                 }
                             }
                             if (!$match_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 ($entity != '' && $right != '') {
             $output["_ldap_rules"]["rules_entities_rights"][] = array($entity, $right, $is_recursive);
         } else {
             if ($entity != '') {
                 if (!is_array($entity)) {
                     $entities_array = array($entity, $is_recursive);
                     $output["_ldap_rules"]["rules_entities"][] = array($entities_array);
                     //If it comes from a regex with multiple results
                 } else {
                     $output["_ldap_rules"]["rules_entities"][] = $entity;
                 }
             } else {
                 if ($right != '') {
                     $output["_ldap_rules"]["rules_rights"][] = $right;
                 }
             }
         }
         return $output;
     }
     return $output_src;
 }