function gotClearanceForTagChain($const_base) { global $rackCode, $expl_tags, $impl_tags; $ptable = array(); foreach ($rackCode as $sentence) { switch ($sentence['type']) { case 'SYNT_DEFINITION': $ptable[$sentence['term']] = $sentence['definition']; break; case 'SYNT_GRANT': if (eval_expression($sentence['condition'], array_merge($const_base, $expl_tags, $impl_tags), $ptable)) { switch ($sentence['decision']) { case 'LEX_ALLOW': return TRUE; case 'LEX_DENY': return FALSE; default: throw new RackTablesError("Condition match for unknown grant decision '{$sentence['decision']}'", RackTablesError::INTERNAL); } } break; case 'SYNT_ADJUSTMENT': if (eval_expression($sentence['condition'], array_merge($const_base, $expl_tags, $impl_tags), $ptable) and processAdjustmentSentence($sentence['modlist'], $expl_tags)) { // recalculate implicit chain only after actual change, not just on matched condition $impl_tags = getImplicitTags($expl_tags); } // recalculate break; default: throw new RackTablesError("Can't process sentence of unknown type '{$sentence['type']}'", RackTablesError::INTERNAL); } } return FALSE; }
function gotClearanceForTagChain($const_base) { global $rackCode, $expl_tags, $impl_tags; $context = array_merge($const_base, $expl_tags, $impl_tags); $context = reindexById($context, 'tag', TRUE); foreach ($rackCode as $sentence) { switch ($sentence['type']) { case 'SYNT_GRANT': if (eval_expression($sentence['condition'], $context)) { return $sentence['decision']; } break; case 'SYNT_ADJUSTMENT': if (eval_expression($sentence['condition'], $context) and processAdjustmentSentence($sentence['modlist'], $expl_tags)) { $impl_tags = getImplicitTags($expl_tags); // recalculate $context = array_merge($const_base, $expl_tags, $impl_tags); $context = reindexById($context, 'tag', TRUE); } break; default: throw new RackTablesError("Can't process sentence of unknown type '{$sentence['type']}'", RackTablesError::INTERNAL); } } return FALSE; }
/** * getResult Function * * Call Racktables API to get Objects and filter the result if required * * @param array $post * @return array Result */ function getResult($post) { $sFilter = ''; if (isset($post['objectIDs'])) { foreach ($post['objectIDs'] as $sFilterValue) { $sFilter .= '{$typeid_' . $sFilterValue . '} or '; } $sFilter = substr($sFilter, 0, -4); $sFilter = '(' . $sFilter . ')'; } $aResult = scanRealmByText('object', $sFilter); // Add tags $aTemp = array(); foreach ($aResult as $Result) { $Result['tags'] = loadEntityTags('object', $Result['id']); $Result['itags'] = getImplicitTags($Result['tags']); array_push($aTemp, $Result); } $aResult = $aTemp; // Search / Filter by name if (isset($post['name_preg']) && $post['name_preg'] != '') { $aTemp = array(); foreach ($aResult as $Result) { if (preg_match('/' . $post['name_preg'] . '/', $Result['name'])) { array_push($aTemp, $Result); } } $aResult = $aTemp; } // Search / Filter by tag if (isset($post['tag_preg']) && $post['tag_preg'] != '') { $aTemp = array(); foreach ($aResult as $Result) { if (preg_match('/' . $post['tag_preg'] . '/', $Result['asset_no'])) { array_push($aTemp, $Result); } } $aResult = $aTemp; } // Search / Filter by comment if (isset($post['comment_preg']) && $post['comment_preg'] != '') { $aTemp = array(); foreach ($aResult as $Result) { if (preg_match('/' . $post['comment_preg'] . '/', $Result['comment'])) { array_push($aTemp, $Result); } } $aResult = $aTemp; } // Tags if (isset($post['tag']) && count($post['tag']) > 0) { $aTemp = array(); $aSearchTags = array_keys($post['tag']); foreach ($aResult as $Result) { foreach ($Result['tags'] as $aTag) { if (in_array($aTag['id'], $aSearchTags)) { array_push($aTemp, $Result); } } foreach ($Result['itags'] as $aTag) { if (in_array($aTag['id'], $aSearchTags)) { array_push($aTemp, $Result); } } } $aResult = $aTemp; } // Ports - Load port data if necessary if (isset($post['Ports'])) { $aTemp = array(); foreach ($aResult as $Result) { $Result['portsLinks'] = getObjectPortsAndLinks($Result['id']); foreach ($Result['portsLinks'] as $i => $port) { $Result['portsLinks'][$i]['remote_object_name'] = 'unknown'; if (!is_null($port['remote_object_id'])) { $remote_object = spotEntity('object', intval($port['remote_object_id'])); $Result['portsLinks'][$i]['remote_object_name'] = $remote_object['name']; } } array_push($aTemp, $Result); } $aResult = $aTemp; } return $aResult; }
function spreadContext($extracell) { global $auto_tags, $expl_tags, $impl_tags, $target_given_tags, $user_given_tags; foreach ($extracell['atags'] as $taginfo) { if (!tagNameOnChain($taginfo['tag'], $auto_tags)) { $auto_tags[] = $taginfo; } } $target_given_tags = mergeTagChains($target_given_tags, $extracell['etags']); $expl_tags = mergeTagChains($user_given_tags, $target_given_tags); $impl_tags = getImplicitTags($expl_tags); }