/** * @param $output * @param $params **/ function executeActions($output, $params) { if (count($this->actions)) { foreach ($this->actions as $action) { switch ($action->fields["action_type"]) { case "send": $ticket = new Ticket(); if ($ticket->getFromDB($output['id'])) { NotificationEvent::raiseEvent('recall', $ticket); } break; case "add_validation": if (isset($output['_add_validation']) && !is_array($output['_add_validation'])) { $output['_add_validation'] = array($output['_add_validation']); } switch ($action->fields['field']) { case 'users_id_validate_requester_supervisor': $output['_add_validation'][] = 'requester_supervisor'; break; case 'users_id_validate_assign_supervisor': $output['_add_validation'][] = 'assign_supervisor'; break; case 'groups_id_validate': $output['_add_validation']['group'][] = $action->fields["value"]; break; case 'users_id_validate': $output['_add_validation'][] = $action->fields["value"]; break; case 'validation_percent': $output[$action->fields["field"]] = $action->fields["value"]; break; default: $output['_add_validation'][] = $action->fields["value"]; break; } break; case "assign": $output[$action->fields["field"]] = $action->fields["value"]; // Special case of users_id_requester if ($action->fields["field"] === '_users_id_requester') { // Add groups of requester if (!isset($output['_groups_id_of_requester'])) { $output['_groups_id_of_requester'] = array(); } foreach (Group_User::getUserGroups($action->fields["value"]) as $g) { $output['_groups_id_of_requester'][$g['id']] = $g['id']; } } break; case "append": $actions = $this->getActions(); $value = $action->fields["value"]; if (isset($actions[$action->fields["field"]]["appendtoarray"]) && isset($actions[$action->fields["field"]]["appendtoarrayfield"])) { $value = $actions[$action->fields["field"]]["appendtoarray"]; $value[$actions[$action->fields["field"]]["appendtoarrayfield"]] = $action->fields["value"]; } $output[$actions[$action->fields["field"]]["appendto"]][] = $value; // Special case of users_id_requester if ($action->fields["field"] === '_users_id_requester') { // Add groups of requester if (!isset($output['_groups_id_of_requester'])) { $output['_groups_id_of_requester'] = array(); } foreach (Group_User::getUserGroups($action->fields["value"]) as $g) { $output['_groups_id_of_requester'][$g['id']] = $g['id']; } } break; case 'fromuser': if ($action->fields['field'] == 'locations_id' && isset($output['users_locations'])) { $output['locations_id'] = $output['users_locations']; } break; case 'fromitem': if ($action->fields['field'] == 'locations_id' && isset($output['items_locations'])) { $output['locations_id'] = $output['items_locations']; } if ($action->fields['field'] == 'groups_id' && isset($output['items_groups'])) { $output['groups_id'] = $output['items_groups']; } break; case 'compute': // Value could be not set (from test) $urgency = isset($output['urgency']) ? $output['urgency'] : 3; $impact = isset($output['impact']) ? $output['impact'] : 3; // Apply priority_matrix from config $output['priority'] = Ticket::computePriority($urgency, $impact); break; case "affectbyip": case "affectbyfqdn": case "affectbymac": if (!isset($output["entities_id"])) { $output["entities_id"] = $params["entities_id"]; } if (isset($this->regex_results[0])) { $regexvalue = RuleAction::getRegexResultById($action->fields["value"], $this->regex_results[0]); } else { $regexvalue = $action->fields["value"]; } switch ($action->fields["action_type"]) { case "affectbyip": $result = IPAddress::getUniqueItemByIPAddress($regexvalue, $output["entities_id"]); break; case "affectbyfqdn": $result = FQDNLabel::getUniqueItemByFQDN($regexvalue, $output["entities_id"]); break; case "affectbymac": $result = NetworkPortInstantiation::getUniqueItemByMac($regexvalue, $output["entities_id"]); break; default: $result = array(); } if (!empty($result)) { $output["items_id"][$result["itemtype"]][] = $result["id"]; } break; } } } return $output; }
/** * Get the full name (internet name) of a NetworkName * * @param $ID ID of the NetworkName * * @return its internet name, or empty string if invalid NetworkName **/ static function getInternetNameFromID($ID) { $networkName = new self(); if ($networkName->can($ID, READ)) { return FQDNLabel::getInternetNameFromLabelAndDomainID($this->fields["name"], $this->fields["fqdns_id"]); } return ""; }
function getSearchOptions() { $tab = parent::getSearchOptions(); $tab[12]['table'] = 'glpi_fqdns'; $tab[12]['field'] = 'fqdn'; $tab[12]['name'] = FQDN::getTypeName(1); $tab[12]['datatype'] = 'string'; $tab[20]['table'] = 'glpi_networknames'; $tab[20]['field'] = 'name'; $tab[20]['name'] = NetworkName::getTypeName(1); $tab[20]['massiveaction'] = false; $tab[20]['datatype'] = 'dropdown'; return $tab; }
/** * Check FQDN Validity * * @param $fqdn the FQDN to check * * @return true if the FQDN is valid **/ static function checkFQDN($fqdn) { // The FQDN must be compose of several labels separated by dots '.' $labels = explode(".", $fqdn); foreach ($labels as $label) { if ($label == "" || !FQDNLabel::checkFQDNLabel($label)) { return false; } } return true; }